[Caching][NFC] Restructure CASOption in swift. NFC

Clean up how CASOptions are kept and passed inside swift to make the
code more readable. Also avoid a copy of CAS configuration in
ClangImporter.
This commit is contained in:
Steven Wu
2024-02-08 16:51:14 -08:00
parent 71640be109
commit 3986937e03
35 changed files with 293 additions and 217 deletions

View File

@@ -1053,7 +1053,7 @@ class ModuleInterfaceLoaderImpl {
}
InterfaceSubContextDelegateImpl astDelegate(
ctx.SourceMgr, &ctx.Diags, ctx.SearchPathOpts, ctx.LangOpts,
ctx.ClangImporterOpts, Opts,
ctx.ClangImporterOpts, ctx.CASOpts, Opts,
/*buildModuleCacheDirIfAbsent*/ true, cacheDir, prebuiltCacheDir,
backupInterfaceDir,
/*serializeDependencyHashes*/ false, trackSystemDependencies,
@@ -1374,17 +1374,16 @@ bool ModuleInterfaceCheckerImpl::tryEmitForwardingModule(
bool ModuleInterfaceLoader::buildSwiftModuleFromSwiftInterface(
SourceManager &SourceMgr, DiagnosticEngine &Diags,
const SearchPathOptions &SearchPathOpts, const LangOptions &LangOpts,
const ClangImporterOptions &ClangOpts, StringRef CacheDir,
StringRef PrebuiltCacheDir, StringRef BackupInterfaceDir,
StringRef ModuleName, StringRef InPath,
StringRef OutPath, StringRef ABIOutputPath,
bool SerializeDependencyHashes,
const ClangImporterOptions &ClangOpts, const CASOptions &CASOpts,
StringRef CacheDir, StringRef PrebuiltCacheDir,
StringRef BackupInterfaceDir, StringRef ModuleName, StringRef InPath,
StringRef OutPath, StringRef ABIOutputPath, bool SerializeDependencyHashes,
bool TrackSystemDependencies, ModuleInterfaceLoaderOptions LoaderOpts,
RequireOSSAModules_t RequireOSSAModules,
RequireNoncopyableGenerics_t RequireNCGenerics,
bool silenceInterfaceDiagnostics) {
InterfaceSubContextDelegateImpl astDelegate(
SourceMgr, &Diags, SearchPathOpts, LangOpts, ClangOpts, LoaderOpts,
SourceMgr, &Diags, SearchPathOpts, LangOpts, ClangOpts, CASOpts, LoaderOpts,
/*CreateCacheDirIfAbsent*/ true, CacheDir, PrebuiltCacheDir,
BackupInterfaceDir,
SerializeDependencyHashes, TrackSystemDependencies,
@@ -1558,7 +1557,7 @@ void ModuleInterfaceLoader::collectVisibleTopLevelModuleNames(
void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
const SearchPathOptions &SearchPathOpts, const LangOptions &LangOpts,
const ClangImporterOptions &clangImporterOpts,
const ClangImporterOptions &clangImporterOpts, const CASOptions &casOpts,
bool suppressRemarks, RequireOSSAModules_t RequireOSSAModules,
RequireNoncopyableGenerics_t requireNCGenerics) {
GenericArgs.push_back("-frontend");
@@ -1674,23 +1673,11 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
GenericArgs.push_back(clangImporterOpts.BuildSessionFilePath);
}
if (clangImporterOpts.CASOpts) {
genericSubInvocation.getClangImporterOptions().CASOpts =
clangImporterOpts.CASOpts;
GenericArgs.push_back("-cache-compile-job");
if (!clangImporterOpts.CASOpts->CASPath.empty()) {
GenericArgs.push_back("-cas-path");
GenericArgs.push_back(clangImporterOpts.CASOpts->CASPath);
}
if (!clangImporterOpts.CASOpts->PluginPath.empty()) {
GenericArgs.push_back("-cas-plugin-path");
GenericArgs.push_back(clangImporterOpts.CASOpts->PluginPath);
for (auto Opt : clangImporterOpts.CASOpts->PluginOptions) {
GenericArgs.push_back("-cas-plugin-option");
std::string pair = (llvm::Twine(Opt.first) + "=" + Opt.second).str();
GenericArgs.push_back(ArgSaver.save(pair));
}
}
if (casOpts.EnableCaching) {
genericSubInvocation.getCASOptions().EnableCaching = casOpts.EnableCaching;
genericSubInvocation.getCASOptions().CASOpts = casOpts.CASOpts;
casOpts.enumerateCASConfigurationFlags(
[&](StringRef Arg) { GenericArgs.push_back(ArgSaver.save(Arg)); });
}
if (!clangImporterOpts.UseClangIncludeTree) {
@@ -1726,7 +1713,7 @@ bool InterfaceSubContextDelegateImpl::extractSwiftInterfaceVersionAndArgs(
InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
SourceManager &SM, DiagnosticEngine *Diags,
const SearchPathOptions &searchPathOpts, const LangOptions &langOpts,
const ClangImporterOptions &clangImporterOpts,
const ClangImporterOptions &clangImporterOpts, const CASOptions &casOpts,
ModuleInterfaceLoaderOptions LoaderOpts, bool buildModuleCacheDirIfAbsent,
StringRef moduleCachePath, StringRef prebuiltCachePath,
StringRef backupModuleInterfaceDir,
@@ -1736,7 +1723,7 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
: SM(SM), Diags(Diags), ArgSaver(Allocator) {
genericSubInvocation.setMainExecutablePath(LoaderOpts.mainExecutablePath);
inheritOptionsForBuildingInterface(searchPathOpts, langOpts,
clangImporterOpts,
clangImporterOpts, casOpts,
Diags->getSuppressRemarks(),
requireOSSAModules,
requireNCGenerics);
@@ -1793,7 +1780,6 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
// required by sourcekitd.
subClangImporterOpts.DetailedPreprocessingRecord =
clangImporterOpts.DetailedPreprocessingRecord;
subClangImporterOpts.CASOpts = clangImporterOpts.CASOpts;
std::vector<std::string> inheritedParentContextClangArgs;
if (LoaderOpts.requestedAction ==