Skip to content

Commit ed5edb8

Browse files
authored
Merge pull request swiftlang#33756 from nkcsgexi/module-loader-opts
ModuleLoader: remove several walk-arounds for not having a persistent ClangImporterOptions available. NFC
2 parents bd99a10 + a4d731e commit ed5edb8

File tree

8 files changed

+24
-49
lines changed

8 files changed

+24
-49
lines changed

include/swift/ClangImporter/ClangImporter.h

-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,6 @@ class ClangImporter final : public ClangModuleLoader {
472472

473473
bool isSerializable(const clang::Type *type,
474474
bool checkCanonical) const override;
475-
ArrayRef<std::string> getExtraClangArgs() const;
476475
};
477476

478477
ImportDecl *createImportDecl(ASTContext &Ctx, DeclContext *DC, ClangNode ClangN,

include/swift/Frontend/ModuleInterfaceLoader.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
420420
DiagnosticEngine &Diags,
421421
const SearchPathOptions &searchPathOpts,
422422
const LangOptions &langOpts,
423+
const ClangImporterOptions &clangImporterOpts,
423424
ModuleInterfaceLoaderOptions LoaderOpts,
424-
ClangModuleLoader *clangImporter,
425425
bool buildModuleCacheDirIfAbsent,
426426
StringRef moduleCachePath,
427427
StringRef prebuiltCachePath,
@@ -448,7 +448,6 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
448448
llvm::SmallString<256> &OutPath,
449449
StringRef &CacheHash);
450450
std::string getCacheHash(StringRef useInterfacePath);
451-
void addExtraClangArg(StringRef Arg);
452451
};
453452
}
454453

lib/ClangImporter/ClangImporter.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -969,10 +969,6 @@ ClangImporter::createClangInvocation(ClangImporter *importer,
969969
nullptr, false, CC1Args);
970970
}
971971

