Skip to content

Commit b6a8af5

Browse files
committed
DependenciesScanner: move -fapinotes-swift-version to extra PCM arguments
Swift interface files may specify the effective language version to use. When building a PCM loadable for these textual interface files, we should respect the language version. This patch moves -fapinotes-swift-version from the generic PCM commands to the extra PCM arguments owned by each loading Swift module.
1 parent 0aa6918 commit b6a8af5

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

lib/ClangImporter/ClangModuleDependencyScanner.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,19 @@ void ClangImporter::recordModuleDependencies(
231231
// Add all args inheritted from creating the importer.
232232
auto It = allArgs.begin();
233233
while(It != allArgs.end()) {
234+
StringRef arg = *It;
234235
// Remove the -target arguments because we should use the target triple
235236
// from the depending Swift modules.
236-
if (*It == "-target") {
237+
if (arg == "-target") {
237238
It += 2;
238-
continue;
239+
} else if (arg.startswith("-fapinotes-swift-version=")) {
240+
// Remove the apinotes version because we should use the language version
241+
// specified in the interface file.
242+
It += 1;
243+
} else {
244+
addClangArg(*It);
245+
++ It;
239246
}
240-
addClangArg(*It);
241-
++ It;
242247
}
243248

244249
// Swift frontend action: -emit-pcm

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,13 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
10501050
GenericArgs.push_back(triple);
10511051
}
10521052

1053+
// Inherit the Swift language version
1054+
subInvocation.getLangOptions().EffectiveLanguageVersion =
1055+
LangOpts.EffectiveLanguageVersion;
1056+
GenericArgs.push_back("-swift-version");
1057+
GenericArgs.push_back(ArgSaver.save(subInvocation.getLangOptions()
1058+
.EffectiveLanguageVersion.asAPINotesVersionString()));
1059+
10531060
subInvocation.setImportSearchPaths(SearchPathOpts.ImportSearchPaths);
10541061
llvm::for_each(SearchPathOpts.ImportSearchPaths,
10551062
[&](const std::string &path) {
@@ -1400,9 +1407,15 @@ bool InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleN
14001407
}
14011408
info.BuildArguments = BuildArgs;
14021409
info.Hash = CacheHash;
1403-
std::array<StringRef, 4> ExtraPCMArgs = {"-Xcc", "-target", "-Xcc",
1404-
// PCMs should use the target tripe the interface will be using to build
1405-
*(std::find(BuildArgs.rbegin(), BuildArgs.rend(), "-target") - 1)};
1410+
auto target = *(std::find(BuildArgs.rbegin(), BuildArgs.rend(), "-target") - 1);
1411+
auto langVersion = *(std::find(BuildArgs.rbegin(), BuildArgs.rend(),
1412+
"-swift-version") - 1);
1413+
std::array<StringRef, 6> ExtraPCMArgs = {
1414+
// PCMs should use the target triple the interface will be using to build
1415+
"-Xcc", "-target", "-Xcc", target,
1416+
// PCMs should use the effective Swift language version for apinotes.
1417+
"-Xcc", ArgSaver.save((llvm::Twine("-fapinotes-swift-version=") + langVersion).str())
1418+
};
14061419
info.ExtraPCMArgs = ExtraPCMArgs;
14071420
// Run the action under the sub compiler instance.
14081421
return action(info);

lib/FrontendTool/ScanDependencies.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,15 @@ bool swift::scanDependencies(CompilerInstance &instance) {
426426
llvm::SmallString<32> mainModulePath = mainModule->getName().str();
427427
llvm::sys::path::replace_extension(mainModulePath, newExt);
428428

429+
std::string apinotesVer = (llvm::Twine("-fapinotes-swift-version=")
430+
+ instance.getASTContext().LangOpts.EffectiveLanguageVersion
431+
.asAPINotesVersionString()).str();
429432
// Compute the dependencies of the main module.
430433
auto mainDependencies =
431434
ModuleDependencies::forMainSwiftModule(mainModulePath.str().str(), {
432-
"-Xcc", "-target", "-Xcc", instance.getASTContext().LangOpts.Target.str()
435+
// ExtraPCMArgs
436+
"-Xcc", "-target", "-Xcc", instance.getASTContext().LangOpts.Target.str(),
437+
"-Xcc", apinotesVer
433438
});
434439
{
435440
llvm::StringSet<> alreadyAddedModules;

test/ScanDependencies/module_deps.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import SubE
6666
// CHECK-NEXT: "-Xcc",
6767
// CHECK-NEXT: "-target",
6868
// CHECK-NEXT: "-Xcc",
69+
// CHECK: "-fapinotes-swift-version=4"
6970

7071
// CHECK: "bridgingHeader":
7172
// CHECK-NEXT: "path":
@@ -134,7 +135,11 @@ import SubE
134135
// CHECK: "G"
135136
// CHECK: "-swift-version"
136137
// CHECK: "5"
137-
// CHECK: ]
138+
// CHECK: ],
139+
// CHECK" "extraPcmArgs": [
140+
// CHECK" "-target",
141+
// CHECK" "-fapinotes-swift-version=5"
142+
// CHECK" ]
138143

139144
/// --------Swift module Swift
140145
// CHECK-LABEL: "modulePath": "Swift.swiftmodule",

0 commit comments

Comments
 (0)