Skip to content

Commit 31235db

Browse files
committed
[stdlib] add OutputSpan to backdeployment library
1 parent 2e0c0fe commit 31235db

File tree

5 files changed

+98
-23
lines changed

5 files changed

+98
-23
lines changed

stdlib/public/core/Span/OutputRawSpan.swift

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if SPAN_COMPATIBILITY_STUB
14+
import Swift
15+
#endif
16+
1317
// OutputRawSpan is a reference to a contiguous region of memory which starts
1418
// some number of initialized bytes, followed by uninitialized memory.
1519
@safe
1620
@frozen
17-
@available(SwiftStdlib 6.2, *)
21+
@available(SwiftCompatibilitySpan 5.0, *)
22+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
1823
public struct OutputRawSpan: ~Copyable, ~Escapable {
1924
@usableFromInline
2025
internal let _pointer: UnsafeMutableRawPointer?
@@ -34,10 +39,12 @@ public struct OutputRawSpan: ~Copyable, ~Escapable {
3439
}
3540
}
3641

37-
@available(SwiftStdlib 6.2, *)
42+
@available(SwiftCompatibilitySpan 5.0, *)
43+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
3844
extension OutputRawSpan: @unchecked Sendable {}
3945

40-
@available(SwiftStdlib 6.2, *)
46+
@available(SwiftCompatibilitySpan 5.0, *)
47+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
4148
extension OutputRawSpan {
4249
@_alwaysEmitIntoClient
4350
@_transparent
@@ -55,7 +62,8 @@ extension OutputRawSpan {
5562
}
5663
}
5764

