Skip to content

Commit 41a09a4

Browse files
committed
[Dependency Scanning] Establish object ownership convention by using a Foundation-style ownership signals naming scheme across the API surface.
Foundation-style ownership signals documentation: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-CJBEJBHH
1 parent d1cc689 commit 41a09a4

File tree

11 files changed

+281
-195
lines changed

11 files changed

+281
-195
lines changed

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 70 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ SWIFTSCAN_BEGIN_DECLS
3535

3636
/**
3737
* A character string used to pass around dependency scan result metadata.
38-
* Lifetime of the string is strictly tied to the object whose field it represents.
39-
* When the owning object is released, string memory is freed. Use \c
40-
* swiftscan_get_C_string() to retrieve the string data.
38+
* Lifetime of the string is strictly tied to the object whose field it
39+
* represents. When the owning object is released, string memory is freed. Use
40+
* \c swiftscan_get_C_string() to retrieve the string data.
4141
*/
4242
typedef struct {
4343
const void *data;
@@ -63,10 +63,10 @@ typedef struct swiftscan_module_details_s *swiftscan_module_details_t;
6363
typedef struct swiftscan_dependency_info_s *swiftscan_dependency_info_t;
6464

6565
/// Opaque container to an overall result of a dependency scan.
66-
typedef struct swiftscan_dependency_result_s *swiftscan_dependency_result_t;
66+
typedef struct swiftscan_dependency_graph_s *swiftscan_dependency_graph_t;
6767

6868
/// Opaque container to contain the result of a dependency prescan.
69-
typedef struct swiftscan_prescan_result_s *swiftscan_prescan_result_t;
69+
typedef struct swiftscan_import_set_s *swiftscan_import_set_t;
7070

7171
/// Full Dependency Graph (Result)
7272
typedef struct {
@@ -86,7 +86,7 @@ typedef struct {
8686

8787
typedef struct {
8888
int count;
89-
swiftscan_dependency_result_t *results;
89+
swiftscan_dependency_graph_t *results;
9090
} swiftscan_batch_scan_result_t;
9191

9292
//=== Scanner Invocation Specification ------------------------------------===//
@@ -104,12 +104,12 @@ swiftscan_get_C_string(swiftscan_string_ref_t string);
104104
//=== Dependency Result Functions -----------------------------------------===//
105105

106106
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
107-
swiftscan_dependency_result_get_main_module_name(
108-
swiftscan_dependency_result_t result);
107+
swiftscan_dependency_graph_get_main_module_name(
108+
swiftscan_dependency_graph_t result);
109109

110110
SWIFTSCAN_PUBLIC swiftscan_dependency_set_t *
111-
swiftscan_dependency_result_get_module_set(
112-
swiftscan_dependency_result_t result);
111+
swiftscan_dependency_graph_get_dependencies(
112+
swiftscan_dependency_graph_t result);
113113

114114
//=== Dependency Module Info Functions ------------------------------------===//
115115

@@ -208,8 +208,39 @@ swiftscan_clang_detail_get_context_hash(swiftscan_module_details_t details);
208208
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
209209
swiftscan_clang_detail_get_command_line(swiftscan_module_details_t details);
210210

211+
//=== Batch Scan Input Functions ------------------------------------------===//
212+
213+
/// Create an \c swiftscan_batch_scan_input_t instance.
214+
/// The returned \c swiftscan_batch_scan_input_t is owned by the caller and must be disposed
215+
/// of using \c swiftscan_batch_scan_input_dispose .
216+
SWIFTSCAN_PUBLIC swiftscan_batch_scan_input_t *
217+
swiftscan_batch_scan_input_create();
218+
219+
SWIFTSCAN_PUBLIC void
220+
swiftscan_batch_scan_input_set_modules(swiftscan_batch_scan_input_t *input,
221+
int count,
222+
swiftscan_batch_scan_entry_t *modules);
223+
211224
//=== Batch Scan Entry Functions ------------------------------------------===//
212225

226+
/// Create an \c swiftscan_batch_scan_entry_t instance.
227+
/// The returned \c swiftscan_batch_scan_entry_t is owned by the caller and must be disposed
228+
/// of using \c swiftscan_batch_scan_entry_dispose .
229+
SWIFTSCAN_PUBLIC swiftscan_batch_scan_entry_t
230+
swiftscan_batch_scan_entry_create();
231+
232+
SWIFTSCAN_PUBLIC void
233+
swiftscan_batch_scan_entry_set_module_name(swiftscan_batch_scan_entry_t entry,
234+
const char *name);
235+
236+
SWIFTSCAN_PUBLIC void
237+
swiftscan_batch_scan_entry_set_arguments(swiftscan_batch_scan_entry_t entry,
238+
const char *arguments);
239+
240+
SWIFTSCAN_PUBLIC void
241+
swiftscan_batch_scan_entry_set_is_swift(swiftscan_batch_scan_entry_t entry,
242+
bool is_swift);
243+
213244
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
214245
swiftscan_batch_scan_entry_get_module_name(swiftscan_batch_scan_entry_t entry);
215246

@@ -222,19 +253,21 @@ swiftscan_batch_scan_entry_get_is_swift(swiftscan_batch_scan_entry_t entry);
222253
//=== Prescan Result Functions --------------------------------------------===//
223254

224255
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
225-
swiftscan_prescan_result_get_import_set(swiftscan_prescan_result_t result);
256+
swiftscan_import_set_get_imports(swiftscan_import_set_t result);
226257

227258
//=== Scanner Invocation Functions ----------------------------------------===//
228259

260+
/// Create an \c swiftscan_scan_invocation_t instance.
261+
/// The returned \c swiftscan_scan_invocation_t is owned by the caller and must be disposed
262+
/// of using \c swiftscan_scan_invocation_dispose .
229263
SWIFTSCAN_PUBLIC swiftscan_scan_invocation_t swiftscan_scan_invocation_create();
230264

231265
SWIFTSCAN_PUBLIC void swiftscan_scan_invocation_set_working_directory(
232-
swiftscan_scan_invocation_t invocation,
233-
swiftscan_string_ref_t working_directory);
266+
swiftscan_scan_invocation_t invocation, const char *working_directory);
234267

235268
SWIFTSCAN_PUBLIC void
236269
swiftscan_scan_invocation_set_argv(swiftscan_scan_invocation_t invocation,
237-
swiftscan_string_set_t *argv);
270+
int argc, const char **argv);
238271

239272
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
240273
swiftscan_scan_invocation_get_working_directory(
@@ -249,19 +282,10 @@ swiftscan_scan_invocation_get_argv(swiftscan_scan_invocation_t invocation);
249282
//=== Cleanup Functions ---------------------------------------------------===//
250283

251284
SWIFTSCAN_PUBLIC void
252-
swiftscan_dependency_info_details_dispose(swiftscan_module_details_t details);
253-
254-
SWIFTSCAN_PUBLIC void
255-
swiftscan_dependency_info_dispose(swiftscan_dependency_info_t info);
256-
257-
SWIFTSCAN_PUBLIC void
258-
swiftscan_dependency_set_dispose(swiftscan_dependency_set_t *set);
285+
swiftscan_dependency_graph_dispose(swiftscan_dependency_graph_t result);
259286

260287
SWIFTSCAN_PUBLIC void
261-
swiftscan_dependency_result_dispose(swiftscan_dependency_result_t result);
262-
263-
SWIFTSCAN_PUBLIC void
264-
swiftscan_prescan_result_dispose(swiftscan_prescan_result_t result);
288+
swiftscan_import_set_dispose(swiftscan_import_set_t result);
265289

266290
SWIFTSCAN_PUBLIC void
267291
swiftscan_batch_scan_entry_dispose(swiftscan_batch_scan_entry_t entry);
@@ -281,19 +305,33 @@ swiftscan_scan_invocation_dispose(swiftscan_scan_invocation_t invocation);
281305
/// scanning.
282306
typedef void *swiftscan_scanner_t;
283307

308+
/// Create an \c swiftscan_scanner_t instance.
309+
/// The returned \c swiftscan_scanner_t is owned by the caller and must be disposed
310+
/// of using \c swiftscan_scanner_dispose .
284311
SWIFTSCAN_PUBLIC swiftscan_scanner_t swiftscan_scanner_create(void);
285-
286312
SWIFTSCAN_PUBLIC void swiftscan_scanner_dispose(swiftscan_scanner_t);
287313

288-
SWIFTSCAN_PUBLIC swiftscan_dependency_result_t swiftscan_scan_dependencies(
314+
/// Invoke a dependency scan using arguments specified in the \c
315+
/// swiftscan_scan_invocation_t argument. The returned \c
316+
/// swiftscan_dependency_graph_t is owned by the caller and must be disposed of
317+
/// using \c swiftscan_dependency_graph_dispose .
318+
SWIFTSCAN_PUBLIC swiftscan_dependency_graph_t swiftscan_dependency_graph_create(
289319
swiftscan_scanner_t scanner, swiftscan_scan_invocation_t invocation);
290320

321+
/// Invoke the scan for an input batch of modules specified in the
322+
/// \c swiftscan_batch_scan_input_t argument. The returned
323+
/// \c swiftscan_batch_scan_result_t is owned by the caller and must be disposed
324+
/// of using \c swiftscan_batch_scan_result_dispose .
291325
SWIFTSCAN_PUBLIC swiftscan_batch_scan_result_t *
292-
swiftscan_batch_scan_dependencies(swiftscan_scanner_t scanner,
293-
swiftscan_batch_scan_input_t *batch_input,
294-
swiftscan_scan_invocation_t invocation);
295-
296-
SWIFTSCAN_PUBLIC swiftscan_prescan_result_t swiftscan_prescan_dependencies(
326+
swiftscan_batch_scan_result_create(swiftscan_scanner_t scanner,
327+
swiftscan_batch_scan_input_t *batch_input,
328+
swiftscan_scan_invocation_t invocation);
329+
330+
/// Invoke the import prescan using arguments specified in the \c
331+
/// swiftscan_scan_invocation_t argument. The returned \c swiftscan_import_set_t
332+
/// is owned by the caller and must be disposed of using \c
333+
/// swiftscan_import_set_dispose .
334+
SWIFTSCAN_PUBLIC swiftscan_import_set_t swiftscan_import_set_create(
297335
swiftscan_scanner_t scanner, swiftscan_scan_invocation_t invocation);
298336

299337
SWIFTSCAN_END_DECLS

include/swift/DependencyScan/DependencyScanImpl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ class DependencyScanningTool;
2424
}
2525
} // namespace swift
2626

27-
struct swiftscan_dependency_result_s {
27+
struct swiftscan_dependency_graph_s {
2828
/// The name of the main module for this dependency graph (root node)
2929
swiftscan_string_ref_t main_module_name;
3030

3131
/// The complete list of modules discovered
32-
swiftscan_dependency_set_t *module_set;
32+
swiftscan_dependency_set_t *dependencies;
3333
};
3434

3535
struct swiftscan_dependency_info_s {
@@ -146,9 +146,9 @@ struct swiftscan_batch_scan_entry_s {
146146
bool is_swift;
147147
};
148148

149-
struct swiftscan_prescan_result_s {
149+
struct swiftscan_import_set_s {
150150
/// The complete list of imports discovered
151-
swiftscan_string_set_t *import_set;
151+
swiftscan_string_set_t *imports;
152152
};
153153

154154
struct swiftscan_scan_invocation_s {

include/swift/DependencyScan/DependencyScanningTool.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,23 @@ class DependencyScanningTool {
3636
///
3737
/// \returns a \c StringError with the diagnostic output if errors
3838
/// occurred, \c swiftscan_dependency_result_t otherwise.
39-
llvm::ErrorOr<swiftscan_dependency_result_t>
39+
llvm::ErrorOr<swiftscan_dependency_graph_t>
4040
getDependencies(ArrayRef<const char *> Command,
4141
const llvm::StringSet<> &PlaceholderModules);
4242

4343
/// Collect the set of imports for the input module
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_import_set_t>
4848
getImports(ArrayRef<const char *> Command);
4949

5050
/// Collect the full module depenedency graph for the input collection of
5151
/// module names (batch inputs) and output them to the
5252
/// BatchScanInput-specified output locations.
5353
///
5454
/// \returns a \c std::error_code if errors occured during scan.
55-
std::vector<llvm::ErrorOr<swiftscan_dependency_result_t>>
55+
std::vector<llvm::ErrorOr<swiftscan_dependency_graph_t>>
5656
getDependencies(ArrayRef<const char *> Command,
5757
const std::vector<BatchScanInput> &BatchInput,
5858
const llvm::StringSet<> &PlaceholderModules);

include/swift/DependencyScan/ScanDependencies.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,22 @@ bool batchPrescanDependencies(CompilerInstance &instance,
5454

5555
// MARK: Dependency scanning execution
5656
/// Scans the dependencies of the main module of \c instance.
57-
llvm::ErrorOr<swiftscan_dependency_result_t>
57+
llvm::ErrorOr<swiftscan_dependency_graph_t>
5858
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_import_set_t>
6363
performModulePrescan(CompilerInstance &instance);
6464

6565
/// Batch scan the dependencies for modules specified in \c batchInputFile.
66-
std::vector<llvm::ErrorOr<swiftscan_dependency_result_t>>
66+
std::vector<llvm::ErrorOr<swiftscan_dependency_graph_t>>
6767
performBatchModuleScan(CompilerInstance &instance,
6868
ModuleDependenciesCache &cache, llvm::StringSaver &saver,
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_import_set_t>>
7373
performBatchModulePrescan(CompilerInstance &instance,
7474
ModuleDependenciesCache &cache,
7575
llvm::StringSaver &saver,

include/swift/DependencyScan/StringUtils.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@ namespace dependencies {
2323
/// Create null string
2424
swiftscan_string_ref_t create_null();
2525

26-
/// Create a swiftscan_string_ref_t object from a nul-terminated C string. New
27-
/// swiftscan_string_ref_t will contain a copy of \p string.
28-
swiftscan_string_ref_t create_dup(const char *string);
26+
/// Create a \c swiftscan_string_ref_t object from a nul-terminated C string. New
27+
/// \c swiftscan_string_ref_t will contain a copy of \p string.
28+
swiftscan_string_ref_t create_clone(const char *string);
2929

30-
/// Create an array of swiftscan_string_ref_t objects from a vector of C++ strings using the
31-
/// create_dup routine.
30+
/// Create an array of \c swiftscan_string_ref_t objects from a vector of C++ strings using the
31+
/// create_clone routine.
3232
swiftscan_string_set_t *create_set(const std::vector<std::string> &strings);
3333

34+
/// Create an array of swiftscan_string_ref_t objects from an array of C strings using the
35+
/// create_clone routine.
36+
swiftscan_string_set_t *create_set(int count, const char **strings);
37+
3438
/// Retrieve the character data associated with the given string.
3539
const char *get_C_string(swiftscan_string_ref_t string);
3640
}

lib/DependencyScan/DependencyScanningTool.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ DependencyScanningTool::DependencyScanningTool()
2828
: SharedCache(std::make_unique<ModuleDependenciesCache>()), PDC(), Alloc(),
2929
Saver(Alloc) {}
3030

31-
llvm::ErrorOr<swiftscan_dependency_result_t>
31+
llvm::ErrorOr<swiftscan_dependency_graph_t>
3232
DependencyScanningTool::getDependencies(
3333
ArrayRef<const char *> Command,
3434
const llvm::StringSet<> &PlaceholderModules) {
@@ -47,7 +47,7 @@ DependencyScanningTool::getDependencies(
4747
return Dependencies;
4848
}
4949

50-
llvm::ErrorOr<swiftscan_prescan_result_t>
50+
llvm::ErrorOr<swiftscan_import_set_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);
@@ -64,15 +64,15 @@ DependencyScanningTool::getImports(ArrayRef<const char *> Command) {
6464
return Dependencies;
6565
}
6666

67-
std::vector<llvm::ErrorOr<swiftscan_dependency_result_t>>
67+
std::vector<llvm::ErrorOr<swiftscan_dependency_graph_t>>
6868
DependencyScanningTool::getDependencies(
6969
ArrayRef<const char *> Command,
7070
const std::vector<BatchScanInput> &BatchInput,
7171
const llvm::StringSet<> &PlaceholderModules) {
7272
// The primary instance used to scan Swift modules
7373
auto InstanceOrErr = initCompilerInstanceForScan(Command);
7474
if (std::error_code EC = InstanceOrErr.getError())
75-
return std::vector<llvm::ErrorOr<swiftscan_dependency_result_t>>(
75+
return std::vector<llvm::ErrorOr<swiftscan_dependency_graph_t>>(
7676
BatchInput.size(), std::make_error_code(std::errc::invalid_argument));
7777
auto Instance = std::move(*InstanceOrErr);
7878

0 commit comments

Comments
 (0)