[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.
This commit is contained in:
Jordan Rose
2018-12-17 18:21:26 -08:00
parent 5417ca0aa2
commit 7562137fab
2 changed files with 17 additions and 11 deletions

View File

@@ -301,10 +301,10 @@ collectDepsForSerialization(clang::vfs::FileSystem &FS,
return false;
}
static bool buildSwiftModuleFromSwiftInterface(
bool ParseableInterfaceModuleLoader::buildSwiftModuleFromSwiftInterface(
clang::vfs::FileSystem &FS, DiagnosticEngine &Diags, SourceLoc DiagLoc,
CompilerInvocation &SubInvocation, StringRef ModuleCachePath,
DependencyTracker *OuterTracker) {
CompilerInvocation &SubInvocation, StringRef InPath, StringRef OutPath,
StringRef ModuleCachePath, DependencyTracker *OuterTracker) {
bool SubError = false;
bool RunSuccess = llvm::CrashRecoveryContext().RunSafelyOnThread([&] {
// Note that we don't assume ModuleCachePath is the same as the Clang
@@ -312,6 +312,8 @@ static bool buildSwiftModuleFromSwiftInterface(
if (!ModuleCachePath.empty())
(void)llvm::sys::fs::create_directory(ModuleCachePath);
configureSubInvocationInputsAndOutputs(SubInvocation, InPath, OutPath);
FrontendOptions &FEOpts = SubInvocation.getFrontendOptions();
const auto &InputInfo = FEOpts.InputsAndOutputs.firstInput();
StringRef InPath = InputInfo.file();
@@ -514,14 +516,13 @@ std::error_code ParseableInterfaceModuleLoader::findModuleFilesInDirectory(
createInvocationForBuildingFromInterface(Ctx, ModuleID.first.str(),
CacheDir);
computeCachedOutputPath(Ctx, SubInvocation, InPath, OutPath);
configureSubInvocationInputsAndOutputs(SubInvocation, InPath, OutPath);
// Evaluate if we need to run this sub-invocation, and if so run it.
if (!swiftModuleIsUpToDate(FS, ModuleID, OutPath, Diags,
dependencyTracker)) {
if (::buildSwiftModuleFromSwiftInterface(FS, Diags, ModuleID.second,
SubInvocation, CacheDir,
dependencyTracker))
if (buildSwiftModuleFromSwiftInterface(FS, Diags, ModuleID.second,
SubInvocation, InPath, OutPath,
CacheDir, dependencyTracker))
return std::make_error_code(std::errc::invalid_argument);
}
}
@@ -549,13 +550,13 @@ ParseableInterfaceModuleLoader::buildSwiftModuleFromSwiftInterface(
StringRef InPath, StringRef OutPath) {
CompilerInvocation SubInvocation =
createInvocationForBuildingFromInterface(Ctx, ModuleName, CacheDir);
configureSubInvocationInputsAndOutputs(SubInvocation, InPath, OutPath);
auto &FS = *Ctx.SourceMgr.getFileSystem();
auto &Diags = Ctx.Diags;
return ::buildSwiftModuleFromSwiftInterface(FS, Diags, /*DiagLoc*/SourceLoc(),
SubInvocation, /*CachePath*/"",
/*OuterTracker*/nullptr);
return buildSwiftModuleFromSwiftInterface(FS, Diags, /*DiagLoc*/SourceLoc(),
SubInvocation, InPath, OutPath,
/*CachePath*/"",
/*OuterTracker*/nullptr);
}
/// Diagnose any scoped imports in \p imports, i.e. those with a non-empty