Skip to content

Commit 0659f7f

Browse files
committed
stdlib: Build libswiftCompatibility62.dylib compatibility shim
This dynamic library contains a copy of the standard library's exported entry points for the Span and RawSpan types. This will allow backward deployment of code that uses those new types.
1 parent 26eaf75 commit 0659f7f

File tree

5 files changed

+131
-0
lines changed

5 files changed

+131
-0
lines changed

stdlib/public/core/Span/RawSpan.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if SPAN_COMPATIBILITY_STUB
14+
import Swift
15+
#endif
16+
1317
/// `RawSpan` represents a contiguous region of memory
1418
/// which contains initialized bytes.
1519
///

stdlib/public/core/Span/Span.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if SPAN_COMPATIBILITY_STUB
14+
import Swift
15+
#endif
16+
1317
/// `Span<Element>` represents a contiguous region of memory
1418
/// which contains initialized instances of `Element`.
1519
///

stdlib/toolchain/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ if(SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT)
5050
add_subdirectory(Compatibility50)
5151
add_subdirectory(Compatibility51)
5252
add_subdirectory(Compatibility56)
53+
add_subdirectory(Compatibility62)
5354
add_subdirectory(CompatibilityDynamicReplacements)
5455
add_subdirectory(CompatibilityConcurrency)
5556
add_subdirectory(CompatibilityThreading)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
set(library_name "swiftCompatibility62")
2+
3+
add_swift_target_library("${library_name}" ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
4+
FakeStdlib.swift
5+
../../public/core/Span/RawSpan.swift
6+
../../public/core/Span/Span.swift
7+
8+
TARGET_SDKS ${SWIFT_APPLE_PLATFORMS}
9+
10+
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
11+
12+
SWIFT_COMPILE_FLAGS
13+
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
14+
-parse-stdlib
15+
-module-abi-name Swift
16+
-DSPAN_COMPATIBILITY_STUB
17+
18+
DEPLOYMENT_VERSION_OSX ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_OSX}
19+
DEPLOYMENT_VERSION_IOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_IOS}
20+
DEPLOYMENT_VERSION_TVOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_TVOS}
21+
DEPLOYMENT_VERSION_WATCHOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_WATCHOS}
22+
23+
MACCATALYST_BUILD_FLAVOR "zippered"
24+
25+
INSTALL_IN_COMPONENT compiler
26+
27+
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}" -Xlinker -not_for_dyld_shared_cache
28+
29+
BACK_DEPLOYMENT_LIBRARY 6.2)
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//===--- FakeStdlib.swift -------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// A handful of standard library stubs to allow Span.swift and RawSpan.swift
14+
// to be compiled as part of the compatibility shim.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
import Swift
19+
20+
@_alwaysEmitIntoClient @_transparent
21+
internal func _precondition(
22+
_ condition: @autoclosure () -> Bool, _ message: StaticString = StaticString(),
23+
file: StaticString = #file, line: UInt = #line
24+
) {
25+
fatalError()
26+
}
27+
28+
@_alwaysEmitIntoClient @_transparent
29+
internal func _internalInvariantFailure(
30+
_ message: StaticString = StaticString(),
31+
file: StaticString = #file, line: UInt = #line
32+
) -> Never {
33+
fatalError()
34+
}
35+
36+
/// Unsafely discard any lifetime dependency on the `dependent` argument. Return
37+
/// a value identical to `dependent` with a lifetime dependency on the caller's
38+
/// borrow scope of the `source` argument.
39+
@unsafe
40+
@_unsafeNonescapableResult
41+
@_alwaysEmitIntoClient
42+
@_transparent
43+
@lifetime(borrow source)
44+
internal func _overrideLifetime<
45+
T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable
46+
>(
47+
_ dependent: consuming T, borrowing source: borrowing U
48+
) -> T {
49+
// TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence
50+
// should be expressed by a builtin that is hidden within the function body.
51+
dependent
52+
}
53+
54+
/// Unsafely discard any lifetime dependency on the `dependent` argument. Return
55+
/// a value identical to `dependent` that inherits all lifetime dependencies from
56+
/// the `source` argument.
57+
@unsafe
58+
@_unsafeNonescapableResult
59+
@_alwaysEmitIntoClient
60+
@_transparent
61+
@lifetime(source)
62+
internal func _overrideLifetime<
63+
T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable
64+
>(
65+
_ dependent: consuming T, copying source: borrowing U
66+
) -> T {
67+
// TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence
68+
// should be expressed by a builtin that is hidden within the function body.
69+
dependent
70+
}
71+
72+
extension Range {
73+
@_alwaysEmitIntoClient
74+
internal init(_uncheckedBounds bounds: (lower: Bound, upper: Bound)) {
75+
self.init(uncheckedBounds: bounds)
76+
}
77+
}
78+
79+
extension Optional {
80+
/// - Returns: `unsafelyUnwrapped`.
81+
///
82+
/// This version is for internal stdlib use; it avoids any checking
83+
/// overhead for users, even in Debug builds.
84+
@_alwaysEmitIntoClient
85+
internal var _unsafelyUnwrappedUnchecked: Wrapped {
86+
get {
87+
if let x = self {
88+
return x
89+
}
90+
_internalInvariantFailure("_unsafelyUnwrappedUnchecked of nil optional")
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)