ModuleLoader: remove several walk-arounds for not having a persistent ClangImporterOptions available. NFC

This commit is contained in:
Xi Ge
2020-09-02 09:34:35 -07:00
parent 773eec1a71
commit a4d731ed9f
8 changed files with 24 additions and 49 deletions

View File

@@ -844,8 +844,8 @@ class ModuleInterfaceLoaderImpl {
}
InterfaceSubContextDelegateImpl astDelegate(ctx.SourceMgr, ctx.Diags,
ctx.SearchPathOpts, ctx.LangOpts,
ctx.ClangImporterOpts,
Opts,
ctx.getClangModuleLoader(),
/*buildModuleCacheDirIfAbsent*/true,
cacheDir,
prebuiltCacheDir,
@@ -1084,20 +1084,12 @@ bool ModuleInterfaceLoader::buildSwiftModuleFromSwiftInterface(
bool SerializeDependencyHashes, bool TrackSystemDependencies,
ModuleInterfaceLoaderOptions LoaderOpts) {
InterfaceSubContextDelegateImpl astDelegate(SourceMgr, Diags,
SearchPathOpts, LangOpts,
SearchPathOpts, LangOpts, ClangOpts,
LoaderOpts,
/*clangImporter*/nullptr,
/*CreateCacheDirIfAbsent*/true,
CacheDir, PrebuiltCacheDir,
SerializeDependencyHashes,
TrackSystemDependencies);
// At this point we don't have an ClangImporter instance because the instance
// is created later when we create a new ASTContext to build the interface.
// Thus, we have to add these extra clang flags manually here to ensure explict
// module building works.
for (auto &Arg: ClangOpts.ExtraArgs) {
astDelegate.addExtraClangArg(Arg);
}
ModuleInterfaceBuilder builder(SourceMgr, Diags, astDelegate, InPath,
ModuleName, CacheDir, PrebuiltCacheDir,
LoaderOpts.disableInterfaceLock);
@@ -1238,19 +1230,13 @@ bool InterfaceSubContextDelegateImpl::extractSwiftInterfaceVersionAndArgs(
return false;
}
void InterfaceSubContextDelegateImpl::addExtraClangArg(StringRef arg) {
genericSubInvocation.getClangImporterOptions().ExtraArgs.push_back(arg);
GenericArgs.push_back("-Xcc");
GenericArgs.push_back(ArgSaver.save(arg));
}
InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
SourceManager &SM,
DiagnosticEngine &Diags,
const SearchPathOptions &searchPathOpts,
const LangOptions &langOpts,
const ClangImporterOptions &clangImporterOpts,
ModuleInterfaceLoaderOptions LoaderOpts,
ClangModuleLoader *clangImporter,
bool buildModuleCacheDirIfAbsent,
StringRef moduleCachePath,
StringRef prebuiltCachePath,
@@ -1288,22 +1274,21 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
StringRef explictSwiftModuleMap = searchPathOpts.ExplicitSwiftModuleMap;
genericSubInvocation.getSearchPathOptions().ExplicitSwiftModuleMap =
explictSwiftModuleMap;
if (clangImporter) {
// We need to add these extra clang flags because explict module building
// related flags are all there: -fno-implicit-modules, -fmodule-map-file=,
// and -fmodule-file=.
// If we don't add these flags, the interface will be built with implicit
// PCMs.
for (auto arg: static_cast<ClangImporter*>(clangImporter)->getExtraClangArgs()) {
addExtraClangArg(arg);
}
// Respect the detailed-record preprocessor setting of the parent context.
// This, and the "raw" clang module format it implicitly enables, are
// required by sourcekitd.
auto &Opts = clangImporter->getClangInstance().getPreprocessorOpts();
if (Opts.DetailedRecord) {
genericSubInvocation.getClangImporterOptions().DetailedPreprocessingRecord = true;
}
auto &subClangImporterOpts = genericSubInvocation.getClangImporterOptions();
// Respect the detailed-record preprocessor setting of the parent context.
// This, and the "raw" clang module format it implicitly enables, are
// required by sourcekitd.
subClangImporterOpts.DetailedPreprocessingRecord =
clangImporterOpts.DetailedPreprocessingRecord;
// We need to add these extra clang flags because explict module building
// related flags are all there: -fno-implicit-modules, -fmodule-map-file=,
// and -fmodule-file=.
// If we don't add these flags, the interface will be built with implicit
// PCMs.
subClangImporterOpts.ExtraArgs = clangImporterOpts.ExtraArgs;
for (auto arg: subClangImporterOpts.ExtraArgs) {
GenericArgs.push_back("-Xcc");
GenericArgs.push_back(ArgSaver.save(arg));
}
// Tell the genericSubInvocation to serialize dependency hashes if asked to do so.