Skip to content

Commit f11e2af

Browse files
authored
[cxx-interop] Always import cxx shim when cxx-interop is enabled (#60336)
1 parent 182946e commit f11e2af

File tree

8 files changed

+18
-6
lines changed

8 files changed

+18
-6
lines changed

include/swift/Frontend/Frontend.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,10 @@ class CompilerInstance {
563563
/// i.e. if it can be found.
564564
bool canImportSwiftStringProcessing() const;
565565

566+
/// Whether the CxxShim library can be imported
567+
/// i.e. if it can be found.
568+
bool canImportCxxShim() const;
569+
566570
/// Gets the SourceFile which is the primary input for this CompilerInstance.
567571
/// \returns the primary SourceFile, or nullptr if there is no primary input;
568572
/// if there are _multiple_ primary inputs, fails with an assertion.

include/swift/Strings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ constexpr static const StringLiteral SWIFT_DISTRIBUTED_NAME = "Distributed";
3030
constexpr static const StringLiteral SWIFT_STRING_PROCESSING_NAME = "_StringProcessing";
3131
/// The name of the SwiftShims module, which contains private stdlib decls.
3232
constexpr static const StringLiteral SWIFT_SHIMS_NAME = "SwiftShims";
33+
/// The name of the CxxShim module, which contains a cxx casting utility.
34+
constexpr static const StringLiteral CXX_SHIM_NAME = "CxxShim";
3335
/// The name of the Builtin module, which contains Builtin functions.
3436
constexpr static const StringLiteral BUILTIN_NAME = "Builtin";
3537
/// The name of the clang imported header module.

lib/Frontend/Frontend.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,14 @@ bool CompilerInstance::canImportSwiftStringProcessing() const {
861861
return getASTContext().canImportModule(modulePath);
862862
}
863863

864+
bool CompilerInstance::canImportCxxShim() const {
865+
ImportPath::Module::Builder builder(
866+
getASTContext().getIdentifier(CXX_SHIM_NAME));
867+
auto modulePath = builder.get();
868+
return getASTContext().canImportModule(modulePath) &&
869+
!Invocation.getFrontendOptions().InputsAndOutputs.hasModuleInterfaceOutputPath();
870+
}
871+
864872
ImplicitImportInfo CompilerInstance::getImplicitImportInfo() const {
865873
auto &frontendOpts = Invocation.getFrontendOptions();
866874

@@ -915,6 +923,10 @@ ImplicitImportInfo CompilerInstance::getImplicitImportInfo() const {
915923
}
916924
}
917925

926+
if (Invocation.getLangOptions().EnableCXXInterop && canImportCxxShim()) {
927+
pushImport(CXX_SHIM_NAME);
928+
}
929+
918930
imports.ShouldImportUnderlyingModule = frontendOpts.ImportUnderlyingModule;
919931
imports.BridgingHeaderPath = frontendOpts.ImplicitObjCHeaderPath;
920932
return imports;

test/Interop/Cxx/class/inheritance/fields.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// UNSUPPORTED: OS=windows-msvc
77

88
import StdlibUnittest
9-
import CxxShim
109
import Fields
1110

1211
var FieldsTestSuite = TestSuite("Getting and setting fields in base classes")

test/Interop/Cxx/class/inheritance/functions.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// XFAIL: OS=windows-msvc
66

77
import StdlibUnittest
8-
import CxxShim
98
import Functions
109

1110
var FunctionsTestSuite = TestSuite("Calling functions in base classes")

test/Interop/Cxx/foreign-reference/pod.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// XFAIL: OS=windows-msvc
55

66
import StdlibUnittest
7-
import CxxShim
87
import POD
98

109
extension IntPair {

test/Interop/Cxx/operators/member-inline.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// XFAIL: OS=windows-msvc
66

77
import MemberInline
8-
import CxxShim
98
import StdlibUnittest
109

1110
var OperatorsTestSuite = TestSuite("Operators")

validation-test/ParseableInterface/verify_all_overlays.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@
5454
output_path = os.path.join(output_dir, module_name + ".swiftmodule")
5555
compiler_args = ["-o", output_path, "-module-name", module_name,
5656
interface_file]
57-
if module_name == "std":
58-
compiler_args += ["-enable-experimental-cxx-interop"]
5957

6058
status = subprocess.call(compiler_invocation +
6159
compiler_args)

0 commit comments

Comments
 (0)