Skip to content

Conversation

susmonteiro
Copy link
Contributor

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

@susmonteiro
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Contributor

@Xazax-hun Xazax-hun left a 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.

@susmonteiro susmonteiro force-pushed the susmonteiro/stl-non-copyable-types branch from 9c3fdcd to 72ed4d9 Compare September 17, 2025 11:24
@susmonteiro
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Contributor

@Xazax-hun Xazax-hun left a 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.

@susmonteiro susmonteiro force-pushed the susmonteiro/stl-non-copyable-types branch from 72ed4d9 to 08bb469 Compare September 17, 2025 14:13
@susmonteiro
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Contributor

@Xazax-hun Xazax-hun left a 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
Copy link
Contributor

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.

Copy link
Contributor Author

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!

Copy link
Contributor

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.

Copy link
Contributor Author

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!

@susmonteiro susmonteiro force-pushed the susmonteiro/stl-non-copyable-types branch from 08bb469 to 229a288 Compare September 17, 2025 14:28
@susmonteiro
Copy link
Contributor Author

@swift-ci please smoke test

@susmonteiro susmonteiro force-pushed the susmonteiro/stl-non-copyable-types branch from 229a288 to b407f08 Compare September 17, 2025 16:55
@susmonteiro
Copy link
Contributor Author

@swift-ci please smoke test

1 similar comment
@susmonteiro
Copy link
Contributor Author

@swift-ci please smoke test

@susmonteiro susmonteiro force-pushed the susmonteiro/stl-non-copyable-types branch from b407f08 to bd1255b Compare September 19, 2025 10:08
@susmonteiro
Copy link
Contributor Author

@swift-ci please smoke test

@susmonteiro susmonteiro force-pushed the susmonteiro/stl-non-copyable-types branch from bd1255b to 2465d52 Compare September 19, 2025 13:19
@susmonteiro
Copy link
Contributor Author

@swift-ci please smoke test

@susmonteiro susmonteiro force-pushed the susmonteiro/stl-non-copyable-types branch from 2465d52 to 83a5968 Compare September 22, 2025 10:12
@susmonteiro
Copy link
Contributor Author

@swift-ci please smoke test

@susmonteiro susmonteiro merged commit 963aad3 into swiftlang:main Sep 22, 2025
3 checks passed
let vecPointer = VectorOfPointer()
takeCopyable(vecPointer)
takeCxxVector(vecPointer)
// CHECK-NOT: error
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ interop Feature: Interoperability with C++

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants