From 67e2024417d406411a72a796236676db578b4d80 Mon Sep 17 00:00:00 2001 From: Egor Zhdan Date: Tue, 17 Jun 2025 19:42:14 +0100 Subject: [PATCH] [cxx-interop] Make usages of Swift Span `@_alwaysEmitIntoClient` in the overlay This fixes a regression where projects that use the C++ stdlib overlay stop building because of a linker error: ``` ld: Shared cache eligible dylib cannot link to ineligible dylib '@rpath/libswiftCompatibilitySpan.dylib'. ``` Usages of `Span` would generally cause a type metadata accessor to be emitted for `Swift.Span`. This becomes a problem with backdeployment, since Span is partially defined in a compatibility binary. This change adds `@_alwaysEmitIntoClient` to generic usages of `Span` to prevent the type metadata accessor from being emitted into `libswiftCxx.a`. rdar://152192080 --- stdlib/public/Cxx/CxxSpan.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stdlib/public/Cxx/CxxSpan.swift b/stdlib/public/Cxx/CxxSpan.swift index fcd202d87c5a2..9a9568a59c5a0 100644 --- a/stdlib/public/Cxx/CxxSpan.swift +++ b/stdlib/public/Cxx/CxxSpan.swift @@ -74,14 +74,14 @@ public protocol CxxSpan { extension CxxSpan { /// Creates a C++ span from a Swift UnsafeBufferPointer - @inlinable + @_alwaysEmitIntoClient public init(_ unsafeBufferPointer: UnsafeBufferPointer) { unsafe precondition(unsafeBufferPointer.baseAddress != nil, "UnsafeBufferPointer should not point to nil") unsafe self.init(unsafeBufferPointer.baseAddress!, Size(unsafeBufferPointer.count)) } - @inlinable + @_alwaysEmitIntoClient public init(_ unsafeMutableBufferPointer: UnsafeMutableBufferPointer) { unsafe precondition(unsafeMutableBufferPointer.baseAddress != nil, "UnsafeMutableBufferPointer should not point to nil") @@ -89,7 +89,7 @@ extension CxxSpan { } @available(SwiftCompatibilitySpan 5.0, *) - @inlinable + @_alwaysEmitIntoClient @unsafe public init(_ span: Span) { let (p, c) = unsafe unsafeBitCast(span, to: (UnsafeRawPointer?, Int).self) @@ -144,7 +144,7 @@ public protocol CxxMutableSpan { extension CxxMutableSpan { /// Creates a C++ span from a Swift UnsafeMutableBufferPointer - @inlinable + @_alwaysEmitIntoClient public init(_ unsafeMutableBufferPointer: UnsafeMutableBufferPointer) { unsafe precondition(unsafeMutableBufferPointer.baseAddress != nil, "UnsafeMutableBufferPointer should not point to nil") @@ -152,7 +152,7 @@ extension CxxMutableSpan { } @available(SwiftCompatibilitySpan 5.0, *) - @inlinable + @_alwaysEmitIntoClient @unsafe public init(_ span: consuming MutableSpan) { let (p, c) = unsafe unsafeBitCast(span, to: (UnsafeMutableRawPointer?, Int).self)