58-
@available(SwiftStdlib 6.2, *)
65+
@available(SwiftCompatibilitySpan 5.0, *)
66+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
5967
extension OutputRawSpan {
6068
/// The number of initialized bytes in this span.
6169
@_alwaysEmitIntoClient
@@ -74,7 +82,8 @@ extension OutputRawSpan {
7482
public var isFull: Bool { _count == capacity }
7583
}
7684

77-
@available(SwiftStdlib 6.2, *)
85+
@available(SwiftCompatibilitySpan 5.0, *)
86+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
7887
extension OutputRawSpan {
7988

8089
@unsafe
@@ -148,7 +157,8 @@ extension OutputRawSpan {
148157
}
149158
}
150159

151-
@available(SwiftStdlib 6.2, *)
160+
@available(SwiftCompatibilitySpan 5.0, *)
161+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
152162
extension OutputRawSpan {
153163

154164
/// Append a single byte to this span.
@@ -193,7 +203,8 @@ extension OutputRawSpan {
193203
}
194204

195205
//MARK: bulk-append functions
196-
@available(SwiftStdlib 6.2, *)
206+
@available(SwiftCompatibilitySpan 5.0, *)
207+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
197208
extension OutputRawSpan {
198209
/// Appends the given value's bytes to this span's bytes.
199210
@_alwaysEmitIntoClient
@@ -221,7 +232,8 @@ extension OutputRawSpan {
221232
}
222233
}
223234

224-
@available(SwiftStdlib 6.2, *)
235+
@available(SwiftCompatibilitySpan 5.0, *)
236+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
225237
extension OutputRawSpan {
226238
/// Borrow the underlying initialized memory for read-only access.
227239
@_alwaysEmitIntoClient
@@ -248,7 +260,8 @@ extension OutputRawSpan {
248260
}
249261
}
250262

251-
@available(SwiftStdlib 6.2, *)
263+
@available(SwiftCompatibilitySpan 5.0, *)
264+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
252265
extension OutputRawSpan {
253266

254267
/// Call the given closure with the unsafe buffer pointer addressed by this
@@ -288,9 +301,15 @@ extension OutputRawSpan {
288301
}
289302
return unsafe try body(buffer, &initializedCount)
290303
}
304+
#if SPAN_COMPATIBILITY_STUB
305+
let buffer = unsafe UnsafeMutableRawBufferPointer(
306+
start: start, count: capacity
307+
)
308+
#else
291309
let buffer = unsafe UnsafeMutableRawBufferPointer(
292310
_uncheckedStart: start, count: capacity
293311
)
312+
#endif
294313
var initializedCount = _count
295314
defer {
296315
_precondition(
@@ -303,7 +322,8 @@ extension OutputRawSpan {
303322
}
304323
}
305324

306-
@available(SwiftStdlib 6.2, *)
325+
@available(SwiftCompatibilitySpan 5.0, *)
326+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
307327
extension OutputRawSpan {
308328
/// Consume the output span (relinquishing its control over the buffer it is
309329
/// addressing), and return the number of initialized bytes in it.

stdlib/public/core/Span/OutputSpan.swift

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if SPAN_COMPATIBILITY_STUB
14+
import Swift
15+
#endif
16+
1317
// `OutputSpan` is a reference to a contiguous region of memory that starts with
1418
// some number of initialized `Element` instances followed by uninitialized
1519
// memory. It provides operations to access the items it stores, as well as to
1620
// add new elements and to remove existing ones.
1721
@safe
1822
@frozen
19-
@available(SwiftStdlib 6.2, *)
23+
@available(SwiftCompatibilitySpan 5.0, *)
24+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
2025
public struct OutputSpan<Element: ~Copyable>: ~Copyable, ~Escapable {
2126
@usableFromInline
2227
internal let _pointer: UnsafeMutableRawPointer?
@@ -49,10 +54,12 @@ public struct OutputSpan<Element: ~Copyable>: ~Copyable, ~Escapable {
4954
}
5055
}
5156

52-
@available(SwiftStdlib 6.2, *)
57+
@available(SwiftCompatibilitySpan 5.0, *)
58+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
5359
extension OutputSpan: @unchecked Sendable where Element: Sendable & ~Copyable {}
5460

55-
@available(SwiftStdlib 6.2, *)
61+
@available(SwiftCompatibilitySpan 5.0, *)
62+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
5663
extension OutputSpan where Element: ~Copyable {
5764
@_alwaysEmitIntoClient
5865
@_transparent
@@ -70,7 +77,8 @@ extension OutputSpan where Element: ~Copyable {
7077
}
7178
}
7279

73-
@available(SwiftStdlib 6.2, *)
80+
@available(SwiftCompatibilitySpan 5.0, *)
81+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
7482
extension OutputSpan where Element: ~Copyable {
7583
/// The number of initialized elements in this span.
7684
@_alwaysEmitIntoClient
@@ -89,7 +97,8 @@ extension OutputSpan where Element: ~Copyable {
8997
public var isFull: Bool { _count == capacity }
9098
}
9199

92-
@available(SwiftStdlib 6.2, *)
100+
@available(SwiftCompatibilitySpan 5.0, *)
101+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
93102
extension OutputSpan where Element: ~Copyable {
94103

95104
@unsafe
@@ -141,7 +150,8 @@ extension OutputSpan where Element: ~Copyable {
141150
}
142151
}
143152

144-
@available(SwiftStdlib 6.2, *)
153+
@available(SwiftCompatibilitySpan 5.0, *)
154+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
145155
extension OutputSpan {
146156

147157
/// Unsafely create an OutputSpan over partly-initialized memory.
@@ -171,7 +181,8 @@ extension OutputSpan {
171181
}
172182
}
173183

174-
@available(SwiftStdlib 6.2, *)
184+
@available(SwiftCompatibilitySpan 5.0, *)
185+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
175186
extension OutputSpan where Element: ~Copyable {
176187
/// The type that represents an initialized position in an `OutputSpan`.
177188
public typealias Index = Int
@@ -259,7 +270,8 @@ extension OutputSpan where Element: ~Copyable {
259270
}
260271
}
261272

262-
@available(SwiftStdlib 6.2, *)
273+
@available(SwiftCompatibilitySpan 5.0, *)
274+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
263275
extension OutputSpan where Element: ~Copyable {
264276
/// Append a single element to this span.
265277
@_alwaysEmitIntoClient
@@ -311,7 +323,8 @@ extension OutputSpan where Element: ~Copyable {
311323
}
312324

313325
//MARK: bulk-append functions
314-
@available(SwiftStdlib 6.2, *)
326+
@available(SwiftCompatibilitySpan 5.0, *)
327+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
315328
extension OutputSpan {
316329

317330
/// Repeatedly append an element to this span.
@@ -326,7 +339,8 @@ extension OutputSpan {
326339
}
327340
}
328341

329-
@available(SwiftStdlib 6.2, *)
342+
@available(SwiftCompatibilitySpan 5.0, *)
343+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
330344
extension OutputSpan where Element: ~Copyable {
331345
/// Borrow the underlying initialized memory for read-only access.
332346
@_alwaysEmitIntoClient
@@ -355,7 +369,8 @@ extension OutputSpan where Element: ~Copyable {
355369
}
356370
}
357371

358-
@available(SwiftStdlib 6.2, *)
372+
@available(SwiftCompatibilitySpan 5.0, *)
373+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
359374
extension OutputSpan where Element: ~Copyable {
360375
/// Call the given closure with the unsafe buffer pointer addressed by this
361376
/// OutputSpan and a mutable reference to its count of initialized elements.
@@ -399,9 +414,15 @@ extension OutputSpan where Element: ~Copyable {
399414
start._rawValue, capacity._builtinWordValue, Element.self
400415
)
401416
defer { Builtin.rebindMemory(start._rawValue, binding) }
417+
#if SPAN_COMPATIBILITY_STUB
418+
let buffer = unsafe UnsafeMutableBufferPointer<Element>(
419+
start: .init(start._rawValue), count: capacity
420+
)
421+
#else
402422
let buffer = unsafe UnsafeMutableBufferPointer<Element>(
403423
_uncheckedStart: .init(start._rawValue), count: capacity
404424
)
425+
#endif
405426
var initializedCount = self._count
406427
defer {
407428
_precondition(
@@ -414,7 +435,8 @@ extension OutputSpan where Element: ~Copyable {
414435
}
415436
}
416437

417-
@available(SwiftStdlib 6.2, *)
438+
@available(SwiftCompatibilitySpan 5.0, *)
439+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
418440
extension OutputSpan where Element: ~Copyable {
419441
/// Consume the output span and return the number of initialized elements.
420442
///
@@ -447,7 +469,8 @@ extension OutputSpan where Element: ~Copyable {
447469
}
448470
}
449471

450-
@available(SwiftStdlib 6.2, *)
472+
@available(SwiftCompatibilitySpan 5.0, *)
473+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
451474
extension OutputSpan {
452475
/// Consume the output span and return the number of initialized elements.
453476
///

stdlib/toolchain/CompatibilitySpan/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND DEFINED SWIFT_STDLIB_LIBRARY_BUILD_TY
66
FakeStdlib.swift
77
../../public/core/Span/MutableRawSpan.swift
88
../../public/core/Span/MutableSpan.swift
9+
../../public/core/Span/OutputRawSpan.swift
10+
../../public/core/Span/OutputSpan.swift
911
../../public/core/Span/RawSpan.swift
1012
../../public/core/Span/Span.swift
1113

test/abi/macOS/arm64/stdlib.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,21 @@ Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss14M
10661066
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss14MutableRawSpanVMa$
10671067
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss14MutableRawSpanVMn$
10681068
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss14MutableRawSpanVN$
1069+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVMa$
1070+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVMn$
1071+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVsRi_zrlE6_countSivM$
1072+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVsRi_zrlE6_countSivg$
1073+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVsRi_zrlE6_countSivs$
1074+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVsRi_zrlE8_pointerSvSgvg$
1075+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVsRi_zrlE8capacitySivg$
1076+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanV6_countSivM$
1077+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanV6_countSivg$
1078+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanV6_countSivs$
1079+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanV8_pointerSvSgvg$
1080+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanV8capacitySivg$
1081+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanVMa$
1082+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanVMn$
1083+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanVN$
10691084
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss4SpanVMa$
10701085
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss4SpanVMn$
10711086
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss4SpanVsRi_zrlE6_countSivg$

test/abi/macOS/x86_64/stdlib.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,21 @@ Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss14M
10661066
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss14MutableRawSpanVMa$
10671067
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss14MutableRawSpanVMn$
10681068
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss14MutableRawSpanVN$
1069+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVMa$
1070+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVMn$
1071+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVsRi_zrlE6_countSivM$
1072+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVsRi_zrlE6_countSivg$
1073+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVsRi_zrlE6_countSivs$
1074+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVsRi_zrlE8_pointerSvSgvg$
1075+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVsRi_zrlE8capacitySivg$
1076+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanV6_countSivM$
1077+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanV6_countSivg$
1078+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanV6_countSivs$
1079+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanV8_pointerSvSgvg$
1080+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanV8capacitySivg$
1081+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanVMa$
1082+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanVMn$
1083+
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanVN$
10691084
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss4SpanVMa$
10701085
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss4SpanVMn$
10711086
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss4SpanVsRi_zrlE6_countSivg$

0 commit comments

Comments
 (0)