Skip to content

Commit 623d3d2

Browse files
committed
[cxx-interop] review fixes for non-copyable patch, ensure we only enable this in upcoming Swift
1 parent ec931c8 commit 623d3d2

12 files changed

+34
-21
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4949,14 +4949,14 @@ const clang::CXXMethodDecl *getCalledBaseCxxMethod(FuncDecl *baseMember) {
49494949
if (!returnStmt)
49504950
return nullptr;
49514951
Expr *returnExpr = returnStmt->getResult();
4952-
// Look through a potential 'reinterpresetCast' that can be used
4952+
// Look through a potential 'reinterpretCast' that can be used
49534953
// to cast UnsafeMutablePointer to UnsafePointer in the synthesized
49544954
// Swift body for `.pointee`.
49554955
if (auto *ce = dyn_cast<CallExpr>(returnExpr)) {
49564956
if (auto *v = ce->getCalledValue()) {
49574957
if (v->getModuleContext() ==
49584958
baseMember->getASTContext().TheBuiltinModule &&
4959-
v->getBaseName().getIdentifier().str() == "reinterpretCast") {
4959+
v->getBaseIdentifier().is("reinterpretCast")) {
49604960
returnExpr = ce->getArgs()->get(0).getExpr();
49614961
}
49624962
}

lib/ClangImporter/ImportDecl.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,12 +2193,23 @@ namespace {
21932193
Impl.ImportedDecls[{decl->getCanonicalDecl(), getVersion()}] = result;
21942194

21952195
if (recordHasMoveOnlySemantics(decl)) {
2196-
if (decl->isInStdNamespace() && decl->getName() == "promise") {
2197-
// Do not import std::promise.
2196+
if (Impl.isCxxInteropCompatVersionAtLeast(
2197+
version::getUpcomingCxxInteropCompatVersion())) {
2198+
if (decl->isInStdNamespace() && decl->getName() == "promise") {
2199+
// Do not import std::promise.
2200+
return nullptr;
2201+
}
2202+
result->getAttrs().add(new (Impl.SwiftContext)
2203+
MoveOnlyAttr(/*Implicit=*/true));
2204+
} else {
2205+
Impl.addImportDiagnostic(
2206+
decl,
2207+
Diagnostic(
2208+
diag::move_only_requires_move_only,
2209+
Impl.SwiftContext.AllocateCopy(decl->getNameAsString())),
2210+
decl->getLocation());
21982211
return nullptr;
21992212
}
2200-
result->getAttrs().add(new (Impl.SwiftContext)
2201-
MoveOnlyAttr(/*Implicit=*/true));
22022213
}
22032214

22042215
// FIXME: Figure out what to do with superclasses in C++. One possible

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-emit-irgen -I %S/Inputs -enable-experimental-cxx-interop %s -validate-tbd-against-ir=none -Xcc -fignore-exceptions | %FileCheck %s
1+
// RUN: %target-swift-emit-irgen -I %S/Inputs -cxx-interoperability-mode=upcoming-swift %s -validate-tbd-against-ir=none -Xcc -fignore-exceptions | %FileCheck %s
22

33
import MoveOnlyCxxValueType
44

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-emit-sil -I %S/Inputs -enable-experimental-cxx-interop %s -validate-tbd-against-ir=none | %FileCheck %s
1+
// RUN: %target-swift-emit-sil -I %S/Inputs -cxx-interoperability-mode=upcoming-swift %s -validate-tbd-against-ir=none | %FileCheck %s
22

33
import MoveOnlyCxxValueType
44

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -enable-experimental-cxx-interop -enable-experimental-feature NoncopyableGenerics)
2-
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -enable-experimental-cxx-interop -enable-experimental-feature NoncopyableGenerics -O -Xfrontend -sil-verify-none)
1+
// RUN: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=upcoming-swift -enable-experimental-feature NoncopyableGenerics)
2+
// RUN: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=upcoming-swift -enable-experimental-feature NoncopyableGenerics -O -Xfrontend -sil-verify-none)
33
//
44
// REQUIRES: executable_test
55
// REQUIRES: GH_ISSUE_70246

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -enable-experimental-cxx-interop)
2-
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -enable-experimental-cxx-interop -O)
1+
// RUN: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=upcoming-swift)
2+
// RUN: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=upcoming-swift -O)
33
//
44
// REQUIRES: executable_test
55

