Skip to content

Commit 2ad47af

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 2ad47af

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
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-6
Original file line numberDiff line numberDiff line change
@@ -2014,12 +2014,7 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
20142014
GenericArgs.push_back(blocklist);
20152015
}
20162016

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

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

0 commit comments

Comments
 (0)