@@ -37,6 +37,68 @@ using ImportStatementInfoMap =
3737 std::unordered_map<ModuleDependencyID,
3838 std::vector<ScannerImportStatementInfo>>;
3939
40+ struct ScannerMetrics {
41+ // / Number of performed queries for a Swift dependency with a given name
42+ std::atomic<uint32_t > SwiftModuleQueries;
43+ // / Number of performed queries for a Clang dependency with a given name
44+ std::atomic<uint32_t > NamedClangModuleQueries;
45+ // / Number of discovered Clang module dependencies which are directly
46+ // / imported from a Swift module by-name
47+ std::atomic<uint32_t > RecordedNamedClangModuleDependencies;
48+ };
49+
50+ class DependencyScannerDiagnosticReporter {
51+ private:
52+ DependencyScannerDiagnosticReporter (DiagnosticEngine &Diagnostics,
53+ bool EmitScanRemarks);
54+
55+ // / Diagnose scanner failure and attempt to reconstruct the dependency
56+ // / path from the main module to the missing dependency
57+ void diagnoseModuleNotFoundFailure (
58+ const ScannerImportStatementInfo &moduleImport,
59+ const ModuleDependenciesCache &cache,
60+ std::optional<ModuleDependencyID> dependencyOf,
61+ std::optional<std::pair<ModuleDependencyID, std::string>>
62+ resolvingSerializedSearchPath,
63+ std::optional<
64+ std::vector<SwiftModuleScannerQueryResult::IncompatibleCandidate>>
65+ foundIncompatibleCandidates = std::nullopt );
66+
67+ // / Upon query failure, if incompatible binary module
68+ // / candidates were found, emit a failure diagnostic
69+ void diagnoseFailureOnOnlyIncompatibleCandidates (
70+ const ScannerImportStatementInfo &moduleImport,
71+ const std::vector<SwiftModuleScannerQueryResult::IncompatibleCandidate>
72+ &candidates,
73+ const ModuleDependenciesCache &cache,
74+ std::optional<ModuleDependencyID> dependencyOf);
75+
76+ // / Emit warnings for each discovered binary Swift module
77+ // / which was incompatible with the current compilation
78+ // / when querying \c moduleName
79+ void warnOnIncompatibleCandidates (
80+ StringRef moduleName,
81+ const std::vector<SwiftModuleScannerQueryResult::IncompatibleCandidate>
82+ &candidates);
83+
84+ // / If remark emission is enabled, increment the
85+ // / corresponding metric.
86+ void registerSwiftModuleQuery ();
87+ void registerNamedClangModuleQuery ();
88+ void registerNamedClangDependency ();
89+
90+ // / Emit various metrics about the current scannig action
91+ void emitScanMetrics (const ModuleDependenciesCache &cache) const ;
92+
93+ DiagnosticEngine &Diagnostics;
94+ bool EmitScanRemarks;
95+ std::unique_ptr<ScannerMetrics> ScanMetrics;
96+ std::unordered_set<std::string> ReportedMissing;
97+ // Restrict access to the parent scanner classes.
98+ friend class ModuleDependencyScanner ;
99+ friend class ModuleDependencyScanningWorker ;
100+ };
101+
40102// / A dependency scanning worker which performs filesystem lookup
41103// / of a named module dependency.
42104class ModuleDependencyScanningWorker {
@@ -48,7 +110,8 @@ class ModuleDependencyScanningWorker {
48110 DependencyTracker &DependencyTracker,
49111 std::shared_ptr<llvm::cas::ObjectStore> CAS,
50112 std::shared_ptr<llvm::cas::ActionCache> ActionCache,
51- llvm::PrefixMapper *mapper, DiagnosticEngine &diags);
113+ DependencyScannerDiagnosticReporter &DiagnosticReporter,
114+ llvm::PrefixMapper *mapper);
52115
53116private:
54117 // / Query dependency information for a named Clang module
@@ -128,6 +191,9 @@ class ModuleDependencyScanningWorker {
128191 std::shared_ptr<llvm::cas::ObjectStore> CAS;
129192 std::shared_ptr<llvm::cas::ActionCache> ActionCache;
130193
194+ // The parent scanner's diagnostic reporter
195+ DependencyScannerDiagnosticReporter &diagnosticReporter;
196+
131197 // Base command line invocation for clang scanner queries (both module and header)
132198 std::vector<std::string> clangScanningBaseCommandLineArgs;
133199 // Command line invocation for clang by-name module lookups
@@ -173,46 +239,6 @@ class SwiftDependencyTracker {
173239 std::map<std::string, FileEntry> TrackedFiles;
174240};
175241
176- class ModuleDependencyIssueReporter {
177- private:
178- ModuleDependencyIssueReporter (DiagnosticEngine &Diagnostics)
179- : Diagnostics(Diagnostics) {}
180-
181- // / Diagnose scanner failure and attempt to reconstruct the dependency
182- // / path from the main module to the missing dependency
183- void diagnoseModuleNotFoundFailure (
184- const ScannerImportStatementInfo &moduleImport,
185- const ModuleDependenciesCache &cache,
186- std::optional<ModuleDependencyID> dependencyOf,
187- std::optional<std::pair<ModuleDependencyID, std::string>>
188- resolvingSerializedSearchPath,
189- std::optional<
190- std::vector<SwiftModuleScannerQueryResult::IncompatibleCandidate>>
191- foundIncompatibleCandidates = std::nullopt );
192-
193- // / Upon query failure, if incompatible binary module
194- // / candidates were found, emit a failure diagnostic
195- void diagnoseFailureOnOnlyIncompatibleCandidates (
196- const ScannerImportStatementInfo &moduleImport,
197- const std::vector<SwiftModuleScannerQueryResult::IncompatibleCandidate>
198- &candidates,
199- const ModuleDependenciesCache &cache,
200- std::optional<ModuleDependencyID> dependencyOf);
201-
202- // / Emit warnings for each discovered binary Swift module
203- // / which was incompatible with the current compilation
204- // / when querying \c moduleName
205- void warnOnIncompatibleCandidates (
206- StringRef moduleName,
207- const std::vector<SwiftModuleScannerQueryResult::IncompatibleCandidate>
208- &candidates);
209-
210- DiagnosticEngine &Diagnostics;
211- std::unordered_set<std::string> ReportedMissing;
212- // Restrict access to the parent scanner class.
213- friend class ModuleDependencyScanner ;
214- };
215-
216242class ModuleDependencyScanner {
217243public:
218244 ModuleDependencyScanner (SwiftDependencyScanningService &ScanningService,
@@ -223,7 +249,8 @@ class ModuleDependencyScanner {
223249 DependencyTracker &DependencyTracker,
224250 std::shared_ptr<llvm::cas::ObjectStore> CAS,
225251 std::shared_ptr<llvm::cas::ActionCache> ActionCache,
226- DiagnosticEngine &Diagnostics, bool ParallelScan);
252+ DiagnosticEngine &Diagnostics, bool ParallelScan,
253+ bool EmitScanRemarks);
227254
228255 // / Identify the scanner invocation's main module's dependencies
229256 llvm::ErrorOr<ModuleDependencyInfo>
@@ -347,7 +374,7 @@ class ModuleDependencyScanner {
347374 // / For the provided collection of unresolved imports
348375 // / belonging to identified Swift dependnecies, execute a parallel
349376 // / query to the Clang dependency scanner for each import's module identifier.
350- void performParallelClangModuleLookup (
377+ void performClangModuleLookup (
351378 const ImportStatementInfoMap &unresolvedImportsMap,
352379 const ImportStatementInfoMap &unresolvedOptionalImportsMap,
353380 BatchClangModuleLookupResult &result);
@@ -396,7 +423,7 @@ class ModuleDependencyScanner {
396423private:
397424 const CompilerInvocation &ScanCompilerInvocation;
398425 ASTContext &ScanASTContext;
399- ModuleDependencyIssueReporter IssueReporter ;
426+ DependencyScannerDiagnosticReporter ScanDiagnosticReporter ;
400427
401428 // / The location of where the explicitly-built modules will be output to
402429 std::string ModuleOutputPath;
0 commit comments