Skip to content

Commit 6414440

Browse files
committed
[Explicit Module Builds] Propagate the C++ Interop mode to interface sub-invocations and dependency scanner
1 parent ddb83d1 commit 6414440

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ class SerializedModuleLoaderBase : public ModuleLoader {
171171
std::string headerImport;
172172
};
173173

174-
static BinaryModuleImports
175-
getImportsOfModule(const ModuleFileSharedCore &loadedModule,
174+
llvm::ErrorOr<BinaryModuleImports>
175+
getImportsOfModule(Twine modulePath,
176176
ModuleLoadingBehavior transitiveBehavior,
177177
StringRef packageName, bool isTestableImport);
178178

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,9 @@ validateCxxInteropCompatibilityMode(StringRef mode) {
506506
// Swift 5 is the default language version.
507507
if (mode == "swift-5.9")
508508
return {CxxCompatMode::enabled, version::Version({5})};
509+
// Note: If this is updated, corresponding code in
510+
// InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl needs
511+
// to be updated also.
509512
return {CxxCompatMode::invalid, {}};
510513
}
511514

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,6 +1969,31 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
19691969
GenericArgs.push_back("-blocklist-file");
19701970
GenericArgs.push_back(blocklist);
19711971
}
1972+
1973+
// For now, we only inherit the C++ interoperability mode in
1974+
// Explicit Module Builds.
1975+
if (langOpts.EnableCXXInterop &&
1976+
(frontendOpts.DisableImplicitModules ||
1977+
LoaderOpts.requestedAction ==
1978+
FrontendOptions::ActionType::ScanDependencies)) {
1979+
// Modelled after a reverse of validateCxxInteropCompatibilityMode
1980+
genericSubInvocation.getLangOptions().EnableCXXInterop = true;
1981+
genericSubInvocation.getLangOptions().cxxInteropCompatVersion =
1982+
langOpts.cxxInteropCompatVersion;
1983+
std::string compatVersion;
1984+
if (langOpts.cxxInteropCompatVersion.empty())
1985+
compatVersion = "default";
1986+
else if (langOpts.cxxInteropCompatVersion[0] == 5)
1987+
compatVersion = "swift-5.9";
1988+
else if (langOpts.cxxInteropCompatVersion[0] ==
1989+
version::getUpcomingCxxInteropCompatVersion())
1990+
compatVersion = "upcoming-swift";
1991+
else // TODO: This may need to be updated once more versions are added
1992+
compatVersion = "default";
1993+
1994+
GenericArgs.push_back(
1995+
ArgSaver.save("-cxx-interoperability-mode=" + compatVersion));
1996+
}
19721997
}
19731998

19741999
/// Calculate an output filename in \p genericSubInvocation's cache path that

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,13 @@ SerializedModuleLoaderBase::getImportsOfModule(
422422
if (dotPos != std::string::npos)
423423
moduleName = moduleName.slice(0, dotPos);
424424

425+
// Reverse rewrite of user-specified C++ standard
426+
// library module name to one used in the modulemap.
427+
// TODO: If we are going to do this for more than this module,
428+
// we will need a centralized system for doing module import name remap.
429+
if (moduleName == Ctx.Id_CxxStdlib.str())
430+
moduleName = "std";
431+
425432
importedModuleNames.insert(moduleName);
426433
}
427434

0 commit comments

Comments
 (0)