Skip to content

Commit f91c8a8

Browse files
committed
[Dependency Scanning] Refactor string implementation to always malloc and tie lifetime to owning object.
1 parent 53e53db commit f91c8a8

File tree

13 files changed

+219
-285
lines changed

13 files changed

+219
-285
lines changed

include/swift-c/DependencyScan/DSString.h

Lines changed: 0 additions & 50 deletions
This file was deleted.

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#ifndef SWIFT_C_DEPENDENCY_SCAN_H
1919
#define SWIFT_C_DEPENDENCY_SCAN_H
2020

21-
#include "DSString.h"
2221
#include "DependencyScanMacros.h"
2322
#include <stdbool.h>
2423
#include <stddef.h>
@@ -34,6 +33,22 @@ SWIFTSCAN_BEGIN_DECLS
3433

3534
//=== Public Scanner Data Types -------------------------------------------===//
3635

36+
/**
37+
* 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.
41+
*/
42+
typedef struct {
43+
const void *data;
44+
unsigned length;
45+
} swiftscan_string_ref_t;
46+
47+
typedef struct {
48+
swiftscan_string_ref_t *strings;
49+
unsigned count;
50+
} swiftscan_string_set_t;
51+
3752
typedef enum {
3853
SWIFTSCAN_DEPENDENCY_INFO_SWIFT_TEXTUAL = 0,
3954
SWIFTSCAN_DEPENDENCY_INFO_SWIFT_BINARY = 1,
@@ -80,9 +95,15 @@ typedef struct {
8095
/// scan (command line arguments, working directory, etc.)
8196
typedef struct swiftscan_scan_invocation_s *swiftscan_scan_invocation_t;
8297

98+
//=== String Functions ----------------------------------------------------===//
99+
100+
/// Retrieve the character data associated with the given string.
101+
SWIFTSCAN_PUBLIC const char *
102+
swiftscan_get_C_string(swiftscan_string_ref_t string);
103+
83104
//=== Dependency Result Functions -----------------------------------------===//
84105

85-
SWIFTSCAN_PUBLIC swiftscan_string_t
106+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
86107
swiftscan_dependency_result_get_main_module_name(
87108
swiftscan_dependency_result_t result);
88109

@@ -92,10 +113,10 @@ swiftscan_dependency_result_get_module_set(
92113

93114
//=== Dependency Module Info Functions ------------------------------------===//
94115

95-
SWIFTSCAN_PUBLIC swiftscan_string_t
116+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
96117
swiftscan_module_info_get_module_name(swiftscan_dependency_info_t info);
97118

98-
SWIFTSCAN_PUBLIC swiftscan_string_t
119+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
99120
swiftscan_module_info_get_module_path(swiftscan_dependency_info_t info);
100121

101122
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
@@ -113,15 +134,15 @@ SWIFTSCAN_PUBLIC swiftscan_dependency_info_kind_t
113134
swiftscan_module_detail_get_kind(swiftscan_module_details_t details);
114135

115136
//=== Swift Textual Module Details query APIs -----------------------------===//
116-
SWIFTSCAN_PUBLIC swiftscan_string_t
137+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
117138
swiftscan_swift_textual_detail_get_module_interface_path(
118139
swiftscan_module_details_t details);
119140

120141
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
121142
swiftscan_swift_textual_detail_get_compiled_module_candidates(
122143
swiftscan_module_details_t details);
123144

124-
SWIFTSCAN_PUBLIC swiftscan_string_t
145+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
125146
swiftscan_swift_textual_detail_get_bridging_header_path(
126147
swiftscan_module_details_t details);
127148

@@ -141,7 +162,7 @@ SWIFTSCAN_PUBLIC swiftscan_string_set_t *
141162
swiftscan_swift_textual_detail_get_extra_pcm_args(
142163
swiftscan_module_details_t details);
143164

144-
SWIFTSCAN_PUBLIC swiftscan_string_t
165+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
145166
swiftscan_swift_textual_detail_get_context_hash(
146167
swiftscan_module_details_t details);
147168

@@ -150,49 +171,49 @@ SWIFTSCAN_PUBLIC bool swiftscan_swift_textual_detail_get_is_framework(
150171

151172
//=== Swift Binary Module Details query APIs ------------------------------===//
152173

153-
SWIFTSCAN_PUBLIC swiftscan_string_t
174+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
154175
swiftscan_swift_binary_detail_get_compiled_module_path(
155176
swiftscan_module_details_t details);
156177

157-
SWIFTSCAN_PUBLIC swiftscan_string_t
178+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
158179
swiftscan_swift_binary_detail_get_module_doc_path(
159180
swiftscan_module_details_t details);
160181

161-
SWIFTSCAN_PUBLIC swiftscan_string_t
182+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
162183
swiftscan_swift_binary_detail_get_module_source_info_path(
163184
swiftscan_module_details_t details);
164185

165186
//=== Swift Placeholder Module Details query APIs -------------------------===//
166187

167-
SWIFTSCAN_PUBLIC swiftscan_string_t
188+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
168189
swiftscan_swift_placeholder_detail_get_compiled_module_path(
169190
swiftscan_module_details_t details);
170191

171-
SWIFTSCAN_PUBLIC swiftscan_string_t
192+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
172193
swiftscan_swift_placeholder_detail_get_module_doc_path(
173194
swiftscan_module_details_t details);
174195

175-
SWIFTSCAN_PUBLIC swiftscan_string_t
196+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
176197
swiftscan_swift_placeholder_detail_get_module_source_info_path(
177198
swiftscan_module_details_t details);
178199

179200
//=== Clang Module Details query APIs -------------------------------------===//
180201

181-
SWIFTSCAN_PUBLIC swiftscan_string_t
202+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
182203
swiftscan_clang_detail_get_module_map_path(swiftscan_module_details_t details);
183204

184-
SWIFTSCAN_PUBLIC swiftscan_string_t
205+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
185206
swiftscan_clang_detail_get_context_hash(swiftscan_module_details_t details);
186207

187208
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
188209
swiftscan_clang_detail_get_command_line(swiftscan_module_details_t details);
189210

190211
//=== Batch Scan Entry Functions ------------------------------------------===//
191212

192-
SWIFTSCAN_PUBLIC swiftscan_string_t
213+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
193214
swiftscan_batch_scan_entry_get_module_name(swiftscan_batch_scan_entry_t entry);
194215

195-
SWIFTSCAN_PUBLIC swiftscan_string_t
216+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
196217
swiftscan_batch_scan_entry_get_arguments(swiftscan_batch_scan_entry_t entry);
197218

198219
SWIFTSCAN_PUBLIC bool
@@ -209,13 +230,13 @@ SWIFTSCAN_PUBLIC swiftscan_scan_invocation_t swiftscan_scan_invocation_create();
209230

210231
SWIFTSCAN_PUBLIC void swiftscan_scan_invocation_set_working_directory(
211232
swiftscan_scan_invocation_t invocation,
212-
swiftscan_string_t working_directory);
233+
swiftscan_string_ref_t working_directory);
213234

214235
SWIFTSCAN_PUBLIC void
215236
swiftscan_scan_invocation_set_argv(swiftscan_scan_invocation_t invocation,
216237
swiftscan_string_set_t *argv);
217238

218-
SWIFTSCAN_PUBLIC swiftscan_string_t
239+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
219240
swiftscan_scan_invocation_get_working_directory(
220241
swiftscan_scan_invocation_t invocation);
221242

include/swift/DependencyScan/DSStringImpl.h

Lines changed: 0 additions & 44 deletions
This file was deleted.

include/swift/DependencyScan/DependencyScanImpl.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ namespace swift {
2222
namespace dependencies {
2323
class DependencyScanningTool;
2424
}
25-
}
25+
} // namespace swift
2626

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

3131
/// The complete list of modules discovered
3232
swiftscan_dependency_set_t *module_set;
@@ -41,10 +41,10 @@ struct swiftscan_dependency_info_s {
4141
/// "swiftBinary"
4242
/// "swiftPlaceholder"
4343
/// "clang""
44-
swiftscan_string_t module_name;
44+
swiftscan_string_ref_t module_name;
4545

4646
/// The path for the module.
47-
swiftscan_string_t module_path;
47+
swiftscan_string_ref_t module_path;
4848

4949
/// The source files used to build this module.
5050
swiftscan_string_set_t *source_files;
@@ -64,13 +64,13 @@ struct swiftscan_dependency_info_s {
6464
/// header.
6565
typedef struct {
6666
/// The module interface from which this module was built, if any.
67-
swiftscan_string_t module_interface_path;
67+
swiftscan_string_ref_t module_interface_path;
6868

6969
/// The paths of potentially ready-to-use compiled modules for the interface.
7070
swiftscan_string_set_t *compiled_module_candidates;
7171

7272
/// The bridging header, if any.
73-
swiftscan_string_t bridging_header_path;
73+
swiftscan_string_ref_t bridging_header_path;
7474

7575
/// The source files referenced by the bridging header.
7676
swiftscan_string_set_t *bridging_source_files;
@@ -87,7 +87,7 @@ typedef struct {
8787
swiftscan_string_set_t *extra_pcm_args;
8888

8989
/// The hash value that will be used for the generated module
90-
swiftscan_string_t context_hash;
90+
swiftscan_string_ref_t context_hash;
9191

9292
/// A flag to indicate whether or not this module is a framework.
9393
bool is_framework;
@@ -96,35 +96,35 @@ typedef struct {
9696
/// Swift modules with only a binary module file.
9797
typedef struct {
9898
/// The path to the pre-compiled binary module
99-
swiftscan_string_t compiled_module_path;
99+
swiftscan_string_ref_t compiled_module_path;
100100

101101
/// The path to the .swiftModuleDoc file.
102-
swiftscan_string_t module_doc_path;
102+
swiftscan_string_ref_t module_doc_path;
103103

104104
/// The path to the .swiftSourceInfo file.
105-
swiftscan_string_t module_source_info_path;
105+
swiftscan_string_ref_t module_source_info_path;
106106
} swiftscan_swift_binary_details_t;
107107

108108
/// Swift placeholder modules carry additional details that specify their
109109
/// module doc path and source info paths.
110110
typedef struct {
111111
/// The path to the pre-compiled binary module
112-
swiftscan_string_t compiled_module_path;
112+
swiftscan_string_ref_t compiled_module_path;
113113

114114
/// The path to the .swiftModuleDoc file.
115-
swiftscan_string_t module_doc_path;
115+
swiftscan_string_ref_t module_doc_path;
116116

117117
/// The path to the .swiftSourceInfo file.
118-
swiftscan_string_t module_source_info_path;
118+
swiftscan_string_ref_t module_source_info_path;
119119
} swiftscan_swift_placeholder_details_t;
120120

121121
/// Clang modules are built from a module map file.
122122
typedef struct {
123123
/// The path to the module map used to build this module.
124-
swiftscan_string_t module_map_path;
124+
swiftscan_string_ref_t module_map_path;
125125

126126
/// clang-generated context hash
127-
swiftscan_string_t context_hash;
127+
swiftscan_string_ref_t context_hash;
128128

129129
/// Options to the compile command required to build this clang modulemap
130130
swiftscan_string_set_t *command_line;
@@ -138,11 +138,11 @@ struct swiftscan_module_details_s {
138138
swiftscan_swift_placeholder_details_t swift_placeholder_details;
139139
swiftscan_clang_details_t clang_details;
140140
};
141-
} ;
141+
};
142142

143143
struct swiftscan_batch_scan_entry_s {
144-
swiftscan_string_t module_name;
145-
swiftscan_string_t arguments;
144+
swiftscan_string_ref_t module_name;
145+
swiftscan_string_ref_t arguments;
146146
bool is_swift;
147147
};
148148

@@ -152,7 +152,7 @@ struct swiftscan_prescan_result_s {
152152
};
153153

154154
struct swiftscan_scan_invocation_s {
155-
swiftscan_string_t working_directory;
155+
swiftscan_string_ref_t working_directory;
156156
swiftscan_string_set_t *argv;
157157
};
158158

include/swift/DependencyScan/DependencyScanningTool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
#include "swift-c/DependencyScan/DependencyScan.h"
1717
#include "swift/AST/ModuleDependencies.h"
18-
#include "swift/Frontend/PrintingDiagnosticConsumer.h"
1918
#include "swift/DependencyScan/ScanDependencies.h"
19+
#include "swift/Frontend/PrintingDiagnosticConsumer.h"
2020
#include "llvm/ADT/StringSet.h"
2121
#include "llvm/Support/Error.h"
2222
#include "llvm/Support/StringSaver.h"

0 commit comments

Comments
 (0)