Skip to content

Commit c40ea46

Browse files
committed
Hard-code the 'Darwin' module as having been built without C++ interop
Textual interfaces for 'Darwin' built with recent compilers specify that it is built witout C++ interop enabled. However, to ensure compatibility with versions of the 'Darwin' module built with older compilers, we hard-code this fact. This is required to break the module cycle that occurs when building the 'Darwin' module with C++ interop enabled, where the underlying 'Darwin' clang module depends on C++ standard library for which the compiler brings in the 'CxxStdlib' Swift overlay, which depends on 'Darwin'.
1 parent a31dd40 commit c40ea46

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ namespace swift {
4545

4646
struct DiagnosticBehavior;
4747
class DiagnosticEngine;
48+
class FrontendOptions;
4849

4950
/// Kind of implicit platform conditions.
5051
enum class PlatformConditionKind {
@@ -339,7 +340,8 @@ namespace swift {
339340
std::optional<version::Version> FormalCxxInteropMode;
340341

341342
void setCxxInteropFromArgs(llvm::opt::ArgList &Args,
342-
swift::DiagnosticEngine &Diags);
343+
swift::DiagnosticEngine &Diags,
344+
const FrontendOptions &FrontendOpts);
343345

344346
/// The C++ standard library used for the current build. This can differ
345347
/// from the default C++ stdlib on a particular platform when `-Xcc

lib/DependencyScan/ModuleDependencyScanner.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,8 @@ void ModuleDependencyScanner::resolveSwiftOverlayDependenciesForModule(
14781478

14791479
// If the textual interface was built without C++ interop, do not query
14801480
// the C++ Standard Library Swift overlay for its compilation.
1481-
if (llvm::find(commandLine, "-formal-cxx-interoperability-mode=off") ==
1481+
if (moduleID.ModuleName != "Darwin" &&
1482+
llvm::find(commandLine, "-formal-cxx-interoperability-mode=off") ==
14821483
commandLine.end()) {
14831484
for (const auto &clangDepName : allClangDependencies) {
14841485
// If this Clang module is a part of the C++ stdlib, and we haven't

lib/DriverTool/swift_symbolgraph_extract_main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args,
214214
Options.AvailabilityIsBlockList = A->getOption().matches(OPT_block_availability_platforms);
215215
}
216216

217-
Invocation.getLangOptions().setCxxInteropFromArgs(ParsedArgs, Diags);
217+
Invocation.getLangOptions().setCxxInteropFromArgs(ParsedArgs, Diags,
218+
Invocation.getFrontendOptions());
218219

219220
std::string InstanceSetupError;
220221
if (CI.setup(Invocation, InstanceSetupError)) {

lib/DriverTool/swift_synthesize_interface_main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ int swift_synthesize_interface_main(ArrayRef<const char *> Args,
133133
Invocation.setImportSearchPaths(ImportSearchPaths);
134134

135135
Invocation.getLangOptions().EnableObjCInterop = Target.isOSDarwin();
136-
Invocation.getLangOptions().setCxxInteropFromArgs(ParsedArgs, Diags);
136+
Invocation.getLangOptions().setCxxInteropFromArgs(ParsedArgs, Diags,
137+
Invocation.getFrontendOptions());
137138

138139
std::string ModuleCachePath = "";
139140
if (auto *A = ParsedArgs.getLastArg(OPT_module_cache_path)) {

lib/Frontend/CompilerInvocation.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,8 @@ static void diagnoseCxxInteropCompatMode(Arg *verArg, ArgList &Args,
682682
}
683683

684684
void LangOptions::setCxxInteropFromArgs(ArgList &Args,
685-
swift::DiagnosticEngine &Diags) {
685+
swift::DiagnosticEngine &Diags,
686+
const FrontendOptions &FrontendOpts) {
686687
if (Arg *A = Args.getLastArg(options::OPT_cxx_interoperability_mode)) {
687688
if (Args.hasArg(options::OPT_enable_experimental_cxx_interop)) {
688689
Diags.diagnose(SourceLoc(), diag::dont_enable_interop_and_compat);
@@ -737,7 +738,10 @@ void LangOptions::setCxxInteropFromArgs(ArgList &Args,
737738
// version, and is either 4, 5, 6, or 7 (even though only 5.9 and 6.* make
738739
// any sense). For now, we don't actually care about the version, so we'll
739740
// just use version 6 (i.e., 'swift-6') to mean that C++ interop mode is on.
740-
if (EnableCXXInterop)
741+
//
742+
// FIXME: Always declare the 'Darwin' module as formally having been built
743+
// without C++Interop, for compatibility with prior versions.
744+
if (EnableCXXInterop && (FrontendOpts.ModuleName.compare("Darwin") != 0))
741745
FormalCxxInteropMode = {6};
742746
else
743747
FormalCxxInteropMode = std::nullopt;
@@ -1560,7 +1564,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
15601564
if (const Arg *A = Args.getLastArg(OPT_clang_target_variant))
15611565
Opts.ClangTargetVariant = llvm::Triple(A->getValue());
15621566

1563-
Opts.setCxxInteropFromArgs(Args, Diags);
1567+
Opts.setCxxInteropFromArgs(Args, Diags, FrontendOpts);
15641568
if (!Args.hasArg(options::OPT_formal_cxx_interoperability_mode))
15651569
ModuleInterfaceOpts.PublicFlags.IgnorableFlags +=
15661570
" " + printFormalCxxInteropVersion(Opts);

0 commit comments

Comments
 (0)