Skip to content

Commit 6990b89

Browse files
authored
Merge pull request #72854 from artemcm/DefaultParallelDepScan
[Dependency Scanning] Enable parallel dependency scanning by-default
2 parents 626e511 + e7a7665 commit 6990b89

File tree

5 files changed

+40
-22
lines changed

5 files changed

+40
-22
lines changed

include/swift/DependencyScan/ModuleDependencyScanner.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ class ModuleDependencyScanningWorker {
5151
scanFilesystemForSwiftModuleDependency(Identifier moduleName,
5252
const ModuleDependenciesCache &cache);
5353

54+
// Worker-specific instance of CompilerInvocation
55+
std::unique_ptr<CompilerInvocation> workerCompilerInvocation;
56+
// Worker-specific instance of ASTContext
57+
std::unique_ptr<ASTContext> workerASTContext;
5458
// An AST delegate for interface scanning.
55-
std::unique_ptr<InterfaceSubContextDelegateImpl> ScanningASTDelegate;
59+
std::unique_ptr<InterfaceSubContextDelegateImpl> scanningASTDelegate;
5660
// The Clang scanner tool used by this worker.
5761
clang::tooling::dependencies::DependencyScanningTool clangScanningTool;
5862
// Swift and Clang module loaders acting as scanners.

include/swift/Frontend/FrontendOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class FrontendOptions {
361361

362362
/// Whether the dependency scanner invocation should resolve imports
363363
/// to filesystem modules in parallel.
364-
bool ParallelDependencyScan = false;
364+
bool ParallelDependencyScan = true;
365365

366366
/// When performing an incremental build, ensure that cross-module incremental
367367
/// build metadata is available in any swift modules emitted by this frontend

include/swift/Option/FrontendOptions.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ def dependency_scan_cache_remarks : Flag<["-"], "Rdependency-scan-cache">,
265265

266266
def parallel_scan : Flag<["-"], "parallel-scan">,
267267
HelpText<"Perform dependency scanning in-parallel.">;
268+
def no_parallel_scan : Flag<["-"], "-no-parallel-scan">,
269+
HelpText<"Perform dependency scanning in a single-threaded fashion.">;
268270

269271
def enable_copy_propagation : Flag<["-"], "enable-copy-propagation">,
270272
HelpText<"Run SIL copy propagation with lexical lifetimes to shorten object "

lib/DependencyScan/ModuleDependencyScanner.cpp

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -166,38 +166,48 @@ ModuleDependencyScanningWorker::ModuleDependencyScanningWorker(
166166
const CompilerInvocation &ScanCompilerInvocation,
167167
const SILOptions &SILOptions, ASTContext &ScanASTContext,
168168
swift::DependencyTracker &DependencyTracker, DiagnosticEngine &Diagnostics)
169-
: // Diagnostics(Diagnostics),
170-
clangScanningTool(*globalScanningService.ClangScanningService,
169+
: clangScanningTool(*globalScanningService.ClangScanningService,
171170
globalScanningService.getClangScanningFS()) {
172-
// Configure the interface scanning AST delegate
171+
// Create a scanner-specific Invocation and ASTContext.
172+
workerCompilerInvocation =
173+
std::make_unique<CompilerInvocation>(ScanCompilerInvocation);
174+
workerASTContext = std::unique_ptr<ASTContext>(
175+
ASTContext::get(workerCompilerInvocation->getLangOptions(),
176+
workerCompilerInvocation->getTypeCheckerOptions(),
177+
workerCompilerInvocation->getSILOptions(),
178+
workerCompilerInvocation->getSearchPathOptions(),
179+
workerCompilerInvocation->getClangImporterOptions(),
180+
workerCompilerInvocation->getSymbolGraphOptions(),
181+
workerCompilerInvocation->getCASOptions(),
182+
ScanASTContext.SourceMgr, Diagnostics));
183+
184+
// Configure the interface scanning AST delegate.
173185
auto ClangModuleCachePath = getModuleCachePathFromClang(
174186
ScanASTContext.getClangModuleLoader()->getClangInstance());
175-
auto &FEOpts = ScanCompilerInvocation.getFrontendOptions();
176-
ModuleInterfaceLoaderOptions LoaderOpts(FEOpts);
177-
ScanningASTDelegate = std::make_unique<InterfaceSubContextDelegateImpl>(
178-
ScanASTContext.SourceMgr, &ScanASTContext.Diags,
179-
ScanASTContext.SearchPathOpts, ScanASTContext.LangOpts,
180-
ScanASTContext.ClangImporterOpts, ScanASTContext.CASOpts, LoaderOpts,
187+
auto &FEOpts = workerCompilerInvocation->getFrontendOptions();
188+
scanningASTDelegate = std::make_unique<InterfaceSubContextDelegateImpl>(
189+
workerASTContext->SourceMgr, &workerASTContext->Diags,
190+
workerASTContext->SearchPathOpts, workerASTContext->LangOpts,
191+
workerASTContext->ClangImporterOpts, workerASTContext->CASOpts, FEOpts,
181192
/*buildModuleCacheDirIfAbsent*/ false, ClangModuleCachePath,
182193
FEOpts.PrebuiltModuleCachePath, FEOpts.BackupModuleInterfaceDir,
183194
FEOpts.SerializeModuleInterfaceDependencyHashes,
184195
FEOpts.shouldTrackSystemDependencies(), RequireOSSAModules_t(SILOptions));
185196

186-
// Set up the Clang importer.
197+
// Set up the ClangImporter.
187198
clangScannerModuleLoader = ClangImporter::create(
188-
ScanASTContext, ScanCompilerInvocation.getPCHHash(), &DependencyTracker);
199+
*workerASTContext, workerCompilerInvocation->getPCHHash(),
200+
&DependencyTracker);
189201
if (!clangScannerModuleLoader)
190202
Diagnostics.diagnose(SourceLoc(), diag::error_clang_importer_create_fail);
191203

192204
// Set up the Swift interface loader for Swift scanning.
193205
swiftScannerModuleLoader = ModuleInterfaceLoader::create(
194-
ScanASTContext,
206+
*workerASTContext,
195207
*static_cast<ModuleInterfaceCheckerImpl *>(
196208
ScanASTContext.getModuleInterfaceChecker()),
197209
&DependencyTracker,
198-
ScanCompilerInvocation.getSearchPathOptions().ModuleLoadMode);
199-
200-
llvm::cl::ResetAllOptionOccurrences();
210+
workerCompilerInvocation->getSearchPathOptions().ModuleLoadMode);
201211
}
202212

203213
ModuleDependencyVector
@@ -210,15 +220,15 @@ ModuleDependencyScanningWorker::scanFilesystemForModuleDependency(
210220
moduleName, cache.getModuleOutputPath(),
211221
cache.getScanService().getCachingFS(),
212222
cache.getAlreadySeenClangModules(), clangScanningTool,
213-
*ScanningASTDelegate, cache.getScanService().getPrefixMapper(),
223+
*scanningASTDelegate, cache.getScanService().getPrefixMapper(),
214224
isTestableImport);
215225

216226
if (moduleDependencies.empty())
217227
moduleDependencies = clangScannerModuleLoader->getModuleDependencies(
218228
moduleName, cache.getModuleOutputPath(),
219229
cache.getScanService().getCachingFS(),
220230
cache.getAlreadySeenClangModules(), clangScanningTool,
221-
*ScanningASTDelegate, cache.getScanService().getPrefixMapper(),
231+
*scanningASTDelegate, cache.getScanService().getPrefixMapper(),
222232
isTestableImport);
223233

224234
return moduleDependencies;
@@ -230,7 +240,7 @@ ModuleDependencyScanningWorker::scanFilesystemForSwiftModuleDependency(
230240
return swiftScannerModuleLoader->getModuleDependencies(
231241
moduleName, cache.getModuleOutputPath(),
232242
cache.getScanService().getCachingFS(), cache.getAlreadySeenClangModules(),
233-
clangScanningTool, *ScanningASTDelegate,
243+
clangScanningTool, *scanningASTDelegate,
234244
cache.getScanService().getPrefixMapper(), false);
235245
}
236246

@@ -240,7 +250,7 @@ ModuleDependencyScanningWorker::scanFilesystemForClangModuleDependency(
240250
return clangScannerModuleLoader->getModuleDependencies(
241251
moduleName, cache.getModuleOutputPath(),
242252
cache.getScanService().getCachingFS(), cache.getAlreadySeenClangModules(),
243-
clangScanningTool, *ScanningASTDelegate,
253+
clangScanningTool, *scanningASTDelegate,
244254
cache.getScanService().getPrefixMapper(), false);
245255
}
246256

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ bool ArgsToFrontendOptionsConverter::convert(
150150
Opts.SerializeDependencyScannerCache |= Args.hasArg(OPT_serialize_dependency_scan_cache);
151151
Opts.ReuseDependencyScannerCache |= Args.hasArg(OPT_reuse_dependency_scan_cache);
152152
Opts.EmitDependencyScannerCacheRemarks |= Args.hasArg(OPT_dependency_scan_cache_remarks);
153-
Opts.ParallelDependencyScan |= Args.hasArg(OPT_parallel_scan);
153+
Opts.ParallelDependencyScan = Args.hasArg(OPT_parallel_scan,
154+
OPT_no_parallel_scan,
155+
true);
154156
if (const Arg *A = Args.getLastArg(OPT_dependency_scan_cache_path)) {
155157
Opts.SerializedDependencyScannerCachePath = A->getValue();
156158
}

0 commit comments

Comments
 (0)