-
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
[cxx-interop] Import STL types as copyable, conditionally #84340
Conversation
@swift-ci please smoke test |
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.
Looks great, I had two comments inline.
9c3fdcd
to
72ed4d9
Compare
@swift-ci please smoke test |
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.
Thanks, looks great! Some nits inline.
72ed4d9
to
08bb469
Compare
@swift-ci please smoke test |
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.
Looks great, thanks!
@@ -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 |
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'
or conform 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 like expected-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!
08bb469
to
229a288
Compare
@swift-ci please smoke test |
229a288
to
b407f08
Compare
@swift-ci please smoke test |
1 similar comment
@swift-ci please smoke test |
b407f08
to
bd1255b
Compare
@swift-ci please smoke test |
bd1255b
to
2465d52
Compare
@swift-ci please smoke test |
2465d52
to
83a5968
Compare
@swift-ci please smoke test |
let vecPointer = VectorOfPointer() | ||
takeCopyable(vecPointer) | ||
takeCxxVector(vecPointer) | ||
// CHECK-NOT: error |
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.
@susmonteiro, this last line of this new test is failing for Android armv7 alone, though it passes for Android AArch64 and x86_64:
2025-09-28T16:12:16.3425383Z FAIL: Swift(android-armv7) :: Interop/Cxx/stdlib/use-std-vector-typechecker.swift (4714 of 19859)
2025-09-28T16:12:16.3431078Z ******************** TEST 'Swift(android-armv7) :: Interop/Cxx/stdlib/use-std-vector-typechecker.swift' FAILED ********************
2025-09-28T16:12:16.3459417Z Exit Code: 1
2025-09-28T16:12:16.3459809Z
2025-09-28T16:12:16.3460010Z Command Output (stderr):
2025-09-28T16:12:16.3467419Z --
2025-09-28T16:12:16.3494220Z RUN: at line 1: not /home/build-user/build/swift-project/Ninja-Release/swift-linux-x86_64/bin/swift-frontend -target armv7-unknown-linux-android -sdk /home/build-user/build/ndk/android-ndk-r27d/toolchains/llvm/prebuilt/linux-x86_64/sysroot -resource-dir /home/build-user/build/swift-project/Ninja-Release/swift-linux-x86_64/lib/swift -module-cache-path /home/build-user/build/swift-project/Ninja-Release/swift-linux-x86_64/swift-test-results/armv7-unknown-linux-androideabi/clang-module-cache -swift-version 4 -define-availability 'SwiftStdlib 9999:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999' -define-availability 'StdlibDeploymentTarget 9999:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999' -define-availability 'SwiftStdlib 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2' -define-availability 'StdlibDeploymentTarget 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2' -define-availability 'SwiftStdlib 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0' -define-availability 'StdlibDeploymentTarget 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0' -define-availability 'SwiftStdlib 5.2:macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4' -define-availability 'StdlibDeploymentTarget 5.2:macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4' -define-availability 'SwiftStdlib 5.3:macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0' -define-availability 'StdlibDeploymentTarget 5.3:macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0' -define-availability 'SwiftStdlib 5.4:macOS 11.3, iOS 14.5, watchOS 7.4, tvOS 14.5' -define-availability 'StdlibDeploymentTarget 5.4:macOS 11.3, iOS 14.5, watchOS 7.4, tvOS 14.5' -define-availability 'SwiftStdlib 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0' -define-availability 'StdlibDeploymentTarget 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0' -define-availability 'SwiftStdlib 5.6:macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4' -define-availability 'StdlibDeploymentTarget 5.6:macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4' -define-availability 'SwiftStdlib 5.7:macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0' -define-availability 'StdlibDeploymentTarget 5.7:macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0' -define-availability 'SwiftStdlib 5.8:macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4' -define-availability 'StdlibDeploymentTarget 5.8:macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4' -define-availability 'SwiftStdlib 5.9:macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0' -define-availability 'StdlibDeploymentTarget 5.9:macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0' -define-availability 'SwiftStdlib 5.10:macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4, visionOS 1.1' -define-availability 'StdlibDeploymentTarget 5.10:macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4, visionOS 1.1' -define-availability 'SwiftStdlib 6.0:macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0' -define-availability 'StdlibDeploymentTarget 6.0:macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0' -define-availability 'SwiftStdlib 6.1:macOS 15.4, iOS 18.4, watchOS 11.4, tvOS 18.4, visionOS 2.4' -define-availability 'StdlibDeploymentTarget 6.1:macOS 15.4, iOS 18.4, watchOS 11.4, tvOS 18.4, visionOS 2.4' -define-availability 'SwiftStdlib 6.2:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999' -define-availability 'StdlibDeploymentTarget 6.2:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999' -define-availability 'SwiftStdlib 6.3:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999' -define-availability 'StdlibDeploymentTarget 6.3:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999' -define-availability 'SwiftCompatibilitySpan 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2, visionOS 1.0' -define-availability 'SwiftCompatibilitySpan 6.2:macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0' -typo-correction-limit 10 /source/swift-project/swift/test/Interop/Cxx/stdlib/use-std-vector-typechecker.swift -typecheck -I /source/swift-project/swift/test/Interop/Cxx/stdlib/Inputs -cxx-interoperability-mode=default -diagnostic-style llvm 2>&1 | /usr/bin/python3.12 /source/swift-project/swift/utils/PathSanitizingFileCheck --allow-unused-prefixes --sanitize BUILD_DIR=/home/build-user/build/swift-project/Ninja-Release/swift-linux-x86_64 --sanitize SOURCE_DIR=/source/swift-project/swift --ignore-runtime-warnings --use-filecheck /home/build-user/build/swift-project/Ninja-Release/llvm-linux-x86_64/bin/FileCheck /source/swift-project/swift/test/Interop/Cxx/stdlib/use-std-vector-typechecker.swift
2025-09-28T16:12:16.3555401Z + not /home/build-user/build/swift-project/Ninja-Release/swift-linux-x86_64/bin/swift-frontend -target armv7-unknown-linux-android -sdk /home/build-user/build/ndk/android-ndk-r27d/toolchains/llvm/prebuilt/linux-x86_64/sysroot -resource-dir /home/build-user/build/swift-project/Ninja-Release/swift-linux-x86_64/lib/swift -module-cache-path /home/build-user/build/swift-project/Ninja-Release/swift-linux-x86_64/swift-test-results/armv7-unknown-linux-androideabi/clang-module-cache -swift-version 4 -define-availability 'SwiftStdlib 9999:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999' -define-availability 'StdlibDeploymentTarget 9999:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999' -define-availability 'SwiftStdlib 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2' -define-availability 'StdlibDeploymentTarget 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2' -define-availability 'SwiftStdlib 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0' -define-availability 'StdlibDeploymentTarget 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0' -define-availability 'SwiftStdlib 5.2:macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4' -define-availability 'StdlibDeploymentTarget 5.2:macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4' -define-availability 'SwiftStdlib 5.3:macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0' -define-availability 'StdlibDeploymentTarget 5.3:macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0' -define-availability 'SwiftStdlib 5.4:macOS 11.3, iOS 14.5, watchOS 7.4, tvOS 14.5' -define-availability 'StdlibDeploymentTarget 5.4:macOS 11.3, iOS 14.5, watchOS 7.4, tvOS 14.5' -define-availability 'SwiftStdlib 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0' -define-availability 'StdlibDeploymentTarget 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0' -define-availability 'SwiftStdlib 5.6:macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4' -define-availability 'StdlibDeploymentTarget 5.6:macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4' -define-availability 'SwiftStdlib 5.7:macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0' -define-availability 'StdlibDeploymentTarget 5.7:macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0' -define-availability 'SwiftStdlib 5.8:macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4' -define-availability 'StdlibDeploymentTarget 5.8:macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4' -define-availability 'SwiftStdlib 5.9:macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0' -define-availability 'StdlibDeploymentTarget 5.9:macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0' -define-availability 'SwiftStdlib 5.10:macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4, visionOS 1.1' -define-availability 'StdlibDeploymentTarget 5.10:macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4, visionOS 1.1' -define-availability 'SwiftStdlib 6.0:macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0' -define-availability 'StdlibDeploymentTarget 6.0:macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0' -define-availability 'SwiftStdlib 6.1:macOS 15.4, iOS 18.4, watchOS 11.4, tvOS 18.4, visionOS 2.4' -define-availability 'StdlibDeploymentTarget 6.1:macOS 15.4, iOS 18.4, watchOS 11.4, tvOS 18.4, visionOS 2.4' -define-availability 'SwiftStdlib 6.2:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999' -define-availability 'StdlibDeploymentTarget 6.2:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999' -define-availability 'SwiftStdlib 6.3:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999' -define-availability 'StdlibDeploymentTarget 6.3:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999' -define-availability 'SwiftCompatibilitySpan 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2, visionOS 1.0' -define-availability 'SwiftCompatibilitySpan 6.2:macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0' -typo-correction-limit 10 /source/swift-project/swift/test/Interop/Cxx/stdlib/use-std-vector-typechecker.swift -typecheck -I /source/swift-project/swift/test/Interop/Cxx/stdlib/Inputs -cxx-interoperability-mode=default -diagnostic-style llvm
2025-09-28T16:12:16.3591738Z + /usr/bin/python3.12 /source/swift-project/swift/utils/PathSanitizingFileCheck --allow-unused-prefixes --sanitize BUILD_DIR=/home/build-user/build/swift-project/Ninja-Release/swift-linux-x86_64 --sanitize SOURCE_DIR=/source/swift-project/swift --ignore-runtime-warnings --use-filecheck /home/build-user/build/swift-project/Ninja-Release/llvm-linux-x86_64/bin/FileCheck /source/swift-project/swift/test/Interop/Cxx/stdlib/use-std-vector-typechecker.swift
2025-09-28T16:12:16.3597560Z /source/swift-project/swift/test/Interop/Cxx/stdlib/use-std-vector-typechecker.swift:21:15: error: CHECK-NOT: excluded string found in input
2025-09-28T16:12:16.3611721Z // CHECK-NOT: error
2025-09-28T16:12:16.3627213Z ^
2025-09-28T16:12:16.3628270Z <stdin>:13:75: note: found here
2025-09-28T16:12:16.3634306Z SOURCE_DIR/test/Interop/Cxx/stdlib/use-std-vector-typechecker.swift:20:1: error: global function 'takeCxxVector' requires that 'VectorOfPointer' (aka 'std.__ndk1.vector<UnsafeMutablePointer<NonCopyable>, std.__ndk1.allocator<UnsafeMutablePointer<NonCopyable>>>') conform to 'CxxVector'
2025-09-28T16:12:16.3640413Z ^~~~~
2025-09-28T16:12:16.3640986Z
2025-09-28T16:12:16.3641211Z Input file: <stdin>
2025-09-28T16:12:16.3645414Z Check file: /source/swift-project/swift/test/Interop/Cxx/stdlib/use-std-vector-typechecker.swift
2025-09-28T16:12:16.3646246Z
2025-09-28T16:12:16.3646654Z -dump-input=help explains the following input dump.
2025-09-28T16:12:16.3651553Z
2025-09-28T16:12:16.3651763Z Input was:
2025-09-28T16:12:16.3655477Z <<<<<<
2025-09-28T16:12:16.3655927Z .
2025-09-28T16:12:16.3659985Z .
2025-09-28T16:12:16.3664337Z .
2025-09-28T16:12:16.3665247Z 8: takeCxxVector(vecNC)
2025-09-28T16:12:16.3669333Z 9: ^
2025-09-28T16:12:16.3674408Z 10: SOURCE_DIR/test/Interop/Cxx/stdlib/use-std-vector-typechecker.swift:7:6: note: where 'V' = 'VectorOfNonCopyable' (aka 'std.__ndk1.vector<NonCopyable, std.__ndk1.allocator<NonCopyable>>')
2025-09-28T16:12:16.3676268Z 11: func takeCxxVector<V: CxxVector>(_ v: V) {}
2025-09-28T16:12:16.3680935Z 12: ^
2025-09-28T16:12:16.3684420Z 13: SOURCE_DIR/test/Interop/Cxx/stdlib/use-std-vector-typechecker.swift:20:1: error: global function 'takeCxxVector' requires that 'VectorOfPointer' (aka 'std.__ndk1.vector<UnsafeMutablePointer<NonCopyable>, std.__ndk1.allocator<UnsafeMutablePointer<NonCopyable>>>') conform to 'CxxVector'
2025-09-28T16:12:16.3687195Z not:21 !~~~~ error: no match expected
2025-09-28T16:12:16.3689033Z 14: takeCxxVector(vecPointer)
2025-09-28T16:12:16.3697027Z 15: ^
2025-09-28T16:12:16.3698773Z 16: SOURCE_DIR/test/Interop/Cxx/stdlib/use-std-vector-typechecker.swift:7:6: note: where 'V' = 'VectorOfPointer' (aka 'std.__ndk1.vector<UnsafeMutablePointer<NonCopyable>, std.__ndk1.allocator<UnsafeMutablePointer<NonCopyable>>>')
2025-09-28T16:12:16.3704517Z 17: func takeCxxVector<V: CxxVector>(_ v: V) {}
2025-09-28T16:12:16.3705161Z 18: ^
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if this failure is surfacing on all 32-bit CI or just Android armv7, let me know what you think.
I'll investigate
Import STL containers as non-copyable if the elements they hold are also non-copyable.
Unfortunately, there isn't a straightforward way to automatically check if an instantiation of a copy constructor is valid, so we reuse escapability's logic that hardcodes, for each STL container, the parameters it depends on.
rdar://148130050