Skip to content

Commit f2fbfaa

Browse files
committed
[cxx-interop] Do not emit C++ interop flag in textual interfaces
This makes sure that the compiler does not emit `-enable-experimental-cxx-interop`/`-cxx-interoperability-mode` flags in `.swiftinterface` files. Those flags were breaking explicit module builds. The module can still be rebuilt from its textual interface if C++ interop was enabled in the current compilation. rdar://140203932
1 parent ec85589 commit f2fbfaa

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

include/swift/Option/Options.td

+2-2
Original file line numberDiff line numberDiff line change
@@ -794,12 +794,12 @@ def enable_experimental_concise_pound_file : Flag<["-"],
794794

795795
def enable_experimental_cxx_interop :
796796
Flag<["-"], "enable-experimental-cxx-interop">,
797-
Flags<[NoDriverOption, FrontendOption, HelpHidden, ModuleInterfaceOption]>,
797+
Flags<[NoDriverOption, FrontendOption, HelpHidden]>,
798798
HelpText<"Enable experimental C++ interop code generation and config directives">;
799799

800800
def cxx_interoperability_mode :
801801
Joined<["-"], "cxx-interoperability-mode=">,
802-
Flags<[FrontendOption, ModuleInterfaceOption, SwiftSymbolGraphExtractOption,
802+
Flags<[FrontendOption, SwiftSymbolGraphExtractOption,
803803
SwiftSynthesizeInterfaceOption]>,
804804
HelpText<"Enables C++ interoperability; pass 'default' to enable or 'off' to disable">;
805805

lib/Frontend/ModuleInterfaceLoader.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -2016,10 +2016,7 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
20162016

20172017
// For now, we only inherit the C++ interoperability mode in
20182018
// Explicit Module Builds.
2019-
if (langOpts.EnableCXXInterop &&
2020-
(frontendOpts.DisableImplicitModules ||
2021-
LoaderOpts.requestedAction ==
2022-
FrontendOptions::ActionType::ScanDependencies)) {
2019+
if (langOpts.EnableCXXInterop) {
20232020
// Modelled after a reverse of validateCxxInteropCompatibilityMode
20242021
genericSubInvocation.getLangOptions().EnableCXXInterop = true;
20252022
genericSubInvocation.getLangOptions().cxxInteropCompatVersion =

lib/Sema/TypeCheckAccess.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "swift/AST/Pattern.h"
2929
#include "swift/AST/TypeCheckRequests.h"
3030
#include "swift/Basic/Assertions.h"
31+
#include "clang/Basic/Module.h"
3132
#include "clang/AST/DeclCXX.h"
3233
#include "clang/AST/DeclObjC.h"
3334

@@ -1887,6 +1888,9 @@ bool isFragileClangNode(const ClangNode &node) {
18871888
if (auto *rd = dyn_cast<clang::RecordDecl>(decl)) {
18881889
if (!isa<clang::CXXRecordDecl>(rd))
18891890
return false;
1891+
// Types in the Darwin module are not always guarded by `extern "C"`.
1892+
if (rd->getOwningModule()->getTopLevelModuleName() == "Darwin")
1893+
return false;
18901894
return !rd->getDeclContext()->isExternCContext();
18911895
}
18921896
return true;

test/Interop/Cxx/modules/emit-module-interface.swift

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
// Check if fragile Swift interface with struct
44
// extensions can be reparsed:
55
// RUN: %target-swift-frontend -swift-version 5 -typecheck -emit-module-interface-path %t/UsesCxxStruct.swiftinterface %s -I %S/Inputs -swift-version 5 -enable-experimental-cxx-interop %S/Inputs/namespace-extension-lib.swift
6-
// RUN: %target-swift-frontend -swift-version 5 -typecheck-module-from-interface %t/UsesCxxStruct.swiftinterface -I %S/Inputs
6+
// RUN: %target-swift-frontend -swift-version 5 -typecheck-module-from-interface %t/UsesCxxStruct.swiftinterface -I %S/Inputs -enable-experimental-cxx-interop
77
// RUN: %FileCheck --input-file=%t/UsesCxxStruct.swiftinterface %s
8-
// CHECK: -enable-experimental-cxx-interop
8+
9+
// The textual module interface should not contain the C++ interop flag.
10+
// CHECK-NOT: -enable-experimental-cxx-interop
11+
// CHECK-NOT: -cxx-interoperability-mode
912

1013

1114
// Check if resilient Swift interface with builtin
1215
// type extensions can be reparsed:
1316
// RUN: %target-swift-emit-module-interface(%t/ResilientStruct.swiftinterface) %s -I %S/Inputs -enable-library-evolution -swift-version 5 -enable-experimental-cxx-interop %S/Inputs/namespace-extension-lib.swift -DRESILIENT
14-
// RUN: %target-swift-typecheck-module-from-interface(%t/ResilientStruct.swiftinterface) -I %S/Inputs -DRESILIENT
17+
// RUN: %target-swift-typecheck-module-from-interface(%t/ResilientStruct.swiftinterface) -I %S/Inputs -DRESILIENT -enable-experimental-cxx-interop
1518
// RUN: %FileCheck --input-file=%t/ResilientStruct.swiftinterface %s
1619

1720
import Namespaces

validation-test/ParseableInterface/verify_all_overlays.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
"DifferentiationUnittest",
4747
"Swift",
4848
"SwiftLang",
49-
"std", # swiftstd uses `-module-interface-preserve-types-as-written`
49+
# swiftCxxStdlib uses `-module-interface-preserve-types-as-written`
50+
"CxxStdlib",
5051
]:
5152
continue
5253

0 commit comments

Comments
 (0)