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 )
2025public 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 )
5359extension 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 )
5663extension 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 )
7482extension 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 )
93102extension 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 )
145155extension 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 )
175186extension 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 )
263275extension 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 )
315328extension 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 )
330344extension 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 )
359374extension 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 )
418440extension 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 )
451474extension OutputSpan {
452475 /// Consume the output span and return the number of initialized elements.
453476 ///
0 commit comments