test/Interop/Cxx/class/type-classification-module-interface.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-swift-ide-test -print-module -module-to-print=TypeClassification -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s
2-
// RUN: %target-swift-ide-test -print-module -skip-unsafe-cxx-methods -module-to-print=TypeClassification -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s -check-prefix=CHECK-SKIP-UNSAFE
1+
// RUN: %target-swift-ide-test -print-module -module-to-print=TypeClassification -I %S/Inputs -source-filename=x -cxx-interoperability-mode=upcoming-swift | %FileCheck %s
2+
// RUN: %target-swift-ide-test -print-module -skip-unsafe-cxx-methods -module-to-print=TypeClassification -I %S/Inputs -source-filename=x -cxx-interoperability-mode=upcoming-swift | %FileCheck %s -check-prefix=CHECK-SKIP-UNSAFE
33

44
// Make sure we don't import objects that we can't copy or destroy.
55
// CHECK-NOT: StructWithPrivateDefaultedCopyConstructor

test/Interop/Cxx/class/type-classification-typechecker.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Test various aspects of the C++ `nodiscard` keyword.
22

3-
// RUN: %target-typecheck-verify-swift -I %S/Inputs -enable-experimental-cxx-interop
3+
// RUN: %target-typecheck-verify-swift -I %S/Inputs -cxx-interoperability-mode=upcoming-swift
44

55
import TypeClassification
66

test/Interop/Cxx/ergonomics/swift-bridging-annotations.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
// RUN: %target-swift-ide-test -print-module -module-to-print=SwiftMod -module-to-print=CxxModule -I %t -I %t/Inputs -I %swift_src_root/lib/ClangImporter -source-filename=x -enable-experimental-cxx-interop -Xcc -DINCMOD | %FileCheck %s
1010

11+
// RUN: %target-swift-ide-test -print-module -module-to-print=SwiftMod -module-to-print=CxxModule -I %t -I %t/Inputs -I %swift_src_root/lib/ClangImporter -source-filename=x -cxx-interoperability-mode=upcoming-swift -Xcc -DINCMOD | %FileCheck --check-prefixes=CHECK,CHECKLATEST %s
12+
1113
// Test through the use of the bridging header
1214
// RUN: %target-swift-frontend -emit-ir -I %t -import-objc-header %t/Inputs/header.h -I %swift_src_root/lib/ClangImporter -enable-experimental-cxx-interop -DBRIDGING_HEADER_TEST -disable-availability-checking %t/SwiftMod.swift
1315

@@ -116,4 +118,4 @@ private:
116118

117119
// CHECK: struct UnsafeSendable : @unchecked Sendable {
118120

119-
// CHECK: struct NonCopyableCopyable
121+
// CHECKLATEST: struct NonCopyableCopyable

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -enable-experimental-cxx-interop)
2-
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -enable-experimental-cxx-interop -O)
1+
// RUN: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=upcoming-swift)
2+
// RUN: %target-run-simple-swift(-I %S/Inputs/ -cxx-interoperability-mode=upcoming-swift -O)
33
//
44
// REQUIRES: executable_test
55

test/Interop/Cxx/operators/move-only/move-only-synthesized-property-typecheck.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// RUN: %target-typecheck-verify-swift -I %S/Inputs -enable-experimental-cxx-interop -DNO_CONSUME
1+
// RUN: %target-typecheck-verify-swift -I %S/Inputs -cxx-interoperability-mode=upcoming-swift -DNO_CONSUME
22

33
// Note: some errors need full SIL emission right now.
44
// FIXME: they should be type checker errors.
5-
// RUN: not %target-swift-emit-sil %s -I %S/Inputs -enable-experimental-cxx-interop 2>&1 | %FileCheck %s
5+
// RUN: not %target-swift-emit-sil %s -I %S/Inputs -cxx-interoperability-mode=upcoming-swift 2>&1 | %FileCheck %s
66

77
import MoveOnlyCxxOperators
88

test/Interop/Cxx/stdlib/std-unique-ptr.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop)
1+
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=upcoming-swift)
22
//
33
// REQUIRES: executable_test
44

0 commit comments

Comments
 (0)