Skip to content

Commit cff741b

Browse files
committed
[Dependency Scanning] Make the prescan dependency scan result (import set) an opaque structure
1 parent c6705ad commit cff741b

File tree

7 files changed

+53
-22
lines changed

7 files changed

+53
-22
lines changed

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,15 @@ typedef void *swiftscan_dependency_info_t;
5050
/// Opaque container to an overall result of a dependency scan.
5151
typedef void *swiftscan_dependency_result_t;
5252

53+
/// Opaque container to contain the result of a dependency prescan.
54+
typedef void *swiftscan_prescan_result_t;
55+
5356
/// Full Dependency Graph (Result)
5457
typedef struct {
5558
int count;
5659
swiftscan_dependency_info_t *modules;
5760
} swiftscan_dependency_set_t;
5861

59-
typedef struct {
60-
/// The complete list of imports discovered
61-
swiftscan_string_set_t *import_set;
62-
} swiftscan_prescan_result_t;
63-
6462
//=== Batch Scan Input Specification --------------------------------------===//
6563

6664
/// Opaque container to a container of batch scan entry information.
@@ -194,6 +192,11 @@ swiftscan_batch_scan_entry_get_arguments(swiftscan_batch_scan_entry_t entry);
194192
SWIFTSCAN_PUBLIC bool
195193
swiftscan_batch_scan_entry_get_is_swift(swiftscan_batch_scan_entry_t entry);
196194

195+
//=== Prescan Result Functions --------------------------------------------===//
196+
197+
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
198+
swiftscan_prescan_result_get_import_set(swiftscan_prescan_result_t result);
199+
197200
//=== Cleanup Functions ---------------------------------------------------===//
198201

199202
SWIFTSCAN_PUBLIC void
@@ -209,7 +212,7 @@ SWIFTSCAN_PUBLIC void
209212
swiftscan_dependency_result_dispose(swiftscan_dependency_result_t result);
210213

211214
SWIFTSCAN_PUBLIC void
212-
swiftscan_prescan_result_dispose(swiftscan_prescan_result_t *result);
215+
swiftscan_prescan_result_dispose(swiftscan_prescan_result_t result);
213216

214217
SWIFTSCAN_PUBLIC void
215218
swiftscan_batch_scan_entry_dispose(swiftscan_batch_scan_entry_t entry);
@@ -241,7 +244,7 @@ swiftscan_batch_scan_dependencies(swiftscan_scanner_t *scanner,
241244
swiftscan_batch_scan_input_t *batch_input,
242245
int argc, const char *const *argv);
243246

244-
SWIFTSCAN_PUBLIC swiftscan_prescan_result_t *
247+
SWIFTSCAN_PUBLIC swiftscan_prescan_result_t
245248
swiftscan_prescan_dependencies(swiftscan_scanner_t *scanner,
246249
const char *working_directory, int argc,
247250
const char *const *argv);

include/swift/DependencyScan/DependencyScanImpl.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ typedef struct {
141141
bool is_swift;
142142
} swiftscan_impl_batch_scan_entry_t;
143143

144+
typedef struct {
145+
/// The complete list of imports discovered
146+
swiftscan_string_set_t *import_set;
147+
} swiftscan_impl_prescan_result_t;
148+
144149
inline swift::dependencies::DependencyScanningTool *
145150
unwrap_scanner(swiftscan_scanner_t P) {
146151
return reinterpret_cast<swift::dependencies::DependencyScanningTool *>(P);
@@ -185,6 +190,17 @@ wrap_result(const swiftscan_impl_dependency_result_t *P) {
185190
const_cast<swiftscan_impl_dependency_result_t *>(P));
186191
}
187192

