From 87642d499a2ee3e1454077526ff3210965285dd5 Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Wed, 24 Sep 2025 22:27:19 -0700 Subject: [PATCH 01/11] [Swiftify] Add support for free functions imported as instance methods This adds support for attaching safe interop wrappers to functions explicitly imported as instance methods using swift_name. rdar://156288883 --- .../swift/AST/DiagnosticsClangImporter.def | 6 + lib/ClangImporter/ImportDecl.cpp | 62 ++++- .../import-as-instance-method.swift | 219 ++++++++++++++++++ .../import-as-instance-method.swift | 218 +++++++++++++++++ 4 files changed, 495 insertions(+), 10 deletions(-) create mode 100644 test/Interop/C/swiftify-import/import-as-instance-method.swift create mode 100644 test/Interop/Cxx/swiftify-import/import-as-instance-method.swift diff --git a/include/swift/AST/DiagnosticsClangImporter.def b/include/swift/AST/DiagnosticsClangImporter.def index 17b7cb7958725..2cf1d185f14a9 100644 --- a/include/swift/AST/DiagnosticsClangImporter.def +++ b/include/swift/AST/DiagnosticsClangImporter.def @@ -105,6 +105,12 @@ GROUPED_WARNING(clang_ignored_sendable_attr, ClangDeclarationImport, none, "cannot be added to it", (Type)) +GROUPED_WARNING(warn_clang_ignored_bounds_on_self, ClangDeclarationImport, none, + "bounds attribute '%0' ignored on parameter mapped to 'self'", + (StringRef)) +NOTE(note_swift_name_instance_method, none, + "swift_name maps free function to instance method here", ()) + WARNING(implicit_bridging_header_imported_from_module,none, "implicit import of bridging header '%0' via module %1 " "is deprecated and will be removed in a later version of Swift", diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index a2f5c792560d8..c05c0e051835f 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -9460,6 +9460,22 @@ void ClangImporter::Implementation::addOptionSetTypealiases( #define SIW_DBG(x) DEBUG_WITH_TYPE("safe-interop-wrappers", llvm::dbgs() << x) +// until CountAttributedType::getAttributeName lands in our LLVM branch +static StringRef getAttributeName(const clang::CountAttributedType *CAT) { + switch (CAT->getKind()) { + case clang::CountAttributedType::CountedBy: + return "__counted_by"; + case clang::CountAttributedType::CountedByOrNull: + return "__counted_by_or_null"; + case clang::CountAttributedType::SizedBy: + return "__sized_by"; + case clang::CountAttributedType::SizedByOrNull: + return "__sized_by_or_null"; + case clang::CountAttributedType::EndedBy: + llvm_unreachable("CountAttributedType cannot be ended_by"); + } +} + void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) { if (!SwiftContext.LangOpts.hasFeature(Feature::SafeInteropWrappers)) return; @@ -9475,9 +9491,6 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) { ClangDecl->getAccess() == clang::AS_private) return; - if (ClangDecl->getNumParams() != MappedDecl->getParameters()->size()) - return; - MacroDecl *SwiftifyImportDecl = dyn_cast_or_null(getKnownSingleDecl(SwiftContext, "_SwiftifyImport")); if (!SwiftifyImportDecl) return; @@ -9534,14 +9547,42 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) { true); returnHasLifetimeInfo = true; } + + bool isClangInstanceMethod = + isa(ClangDecl) && + !isa(ClangDecl) && + cast(ClangDecl)->isInstance(); + ASSERT((MappedDecl->isImportAsInstanceMember() == isClangInstanceMethod) == + (ClangDecl->getNumParams() == MappedDecl->getParameters()->size())); + + size_t selfParamIndex = MappedDecl->isImportAsInstanceMember() + ? MappedDecl->getSelfIndex() + : ClangDecl->getNumParams(); for (auto [index, clangParam] : llvm::enumerate(ClangDecl->parameters())) { auto clangParamTy = clangParam->getType(); - auto swiftParam = MappedDecl->getParameters()->get(index); + int mappedIndex = index < selfParamIndex ? index : + index > selfParamIndex ? index - 1 : + SwiftifyInfoPrinter::SELF_PARAM_INDEX; + ParamDecl *swiftParam = nullptr; + if (mappedIndex == SwiftifyInfoPrinter::SELF_PARAM_INDEX) { + swiftParam = MappedDecl->getImplicitSelfDecl(/*createIfNeeded*/true); + } else { + swiftParam = MappedDecl->getParameters()->get(mappedIndex); + } + ASSERT(swiftParam); Type swiftParamTy = swiftParam->getInterfaceType(); bool paramHasBoundsInfo = false; auto *CAT = clangParamTy->getAs(); - if (SwiftifiableCAT(getClangASTContext(), CAT, swiftParamTy)) { - printer.printCountedBy(CAT, index); + if (CAT && mappedIndex == SwiftifyInfoPrinter::SELF_PARAM_INDEX) { + diagnose(HeaderLoc(clangParam->getLocation()), + diag::warn_clang_ignored_bounds_on_self, getAttributeName(CAT)); + auto swiftName = ClangDecl->getAttr(); + ASSERT(swiftName && + "free function mapped to instance method without swift_name??"); + diagnose(HeaderLoc(swiftName->getLocation()), + diag::note_swift_name_instance_method); + } else if (SwiftifiableCAT(getClangASTContext(), CAT, swiftParamTy)) { + printer.printCountedBy(CAT, mappedIndex); SIW_DBG(" Found bounds info '" << clangParamTy << "' on parameter '" << *clangParam << "'\n"); attachMacro = paramHasBoundsInfo = true; @@ -9553,7 +9594,7 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) { bool paramHasLifetimeInfo = false; if (clangParam->hasAttr()) { SIW_DBG(" Found noescape attribute on parameter '" << *clangParam << "'\n"); - printer.printNonEscaping(index); + printer.printNonEscaping(mappedIndex); paramHasLifetimeInfo = true; } if (clangParam->hasAttr()) { @@ -9561,8 +9602,10 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) { << *clangParam << "'\n"); // If this parameter has bounds info we will tranform it into a Span, // so then it will no longer be Escapable. - bool willBeEscapable = swiftParamTy->isEscapable() && !paramHasBoundsInfo; - printer.printLifetimeboundReturn(index, willBeEscapable); + bool willBeEscapable = swiftParamTy->isEscapable() && + (!paramHasBoundsInfo || + mappedIndex == SwiftifyInfoPrinter::SELF_PARAM_INDEX); + printer.printLifetimeboundReturn(mappedIndex, willBeEscapable); paramHasLifetimeInfo = true; returnHasLifetimeInfo = true; } @@ -9578,7 +9621,6 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) { } printer.printAvailability(); printer.printTypeMapping(typeMapping); - } if (attachMacro) { diff --git a/test/Interop/C/swiftify-import/import-as-instance-method.swift b/test/Interop/C/swiftify-import/import-as-instance-method.swift new file mode 100644 index 0000000000000..bd0b77682a825 --- /dev/null +++ b/test/Interop/C/swiftify-import/import-as-instance-method.swift @@ -0,0 +1,219 @@ +// 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 -dump-macro-expansions 2> %t/out.txt +// RUN: diff %t/out.txt %t/out.expected +// 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 -verify -verify-additional-file %t/Inputs/instance.h %t/test.swift -DVERIFY + +//--- test.swift +import Instance + +@available(macOS 13.3.0, *) +func foo(_ p: inout MutableSpan, a: A, aa: inout A, c: C, b: B, bb: inout B) { + aa.basic(&p) + aa.bar(&p) + a.constSelf(&p) + a.valSelf(&p) + let _: MutableSpan = a.lifetimeBoundSelf(3) + c.refSelf(&p) + b.nonescaping(&p) + let _: MutableSpan = bb.nonescapingLifetimebound(73) + +#if VERIFY + aa.countedSelf(&p) + a.basic(&p) // expected-error{{cannot use mutating member on immutable value: 'a' is a 'let' constant}} +#endif +} + +//--- Inputs/instance.h +#include +#include + +#define SWIFT_IMMORTAL_REFERENCE \ + __attribute__((swift_attr("import_reference"))) \ + __attribute__((swift_attr("retain:immortal"))) \ + __attribute__((swift_attr("release:immortal"))) + +#define SWIFT_NONESCAPABLE \ + __attribute__((swift_attr("~Escapable"))) + +struct A {}; +struct SWIFT_NONESCAPABLE B {}; +struct SWIFT_IMMORTAL_REFERENCE C {}; + +void basic(struct A *a, int * __counted_by(len) p __noescape, int len) __attribute__((swift_name("A.basic(self:_:_:)"))); + +void renamed(struct A *a, int * __counted_by(len) p __noescape, int len) __attribute__((swift_name("A.bar(self:_:_:)"))); + +void countedSelf(struct A * __counted_by(len) + a, // expected-warning{{bounds attribute '__counted_by' ignored on parameter mapped to 'self'}} + int * __counted_by(len) p __noescape, int len) + __attribute__(( + swift_name // expected-note{{swift_name maps free function to instance method here}} + ("A.countedSelf(self:_:_:)"))); + +void constSelf(const struct A *a, int * __counted_by(len) p __noescape, int len) __attribute__((swift_name("A.constSelf(self:_:_:)"))); + +void valSelf(struct A a, int * __counted_by(len) p __noescape, int len) __attribute__((swift_name("A.valSelf(self:_:_:)"))); + +void refSelf(struct C *c, int * __counted_by(len) p __noescape, int len) __attribute__((swift_name("C.refSelf(self:_:_:)"))); + +int * __counted_by(len) lifetimeBoundSelf(struct A a __lifetimebound, int len) __attribute__((swift_name("A.lifetimeBoundSelf(self:_:)"))); + +void nonescaping(const struct B *d, int * __counted_by(len) p __noescape, int len) __attribute__((swift_name("B.nonescaping(self:_:_:)"))); + +int * __counted_by(len) nonescapingLifetimebound(struct B *d __lifetimebound, int len) __attribute__((swift_name("B.nonescapingLifetimebound(self:_:)"))); + +//--- Inputs/module.modulemap +module Instance { + header "instance.h" +} + +//--- out.expected +@__swiftmacro_So1AV5basic15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload +public mutating func basic(_ p: inout MutableSpan) { + let len = Int32(exactly: p.count)! + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe basic(_pPtr.baseAddress!, len) + } +} +------------------------------ +@__swiftmacro_So5basic15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@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 +public func basic(_ a: UnsafeMutablePointer!, _ p: inout MutableSpan) { + let len = Int32(exactly: p.count)! + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe basic(a, _pPtr.baseAddress!, len) + } +} +------------------------------ +@__swiftmacro_So1AV3bar15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload +public mutating func bar(_ p: inout MutableSpan) { + let len = Int32(exactly: p.count)! + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe bar(_pPtr.baseAddress!, len) + } +} +------------------------------ +@__swiftmacro_So7renamed15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@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 +public func renamed(_ a: UnsafeMutablePointer!, _ p: inout MutableSpan) { + let len = Int32(exactly: p.count)! + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe renamed(a, _pPtr.baseAddress!, len) + } +} +------------------------------ +@__swiftmacro_So1AV9constSelf15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload +public func constSelf(_ p: inout MutableSpan) { + let len = Int32(exactly: p.count)! + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe constSelf(_pPtr.baseAddress!, len) + } +} +------------------------------ +@__swiftmacro_So9constSelf15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@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 +public func constSelf(_ a: UnsafePointer!, _ p: inout MutableSpan) { + let len = Int32(exactly: p.count)! + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe constSelf(a, _pPtr.baseAddress!, len) + } +} +------------------------------ +@__swiftmacro_So1AV7valSelf15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload +public func valSelf(_ p: inout MutableSpan) { + let len = Int32(exactly: p.count)! + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe valSelf(_pPtr.baseAddress!, len) + } +} +------------------------------ +@__swiftmacro_So7valSelf15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@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 +public func valSelf(_ a: A, _ p: inout MutableSpan) { + let len = Int32(exactly: p.count)! + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe valSelf(a, _pPtr.baseAddress!, len) + } +} +------------------------------ +@__swiftmacro_So1AV17lifetimeBoundSelf15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(borrow self) @_disfavoredOverload +public func lifetimeBoundSelf(_ len: Int32) -> MutableSpan { + return unsafe _swiftifyOverrideLifetime(MutableSpan(_unsafeStart: unsafe lifetimeBoundSelf(len), count: Int(len)), copying: ()) +} +------------------------------ +@__swiftmacro_So17lifetimeBoundSelf15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@available(swift, obsoleted: 3, renamed: "A.lifetimeBoundSelf(self:_:)") @_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(borrow a) @_disfavoredOverload +public func lifetimeBoundSelf(_ a: A, _ len: Int32) -> MutableSpan { + return unsafe _swiftifyOverrideLifetime(MutableSpan(_unsafeStart: unsafe lifetimeBoundSelf(a, len), count: Int(len)), copying: ()) +} +------------------------------ +@__swiftmacro_So1CV7refSelf15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload +public func refSelf(_ p: inout MutableSpan) { + let len = Int32(exactly: p.count)! + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe refSelf(_pPtr.baseAddress!, len) + } +} +------------------------------ +@__swiftmacro_So7refSelf15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@available(swift, obsoleted: 3, renamed: "C.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 +public func refSelf(_ c: C!, _ p: inout MutableSpan) { + let len = Int32(exactly: p.count)! + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe refSelf(c, _pPtr.baseAddress!, len) + } +} +------------------------------ +@__swiftmacro_So1BV11nonescaping15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload +public func nonescaping(_ p: inout MutableSpan) { + let len = Int32(exactly: p.count)! + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe nonescaping(_pPtr.baseAddress!, len) + } +} +------------------------------ +@__swiftmacro_So1BV24nonescapingLifetimebound15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(copy self) @_disfavoredOverload +public mutating func nonescapingLifetimebound(_ len: Int32) -> MutableSpan { + return unsafe _swiftifyOverrideLifetime(MutableSpan(_unsafeStart: unsafe nonescapingLifetimebound(len), count: Int(len)), copying: ()) +} +------------------------------ diff --git a/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift b/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift new file mode 100644 index 0000000000000..8a77d86e80925 --- /dev/null +++ b/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift @@ -0,0 +1,218 @@ +// 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 -dump-macro-expansions 2> %t/out.txt +// RUN: diff %t/out.txt %t/out.expected +// 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 %t/test.swift -DVERIFY + +//--- test.swift +import Instance + +func foo(_ p: inout MutableSpan, a: A, aa: inout A, s: IntSpan, cs: ConstIntSpan, asp: AliasingSpan) { + aa.basic(&p) + aa.bar(&p) + a.constSelf(&p) + a.valSelf(&p) + aa.refSelf(&p) + + let _: IntSpan = unsafe s.spanSelf() + let _: MutableSpan = unsafe s.spanSelf() + let _: IntSpan = unsafe s.spanConstSelf() + let _: MutableSpan = unsafe s.spanConstSelf() + let _: ConstIntSpan = unsafe cs.constSpanSelf() + let _: Span = unsafe cs.constSpanSelf() + let _: IntSpan = unsafe asp.spanSelf() + let _: MutableSpan = unsafe asp.spanSelf() +#if VERIFY + p.spanSelf() // expected-error{{value of type 'MutableSpan' (aka 'MutableSpan') has no member 'spanSelf'}} +#endif +} + +//--- Inputs/instance.h +#include +#include +#include + +struct A {}; + +using IntSpan = std::span; +using ConstIntSpan = std::span; +using AliasingSpan = std::span; + +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:)"))); + +//--- Inputs/module.modulemap +module Instance { + header "instance.h" + export std.span +} + +//--- out.expected +@__swiftmacro_So1AV5basic15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload +public mutating func basic(_ p: inout MutableSpan) { + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe basic(IntSpan(_pPtr)) + } +} +------------------------------ +@__swiftmacro_So5basic15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@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 +public func basic(_ a: UnsafeMutablePointer!, _ p: inout MutableSpan) { + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe basic(a, IntSpan(_pPtr)) + } +} +------------------------------ +@__swiftmacro_So1AV3bar15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload +public mutating func bar(_ p: inout MutableSpan) { + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe bar(IntSpan(_pPtr)) + } +} +------------------------------ +@__swiftmacro_So7renamed15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@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 +public func renamed(_ a: UnsafeMutablePointer!, _ p: inout MutableSpan) { + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe renamed(a, IntSpan(_pPtr)) + } +} +------------------------------ +@__swiftmacro_So1AV9constSelf15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload +public func constSelf(_ p: inout MutableSpan) { + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe constSelf(IntSpan(_pPtr)) + } +} +------------------------------ +@__swiftmacro_So9constSelf15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@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 +public func constSelf(_ a: UnsafePointer!, _ p: inout MutableSpan) { + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe constSelf(a, IntSpan(_pPtr)) + } +} +------------------------------ +@__swiftmacro_So1AV7valSelf15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload +public func valSelf(_ p: inout MutableSpan) { + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe valSelf(IntSpan(_pPtr)) + } +} +------------------------------ +@__swiftmacro_So7valSelf15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@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 +public func valSelf(_ a: A, _ p: inout MutableSpan) { + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe valSelf(a, IntSpan(_pPtr)) + } +} +------------------------------ +@__swiftmacro_So1AV7refSelf15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload +public mutating func refSelf(_ p: inout MutableSpan) { + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe refSelf(IntSpan(_pPtr)) + } +} +------------------------------ +@__swiftmacro_So7refSelf15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@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 +public func refSelf(_ a: inout A, _ p: inout MutableSpan) { + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe refSelf(a, IntSpan(_pPtr)) + } +} +------------------------------ +@__swiftmacro_So3stdO3__1O0056spanCInt_CUnsignedLong_18446744073709551615_syGJqopasxheV8InstanceE8spanSelf15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(borrow self) @_disfavoredOverload +public func spanSelf() -> MutableSpan { + return unsafe _swiftifyOverrideLifetime(MutableSpan(_unsafeCxxSpan: unsafe spanSelf()), copying: ()) +} +------------------------------ +@__swiftmacro_So8spanSelf15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@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 +public func spanSelf(_ p: inout MutableSpan) -> MutableSpan { + return unsafe _swiftifyOverrideLifetime(MutableSpan(_unsafeCxxSpan: unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe spanSelf(IntSpan(_pPtr)) + }), copying: ()) +} +------------------------------ +@__swiftmacro_So3stdO3__1O0056spanCInt_CUnsignedLong_18446744073709551615_syGJqopasxheV8InstanceE13spanConstSelf15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(borrow self) @_disfavoredOverload +public func spanConstSelf() -> MutableSpan { + return unsafe _swiftifyOverrideLifetime(MutableSpan(_unsafeCxxSpan: unsafe spanConstSelf()), copying: ()) +} +------------------------------ +@__swiftmacro_So13spanConstSelf15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@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 +public func spanConstSelf(_ p: inout MutableSpan) -> MutableSpan { + return unsafe _swiftifyOverrideLifetime(MutableSpan(_unsafeCxxSpan: unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe spanConstSelf(IntSpan(_pPtr)) + }), copying: ()) +} +------------------------------ +@__swiftmacro_So3stdO3__1O0071span__cxxConstCInt_CUnsignedLong_18446744073709551615_ilHEvDsarBakaEjpbV8InstanceE13constSpanSelf15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(borrow self) @_disfavoredOverload +public func constSpanSelf() -> Span { + return unsafe _swiftifyOverrideLifetime(Span(_unsafeCxxSpan: unsafe constSpanSelf()), copying: ()) +} +------------------------------ +@__swiftmacro_So13constSpanSelf15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@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 +public func constSpanSelf(_ p: Span) -> Span { + return unsafe _swiftifyOverrideLifetime(Span(_unsafeCxxSpan: unsafe constSpanSelf(ConstIntSpan(p))), copying: ()) +} +------------------------------ From 748ef20c8cce90bee7ebd4e3ee832171a3d3c2fe Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Thu, 25 Sep 2025 09:12:53 -0700 Subject: [PATCH 02/11] fix tests in CI --- .../Interop/C/swiftify-import/import-as-instance-method.swift | 4 ++-- .../Cxx/swiftify-import/import-as-instance-method.swift | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Interop/C/swiftify-import/import-as-instance-method.swift b/test/Interop/C/swiftify-import/import-as-instance-method.swift index bd0b77682a825..e31bd53dbe636 100644 --- a/test/Interop/C/swiftify-import/import-as-instance-method.swift +++ b/test/Interop/C/swiftify-import/import-as-instance-method.swift @@ -3,8 +3,8 @@ // 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 -dump-macro-expansions 2> %t/out.txt -// RUN: diff %t/out.txt %t/out.expected +// 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 -dump-macro-expansions 2> %t/out.txt +// RUN: diff --strip-trailing-cr %t/out.txt %t/out.expected // 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 -verify -verify-additional-file %t/Inputs/instance.h %t/test.swift -DVERIFY //--- test.swift diff --git a/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift b/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift index 8a77d86e80925..a20b2a61418e9 100644 --- a/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift +++ b/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift @@ -3,8 +3,8 @@ // 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 -dump-macro-expansions 2> %t/out.txt -// RUN: diff %t/out.txt %t/out.expected +// 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> %t/out.txt +// RUN: diff --strip-trailing-cr %t/out.txt %t/out.expected // 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 %t/test.swift -DVERIFY //--- test.swift From 8af7a4be05cf4cb52c7e13126d9fd4a9bd352172 Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Thu, 25 Sep 2025 09:23:50 -0700 Subject: [PATCH 03/11] add namespace tests --- .../import-as-instance-method.swift | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift b/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift index a20b2a61418e9..7e9dd2cb831ff 100644 --- a/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift +++ b/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift @@ -10,12 +10,14 @@ //--- test.swift import Instance -func foo(_ p: inout MutableSpan, a: A, aa: inout A, s: IntSpan, cs: ConstIntSpan, asp: AliasingSpan) { +func foo(_ p: inout MutableSpan, 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) let _: IntSpan = unsafe s.spanSelf() let _: MutableSpan = unsafe s.spanSelf() @@ -57,6 +59,13 @@ const IntSpan spanConstSelf(const IntSpan p __lifetimebound) __attribute__((swif ConstIntSpan constSpanSelf(ConstIntSpan p __lifetimebound) __attribute__((swift_name("ConstIntSpan.constSpanSelf(self:)"))); +namespace baz { + void namespaced(A *a, IntSpan p __noescape) __attribute__((swift_name("A.namespaced(self:_:)"))); + struct B {}; +} + +void decapseman(baz::B *b, IntSpan p __noescape) __attribute__((swift_name("baz.B.decapseman(self:_:)"))); + //--- Inputs/module.modulemap module Instance { header "instance.h" @@ -164,6 +173,46 @@ public func refSelf(_ a: inout A, _ p: inout MutableSpan) { } } ------------------------------ +@__swiftmacro_So1AV10namespaced15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload +public mutating func namespaced(_ p: inout MutableSpan) { + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe namespaced(IntSpan(_pPtr)) + } +} +------------------------------ +@__swiftmacro_So3bazO10namespaced15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@available(swift, obsoleted: 3, renamed: "A.namespaced(self:_:)") @_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload + public static func namespaced(_ a: UnsafeMutablePointer!, _ p: inout MutableSpan) { + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe namespaced(a, IntSpan(_pPtr)) + } +} +------------------------------ +@__swiftmacro_So3bazO1BV8InstanceE10decapseman15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload +public mutating func decapseman(_ p: inout MutableSpan) { + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe decapseman(IntSpan(_pPtr)) + } +} +------------------------------ +@__swiftmacro_So10decapseman15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@available(swift, obsoleted: 3, renamed: "baz.B.decapseman(self:_:)") @_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload +public func decapseman(_ b: UnsafeMutablePointer!, _ p: inout MutableSpan) { + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe decapseman(b, IntSpan(_pPtr)) + } +} +------------------------------ @__swiftmacro_So3stdO3__1O0056spanCInt_CUnsignedLong_18446744073709551615_syGJqopasxheV8InstanceE8spanSelf15_SwiftifyImportfMp_.swift ------------------------------ /// This is an auto-generated wrapper for safer interop From 439b9e437b7acbfe235e411167e471c156a85a0f Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Thu, 25 Sep 2025 09:38:23 -0700 Subject: [PATCH 04/11] use swift/bridging in test --- .../swiftify-import/import-as-instance-method.swift | 13 +++---------- test/Interop/lit.local.cfg | 2 ++ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/test/Interop/C/swiftify-import/import-as-instance-method.swift b/test/Interop/C/swiftify-import/import-as-instance-method.swift index e31bd53dbe636..7b5e97aaaf10c 100644 --- a/test/Interop/C/swiftify-import/import-as-instance-method.swift +++ b/test/Interop/C/swiftify-import/import-as-instance-method.swift @@ -3,9 +3,9 @@ // RUN: %empty-directory(%t) // RUN: split-file %s %t -// 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 -dump-macro-expansions 2> %t/out.txt +// 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 -dump-macro-expansions -I %bridging-path 2> %t/out.txt // RUN: diff --strip-trailing-cr %t/out.txt %t/out.expected -// 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 -verify -verify-additional-file %t/Inputs/instance.h %t/test.swift -DVERIFY +// 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 -verify -verify-additional-file %t/Inputs/instance.h %t/test.swift -I %bridging-path -DVERIFY //--- test.swift import Instance @@ -30,14 +30,7 @@ func foo(_ p: inout MutableSpan, a: A, aa: inout A, c: C, b: B, bb: inout //--- Inputs/instance.h #include #include - -#define SWIFT_IMMORTAL_REFERENCE \ - __attribute__((swift_attr("import_reference"))) \ - __attribute__((swift_attr("retain:immortal"))) \ - __attribute__((swift_attr("release:immortal"))) - -#define SWIFT_NONESCAPABLE \ - __attribute__((swift_attr("~Escapable"))) +#include struct A {}; struct SWIFT_NONESCAPABLE B {}; diff --git a/test/Interop/lit.local.cfg b/test/Interop/lit.local.cfg index 0a12b6af32e68..65e4f12046386 100644 --- a/test/Interop/lit.local.cfg +++ b/test/Interop/lit.local.cfg @@ -72,3 +72,5 @@ config.substitutions.insert(0, ( r'%check-c-header-in-clang -std=c11 -Wno-padded -Wno-c++-keyword -Wno-unknown-warning-option -Wno-pre-c11-compat \1' ) )) + +config.substitutions.insert(0, ('%bridging-path', '%swift_src_root%{fs-sep}lib%{fs-sep}ClangImporter%{fs-sep}SwiftBridging')) From 663ba2efb4189f681cdcf1fab5b21cda41e572ff Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Thu, 25 Sep 2025 10:28:04 -0700 Subject: [PATCH 05/11] [Swiftify] properly forward inout parameters using `&` While we handled prepending & to MutableSpan parameters, regular parameters that were unchanged during the transformation were not checked for inout-ness. --- lib/ClangImporter/ImportDecl.cpp | 4 +- .../SwiftMacros/SwiftifyImportMacro.swift | 9 +++- .../import-as-instance-method.swift | 46 ++++++++++++++++++- 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index c05c0e051835f..4fc13e2b4124a 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -9552,8 +9552,10 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) { isa(ClangDecl) && !isa(ClangDecl) && cast(ClangDecl)->isInstance(); + size_t swiftNumParams = MappedDecl->getParameters()->size() - + (ClangDecl->isVariadic() ? 1 : 0); ASSERT((MappedDecl->isImportAsInstanceMember() == isClangInstanceMethod) == - (ClangDecl->getNumParams() == MappedDecl->getParameters()->size())); + (ClangDecl->getNumParams() == swiftNumParams)); size_t selfParamIndex = MappedDecl->isImportAsInstanceMember() ? MappedDecl->getSelfIndex() diff --git a/lib/Macros/Sources/SwiftMacros/SwiftifyImportMacro.swift b/lib/Macros/Sources/SwiftMacros/SwiftifyImportMacro.swift index 0b83bb130e3c6..3f2a99749f998 100644 --- a/lib/Macros/Sources/SwiftMacros/SwiftifyImportMacro.swift +++ b/lib/Macros/Sources/SwiftMacros/SwiftifyImportMacro.swift @@ -468,7 +468,14 @@ struct FunctionCallBuilder: BoundsCheckedThunkBuilder { let functionRef = DeclReferenceExprSyntax(baseName: base.name) let args: [ExprSyntax] = base.signature.parameterClause.parameters.enumerated() .map { (i: Int, param: FunctionParameterSyntax) in - return pointerArgs[i] ?? ExprSyntax("\(param.name)") + if let overrideArg = pointerArgs[i] { + return overrideArg + } + if isInout(getParam(base.signature, i).type) { + return ExprSyntax("&\(param.name)") + } else { + return ExprSyntax("\(param.name)") + } } let labels: [TokenSyntax?] = base.signature.parameterClause.parameters.map { param in let firstName = param.firstName.trimmed diff --git a/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift b/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift index 7e9dd2cb831ff..95763ebad7441 100644 --- a/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift +++ b/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift @@ -18,6 +18,8 @@ func foo(_ p: inout MutableSpan, a: A, aa: inout A, s: IntSpan, cs: ConstI aa.refSelf(&p) aa.namespaced(&p) b.decapseman(&p) + baz.bar(&aa, &p) + baz.this(&aa, &p) let _: IntSpan = unsafe s.spanSelf() let _: MutableSpan = unsafe s.spanSelf() @@ -62,6 +64,8 @@ ConstIntSpan constSpanSelf(ConstIntSpan p __lifetimebound) __attribute__((swift_ 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:_:)"))); @@ -169,7 +173,7 @@ public mutating func refSelf(_ p: inout MutableSpan) { @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 public func refSelf(_ a: inout A, _ p: inout MutableSpan) { return unsafe p.withUnsafeMutableBufferPointer { _pPtr in - return unsafe refSelf(a, IntSpan(_pPtr)) + return unsafe refSelf(&a, IntSpan(_pPtr)) } } ------------------------------ @@ -213,6 +217,46 @@ public func decapseman(_ b: UnsafeMutablePointer!, _ p: inout MutableSpan } } ------------------------------ +@__swiftmacro_So3bazO8InstanceE3bar15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload +public static func bar(_ a: inout A, _ p: inout MutableSpan) { + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe bar(&a, IntSpan(_pPtr)) + } +} +------------------------------ +@__swiftmacro_So3bazO7renamed15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@available(swift, obsoleted: 3, renamed: "baz.bar(_:_:)") @_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload + public static func renamed(_ a: inout A, _ p: inout MutableSpan) { + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe renamed(&a, IntSpan(_pPtr)) + } +} +------------------------------ +@__swiftmacro_So3bazO4this15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload +public static func this(_ a: inout A, _ p: inout MutableSpan) { + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe this(&a, IntSpan(_pPtr)) + } +} +------------------------------ +@__swiftmacro_So3bazO4that15_SwiftifyImportfMp_.swift +------------------------------ +/// This is an auto-generated wrapper for safer interop +@available(swift, obsoleted: 3, renamed: "this(_:_:)") @_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload + public static func that(_ a: inout A, _ p: inout MutableSpan) { + return unsafe p.withUnsafeMutableBufferPointer { _pPtr in + return unsafe that(&a, IntSpan(_pPtr)) + } +} +------------------------------ @__swiftmacro_So3stdO3__1O0056spanCInt_CUnsignedLong_18446744073709551615_syGJqopasxheV8InstanceE8spanSelf15_SwiftifyImportfMp_.swift ------------------------------ /// This is an auto-generated wrapper for safer interop From b59dc2326e8d73c6af15418b314d5403c290319a Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Thu, 25 Sep 2025 14:46:59 -0700 Subject: [PATCH 06/11] try to debug CI diff failure --- .../Interop/Cxx/swiftify-import/import-as-instance-method.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift b/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift index 95763ebad7441..da7aaf245e226 100644 --- a/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift +++ b/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift @@ -4,7 +4,7 @@ // RUN: split-file %s %t // 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> %t/out.txt -// RUN: diff --strip-trailing-cr %t/out.txt %t/out.expected +// RUN: diff -u --strip-trailing-cr %t/out.txt %t/out.expected // 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 %t/test.swift -DVERIFY //--- test.swift From bfe96dd84b211192430c67ed45903e339660d495 Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Thu, 25 Sep 2025 17:42:02 -0700 Subject: [PATCH 07/11] [Swiftify] Reorder RUN lines (NFC) Since the compiler invokation performing the macro expansion dump redirects its stderr output, any errors are not displayed by default. This is extra problematic for test failures in CI. By performing the compiler invokation with -verify first, errors are shown. --- test/Interop/C/swiftify-import/import-as-instance-method.swift | 2 +- .../Interop/Cxx/swiftify-import/import-as-instance-method.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Interop/C/swiftify-import/import-as-instance-method.swift b/test/Interop/C/swiftify-import/import-as-instance-method.swift index 7b5e97aaaf10c..53ba6c2e3c3a6 100644 --- a/test/Interop/C/swiftify-import/import-as-instance-method.swift +++ b/test/Interop/C/swiftify-import/import-as-instance-method.swift @@ -3,9 +3,9 @@ // 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 -verify -verify-additional-file %t/Inputs/instance.h %t/test.swift -I %bridging-path -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 -dump-macro-expansions -I %bridging-path 2> %t/out.txt // RUN: diff --strip-trailing-cr %t/out.txt %t/out.expected -// 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 -verify -verify-additional-file %t/Inputs/instance.h %t/test.swift -I %bridging-path -DVERIFY //--- test.swift import Instance diff --git a/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift b/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift index da7aaf245e226..8d5fdbf53eaa9 100644 --- a/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift +++ b/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift @@ -3,9 +3,9 @@ // 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 %t/test.swift -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> %t/out.txt // RUN: diff -u --strip-trailing-cr %t/out.txt %t/out.expected -// 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 %t/test.swift -DVERIFY //--- test.swift import Instance From e3df479943b49b3c59cf3cb3c16f8aa39592fe29 Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Thu, 25 Sep 2025 19:12:40 -0700 Subject: [PATCH 08/11] deduplicate path --- .../Interop/Cxx/swiftify-import/import-as-instance-method.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift b/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift index 8d5fdbf53eaa9..3ea6cca02dbe6 100644 --- a/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift +++ b/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift @@ -3,7 +3,7 @@ // 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 %t/test.swift -DVERIFY +// 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> %t/out.txt // RUN: diff -u --strip-trailing-cr %t/out.txt %t/out.expected From 34f3195a71b0f53502b992b9e22e45ff3d30b1c3 Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Thu, 25 Sep 2025 21:49:29 -0700 Subject: [PATCH 09/11] re-export std::span regardless of module name --- .../Interop/Cxx/swiftify-import/import-as-instance-method.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift b/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift index 3ea6cca02dbe6..571126c7ccfb6 100644 --- a/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift +++ b/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift @@ -73,7 +73,7 @@ void decapseman(baz::B *b, IntSpan p __noescape) __attribute__((swift_name("baz. //--- Inputs/module.modulemap module Instance { header "instance.h" - export std.span + export * } //--- out.expected From f7d5902db5e3d5451de1b5f6a6854a97debd6697 Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Tue, 30 Sep 2025 13:59:34 -0700 Subject: [PATCH 10/11] add std::span to module map for libstdc++ --- .../public/Cxx/libstdcxx/libstdcxx.modulemap | 1 + .../access/swiftify-private-fileid.swift | 3 - .../Cxx/stdlib/std-span-interface.swift | 3 - .../std-span-transformed-execution.swift | 3 - .../Cxx/stdlib/use-std-span-typechecker.swift | 3 - test/Interop/Cxx/stdlib/use-std-span.swift | 3 - .../import-as-instance-method.swift | 467 +++++++++--------- .../Cxx/swiftify-import/span-in-ctor.swift | 3 - .../CxxToSwiftToCxx/span/span-execution.cpp | 3 - 9 files changed, 234 insertions(+), 255 deletions(-) diff --git a/stdlib/public/Cxx/libstdcxx/libstdcxx.modulemap b/stdlib/public/Cxx/libstdcxx/libstdcxx.modulemap index 4627ffd22307b..aec95fcd5523c 100644 --- a/stdlib/public/Cxx/libstdcxx/libstdcxx.modulemap +++ b/stdlib/public/Cxx/libstdcxx/libstdcxx.modulemap @@ -42,6 +42,7 @@ module std { header "ostream" header "queue" header "set" + header "span" header "sstream" header "stack" header "stdexcept" diff --git a/test/Interop/Cxx/class/access/swiftify-private-fileid.swift b/test/Interop/Cxx/class/access/swiftify-private-fileid.swift index 020295d8f8d8b..cd12684535fd3 100644 --- a/test/Interop/Cxx/class/access/swiftify-private-fileid.swift +++ b/test/Interop/Cxx/class/access/swiftify-private-fileid.swift @@ -5,9 +5,6 @@ // REQUIRES: swift_feature_SafeInteropWrappers -// FIXME swift-ci linux tests do not support std::span -// UNSUPPORTED: OS=linux-gnu, OS=linux-android, OS=linux-androideabi - //--- Inputs/swiftify-non-public.h #pragma once diff --git a/test/Interop/Cxx/stdlib/std-span-interface.swift b/test/Interop/Cxx/stdlib/std-span-interface.swift index 0cf298f6b63f2..680cb5adb16a0 100644 --- a/test/Interop/Cxx/stdlib/std-span-interface.swift +++ b/test/Interop/Cxx/stdlib/std-span-interface.swift @@ -8,9 +8,6 @@ // REQUIRES: swift_feature_SafeInteropWrappers // REQUIRES: swift_feature_Lifetimes -// FIXME swift-ci linux tests do not support std::span -// UNSUPPORTED: OS=linux-gnu, OS=linux-android, OS=linux-androideabi - #if !BRIDGING_HEADER import StdSpan #endif diff --git a/test/Interop/Cxx/stdlib/std-span-transformed-execution.swift b/test/Interop/Cxx/stdlib/std-span-transformed-execution.swift index a1ada02cb4dff..aac46b5afa75b 100644 --- a/test/Interop/Cxx/stdlib/std-span-transformed-execution.swift +++ b/test/Interop/Cxx/stdlib/std-span-transformed-execution.swift @@ -1,8 +1,5 @@ // RUN: %target-run-simple-swift(-plugin-path %swift-plugin-dir -I %S/Inputs -Xfrontend -enable-experimental-cxx-interop -swift-version 6 -Xfrontend -disable-availability-checking -Xcc -std=c++20 -enable-experimental-feature LifetimeDependence -enable-experimental-feature SafeInteropWrappers) -// FIXME swift-ci linux tests do not support std::span -// UNSUPPORTED: OS=linux-gnu - // TODO: test failed in Windows PR testing: rdar://144384453 // UNSUPPORTED: OS=windows-msvc diff --git a/test/Interop/Cxx/stdlib/use-std-span-typechecker.swift b/test/Interop/Cxx/stdlib/use-std-span-typechecker.swift index 7b868bb347748..98ad28fac487e 100644 --- a/test/Interop/Cxx/stdlib/use-std-span-typechecker.swift +++ b/test/Interop/Cxx/stdlib/use-std-span-typechecker.swift @@ -1,8 +1,5 @@ // RUN: %target-typecheck-verify-swift -I %S/Inputs -enable-experimental-cxx-interop -Xcc -std=c++20 2>&1 -// FIXME swift-ci linux tests do not support std::span -// UNSUPPORTED: OS=linux-gnu - import StdSpan let arr: [Int32] = [1, 2, 3] diff --git a/test/Interop/Cxx/stdlib/use-std-span.swift b/test/Interop/Cxx/stdlib/use-std-span.swift index 89644de5a9d90..478be72399651 100644 --- a/test/Interop/Cxx/stdlib/use-std-span.swift +++ b/test/Interop/Cxx/stdlib/use-std-span.swift @@ -1,9 +1,6 @@ // RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop -Xcc -std=c++20) // RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop -Xcc -std=c++20 -Xcc -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG) -// FIXME swift-ci linux tests do not support std::span -// UNSUPPORTED: OS=linux-gnu - // TODO: test failed in Windows PR testing: rdar://144384453 // UNSUPPORTED: OS=windows-msvc diff --git a/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift b/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift index 571126c7ccfb6..b9406f0d3e0d8 100644 --- a/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift +++ b/test/Interop/Cxx/swiftify-import/import-as-instance-method.swift @@ -4,8 +4,7 @@ // 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> %t/out.txt -// RUN: diff -u --strip-trailing-cr %t/out.txt %t/out.expected +// 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 //--- test.swift import Instance @@ -77,235 +76,235 @@ module Instance { } //--- out.expected -@__swiftmacro_So1AV5basic15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload -public mutating func basic(_ p: inout MutableSpan) { - return unsafe p.withUnsafeMutableBufferPointer { _pPtr in - return unsafe basic(IntSpan(_pPtr)) - } -} ------------------------------- -@__swiftmacro_So5basic15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@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 -public func basic(_ a: UnsafeMutablePointer!, _ p: inout MutableSpan) { - return unsafe p.withUnsafeMutableBufferPointer { _pPtr in - return unsafe basic(a, IntSpan(_pPtr)) - } -} ------------------------------- -@__swiftmacro_So1AV3bar15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload -public mutating func bar(_ p: inout MutableSpan) { - return unsafe p.withUnsafeMutableBufferPointer { _pPtr in - return unsafe bar(IntSpan(_pPtr)) - } -} ------------------------------- -@__swiftmacro_So7renamed15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@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 -public func renamed(_ a: UnsafeMutablePointer!, _ p: inout MutableSpan) { - return unsafe p.withUnsafeMutableBufferPointer { _pPtr in - return unsafe renamed(a, IntSpan(_pPtr)) - } -} ------------------------------- -@__swiftmacro_So1AV9constSelf15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload -public func constSelf(_ p: inout MutableSpan) { - return unsafe p.withUnsafeMutableBufferPointer { _pPtr in - return unsafe constSelf(IntSpan(_pPtr)) - } -} ------------------------------- -@__swiftmacro_So9constSelf15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@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 -public func constSelf(_ a: UnsafePointer!, _ p: inout MutableSpan) { - return unsafe p.withUnsafeMutableBufferPointer { _pPtr in - return unsafe constSelf(a, IntSpan(_pPtr)) - } -} ------------------------------- -@__swiftmacro_So1AV7valSelf15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload -public func valSelf(_ p: inout MutableSpan) { - return unsafe p.withUnsafeMutableBufferPointer { _pPtr in - return unsafe valSelf(IntSpan(_pPtr)) - } -} ------------------------------- -@__swiftmacro_So7valSelf15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@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 -public func valSelf(_ a: A, _ p: inout MutableSpan) { - return unsafe p.withUnsafeMutableBufferPointer { _pPtr in - return unsafe valSelf(a, IntSpan(_pPtr)) - } -} ------------------------------- -@__swiftmacro_So1AV7refSelf15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload -public mutating func refSelf(_ p: inout MutableSpan) { - return unsafe p.withUnsafeMutableBufferPointer { _pPtr in - return unsafe refSelf(IntSpan(_pPtr)) - } -} ------------------------------- -@__swiftmacro_So7refSelf15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@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 -public func refSelf(_ a: inout A, _ p: inout MutableSpan) { - return unsafe p.withUnsafeMutableBufferPointer { _pPtr in - return unsafe refSelf(&a, IntSpan(_pPtr)) - } -} ------------------------------- -@__swiftmacro_So1AV10namespaced15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload -public mutating func namespaced(_ p: inout MutableSpan) { - return unsafe p.withUnsafeMutableBufferPointer { _pPtr in - return unsafe namespaced(IntSpan(_pPtr)) - } -} ------------------------------- -@__swiftmacro_So3bazO10namespaced15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@available(swift, obsoleted: 3, renamed: "A.namespaced(self:_:)") @_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload - public static func namespaced(_ a: UnsafeMutablePointer!, _ p: inout MutableSpan) { - return unsafe p.withUnsafeMutableBufferPointer { _pPtr in - return unsafe namespaced(a, IntSpan(_pPtr)) - } -} ------------------------------- -@__swiftmacro_So3bazO1BV8InstanceE10decapseman15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload -public mutating func decapseman(_ p: inout MutableSpan) { - return unsafe p.withUnsafeMutableBufferPointer { _pPtr in - return unsafe decapseman(IntSpan(_pPtr)) - } -} ------------------------------- -@__swiftmacro_So10decapseman15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@available(swift, obsoleted: 3, renamed: "baz.B.decapseman(self:_:)") @_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload -public func decapseman(_ b: UnsafeMutablePointer!, _ p: inout MutableSpan) { - return unsafe p.withUnsafeMutableBufferPointer { _pPtr in - return unsafe decapseman(b, IntSpan(_pPtr)) - } -} ------------------------------- -@__swiftmacro_So3bazO8InstanceE3bar15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload -public static func bar(_ a: inout A, _ p: inout MutableSpan) { - return unsafe p.withUnsafeMutableBufferPointer { _pPtr in - return unsafe bar(&a, IntSpan(_pPtr)) - } -} ------------------------------- -@__swiftmacro_So3bazO7renamed15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@available(swift, obsoleted: 3, renamed: "baz.bar(_:_:)") @_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload - public static func renamed(_ a: inout A, _ p: inout MutableSpan) { - return unsafe p.withUnsafeMutableBufferPointer { _pPtr in - return unsafe renamed(&a, IntSpan(_pPtr)) - } -} ------------------------------- -@__swiftmacro_So3bazO4this15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload -public static func this(_ a: inout A, _ p: inout MutableSpan) { - return unsafe p.withUnsafeMutableBufferPointer { _pPtr in - return unsafe this(&a, IntSpan(_pPtr)) - } -} ------------------------------- -@__swiftmacro_So3bazO4that15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@available(swift, obsoleted: 3, renamed: "this(_:_:)") @_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(p: copy p) @_disfavoredOverload - public static func that(_ a: inout A, _ p: inout MutableSpan) { - return unsafe p.withUnsafeMutableBufferPointer { _pPtr in - return unsafe that(&a, IntSpan(_pPtr)) - } -} ------------------------------- -@__swiftmacro_So3stdO3__1O0056spanCInt_CUnsignedLong_18446744073709551615_syGJqopasxheV8InstanceE8spanSelf15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(borrow self) @_disfavoredOverload -public func spanSelf() -> MutableSpan { - return unsafe _swiftifyOverrideLifetime(MutableSpan(_unsafeCxxSpan: unsafe spanSelf()), copying: ()) -} ------------------------------- -@__swiftmacro_So8spanSelf15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@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 -public func spanSelf(_ p: inout MutableSpan) -> MutableSpan { - return unsafe _swiftifyOverrideLifetime(MutableSpan(_unsafeCxxSpan: unsafe p.withUnsafeMutableBufferPointer { _pPtr in - return unsafe spanSelf(IntSpan(_pPtr)) - }), copying: ()) -} ------------------------------- -@__swiftmacro_So3stdO3__1O0056spanCInt_CUnsignedLong_18446744073709551615_syGJqopasxheV8InstanceE13spanConstSelf15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(borrow self) @_disfavoredOverload -public func spanConstSelf() -> MutableSpan { - return unsafe _swiftifyOverrideLifetime(MutableSpan(_unsafeCxxSpan: unsafe spanConstSelf()), copying: ()) -} ------------------------------- -@__swiftmacro_So13spanConstSelf15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@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 -public func spanConstSelf(_ p: inout MutableSpan) -> MutableSpan { - return unsafe _swiftifyOverrideLifetime(MutableSpan(_unsafeCxxSpan: unsafe p.withUnsafeMutableBufferPointer { _pPtr in - return unsafe spanConstSelf(IntSpan(_pPtr)) - }), copying: ()) -} ------------------------------- -@__swiftmacro_So3stdO3__1O0071span__cxxConstCInt_CUnsignedLong_18446744073709551615_ilHEvDsarBakaEjpbV8InstanceE13constSpanSelf15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@_alwaysEmitIntoClient @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) @_lifetime(borrow self) @_disfavoredOverload -public func constSpanSelf() -> Span { - return unsafe _swiftifyOverrideLifetime(Span(_unsafeCxxSpan: unsafe constSpanSelf()), copying: ()) -} ------------------------------- -@__swiftmacro_So13constSpanSelf15_SwiftifyImportfMp_.swift ------------------------------- -/// This is an auto-generated wrapper for safer interop -@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 -public func constSpanSelf(_ p: Span) -> Span { - return unsafe _swiftifyOverrideLifetime(Span(_unsafeCxxSpan: unsafe constSpanSelf(ConstIntSpan(p))), copying: ()) -} ------------------------------- +// 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) { +// 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!, _ p: inout MutableSpan) { +// 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) { +// 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!, _ p: inout MutableSpan) { +// 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) { +// 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!, _ p: inout MutableSpan) { +// 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) { +// 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) { +// 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) { +// 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) { +// 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_{{.*}}namespaced{{.*}}_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 namespaced(_ p: inout MutableSpan) { +// CHECK-NEXT: return unsafe p.withUnsafeMutableBufferPointer { _pPtr in +// CHECK-NEXT: return unsafe namespaced(IntSpan(_pPtr)) +// CHECK-NEXT: } +// CHECK-NEXT:} +// CHECK-NEXT:------------------------------ +// CHECK-NEXT:@__swiftmacro_{{.*}}baz{{.*}}namespaced{{.*}}_SwiftifyImportfMp_.swift +// CHECK-NEXT:------------------------------ +// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop +// CHECK-NEXT:@available(swift, obsoleted: 3, renamed: "A.namespaced(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 static func namespaced(_ a: UnsafeMutablePointer!, _ p: inout MutableSpan) { +// CHECK-NEXT: return unsafe p.withUnsafeMutableBufferPointer { _pPtr in +// CHECK-NEXT: return unsafe namespaced(a, IntSpan(_pPtr)) +// CHECK-NEXT: } +// CHECK-NEXT:} +// CHECK-NEXT:------------------------------ +// CHECK-NEXT:@__swiftmacro_{{.*}}baz{{.*}}Instance{{.*}}decapseman{{.*}}_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 decapseman(_ p: inout MutableSpan) { +// CHECK-NEXT: return unsafe p.withUnsafeMutableBufferPointer { _pPtr in +// CHECK-NEXT: return unsafe decapseman(IntSpan(_pPtr)) +// CHECK-NEXT: } +// CHECK-NEXT:} +// CHECK-NEXT:------------------------------ +// CHECK-NEXT:@__swiftmacro_{{.*}}decapseman{{.*}}_SwiftifyImportfMp_.swift +// CHECK-NEXT:------------------------------ +// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop +// CHECK-NEXT:@available(swift, obsoleted: 3, renamed: "baz.B.decapseman(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 decapseman(_ b: UnsafeMutablePointer!, _ p: inout MutableSpan) { +// CHECK-NEXT: return unsafe p.withUnsafeMutableBufferPointer { _pPtr in +// CHECK-NEXT: return unsafe decapseman(b, IntSpan(_pPtr)) +// CHECK-NEXT: } +// CHECK-NEXT:} +// CHECK-NEXT:------------------------------ +// CHECK-NEXT:@__swiftmacro_{{.*}}baz{{.*}}Instance{{.*}}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 static func bar(_ a: inout A, _ p: inout MutableSpan) { +// CHECK-NEXT: return unsafe p.withUnsafeMutableBufferPointer { _pPtr in +// CHECK-NEXT: return unsafe bar(&a, IntSpan(_pPtr)) +// CHECK-NEXT: } +// CHECK-NEXT:} +// CHECK-NEXT:------------------------------ +// CHECK-NEXT:@__swiftmacro_{{.*}}baz{{.*}}renamed{{.*}}_SwiftifyImportfMp_.swift +// CHECK-NEXT:------------------------------ +// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop +// CHECK-NEXT:@available(swift, obsoleted: 3, renamed: "baz.bar(_:_:)") @_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 static func renamed(_ a: inout A, _ p: inout MutableSpan) { +// 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_{{.*}}baz{{.*}}this{{.*}}_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 static func this(_ a: inout A, _ p: inout MutableSpan) { +// CHECK-NEXT: return unsafe p.withUnsafeMutableBufferPointer { _pPtr in +// CHECK-NEXT: return unsafe this(&a, IntSpan(_pPtr)) +// CHECK-NEXT: } +// CHECK-NEXT:} +// CHECK-NEXT:------------------------------ +// CHECK-NEXT:@__swiftmacro_{{.*}}baz{{.*}}that{{.*}}_SwiftifyImportfMp_.swift +// CHECK-NEXT:------------------------------ +// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop +// CHECK-NEXT:@available(swift, obsoleted: 3, renamed: "this(_:_:)") @_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 static func that(_ a: inout A, _ p: inout MutableSpan) { +// CHECK-NEXT: return unsafe p.withUnsafeMutableBufferPointer { _pPtr in +// CHECK-NEXT: return unsafe that(&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 { +// 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) -> MutableSpan { +// 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 { +// 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) -> MutableSpan { +// 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 { +// 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) -> Span { +// CHECK-NEXT: return unsafe _swiftifyOverrideLifetime(Span(_unsafeCxxSpan: unsafe constSpanSelf(ConstIntSpan(p))), copying: ()) +// CHECK-NEXT:} +// CHECK-NEXT:------------------------------ diff --git a/test/Interop/Cxx/swiftify-import/span-in-ctor.swift b/test/Interop/Cxx/swiftify-import/span-in-ctor.swift index 7e824cd0ea9ec..d138152bb06b1 100644 --- a/test/Interop/Cxx/swiftify-import/span-in-ctor.swift +++ b/test/Interop/Cxx/swiftify-import/span-in-ctor.swift @@ -1,8 +1,5 @@ // REQUIRES: swift_feature_SafeInteropWrappers -// FIXME swift-ci linux tests do not support std::span -// UNSUPPORTED: OS=linux-gnu, OS=linux-android, OS=linux-androideabi - // RUN: rm -rf %t // RUN: split-file %s %t // RUN: %target-swift-frontend -c -plugin-path %swift-plugin-dir -I %t/Inputs -Xcc -std=c++20 -cxx-interoperability-mode=default -enable-experimental-feature SafeInteropWrappers %t/method.swift -dump-macro-expansions -verify 2>&1 | %FileCheck %s diff --git a/test/Interop/CxxToSwiftToCxx/span/span-execution.cpp b/test/Interop/CxxToSwiftToCxx/span/span-execution.cpp index 06864db50f3c3..d087c08d4a463 100644 --- a/test/Interop/CxxToSwiftToCxx/span/span-execution.cpp +++ b/test/Interop/CxxToSwiftToCxx/span/span-execution.cpp @@ -9,9 +9,6 @@ // RUN: %target-codesign %t/swift-cxx-execution // RUN: %target-run %t/swift-cxx-execution | %FileCheck %s -// FIXME swift-ci linux tests do not support std::span -// UNSUPPORTED: OS=linux-gnu - // REQUIRES: executable_test //--- header.h From 0c3db50e3dca6f4b0232483a2f5dd105ba8d9388 Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Tue, 30 Sep 2025 18:59:57 -0700 Subject: [PATCH 11/11] fix -verify-additional-file path on windows --- test/Interop/C/swiftify-import/import-as-instance-method.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Interop/C/swiftify-import/import-as-instance-method.swift b/test/Interop/C/swiftify-import/import-as-instance-method.swift index 53ba6c2e3c3a6..577cf7f122fbe 100644 --- a/test/Interop/C/swiftify-import/import-as-instance-method.swift +++ b/test/Interop/C/swiftify-import/import-as-instance-method.swift @@ -3,7 +3,7 @@ // 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 -verify -verify-additional-file %t/Inputs/instance.h %t/test.swift -I %bridging-path -DVERIFY +// RUN: %target-swift-frontend -emit-module -plugin-path %swift-plugin-dir -o %t/Test.swiftmodule -I %t%{fs-sep}Inputs -enable-experimental-feature SafeInteropWrappers -strict-memory-safety -verify -verify-additional-file %t%{fs-sep}Inputs%{fs-sep}instance.h %t/test.swift -I %bridging-path -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 -dump-macro-expansions -I %bridging-path 2> %t/out.txt // RUN: diff --strip-trailing-cr %t/out.txt %t/out.expected