972-
ArrayRef<std::string> ClangImporter::getExtraClangArgs() const {
973-
return Impl.ExtraClangArgs;
974-
}
975-
976972
std::unique_ptr<ClangImporter>
977973
ClangImporter::create(ASTContext &ctx,
978974
std::string swiftPCHHash, DependencyTracker *tracker,
@@ -982,7 +978,6 @@ ClangImporter::create(ASTContext &ctx,
982978
auto &importerOpts = ctx.ClangImporterOpts;
983979
importer->Impl.ClangArgs = getClangArguments(ctx);
984980
ArrayRef<std::string> invocationArgStrs = importer->Impl.ClangArgs;
985-
importer->Impl.ExtraClangArgs = importerOpts.ExtraArgs;
986981
if (importerOpts.DumpClangDiagnostics) {
987982
llvm::errs() << "'";
988983
llvm::interleave(

lib/ClangImporter/ImporterImpl.h

-2
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,6 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
393393
/// Clang arguments used to create the Clang invocation.
394394
std::vector<std::string> ClangArgs;
395395

396-
/// Extra clang args specified via "-Xcc"
397-
std::vector<std::string> ExtraClangArgs;
398396
public:
399397
/// Mapping of already-imported declarations.
400398
llvm::DenseMap<std::pair<const clang::Decl *, Version>, Decl *> ImportedDecls;

lib/Frontend/Frontend.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,8 @@ bool CompilerInstance::setUpModuleLoaders() {
538538
ModuleInterfaceLoaderOptions LoaderOpts(FEOpts);
539539
InterfaceSubContextDelegateImpl ASTDelegate(Context->SourceMgr, Context->Diags,
540540
Context->SearchPathOpts, Context->LangOpts,
541+
Context->ClangImporterOpts,
541542
LoaderOpts,
542-
Context->getClangModuleLoader(),
543543
/*buildModuleCacheDirIfAbsent*/false,
544544
ModuleCachePath,
545545
FEOpts.PrebuiltModuleCachePath,

lib/Frontend/ModuleInterfaceLoader.cpp

+18-33
Original file line numberDiff line numberDiff line change
@@ -844,8 +844,8 @@ class ModuleInterfaceLoaderImpl {
844844
}
845845
InterfaceSubContextDelegateImpl astDelegate(ctx.SourceMgr, ctx.Diags,
846846
ctx.SearchPathOpts, ctx.LangOpts,
847+
ctx.ClangImporterOpts,
847848
Opts,
848-
ctx.getClangModuleLoader(),
849849
/*buildModuleCacheDirIfAbsent*/true,
850850
cacheDir,
851851
prebuiltCacheDir,
@@ -1084,20 +1084,12 @@ bool ModuleInterfaceLoader::buildSwiftModuleFromSwiftInterface(
10841084
bool SerializeDependencyHashes, bool TrackSystemDependencies,
10851085
ModuleInterfaceLoaderOptions LoaderOpts) {
10861086
InterfaceSubContextDelegateImpl astDelegate(SourceMgr, Diags,
1087-
SearchPathOpts, LangOpts,
1087+
SearchPathOpts, LangOpts, ClangOpts,
10881088
LoaderOpts,
1089-
/*clangImporter*/nullptr,
10901089
/*CreateCacheDirIfAbsent*/true,
10911090
CacheDir, PrebuiltCacheDir,
10921091
SerializeDependencyHashes,
10931092
TrackSystemDependencies);
1094-
// At this point we don't have an ClangImporter instance because the instance
1095-
// is created later when we create a new ASTContext to build the interface.
1096-
// Thus, we have to add these extra clang flags manually here to ensure explict
1097-
// module building works.
1098-
for (auto &Arg: ClangOpts.ExtraArgs) {
1099-
astDelegate.addExtraClangArg(Arg);
1100-
}
11011093
ModuleInterfaceBuilder builder(SourceMgr, Diags, astDelegate, InPath,
11021094
ModuleName, CacheDir, PrebuiltCacheDir,
11031095
LoaderOpts.disableInterfaceLock);
@@ -1238,19 +1230,13 @@ bool InterfaceSubContextDelegateImpl::extractSwiftInterfaceVersionAndArgs(
12381230
return false;
12391231
}
12401232

1241-
void InterfaceSubContextDelegateImpl::addExtraClangArg(StringRef arg) {
1242-
genericSubInvocation.getClangImporterOptions().ExtraArgs.push_back(arg);
1243-
GenericArgs.push_back("-Xcc");
1244-
GenericArgs.push_back(ArgSaver.save(arg));
1245-
}
1246-
12471233
InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
12481234
SourceManager &SM,
12491235
DiagnosticEngine &Diags,
12501236
const SearchPathOptions &searchPathOpts,
12511237
const LangOptions &langOpts,
1238+
const ClangImporterOptions &clangImporterOpts,
12521239
ModuleInterfaceLoaderOptions LoaderOpts,
1253-
ClangModuleLoader *clangImporter,
12541240
bool buildModuleCacheDirIfAbsent,
12551241
StringRef moduleCachePath,
12561242
StringRef prebuiltCachePath,
@@ -1288,22 +1274,21 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
12881274
StringRef explictSwiftModuleMap = searchPathOpts.ExplicitSwiftModuleMap;
12891275
genericSubInvocation.getSearchPathOptions().ExplicitSwiftModuleMap =
12901276
explictSwiftModuleMap;
1291-
if (clangImporter) {
1292-
// We need to add these extra clang flags because explict module building
1293-
// related flags are all there: -fno-implicit-modules, -fmodule-map-file=,
1294-
// and -fmodule-file=.
1295-
// If we don't add these flags, the interface will be built with implicit
1296-
// PCMs.
1297-
for (auto arg: static_cast<ClangImporter*>(clangImporter)->getExtraClangArgs()) {
1298-
addExtraClangArg(arg);
1299-
}
1300-
// Respect the detailed-record preprocessor setting of the parent context.
1301-
// This, and the "raw" clang module format it implicitly enables, are
1302-
// required by sourcekitd.
1303-
auto &Opts = clangImporter->getClangInstance().getPreprocessorOpts();
1304-
if (Opts.DetailedRecord) {
1305-
genericSubInvocation.getClangImporterOptions().DetailedPreprocessingRecord = true;
1306-
}
1277+
auto &subClangImporterOpts = genericSubInvocation.getClangImporterOptions();
1278+
// Respect the detailed-record preprocessor setting of the parent context.
1279+
// This, and the "raw" clang module format it implicitly enables, are
1280+
// required by sourcekitd.
1281+
subClangImporterOpts.DetailedPreprocessingRecord =
1282+
clangImporterOpts.DetailedPreprocessingRecord;
1283+
// We need to add these extra clang flags because explict module building
1284+
// related flags are all there: -fno-implicit-modules, -fmodule-map-file=,
1285+
// and -fmodule-file=.
1286+
// If we don't add these flags, the interface will be built with implicit
1287+
// PCMs.
1288+
subClangImporterOpts.ExtraArgs = clangImporterOpts.ExtraArgs;
1289+
for (auto arg: subClangImporterOpts.ExtraArgs) {
1290+
GenericArgs.push_back("-Xcc");
1291+
GenericArgs.push_back(ArgSaver.save(arg));
13071292
}
13081293

13091294
// Tell the genericSubInvocation to serialize dependency hashes if asked to do so.

lib/FrontendTool/ScanDependencies.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,8 @@ static bool scanModuleDependencies(CompilerInstance &instance,
641641
ModuleDependenciesCache cache;
642642
InterfaceSubContextDelegateImpl ASTDelegate(ctx.SourceMgr, ctx.Diags,
643643
ctx.SearchPathOpts, ctx.LangOpts,
644+
ctx.ClangImporterOpts,
644645
LoaderOpts,
645-
ctx.getClangModuleLoader(),
646646
/*buildModuleCacheDirIfAbsent*/false,
647647
ModuleCachePath,
648648
FEOpts.PrebuiltModuleCachePath,
@@ -839,8 +839,8 @@ bool swift::scanDependencies(CompilerInstance &instance) {
839839
ModuleInterfaceLoaderOptions LoaderOpts(FEOpts);
840840
InterfaceSubContextDelegateImpl ASTDelegate(ctx.SourceMgr, ctx.Diags,
841841
ctx.SearchPathOpts, ctx.LangOpts,
842+
ctx.ClangImporterOpts,
842843
LoaderOpts,
843-
ctx.getClangModuleLoader(),
844844
/*buildModuleCacheDirIfAbsent*/false,
845845
ModuleCachePath,
846846
FEOpts.PrebuiltModuleCachePath,

tools/swift-api-digester/swift-api-digester.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -2425,9 +2425,8 @@ static int diagnoseModuleChange(StringRef LeftPath, StringRef RightPath,
24252425
LeftCollector.deSerialize(LeftPath);
24262426
SwiftDeclCollector RightCollector(Ctx);
24272427
RightCollector.deSerialize(RightPath);
2428-
diagnoseModuleChange(Ctx, LeftCollector.getSDKRoot(), RightCollector.getSDKRoot(),
2429-
OutputPath, std::move(ProtocolReqAllowlist));
2430-
return options::CompilerStyleDiags && Ctx.getDiags().hadAnyError() ? 1 : 0;
2428+
return diagnoseModuleChange(Ctx, LeftCollector.getSDKRoot(),
2429+
RightCollector.getSDKRoot(), OutputPath, std::move(ProtocolReqAllowlist));
24312430
}
24322431

24332432
static void populateAliasChanges(NodeMap &AliasMap, DiffVector &AllItems,

0 commit comments

Comments
 (0)