193+
inline swiftscan_impl_prescan_result_t *
194+
unwrap_prescan_result(swiftscan_prescan_result_t P) {
195+
return reinterpret_cast<swiftscan_impl_prescan_result_t *>(P);
196+
}
197+
198+
inline swiftscan_prescan_result_t
199+
wrap_prescan_result(const swiftscan_impl_prescan_result_t *P) {
200+
return reinterpret_cast<swiftscan_prescan_result_t>(
201+
const_cast<swiftscan_impl_prescan_result_t *>(P));
202+
}
203+
188204
inline swiftscan_impl_batch_scan_entry_t *
189205
unwrap_batch_entry(swiftscan_batch_scan_entry_t P) {
190206
return reinterpret_cast<swiftscan_impl_batch_scan_entry_t *>(P);

include/swift/DependencyScan/DependencyScanningTool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class DependencyScanningTool {
4444
///
4545
/// \returns a \c StringError with the diagnostic output if errors
4646
/// occurred, \c swiftscan_prescan_result_t otherwise.
47-
llvm::ErrorOr<swiftscan_prescan_result_t*>
47+
llvm::ErrorOr<swiftscan_prescan_result_t>
4848
getImports(ArrayRef<const char *> Command);
4949

5050
/// Collect the full module depenedency graph for the input collection of

include/swift/DependencyScan/ScanDependencies.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ performModuleScan(CompilerInstance &instance,
5959
ModuleDependenciesCache &cache);
6060

6161
/// Scans the main module of \c instance for all direct module imports
62-
llvm::ErrorOr<swiftscan_prescan_result_t*>
62+
llvm::ErrorOr<swiftscan_prescan_result_t>
6363
performModulePrescan(CompilerInstance &instance);
6464

6565
/// Batch scan the dependencies for modules specified in \c batchInputFile.
@@ -69,7 +69,7 @@ performBatchModuleScan(CompilerInstance &instance,
6969
const std::vector<BatchScanInput> &BatchInput);
7070

7171
/// Batch prescan the imports of modules specified in \c batchInputFile.
72-
std::vector<llvm::ErrorOr<swiftscan_prescan_result_t*>>
72+
std::vector<llvm::ErrorOr<swiftscan_prescan_result_t>>
7373
performBatchModulePrescan(CompilerInstance &instance,
7474
ModuleDependenciesCache &cache,
7575
llvm::StringSaver &saver,

lib/DependencyScan/DependencyScanImpl.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ swiftscan_batch_scan_dependencies(swiftscan_scanner_t *scanner,
8181
return Result;
8282
}
8383

84-
swiftscan_prescan_result_t *
84+
swiftscan_prescan_result_t
8585
swiftscan_prescan_dependencies(swiftscan_scanner_t *scanner,
8686
const char *working_directory, int argc,
8787
const char *const *argv) {
@@ -254,6 +254,13 @@ bool swiftscan_batch_scan_entry_get_is_swift(
254254
return unwrap_batch_entry(entry)->is_swift;
255255
}
256256

257+
//=== Prescan Result Functions --------------------------------------------===//
258+
259+
swiftscan_string_set_t *
260+
swiftscan_prescan_result_get_import_set(swiftscan_prescan_result_t result) {
261+
return unwrap_prescan_result(result)->import_set;
262+
}
263+
257264
//=== Cleanup Functions ---------------------------------------------------===//
258265

259266
void swiftscan_dependency_info_details_dispose(
@@ -327,9 +334,10 @@ void swiftscan_dependency_result_dispose(swiftscan_dependency_result_t result) {
327334
delete result_impl;
328335
}
329336

330-
void swiftscan_prescan_result_dispose(swiftscan_prescan_result_t *result) {
331-
swiftscan_string_set_dispose(result->import_set);
332-
delete result;
337+
void swiftscan_prescan_result_dispose(swiftscan_prescan_result_t result) {
338+
swiftscan_impl_prescan_result_t *result_impl = unwrap_prescan_result(result);
339+
swiftscan_string_set_dispose(result_impl->import_set);
340+
delete result_impl;
333341
}
334342

335343
void swiftscan_batch_scan_entry_dispose(swiftscan_batch_scan_entry_t entry) {
@@ -343,11 +351,15 @@ void swiftscan_batch_scan_input_dispose(swiftscan_batch_scan_input_t *input) {
343351
for (int i = 0; i < input->count; ++i) {
344352
swiftscan_batch_scan_entry_dispose(&input->modules[i]);
345353
}
354+
delete[] input->modules;
355+
delete input;
346356
}
347357

348358
void swiftscan_batch_scan_result_dispose(
349359
swiftscan_batch_scan_result_t *result) {
350360
for (int i = 0; i < result->count; ++i) {
351361
swiftscan_dependency_result_dispose(result->results[i]);
352362
}
363+
delete[] result->results;
364+
delete result;
353365
}

lib/DependencyScan/DependencyScanningTool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ DependencyScanningTool::getDependencies(
4747
return Dependencies;
4848
}
4949

50-
llvm::ErrorOr<swiftscan_prescan_result_t *>
50+
llvm::ErrorOr<swiftscan_prescan_result_t>
5151
DependencyScanningTool::getImports(ArrayRef<const char *> Command) {
5252
// The primary instance used to scan the query Swift source-code
5353
auto InstanceOrErr = initCompilerInstanceForScan(Command);

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ getAsClangDependencyModule(swiftscan_module_details_t details) {
479479
}
480480

481481
static void writePrescanJSON(llvm::raw_ostream &out,
482-
const swiftscan_prescan_result_t *importSet) {
482+
const swiftscan_prescan_result_t importSet) {
483483
// Write out a JSON containing all main module imports.
484484
out << "{\n";
485485
SWIFT_DEFER { out << "}\n"; };
@@ -1275,13 +1275,13 @@ swift::dependencies::performModuleScan(CompilerInstance &instance,
12751275
return dependencyGraph;
12761276
}
12771277

1278-
llvm::ErrorOr<swiftscan_prescan_result_t *>
1278+
llvm::ErrorOr<swiftscan_prescan_result_t>
12791279
swift::dependencies::performModulePrescan(CompilerInstance &instance) {
12801280
// Execute import prescan, and write JSON output to the output stream
12811281
auto mainDependencies = identifyMainModuleDependencies(instance);
1282-
swiftscan_prescan_result_t *importSet = new swiftscan_prescan_result_t;
1282+
auto *importSet = new swiftscan_impl_prescan_result_t;
12831283
importSet->import_set = create_set(mainDependencies.getModuleDependencies());
1284-
return importSet;
1284+
return wrap_prescan_result(importSet);
12851285
}
12861286

12871287
std::vector<llvm::ErrorOr<swiftscan_dependency_result_t>>
@@ -1353,11 +1353,11 @@ swift::dependencies::performBatchModuleScan(
13531353
return batchScanResult;
13541354
}
13551355

1356-
std::vector<llvm::ErrorOr<swiftscan_prescan_result_t *>>
1356+
std::vector<llvm::ErrorOr<swiftscan_prescan_result_t>>
13571357
swift::dependencies::performBatchModulePrescan(
13581358
CompilerInstance &instance, ModuleDependenciesCache &cache,
13591359
llvm::StringSaver &saver, const std::vector<BatchScanInput> &batchInput) {
1360-
std::vector<llvm::ErrorOr<swiftscan_prescan_result_t *>> batchPrescanResult;
1360+
std::vector<llvm::ErrorOr<swiftscan_prescan_result_t>> batchPrescanResult;
13611361

13621362
// Perform a full dependency scan for each batch entry module
13631363
forEachBatchEntry(
@@ -1400,7 +1400,7 @@ swift::dependencies::performBatchModulePrescan(
14001400
return;
14011401
}
14021402

1403-
swiftscan_prescan_result_t *importSet = new swiftscan_prescan_result_t;
1403+
auto *importSet = new swiftscan_impl_prescan_result_t;
14041404
importSet->import_set = create_set(rootDeps->getModuleDependencies());
14051405
batchPrescanResult.push_back(importSet);
14061406
});

0 commit comments

Comments
 (0)