10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
+ #if SPAN_COMPATIBILITY_STUB
14
+ import Swift
15
+ #endif
16
+
13
17
// `OutputSpan` is a reference to a contiguous region of memory that starts with
14
18
// some number of initialized `Element` instances followed by uninitialized
15
19
// memory. It provides operations to access the items it stores, as well as to
16
20
// add new elements and to remove existing ones.
17
21
@safe
18
22
@frozen
19
- @available ( SwiftStdlib 6 . 2 , * )
23
+ @available ( SwiftCompatibilitySpan 5 . 0 , * )
24
+ @_originallyDefinedIn ( module: " Swift;CompatibilitySpan " , SwiftCompatibilitySpan 6 . 2 )
20
25
public struct OutputSpan < Element: ~ Copyable> : ~ Copyable, ~ Escapable {
21
26
@usableFromInline
22
27
internal let _pointer : UnsafeMutableRawPointer ?
@@ -49,10 +54,12 @@ public struct OutputSpan<Element: ~Copyable>: ~Copyable, ~Escapable {
49
54
}
50
55
}
51
56
52
- @available ( SwiftStdlib 6 . 2 , * )
57
+ @available ( SwiftCompatibilitySpan 5 . 0 , * )
58
+ @_originallyDefinedIn ( module: " Swift;CompatibilitySpan " , SwiftCompatibilitySpan 6 . 2 )
53
59
extension OutputSpan : @unchecked Sendable where Element: Sendable & ~ Copyable { }
54
60
55
- @available ( SwiftStdlib 6 . 2 , * )
61
+ @available ( SwiftCompatibilitySpan 5 . 0 , * )
62
+ @_originallyDefinedIn ( module: " Swift;CompatibilitySpan " , SwiftCompatibilitySpan 6 . 2 )
56
63
extension OutputSpan where Element: ~ Copyable {
57
64
@_alwaysEmitIntoClient
58
65
@_transparent
@@ -70,7 +77,8 @@ extension OutputSpan where Element: ~Copyable {
70
77
}
71
78
}
72
79
73
- @available ( SwiftStdlib 6 . 2 , * )
80
+ @available ( SwiftCompatibilitySpan 5 . 0 , * )
81
+ @_originallyDefinedIn ( module: " Swift;CompatibilitySpan " , SwiftCompatibilitySpan 6 . 2 )
74
82
extension OutputSpan where Element: ~ Copyable {
75
83
/// The number of initialized elements in this span.
76
84
@_alwaysEmitIntoClient
@@ -89,7 +97,8 @@ extension OutputSpan where Element: ~Copyable {
89
97
public var isFull : Bool { _count == capacity }
90
98
}
91
99
92
- @available ( SwiftStdlib 6 . 2 , * )
100
+ @available ( SwiftCompatibilitySpan 5 . 0 , * )
101
+ @_originallyDefinedIn ( module: " Swift;CompatibilitySpan " , SwiftCompatibilitySpan 6 . 2 )
93
102
extension OutputSpan where Element: ~ Copyable {
94
103
95
104
@unsafe
@@ -141,7 +150,8 @@ extension OutputSpan where Element: ~Copyable {
141
150
}
142
151
}
143
152
144
- @available ( SwiftStdlib 6 . 2 , * )
153
+ @available ( SwiftCompatibilitySpan 5 . 0 , * )
154
+ @_originallyDefinedIn ( module: " Swift;CompatibilitySpan " , SwiftCompatibilitySpan 6 . 2 )
145
155
extension OutputSpan {
146
156
147
157
/// Unsafely create an OutputSpan over partly-initialized memory.
@@ -171,7 +181,8 @@ extension OutputSpan {
171
181
}
172
182
}
173
183
174
- @available ( SwiftStdlib 6 . 2 , * )
184
+ @available ( SwiftCompatibilitySpan 5 . 0 , * )
185
+ @_originallyDefinedIn ( module: " Swift;CompatibilitySpan " , SwiftCompatibilitySpan 6 . 2 )
175
186
extension OutputSpan where Element: ~ Copyable {
176
187
/// The type that represents an initialized position in an `OutputSpan`.
177
188
public typealias Index = Int
@@ -259,7 +270,8 @@ extension OutputSpan where Element: ~Copyable {
259
270
}
260
271
}
261
272
262
- @available ( SwiftStdlib 6 . 2 , * )
273
+ @available ( SwiftCompatibilitySpan 5 . 0 , * )
274
+ @_originallyDefinedIn ( module: " Swift;CompatibilitySpan " , SwiftCompatibilitySpan 6 . 2 )
263
275
extension OutputSpan where Element: ~ Copyable {
264
276
/// Append a single element to this span.
265
277
@_alwaysEmitIntoClient
@@ -311,7 +323,8 @@ extension OutputSpan where Element: ~Copyable {
311
323
}
312
324
313
325
//MARK: bulk-append functions
314
- @available ( SwiftStdlib 6 . 2 , * )
326
+ @available ( SwiftCompatibilitySpan 5 . 0 , * )
327
+ @_originallyDefinedIn ( module: " Swift;CompatibilitySpan " , SwiftCompatibilitySpan 6 . 2 )
315
328
extension OutputSpan {
316
329
317
330
/// Repeatedly append an element to this span.
@@ -326,7 +339,8 @@ extension OutputSpan {
326
339
}
327
340
}
328
341
329
- @available ( SwiftStdlib 6 . 2 , * )
342
+ @available ( SwiftCompatibilitySpan 5 . 0 , * )
343
+ @_originallyDefinedIn ( module: " Swift;CompatibilitySpan " , SwiftCompatibilitySpan 6 . 2 )
330
344
extension OutputSpan where Element: ~ Copyable {
331
345
/// Borrow the underlying initialized memory for read-only access.
332
346
@_alwaysEmitIntoClient
@@ -355,7 +369,8 @@ extension OutputSpan where Element: ~Copyable {
355
369
}
356
370
}
357
371
358
- @available ( SwiftStdlib 6 . 2 , * )
372
+ @available ( SwiftCompatibilitySpan 5 . 0 , * )
373
+ @_originallyDefinedIn ( module: " Swift;CompatibilitySpan " , SwiftCompatibilitySpan 6 . 2 )
359
374
extension OutputSpan where Element: ~ Copyable {
360
375
/// Call the given closure with the unsafe buffer pointer addressed by this
361
376
/// OutputSpan and a mutable reference to its count of initialized elements.
@@ -399,9 +414,15 @@ extension OutputSpan where Element: ~Copyable {
399
414
start. _rawValue, capacity. _builtinWordValue, Element . self
400
415
)
401
416
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
402
422
let buffer = unsafe UnsafeMutableBufferPointer< Element > (
403
423
_uncheckedStart: . init( start. _rawValue) , count: capacity
404
424
)
425
+ #endif
405
426
var initializedCount = self . _count
406
427
defer {
407
428
_precondition (
@@ -414,7 +435,8 @@ extension OutputSpan where Element: ~Copyable {
414
435
}
415
436
}
416
437
417
- @available ( SwiftStdlib 6 . 2 , * )
438
+ @available ( SwiftCompatibilitySpan 5 . 0 , * )
439
+ @_originallyDefinedIn ( module: " Swift;CompatibilitySpan " , SwiftCompatibilitySpan 6 . 2 )
418
440
extension OutputSpan where Element: ~ Copyable {
419
441
/// Consume the output span and return the number of initialized elements.
420
442
///
@@ -447,7 +469,8 @@ extension OutputSpan where Element: ~Copyable {
447
469
}
448
470
}
449
471
450
- @available ( SwiftStdlib 6 . 2 , * )
472
+ @available ( SwiftCompatibilitySpan 5 . 0 , * )
473
+ @_originallyDefinedIn ( module: " Swift;CompatibilitySpan " , SwiftCompatibilitySpan 6 . 2 )
451
474
extension OutputSpan {
452
475
/// Consume the output span and return the number of initialized elements.
453
476
///
0 commit comments