-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[cxx-interop] Import STL types as copyable, conditionally #84340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// RUN: not %target-swift-frontend %s -typecheck -I %S/Inputs -cxx-interoperability-mode=default -diagnostic-style llvm 2>&1 | %FileCheck %s | ||
|
||
import StdMap | ||
import CxxStdlib | ||
|
||
func takeCopyable<T: Copyable>(_ x: T) {} | ||
|
||
let mapNonCopyableKey = MapNonCopyableKey() | ||
takeCopyable(mapNonCopyableKey) | ||
// CHECK: error: global function 'takeCopyable' requires that 'MapNonCopyableKey' {{.*}} conform to 'Copyable' | ||
// CHECK: note: 'where T: Copyable' is implicit here | ||
|
||
let mapNonCopyableValue = MapNonCopyableValue() | ||
takeCopyable(mapNonCopyableValue) | ||
// CHECK: error: global function 'takeCopyable' requires that 'MapNonCopyableValue' {{.*}} conform to 'Copyable' | ||
// CHECK: note: 'where T: Copyable' is implicit here |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// RUN: not %target-swift-frontend %s -typecheck -I %S/Inputs -cxx-interoperability-mode=default -diagnostic-style llvm 2>&1 | %FileCheck %s | ||
|
||
import StdOptional | ||
import CxxStdlib | ||
|
||
func takeCopyable<T: Copyable>(_ x: T) {} | ||
|
||
let nonNilOptNonCopyable = getNonNilOptionalHasDeletedCopyCtor() | ||
takeCopyable(nonNilOptNonCopyable) | ||
// CHECK: error: global function 'takeCopyable' requires that 'StdOptionalHasDeletedCopyCtor' {{.*}} conform to 'Copyable' | ||
// CHECK: note: 'where T: Copyable' is implicit here |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// RUN: not %target-swift-frontend %s -typecheck -I %S/Inputs -cxx-interoperability-mode=default -diagnostic-style llvm 2>&1 | %FileCheck %s | ||
|
||
import StdSet | ||
import CxxStdlib | ||
|
||
func takeCopyable<T: Copyable>(_ x: T) {} | ||
|
||
let setNonCopyable = SetOfNonCopyable() | ||
takeCopyable(setNonCopyable) | ||
// CHECK: error: global function 'takeCopyable' requires that 'SetOfNonCopyable' {{.*}} conform to 'Copyable' | ||
// CHECK: note: 'where T: Copyable' is implicit here |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// RUN: not %target-swift-frontend %s -typecheck -I %S/Inputs -cxx-interoperability-mode=default -diagnostic-style llvm 2>&1 | %FileCheck %s | ||
|
||
// UNSUPPORTED: OS=windows-msvc | ||
|
||
import StdUniquePtr | ||
import CxxStdlib | ||
|
||
func takeCopyable<T: Copyable>(_ x: T) {} | ||
|
||
let vecUniquePtr = getVectorNonCopyableUniquePtr() | ||
takeCopyable(vecUniquePtr) | ||
// CHECK: error: global function 'takeCopyable' requires that 'std{{.*}}vector{{.*}}unique_ptr{{.*}}NonCopyable{{.*}}' conform to 'Copyable' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// RUN: not %target-swift-frontend %s -typecheck -I %S/Inputs -cxx-interoperability-mode=default -diagnostic-style llvm 2>&1 | %FileCheck %s | ||
|
||
import StdVector | ||
import CxxStdlib | ||
|
||
func takeCopyable<T: Copyable>(_ x: T) {} | ||
func takeCxxVector<V: CxxVector>(_ v: V) {} | ||
|
||
let vecNC = VectorOfNonCopyable() | ||
takeCopyable(vecNC) | ||
// CHECK: error: global function 'takeCopyable' requires that 'VectorOfNonCopyable' {{.*}} conform to 'Copyable' | ||
// CHECK: note: 'where T: Copyable' is implicit here | ||
|
||
takeCxxVector(vecNC) | ||
// CHECK: error: global function 'takeCxxVector' requires that 'VectorOfNonCopyable' {{.*}} conform to 'CxxVector' | ||
// CHECK: note: where 'V' = 'VectorOfNonCopyable' {{.*}} | ||
|
||
let vecPointer = VectorOfPointer() | ||
takeCopyable(vecPointer) | ||
takeCxxVector(vecPointer) | ||
// CHECK-NOT: error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @susmonteiro, this last line of this new test is failing for Android armv7 alone, though it passes for Android AArch64 and x86_64:
I know there are 32-bit Apple CI that eventually run on all commits, do they work fine? Wondering if this failure is surfacing on all 32-bit CI or just Android armv7, let me know what you think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Disabled the test in #84608 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'll investigate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: maybe it is more elegant to do these tests via
-verify
. But I don't have strong feelings.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with
-verify
is that afaik there's no equivalent to{{.*}}
. The alternative is to include only part of the message, which can be either, for instance,global function 'takeCopyable' requires that 'MapNonCopyableKey'
orconform to 'Copyable'
but not both parts.I'd also prefer to use
-verify
, so please let me know if you see any way around this!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In clang's implementation of
-verify
you can use regexes likeexpected-error-re{{foo .* bar}}
. Perhaps we ought to add that to Swift also.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that'd be useful!