Skip to content

Commit 3037564

Browse files
authored
Merge pull request #73640 from kavon/6.0-use-newer-cxx-moveonly-import-by-default
[6.0🍒] CxxInterop: Use newer cxx moveonly import by default
2 parents 1c3b994 + 49bf2c6 commit 3037564

13 files changed

+32
-39
lines changed

SwiftCompilerSources/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ function(add_swift_compiler_modules_library name)
120120
"-Xfrontend" "${SWIFT_MIN_RUNTIME_VERSION}")
121121
endif()
122122
list(APPEND swift_compile_options "-Xfrontend" "-disable-implicit-string-processing-module-import")
123+
124+
# We cannot use Unsafe*Pointer when importing C++ move-only types until the
125+
# host libraries are updated to Swift 6.0, because that importing strategy
126+
# requires _Pointer have its Pointee: ~Copyable. (rdar://128013193)
127+
list(APPEND swift_compile_options "-Xfrontend" "-cxx-interop-use-opaque-pointer-for-moveonly")
123128
endif()
124129

125130
if(CMAKE_BUILD_TYPE STREQUAL "Debug")

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ namespace swift {
328328
/// when importing Swift modules that enable C++ interoperability.
329329
bool RequireCxxInteropToImportCxxInteropModule = true;
330330

331+
// Workaround for bug when building SwiftCompilerSources (rdar://128013193)
332+
bool CxxInteropUseOpaquePointerForMoveOnly = false;
333+
331334
/// On Darwin platforms, use the pre-stable ABI's mark bit for Swift
332335
/// classes instead of the stable ABI's bit. This is needed when
333336
/// targeting OSes prior to macOS 10.14.4 and iOS 12.2, where

include/swift/Option/FrontendOptions.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,11 @@ def cxx_interop_disable_requirement_at_import :
935935
HelpText<"Do not require C++ interoperability to be enabled when importing a Swift module that enables C++ interoperability">,
936936
Flags<[FrontendOption, HelpHidden]>;
937937

938+
def cxx_interop_use_opaque_pointer_for_moveonly :
939+
Flag<["-"], "cxx-interop-use-opaque-pointer-for-moveonly">,
940+
HelpText<"Testing flag that will be eliminated soon. Do not use.">,
941+
Flags<[FrontendOption, HelpHidden]>;
942+
938943
def use_malloc : Flag<["-"], "use-malloc">,
939944
HelpText<"Allocate internal data structures using malloc "
940945
"(for memory debugging)">;

lib/ClangImporter/ClangImporter.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5778,16 +5778,9 @@ cloneBaseMemberDecl(ValueDecl *decl, DeclContext *newContext) {
57785778
if (auto var = dyn_cast<VarDecl>(decl)) {
57795779
auto oldContext = var->getDeclContext();
57805780
auto oldTypeDecl = oldContext->getSelfNominalTypeDecl();
5781-
// If the base type is non-copyable, we cannot synthesize the accessor,
5782-
// because its implementation would use `UnsafePointer<BaseTy>`, and that
5783-
// triggers a bug when building SwiftCompilerSources. (rdar://128013193)
5784-
//
5785-
// We cannot use `ty->isNoncopyable()` here because that would create a
5786-
// cyclic dependency between ModuleQualifiedLookupRequest and
5787-
// LookupConformanceInModuleRequest, so we check for the presence of
5788-
// move-only attribute that is implicitly added to non-copyable C++ types by
5789-
// ClangImporter.
5790-
if (oldTypeDecl->getAttrs().hasAttribute<MoveOnlyAttr>())
5781+
// FIXME: this is a workaround for rdar://128013193
5782+
if (oldTypeDecl->getAttrs().hasAttribute<MoveOnlyAttr>() &&
5783+
context.LangOpts.CxxInteropUseOpaquePointerForMoveOnly)
57915784
return nullptr;
57925785

57935786
auto rawMemory = allocateMemoryForDecl<VarDecl>(var->getASTContext(),

lib/ClangImporter/ImportType.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -509,19 +509,12 @@ namespace {
509509
return importFunctionPointerLikeType(*type, pointeeType);
510510
}
511511

512-
// We cannot specify UnsafePointer<T> with a non-copyable type T just yet,
513-
// because it triggers a bug when building SwiftCompilerSources.
514-
// (rdar://128013193)
515-
//
516-
// We cannot use `ty->isNoncopyable()` here because that would create a
517-
// cyclic dependency between ModuleQualifiedLookupRequest and
518-
// LookupConformanceInModuleRequest, so we check for the presence of
519-
// move-only attribute that is implicitly added to non-copyable C++ types
520-
// by ClangImporter.
512+
// FIXME: this is a workaround for rdar://128013193
521513
if (pointeeType && pointeeType->getAnyNominal() &&
522514
pointeeType->getAnyNominal()
523515
->getAttrs()
524-
.hasAttribute<MoveOnlyAttr>()) {
516+
.hasAttribute<MoveOnlyAttr>() &&
517+
Impl.SwiftContext.LangOpts.CxxInteropUseOpaquePointerForMoveOnly) {
525518
auto opaquePointerDecl = Impl.SwiftContext.getOpaquePointerDecl();
526519
if (!opaquePointerDecl)
527520
return Type();

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
12671267
Opts.CxxInteropGettersSettersAsProperties = Args.hasArg(OPT_cxx_interop_getters_setters_as_properties);
12681268
Opts.RequireCxxInteropToImportCxxInteropModule =
12691269
!Args.hasArg(OPT_cxx_interop_disable_requirement_at_import);
1270+
Opts.CxxInteropUseOpaquePointerForMoveOnly =
1271+
Args.hasArg(OPT_cxx_interop_use_opaque_pointer_for_moveonly);
12701272

12711273
Opts.VerifyAllSubstitutionMaps |= Args.hasArg(OPT_verify_all_substitution_maps);
12721274

test/Interop/Cxx/class/move-only/inherited-field-access-irgen.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
// REQUIRES: rdar128013193
55

6-
// REQUIRES: rdar128013193
7-
86
import MoveOnlyCxxValueType
97

108
func testGetX() -> CInt {

test/Interop/Cxx/class/move-only/inherited-field-access-silgen.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
// REQUIRES: rdar128013193
55

6-
// REQUIRES: rdar128013193
7-
86
import MoveOnlyCxxValueType
97

108
func testGetX() -> CInt {

test/Interop/Cxx/class/move-only/move-only-cxx-value-type-generics.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// RUN: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=upcoming-swift -O -Xfrontend -sil-verify-none)
33
//
44
// REQUIRES: executable_test
5-
// REQUIRES: GH_ISSUE_70246
65

76

87

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
// RUN: %target-swift-ide-test -print-module -module-to-print=MoveOnlyCxxValueType -I %S/Inputs -cxx-interoperability-mode=upcoming-swift -source-filename=x | %FileCheck %s --check-prefix=CHECK
1+
// RUN: %target-swift-ide-test -print-module -module-to-print=MoveOnlyCxxValueType -I %S/Inputs -cxx-interoperability-mode=upcoming-swift -source-filename=x | %FileCheck %s
22

3-
// CHECK: func getNonCopyablePtr() -> OpaquePointer
4-
// CHECK: func getNonCopyableDerivedPtr() -> OpaquePointer
5-
6-
// FIXME: would prefer to have this (rdar://128013193)
7-
// func getNonCopyablePtr() -> UnsafeMutablePointer<NonCopyable>
8-
// func getNonCopyableDerivedPtr() -> UnsafeMutablePointer<NonCopyableDerived>
3+
// CHECK: func getNonCopyablePtr() -> UnsafeMutablePointer<NonCopyable>
4+
// CHECK: func getNonCopyableDerivedPtr() -> UnsafeMutablePointer<NonCopyableDerived>

test/Interop/Cxx/class/move-only/move-only-cxx-value-type.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// RUN: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=upcoming-swift)
2-
// -- FIXME: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=upcoming-swift -D HAS_RDAR_128013193)
2+
// RUN: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=upcoming-swift -D HAS_NONCOPYABLE_GENERICS)
33
// RUN: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=swift-5.9 -O)
44
// RUN: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=swift-6 -O)
5+
// RUN: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=swift-6 -O -D HAS_NONCOPYABLE_GENERICS)
56

67
// REQUIRES: executable_test
78

@@ -28,7 +29,7 @@ MoveOnlyCxxValueType.test("Test derived move only type member access") {
2829
var k = c.method(-3)
2930
expectEqual(k, -6)
3031
expectEqual(c.method(1), 2)
31-
#if HAS_RDAR_128013193
32+
#if HAS_NONCOPYABLE_GENERICS
3233
k = c.x
3334
expectEqual(k, 2)
3435
c.x = 11
@@ -59,7 +60,7 @@ MoveOnlyCxxValueType.test("Test move only field access in holder") {
5960
expectEqual(c.x.x, 5)
6061
}
6162

62-
#if HAS_RDAR_128013193
63+
#if HAS_NONCOPYABLE_GENERICS
6364
MoveOnlyCxxValueType.test("Test move only field access in derived holder") {
6465
var c = NonCopyableHolderDerivedDerived(-11)
6566
var k = borrowNC(c.x)

test/Interop/Cxx/operators/move-only/move-only-synthesized-properties.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// RUN: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=swift-5.9)
22
// RUN: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=swift-6)
33
// RUN: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=upcoming-swift)
4-
// -- FIXME: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=upcoming-swift -D HAS_RDAR_128013193)
4+
// RUN: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=upcoming-swift -D HAS_NONCOPYABLE_GENERICS)
55
// RUN: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=swift-5.9 -O)
66
// RUN: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=swift-6 -O)
77
// RUN: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=upcoming-swift -O)
8-
// -- FIXME: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=upcoming-swift -O -D HAS_RDAR_128013193)
8+
// RUN: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=upcoming-swift -O -D HAS_NONCOPYABLE_GENERICS)
99
//
1010
// REQUIRES: executable_test
1111

@@ -92,7 +92,7 @@ MoveOnlyCxxOperators.test("testNonCopyableHolderValueMutDeref pointee value") {
9292
expectEqual(k.x, k2.x)
9393
}
9494

95-
#if HAS_RDAR_128013193
95+
#if HAS_NONCOPYABLE_GENERICS
9696
MoveOnlyCxxOperators.test("NonCopyableHolderConstDerefDerivedDerived pointee borrow") {
9797
let holder = NonCopyableHolderConstDerefDerivedDerived(11)
9898
var k = borrowNC(holder.pointee)

test/SILOptimizer/moveonly_optional_force_unwrap.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -enable-experimental-feature NoncopyableGenerics -emit-sil -verify %s
1+
// RUN: %target-swift-frontend -emit-sil -verify %s
22

33
struct NC: ~Copyable {
44
borrowing func borrow() {}

0 commit comments

Comments
 (0)