@@ -68,16 +68,16 @@ llvm::ErrorOr<swiftscan_string_ref_t> getTargetInfo(ArrayRef<const char *> Comma
68
68
return c_string_utils::create_clone (ResultStr.c_str ());
69
69
}
70
70
71
- void DependencyScannerDiagnosticCollectingConsumer ::handleDiagnostic (SourceManager &SM,
71
+ void DependencyScanDiagnosticCollector ::handleDiagnostic (SourceManager &SM,
72
72
const DiagnosticInfo &Info) {
73
73
addDiagnostic (SM, Info);
74
74
for (auto ChildInfo : Info.ChildDiagnosticInfo ) {
75
75
addDiagnostic (SM, *ChildInfo);
76
76
}
77
77
}
78
78
79
- void DependencyScannerDiagnosticCollectingConsumer ::addDiagnostic (SourceManager &SM, const DiagnosticInfo &Info) {
80
- llvm::sys::SmartScopedLock< true > Lock (ScanningDiagnosticConsumerStateLock);
79
+ void DependencyScanDiagnosticCollector ::addDiagnostic (
80
+ SourceManager &SM, const DiagnosticInfo &Info) {
81
81
// Determine what kind of diagnostic we're emitting.
82
82
llvm::SourceMgr::DiagKind SMKind;
83
83
switch (Info.Kind ) {
@@ -115,6 +115,12 @@ void DependencyScannerDiagnosticCollectingConsumer::addDiagnostic(SourceManager
115
115
Diagnostics.push_back (ScannerDiagnosticInfo{Msg.getMessage ().str (), SMKind});
116
116
}
117
117
118
+ void LockingDependencyScanDiagnosticCollector::addDiagnostic (
119
+ SourceManager &SM, const DiagnosticInfo &Info) {
120
+ llvm::sys::SmartScopedLock<true > Lock (ScanningDiagnosticConsumerStateLock);
121
+ DependencyScanDiagnosticCollector::addDiagnostic (SM, Info);
122
+ }
123
+
118
124
DependencyScanningTool::DependencyScanningTool ()
119
125
: ScanningService(std::make_unique<SwiftDependencyScanningService>()),
120
126
VersionedPCMInstanceCacheCache (
@@ -126,18 +132,20 @@ DependencyScanningTool::getDependencies(
126
132
ArrayRef<const char *> Command,
127
133
const llvm::StringSet<> &PlaceholderModules) {
128
134
// The primary instance used to scan the query Swift source-code
129
- auto InstanceOrErr = initScannerForAction (Command);
130
- if (std::error_code EC = InstanceOrErr .getError ())
135
+ auto QueryContextOrErr = initScannerForAction (Command);
136
+ if (std::error_code EC = QueryContextOrErr .getError ())
131
137
return EC;
132
- auto Instance = std::move (*InstanceOrErr );
138
+ auto QueryContext = std::move (*QueryContextOrErr );
133
139
134
140
// Local scan cache instance, wrapping the shared global cache.
135
141
ModuleDependenciesCache cache (
136
- *ScanningService, Instance ->getMainModule ()->getNameStr ().str (),
137
- Instance ->getInvocation ().getFrontendOptions ().ExplicitModulesOutputPath ,
138
- Instance ->getInvocation ().getModuleScanningHash ());
142
+ *ScanningService, QueryContext. ScanInstance ->getMainModule ()->getNameStr ().str (),
143
+ QueryContext. ScanInstance ->getInvocation ().getFrontendOptions ().ExplicitModulesOutputPath ,
144
+ QueryContext. ScanInstance ->getInvocation ().getModuleScanningHash ());
139
145
// Execute the scanning action, retrieving the in-memory result
140
- auto DependenciesOrErr = performModuleScan (*Instance.get (), cache);
146
+ auto DependenciesOrErr = performModuleScan (*QueryContext.ScanInstance .get (),
147
+ QueryContext.ScanDiagnostics .get (),
148
+ cache);
141
149
if (DependenciesOrErr.getError ())
142
150
return std::make_error_code (std::errc::not_supported);
143
151
auto Dependencies = std::move (*DependenciesOrErr);
@@ -148,17 +156,19 @@ DependencyScanningTool::getDependencies(
148
156
llvm::ErrorOr<swiftscan_import_set_t >
149
157
DependencyScanningTool::getImports (ArrayRef<const char *> Command) {
150
158
// The primary instance used to scan the query Swift source-code
151
- auto InstanceOrErr = initScannerForAction (Command);
152
- if (std::error_code EC = InstanceOrErr .getError ())
159
+ auto QueryContextOrErr = initScannerForAction (Command);
160
+ if (std::error_code EC = QueryContextOrErr .getError ())
153
161
return EC;
154
- auto Instance = std::move (*InstanceOrErr );
162
+ auto QueryContext = std::move (*QueryContextOrErr );
155
163
156
164
// Local scan cache instance, wrapping the shared global cache.
157
165
ModuleDependenciesCache cache (
158
- *ScanningService, Instance->getMainModule ()->getNameStr ().str (),
159
- Instance->getInvocation ().getFrontendOptions ().ExplicitModulesOutputPath ,
160
- Instance->getInvocation ().getModuleScanningHash ());
161
- auto DependenciesOrErr = performModulePrescan (*Instance.get (), cache);
166
+ *ScanningService, QueryContext.ScanInstance ->getMainModule ()->getNameStr ().str (),
167
+ QueryContext.ScanInstance ->getInvocation ().getFrontendOptions ().ExplicitModulesOutputPath ,
168
+ QueryContext.ScanInstance ->getInvocation ().getModuleScanningHash ());
169
+ auto DependenciesOrErr = performModulePrescan (*QueryContext.ScanInstance .get (),
170
+ QueryContext.ScanDiagnostics .get (),
171
+ cache);
162
172
if (DependenciesOrErr.getError ())
163
173
return std::make_error_code (std::errc::not_supported);
164
174
auto Dependencies = std::move (*DependenciesOrErr);
@@ -172,19 +182,20 @@ DependencyScanningTool::getDependencies(
172
182
const std::vector<BatchScanInput> &BatchInput,
173
183
const llvm::StringSet<> &PlaceholderModules) {
174
184
// The primary instance used to scan Swift modules
175
- auto InstanceOrErr = initScannerForAction (Command);
176
- if (std::error_code EC = InstanceOrErr .getError ())
185
+ auto QueryContextOrErr = initScannerForAction (Command);
186
+ if (std::error_code EC = QueryContextOrErr .getError ())
177
187
return std::vector<llvm::ErrorOr<swiftscan_dependency_graph_t >>(
178
188
BatchInput.size (), std::make_error_code (std::errc::invalid_argument));
179
- auto Instance = std::move (*InstanceOrErr );
189
+ auto QueryContext = std::move (*QueryContextOrErr );
180
190
181
191
// Local scan cache instance, wrapping the shared global cache.
182
192
ModuleDependenciesCache cache (
183
- *ScanningService, Instance ->getMainModule ()->getNameStr ().str (),
184
- Instance ->getInvocation ().getFrontendOptions ().ExplicitModulesOutputPath ,
185
- Instance ->getInvocation ().getModuleScanningHash ());
193
+ *ScanningService, QueryContext. ScanInstance ->getMainModule ()->getNameStr ().str (),
194
+ QueryContext. ScanInstance ->getInvocation ().getFrontendOptions ().ExplicitModulesOutputPath ,
195
+ QueryContext. ScanInstance ->getInvocation ().getModuleScanningHash ());
186
196
auto BatchScanResults = performBatchModuleScan (
187
- *Instance.get (), cache, VersionedPCMInstanceCacheCache.get (),
197
+ *QueryContext.ScanInstance .get (), QueryContext.ScanDiagnostics .get (),
198
+ cache, VersionedPCMInstanceCacheCache.get (),
188
199
Saver, BatchInput);
189
200
190
201
return BatchScanResults;
@@ -221,7 +232,7 @@ void DependencyScanningTool::resetCache() {
221
232
}
222
233
223
234
std::vector<
224
- DependencyScannerDiagnosticCollectingConsumer ::ScannerDiagnosticInfo>
235
+ DependencyScanDiagnosticCollector ::ScannerDiagnosticInfo>
225
236
DependencyScanningTool::getDiagnostics () {
226
237
llvm::sys::SmartScopedLock<true > Lock (DependencyScanningToolStateLock);
227
238
return CDC.Diagnostics ;
@@ -232,25 +243,27 @@ void DependencyScanningTool::resetDiagnostics() {
232
243
CDC.reset ();
233
244
}
234
245
235
- llvm::ErrorOr<std::unique_ptr<CompilerInstance> >
246
+ llvm::ErrorOr<ScanQueryInstance >
236
247
DependencyScanningTool::initScannerForAction (
237
248
ArrayRef<const char *> Command) {
238
249
// The remainder of this method operates on shared state in the
239
250
// scanning service and global LLVM state with:
240
251
// llvm::cl::ResetAllOptionOccurrences
241
252
llvm::sys::SmartScopedLock<true > Lock (DependencyScanningToolStateLock);
242
- auto instanceOrErr = initCompilerInstanceForScan (Command);
243
- if (instanceOrErr.getError ())
244
- return instanceOrErr;
245
- return instanceOrErr;
253
+ return initCompilerInstanceForScan (Command);
246
254
}
247
255
248
- llvm::ErrorOr<std::unique_ptr<CompilerInstance> >
256
+ llvm::ErrorOr<ScanQueryInstance >
249
257
DependencyScanningTool::initCompilerInstanceForScan (
250
258
ArrayRef<const char *> CommandArgs) {
251
259
// State unique to an individual scan
252
260
auto Instance = std::make_unique<CompilerInstance>();
261
+ auto ScanDiagnosticConsumer = std::make_unique<DependencyScanDiagnosticCollector>();
262
+
263
+ // FIXME: The shared CDC must be deprecated once all clients have switched
264
+ // to using per-scan diagnostic output embedded in the `swiftscan_dependency_graph_s`
253
265
Instance->addDiagnosticConsumer (&CDC);
266
+ Instance->addDiagnosticConsumer (ScanDiagnosticConsumer.get ());
254
267
255
268
// Basic error checking on the arguments
256
269
if (CommandArgs.empty ()) {
@@ -300,7 +313,8 @@ DependencyScanningTool::initCompilerInstanceForScan(
300
313
301
314
(void )Instance->getMainModule ();
302
315
303
- return Instance;
316
+ return ScanQueryInstance{std::move (Instance),
317
+ std::move (ScanDiagnosticConsumer)};
304
318
}
305
319
306
320
} // namespace dependencies
0 commit comments