Files
swift-mirror/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift
Henrik G. Olsson 2afd4ec7a4 Revert "add std::span to module map for libstdc++"
This reverts commit f7d5902db5.

It was part of a larger PR in
https://github.com/swiftlang/swift/pull/84755, but turned out to be
broken for older versions of libstdc++. Since it's not critical to the
functionality of the larger PR, this reverts the problematic part.

rdar://161999183
2025-10-15 13:52:31 -07:00

238 lines
14 KiB
Swift

// REQUIRES: swift_feature_SafeInteropWrappers
// RUN: %empty-directory(%t)
// RUN: split-file %s %t
// RUN: %target-swift-frontend -emit-module -plugin-path %swift-plugin-dir -o %t/Test.swiftmodule -I %t/Inputs -enable-experimental-feature SafeInteropWrappers -strict-memory-safety -warnings-as-errors -Xcc -Werror %t/test.swift -cxx-interoperability-mode=default -Xcc -std=c++20 -verify -verify-additional-file %t/Inputs/instance.h -DVERIFY
// RUN: env SWIFT_BACKTRACE="" %target-swift-frontend -emit-module -plugin-path %swift-plugin-dir -o %t/Test.swiftmodule -I %t/Inputs -enable-experimental-feature SafeInteropWrappers -strict-memory-safety -warnings-as-errors -Xcc -Werror %t/test.swift -cxx-interoperability-mode=default -Xcc -std=c++20 -dump-macro-expansions 2>&1 | %FileCheck %s --match-full-lines --strict-whitespace --implicit-check-not __swiftmacro
// FIXME swift-ci linux tests do not support std::span
// UNSUPPORTED: OS=linux-gnu, OS=linux-android, OS=linux-androideabi
//--- test.swift
import Instance
func foo(_ p: inout MutableSpan<CInt>, a: A, aa: inout A, s: IntSpan, cs: ConstIntSpan, asp: AliasingSpan/*, b: inout baz.B*/) {
aa.basic(&p)
aa.bar(&p)
a.constSelf(&p)
a.valSelf(&p)
aa.refSelf(&p)
//aa.namespaced(&p)
//b.decapseman(&p)
//baz.bar(&aa, &p)
//baz.this(&aa, &p)
let _: IntSpan = unsafe s.spanSelf()
let _: MutableSpan<CInt> = unsafe s.spanSelf()
let _: IntSpan = unsafe s.spanConstSelf()
let _: MutableSpan<CInt> = unsafe s.spanConstSelf()
let _: ConstIntSpan = unsafe cs.constSpanSelf()
let _: Span<CInt> = unsafe cs.constSpanSelf()
let _: IntSpan = unsafe asp.spanSelf()
let _: MutableSpan<CInt> = unsafe asp.spanSelf()
#if VERIFY
p.spanSelf() // expected-error{{value of type 'MutableSpan<CInt>' (aka 'MutableSpan<Int32>') has no member 'spanSelf'}}
#endif
}
//--- Inputs/instance.h
#include <ptrcheck.h>
#include <lifetimebound.h>
#include <span>
struct A {};
using IntSpan = std::span<int>;
using ConstIntSpan = std::span<const int>;
using AliasingSpan = std::span<int>;
void basic(A *a, IntSpan p __noescape) __attribute__((swift_name("A.basic(self:_:)")));
void renamed(A *a, IntSpan p __noescape) __attribute__((swift_name("A.bar(self:_:)")));
void constSelf(const A *a, IntSpan p __noescape) __attribute__((swift_name("A.constSelf(self:_:)")));
void valSelf(A a, IntSpan p __noescape) __attribute__((swift_name("A.valSelf(self:_:)")));
void refSelf(A &a, IntSpan p __noescape) __attribute__((swift_name("A.refSelf(self:_:)")));
IntSpan spanSelf(IntSpan p __lifetimebound) __attribute__((swift_name("IntSpan.spanSelf(self:)")));
const IntSpan spanConstSelf(const IntSpan p __lifetimebound) __attribute__((swift_name("IntSpan.spanConstSelf(self:)")));
ConstIntSpan constSpanSelf(ConstIntSpan p __lifetimebound) __attribute__((swift_name("ConstIntSpan.constSpanSelf(self:)")));
/*
* Swift 6.2 error: 'swift_name' attribute has invalid identifier for the base name.
* Requires https://github.com/llvm/llvm-project/pull/145947
namespace baz {
void namespaced(A *a, IntSpan p __noescape) __attribute__((swift_name("A.namespaced(self:_:)")));
struct B {};
void renamed(A &a, IntSpan p __noescape) __attribute__((swift_name("baz.bar(_:_:)")));
void that(A &a, IntSpan p __noescape) __attribute__((swift_name("this(_:_:)")));
}
void decapseman(baz::B *b, IntSpan p __noescape) __attribute__((swift_name("baz.B.decapseman(self:_:)")));
*/
//--- Inputs/module.modulemap
module Instance {
header "instance.h"
export *
}
//--- out.expected
// CHECK:@__swiftmacro_{{.*}}basic{{.*}}_SwiftifyImportfMp_.swift
// CHECK-NEXT:------------------------------
// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop
// CHECK-NEXT:@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload
// CHECK-NEXT:public mutating func basic(_ p: inout MutableSpan<CInt>) {
// CHECK-NEXT: return unsafe p.withUnsafeMutableBufferPointer { _pPtr in
// CHECK-NEXT: return unsafe basic(IntSpan(_pPtr))
// CHECK-NEXT: }
// CHECK-NEXT:}
// CHECK-NEXT:------------------------------
// CHECK-NEXT:@__swiftmacro_{{.*}}basic{{.*}}_SwiftifyImportfMp_.swift
// CHECK-NEXT:------------------------------
// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop
// CHECK-NEXT:@available(swift, obsoleted: 3, renamed: "A.basic(self:_:)") @_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload
// CHECK-NEXT:public func basic(_ a: UnsafeMutablePointer<A>!, _ p: inout MutableSpan<CInt>) {
// CHECK-NEXT: return unsafe p.withUnsafeMutableBufferPointer { _pPtr in
// CHECK-NEXT: return unsafe basic(a, IntSpan(_pPtr))
// CHECK-NEXT: }
// CHECK-NEXT:}
// CHECK-NEXT:------------------------------
// CHECK-NEXT:@__swiftmacro_{{.*}}bar{{.*}}_SwiftifyImportfMp_.swift
// CHECK-NEXT:------------------------------
// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop
// CHECK-NEXT:@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload
// CHECK-NEXT:public mutating func bar(_ p: inout MutableSpan<CInt>) {
// CHECK-NEXT: return unsafe p.withUnsafeMutableBufferPointer { _pPtr in
// CHECK-NEXT: return unsafe bar(IntSpan(_pPtr))
// CHECK-NEXT: }
// CHECK-NEXT:}
// CHECK-NEXT:------------------------------
// CHECK-NEXT:@__swiftmacro_{{.*}}renamed{{.*}}_SwiftifyImportfMp_.swift
// CHECK-NEXT:------------------------------
// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop
// CHECK-NEXT:@available(swift, obsoleted: 3, renamed: "A.bar(self:_:)") @_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload
// CHECK-NEXT:public func renamed(_ a: UnsafeMutablePointer<A>!, _ p: inout MutableSpan<CInt>) {
// CHECK-NEXT: return unsafe p.withUnsafeMutableBufferPointer { _pPtr in
// CHECK-NEXT: return unsafe renamed(a, IntSpan(_pPtr))
// CHECK-NEXT: }
// CHECK-NEXT:}
// CHECK-NEXT:------------------------------
// CHECK-NEXT:@__swiftmacro_{{.*}}constSelf{{.*}}_SwiftifyImportfMp_.swift
// CHECK-NEXT:------------------------------
// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop
// CHECK-NEXT:@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload
// CHECK-NEXT:public func constSelf(_ p: inout MutableSpan<CInt>) {
// CHECK-NEXT: return unsafe p.withUnsafeMutableBufferPointer { _pPtr in
// CHECK-NEXT: return unsafe constSelf(IntSpan(_pPtr))
// CHECK-NEXT: }
// CHECK-NEXT:}
// CHECK-NEXT:------------------------------
// CHECK-NEXT:@__swiftmacro_{{.*}}constSelf{{.*}}_SwiftifyImportfMp_.swift
// CHECK-NEXT:------------------------------
// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop
// CHECK-NEXT:@available(swift, obsoleted: 3, renamed: "A.constSelf(self:_:)") @_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload
// CHECK-NEXT:public func constSelf(_ a: UnsafePointer<A>!, _ p: inout MutableSpan<CInt>) {
// CHECK-NEXT: return unsafe p.withUnsafeMutableBufferPointer { _pPtr in
// CHECK-NEXT: return unsafe constSelf(a, IntSpan(_pPtr))
// CHECK-NEXT: }
// CHECK-NEXT:}
// CHECK-NEXT:------------------------------
// CHECK-NEXT:@__swiftmacro_{{.*}}valSelf{{.*}}_SwiftifyImportfMp_.swift
// CHECK-NEXT:------------------------------
// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop
// CHECK-NEXT:@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload
// CHECK-NEXT:public func valSelf(_ p: inout MutableSpan<CInt>) {
// CHECK-NEXT: return unsafe p.withUnsafeMutableBufferPointer { _pPtr in
// CHECK-NEXT: return unsafe valSelf(IntSpan(_pPtr))
// CHECK-NEXT: }
// CHECK-NEXT:}
// CHECK-NEXT:------------------------------
// CHECK-NEXT:@__swiftmacro_{{.*}}valSelf{{.*}}_SwiftifyImportfMp_.swift
// CHECK-NEXT:------------------------------
// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop
// CHECK-NEXT:@available(swift, obsoleted: 3, renamed: "A.valSelf(self:_:)") @_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload
// CHECK-NEXT:public func valSelf(_ a: A, _ p: inout MutableSpan<CInt>) {
// CHECK-NEXT: return unsafe p.withUnsafeMutableBufferPointer { _pPtr in
// CHECK-NEXT: return unsafe valSelf(a, IntSpan(_pPtr))
// CHECK-NEXT: }
// CHECK-NEXT:}
// CHECK-NEXT:------------------------------
// CHECK-NEXT:@__swiftmacro_{{.*}}refSelf{{.*}}_SwiftifyImportfMp_.swift
// CHECK-NEXT:------------------------------
// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop
// CHECK-NEXT:@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload
// CHECK-NEXT:public mutating func refSelf(_ p: inout MutableSpan<CInt>) {
// CHECK-NEXT: return unsafe p.withUnsafeMutableBufferPointer { _pPtr in
// CHECK-NEXT: return unsafe refSelf(IntSpan(_pPtr))
// CHECK-NEXT: }
// CHECK-NEXT:}
// CHECK-NEXT:------------------------------
// CHECK-NEXT:@__swiftmacro_{{.*}}refSelf{{.*}}_SwiftifyImportfMp_.swift
// CHECK-NEXT:------------------------------
// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop
// CHECK-NEXT:@available(swift, obsoleted: 3, renamed: "A.refSelf(self:_:)") @_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload
// CHECK-NEXT:public func refSelf(_ a: inout A, _ p: inout MutableSpan<CInt>) {
// CHECK-NEXT: return unsafe p.withUnsafeMutableBufferPointer { _pPtr in
// CHECK-NEXT: return unsafe refSelf(&a, IntSpan(_pPtr))
// CHECK-NEXT: }
// CHECK-NEXT:}
// CHECK-NEXT:------------------------------
// CHECK-NEXT:@__swiftmacro_{{.*}}Instance{{.*}}spanSelf{{.*}}_SwiftifyImportfMp_.swift
// CHECK-NEXT:------------------------------
// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop
// CHECK-NEXT:@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(borrow self) @_disfavoredOverload
// CHECK-NEXT:public func spanSelf() -> MutableSpan<CInt> {
// CHECK-NEXT: return unsafe _swiftifyOverrideLifetime(MutableSpan(_unsafeCxxSpan: unsafe spanSelf()), copying: ())
// CHECK-NEXT:}
// CHECK-NEXT:------------------------------
// CHECK-NEXT:@__swiftmacro_So8spanSelf{{.*}}_SwiftifyImportfMp_.swift
// CHECK-NEXT:------------------------------
// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop
// CHECK-NEXT:@available(swift, obsoleted: 3, renamed: "IntSpan.spanSelf(self:)") @_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(copy p) @_lifetime(p: copy p) @_disfavoredOverload
// CHECK-NEXT:public func spanSelf(_ p: inout MutableSpan<CInt>) -> MutableSpan<CInt> {
// CHECK-NEXT: return unsafe _swiftifyOverrideLifetime(MutableSpan(_unsafeCxxSpan: unsafe p.withUnsafeMutableBufferPointer { _pPtr in
// CHECK-NEXT: return unsafe spanSelf(IntSpan(_pPtr))
// CHECK-NEXT: }), copying: ())
// CHECK-NEXT:}
// CHECK-NEXT:------------------------------
// CHECK-NEXT:@__swiftmacro_{{.*}}Instance{{.*}}spanConstSelf{{.*}}_SwiftifyImportfMp_.swift
// CHECK-NEXT:------------------------------
// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop
// CHECK-NEXT:@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(borrow self) @_disfavoredOverload
// CHECK-NEXT:public func spanConstSelf() -> MutableSpan<CInt> {
// CHECK-NEXT: return unsafe _swiftifyOverrideLifetime(MutableSpan(_unsafeCxxSpan: unsafe spanConstSelf()), copying: ())
// CHECK-NEXT:}
// CHECK-NEXT:------------------------------
// CHECK-NEXT:@__swiftmacro_{{.*}}spanConstSelf{{.*}}_SwiftifyImportfMp_.swift
// CHECK-NEXT:------------------------------
// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop
// CHECK-NEXT:@available(swift, obsoleted: 3, renamed: "IntSpan.spanConstSelf(self:)") @_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(copy p) @_lifetime(p: copy p) @_disfavoredOverload
// CHECK-NEXT:public func spanConstSelf(_ p: inout MutableSpan<CInt>) -> MutableSpan<CInt> {
// CHECK-NEXT: return unsafe _swiftifyOverrideLifetime(MutableSpan(_unsafeCxxSpan: unsafe p.withUnsafeMutableBufferPointer { _pPtr in
// CHECK-NEXT: return unsafe spanConstSelf(IntSpan(_pPtr))
// CHECK-NEXT: }), copying: ())
// CHECK-NEXT:}
// CHECK-NEXT:------------------------------
// CHECK-NEXT:@__swiftmacro_{{.*}}Instance{{.*}}constSpanSelf{{.*}}_SwiftifyImportfMp_.swift
// CHECK-NEXT:------------------------------
// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop
// CHECK-NEXT:@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(borrow self) @_disfavoredOverload
// CHECK-NEXT:public func constSpanSelf() -> Span<CInt> {
// CHECK-NEXT: return unsafe _swiftifyOverrideLifetime(Span(_unsafeCxxSpan: unsafe constSpanSelf()), copying: ())
// CHECK-NEXT:}
// CHECK-NEXT:------------------------------
// CHECK-NEXT:@__swiftmacro_{{.*}}constSpanSelf{{.*}}_SwiftifyImportfMp_.swift
// CHECK-NEXT:------------------------------
// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop
// CHECK-NEXT:@available(swift, obsoleted: 3, renamed: "ConstIntSpan.constSpanSelf(self:)") @_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(copy p) @_disfavoredOverload
// CHECK-NEXT:public func constSpanSelf(_ p: Span<CInt>) -> Span<CInt> {
// CHECK-NEXT: return unsafe _swiftifyOverrideLifetime(Span(_unsafeCxxSpan: unsafe constSpanSelf(ConstIntSpan(p))), copying: ())
// CHECK-NEXT:}
// CHECK-NEXT:------------------------------