Skip to content

Commit 7562137

Browse files
committed
[ParseableInterfaces] Move call to helper to the one place it's needed
This is a little trickier than it sounds because we have 'friend' access into the FrontendInputsAndOutputs structure, which means all the helpers need to be declared in the header file. But it makes the two use sites simpler, and does slightly less work in the cache hit path.
1 parent 5417ca0 commit 7562137

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

include/swift/Frontend/ParseableInterfaceSupport.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ class ParseableInterfaceModuleLoader : public SerializedModuleLoaderBase {
7979
static void configureSubInvocationInputsAndOutputs(
8080
CompilerInvocation &SubInvocation, StringRef InPath, StringRef OutPath);
8181

82+
static bool buildSwiftModuleFromSwiftInterface(
83+
clang::vfs::FileSystem &FS, DiagnosticEngine &Diags, SourceLoc DiagLoc,
84+
CompilerInvocation &SubInvocation, StringRef InPath, StringRef OutPath,
85+
StringRef ModuleCachePath, DependencyTracker *OuterTracker);
86+
8287
std::error_code findModuleFilesInDirectory(
8388
AccessPathElem ModuleID, StringRef DirPath, StringRef ModuleFilename,
8489
StringRef ModuleDocFilename,

lib/Frontend/ParseableInterfaceSupport.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -301,17 +301,19 @@ collectDepsForSerialization(clang::vfs::FileSystem &FS,
301301
return false;
302302
}
303303

304-
static bool buildSwiftModuleFromSwiftInterface(
304+
bool ParseableInterfaceModuleLoader::buildSwiftModuleFromSwiftInterface(
305305
clang::vfs::FileSystem &FS, DiagnosticEngine &Diags, SourceLoc DiagLoc,
306-
CompilerInvocation &SubInvocation, StringRef ModuleCachePath,
307-
DependencyTracker *OuterTracker) {
306+
CompilerInvocation &SubInvocation, StringRef InPath, StringRef OutPath,
307+
StringRef ModuleCachePath, DependencyTracker *OuterTracker) {
308308
bool SubError = false;
309309
bool RunSuccess = llvm::CrashRecoveryContext().RunSafelyOnThread([&] {
310310
// Note that we don't assume ModuleCachePath is the same as the Clang
311311
// module cache path at this point.
312312
if (!ModuleCachePath.empty())
313313
(void)llvm::sys::fs::create_directory(ModuleCachePath);
314314

315+
configureSubInvocationInputsAndOutputs(SubInvocation, InPath, OutPath);
316+
315317
FrontendOptions &FEOpts = SubInvocation.getFrontendOptions();
316318
const auto &InputInfo = FEOpts.InputsAndOutputs.firstInput();
317319
StringRef InPath = InputInfo.file();
@@ -514,14 +516,13 @@ std::error_code ParseableInterfaceModuleLoader::findModuleFilesInDirectory(
514516
createInvocationForBuildingFromInterface(Ctx, ModuleID.first.str(),
515517
CacheDir);
516518
computeCachedOutputPath(Ctx, SubInvocation, InPath, OutPath);
517-
configureSubInvocationInputsAndOutputs(SubInvocation, InPath, OutPath);
518519

519520
// Evaluate if we need to run this sub-invocation, and if so run it.
520521
if (!swiftModuleIsUpToDate(FS, ModuleID, OutPath, Diags,
521522
dependencyTracker)) {
522-
if (::buildSwiftModuleFromSwiftInterface(FS, Diags, ModuleID.second,
523-
SubInvocation, CacheDir,
524-
dependencyTracker))
523+
if (buildSwiftModuleFromSwiftInterface(FS, Diags, ModuleID.second,
524+
SubInvocation, InPath, OutPath,
525+
CacheDir, dependencyTracker))
525526
return std::make_error_code(std::errc::invalid_argument);
526527
}
527528
}
@@ -549,13 +550,13 @@ ParseableInterfaceModuleLoader::buildSwiftModuleFromSwiftInterface(
549550
StringRef InPath, StringRef OutPath) {
550551
CompilerInvocation SubInvocation =
551552
createInvocationForBuildingFromInterface(Ctx, ModuleName, CacheDir);
552-
configureSubInvocationInputsAndOutputs(SubInvocation, InPath, OutPath);
553553

554554
auto &FS = *Ctx.SourceMgr.getFileSystem();
555555
auto &Diags = Ctx.Diags;
556-
return ::buildSwiftModuleFromSwiftInterface(FS, Diags, /*DiagLoc*/SourceLoc(),
557-
SubInvocation, /*CachePath*/"",
558-
/*OuterTracker*/nullptr);
556+
return buildSwiftModuleFromSwiftInterface(FS, Diags, /*DiagLoc*/SourceLoc(),
557+
SubInvocation, InPath, OutPath,
558+
/*CachePath*/"",
559+
/*OuterTracker*/nullptr);
559560
}
560561

561562
/// Diagnose any scoped imports in \p imports, i.e. those with a non-empty

0 commit comments

Comments
 (0)