1
1
import Builtin
2
2
3
+ /// Unsafely discard any lifetime dependency on the `dependent` argument. Return
4
+ /// a value identical to `dependent` with a lifetime dependency on the caller's
5
+ /// borrow scope of the `source` argument.
6
+ @unsafe
3
7
@_unsafeNonescapableResult
4
- @inlinable @inline ( __always)
8
+ @_alwaysEmitIntoClient
9
+ @_transparent
5
10
@lifetime ( borrow source)
6
- public func _overrideLifetime<
7
- T: ~ Copyable & ~ Escapable,
8
- U: ~ Copyable & ~ Escapable
11
+ internal func _overrideLifetime<
12
+ T: ~ Copyable & ~ Escapable, U: ~ Copyable & ~ Escapable
9
13
> (
10
- of dependent: consuming T ,
11
- to source: borrowing U
14
+ _ dependent: consuming T , borrowing source: borrowing U
12
15
) -> T {
16
+ // TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence
17
+ // should be expressed by a builtin that is hidden within the function body.
13
18
dependent
14
19
}
15
20
21
+ /// Unsafely discard any lifetime dependency on the `dependent` argument. Return
22
+ /// a value identical to `dependent` that inherits all lifetime dependencies from
23
+ /// the `source` argument.
24
+ @unsafe
16
25
@_unsafeNonescapableResult
17
- @inlinable @inline ( __always)
26
+ @_alwaysEmitIntoClient
27
+ @_transparent
18
28
@lifetime ( source)
19
- public func _overrideLifetime<
20
- T: ~ Copyable & ~ Escapable,
21
- U: ~ Copyable & ~ Escapable
29
+ internal func _overrideLifetime<
30
+ T: ~ Copyable & ~ Escapable, U: ~ Copyable & ~ Escapable
22
31
> (
23
- of dependent: consuming T ,
24
- copyingFrom source: consuming U
32
+ _ dependent: consuming T , copying source: borrowing U
25
33
) -> T {
34
+ // TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence
35
+ // should be expressed by a builtin that is hidden within the function body.
26
36
dependent
27
37
}
28
38
39
+ @unsafe
29
40
@_unsafeNonescapableResult
30
- @inlinable @inline ( __always)
41
+ @_alwaysEmitIntoClient
42
+ @_transparent
31
43
@lifetime ( source)
32
- public func _overrideLifetime<
33
- T: ~ Copyable & ~ Escapable,
34
- U: ~ Copyable & ~ Escapable
44
+ internal func _overrideLifetime<
45
+ T: ~ Copyable & ~ Escapable, U: ~ Copyable & ~ Escapable
35
46
> (
36
- of dependent: consuming T ,
37
- mutating source: inout U
47
+ _ dependent: consuming T , mutating source: inout U
38
48
) -> T {
49
+ // TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence
50
+ // should be expressed by a builtin that is hidden within the function body.
39
51
dependent
40
52
}
41
53
@@ -91,7 +103,7 @@ extension MutableSpan where Element: ~Copyable {
91
103
" baseAddress must be properly aligned to access Element "
92
104
)
93
105
let ms = MutableSpan < Element > ( _unchecked: buffer)
94
- self = _overrideLifetime ( of : ms, to : buffer)
106
+ self = _overrideLifetime ( ms, borrowing : buffer)
95
107
}
96
108
97
109
@_alwaysEmitIntoClient
@@ -103,7 +115,7 @@ extension MutableSpan where Element: ~Copyable {
103
115
precondition ( count >= 0 , " Count must not be negative " )
104
116
let buffer = UnsafeMutableBufferPointer ( start: start, count: count)
105
117
let ms = MutableSpan ( _unsafeElements: buffer)
106
- self = _overrideLifetime ( of : ms, to : start)
118
+ self = _overrideLifetime ( ms, borrowing : start)
107
119
}
108
120
}
109
121
@@ -117,7 +129,7 @@ extension MutableSpan {
117
129
) {
118
130
let rb = UnsafeMutableBufferPointer ( rebasing: elements)
119
131
let ms = MutableSpan ( _unsafeElements: rb)
120
- self = _overrideLifetime ( of : ms, to : rb)
132
+ self = _overrideLifetime ( ms, borrowing : rb)
121
133
}
122
134
}
123
135
@@ -142,7 +154,7 @@ extension MutableSpan where Element: BitwiseCopyable {
142
154
count: count
143
155
)
144
156
let ms = MutableSpan ( _unsafeElements: elements)
145
- self = _overrideLifetime ( of : ms, to : buffer)
157
+ self = _overrideLifetime ( ms, borrowing : buffer)
146
158
}
147
159
148
160
@_alwaysEmitIntoClient
@@ -154,7 +166,7 @@ extension MutableSpan where Element: BitwiseCopyable {
154
166
precondition ( byteCount >= 0 , " Count must not be negative " )
155
167
let bytes = UnsafeMutableRawBufferPointer ( start: pointer, count: byteCount)
156
168
let ms = MutableSpan ( _unsafeBytes: bytes)
157
- self = _overrideLifetime ( of : ms, to : pointer)
169
+ self = _overrideLifetime ( ms, borrowing : pointer)
158
170
}
159
171
160
172
@_alwaysEmitIntoClient
@@ -164,7 +176,7 @@ extension MutableSpan where Element: BitwiseCopyable {
164
176
) {
165
177
let bytes = UnsafeMutableRawBufferPointer ( rebasing: buffer)
166
178
let ms = MutableSpan ( _unsafeBytes: bytes)
167
- self = _overrideLifetime ( of : ms, to : buffer)
179
+ self = _overrideLifetime ( ms, borrowing : buffer)
168
180
}
169
181
}
170
182
@@ -176,7 +188,7 @@ extension Span where Element: ~Copyable {
176
188
let pointer = mutableSpan. _pointer? . assumingMemoryBound ( to: Element . self)
177
189
let buffer = UnsafeBufferPointer ( start: pointer, count: mutableSpan. count)
178
190
let span = Span ( _unsafeElements: buffer)
179
- self = _overrideLifetime ( of : span, to : mutableSpan)
191
+ self = _overrideLifetime ( span, borrowing : mutableSpan)
180
192
}
181
193
}
182
194
@@ -210,7 +222,7 @@ extension RawSpan {
210
222
let byteCount = mutableSpan. count &* MemoryLayout< Element> . stride
211
223
let buffer = UnsafeRawBufferPointer ( start: pointer, count: byteCount)
212
224
let rawSpan = RawSpan ( _unsafeBytes: buffer)
213
- self = _overrideLifetime ( of : rawSpan, to : mutableSpan)
225
+ self = _overrideLifetime ( rawSpan, borrowing : mutableSpan)
214
226
}
215
227
}
216
228
@@ -516,45 +528,7 @@ extension MutableSpan {
516
528
}
517
529
518
530
@available( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , visionOS 9999 , * )
519
- extension MutableSpan where Element: ~ Copyable {
520
531
521
- @_alwaysEmitIntoClient
522
- public mutating func moveUpdate(
523
- fromContentsOf source: consuming OutputSpan < Element >
524
- ) -> Index {
525
- guard !source. isEmpty else { return 0 }
526
- precondition (
527
- source. count <= self . count,
528
- " destination span cannot contain every element from source. "
529
- )
530
- let buffer = source. relinquishBorrowedMemory ( )
531
- // we must now deinitialize the returned UMBP
532
- _start ( ) . moveInitializeMemory (
533
- as: Element . self, from: buffer. baseAddress!, count: buffer. count
534
- )
535
- return buffer. count
536
- }
537
-
538
- public mutating func moveUpdate(
539
- fromContentsOf source: UnsafeMutableBufferPointer < Element >
540
- ) -> Index {
541
- let source = OutputSpan ( _initializing: source, initialized: source. count)
542
- return self . moveUpdate ( fromContentsOf: source)
543
- }
544
- }
545
-
546
- @available( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , visionOS 9999 , * )
547
- extension MutableSpan {
548
-
549
- public mutating func moveUpdate(
550
- fromContentsOf source: Slice < UnsafeMutableBufferPointer < Element > >
551
- ) -> Index {
552
- self . moveUpdate ( fromContentsOf: . init( rebasing: source) )
553
- }
554
- }
555
-
556
-
557
- @available ( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , visionOS 9999 , * )
558
532
extension MutableSpan where Element: BitwiseCopyable {
559
533
560
534
@_alwaysEmitIntoClient
@@ -686,115 +660,12 @@ public struct OutputSpan<Element: ~Copyable>: ~Copyable, ~Escapable {
686
660
@available ( * , unavailable)
687
661
extension OutputSpan: Sendable { }
688
662
689
- @available ( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , visionOS 9999 , * )
690
- extension OutputSpan where Element: ~ Copyable {
691
-
692
- @usableFromInline @inline ( __always)
693
- @lifetime ( borrow buffer)
694
- init (
695
- _unchecked buffer: UnsafeMutableBufferPointer < Element > ,
696
- initialized: Int
697
- ) {
698
- _pointer = . init( buffer. baseAddress)
699
- capacity = buffer. count
700
- _initialized = initialized
701
- }
702
-
703
- @_alwaysEmitIntoClient
704
- @lifetime( borrow buffer)
705
- public init(
706
- _initializing buffer: UnsafeMutableBufferPointer < Element > ,
707
- initialized: Int = 0
708
- ) {
709
- precondition (
710
- ( ( Int ( bitPattern: buffer. baseAddress) &
711
- ( MemoryLayout < Element > . alignment&- 1 ) ) == 0 ) ,
712
- " baseAddress must be properly aligned to access Element "
713
- )
714
- self . init ( _unchecked: buffer, initialized: initialized)
715
- }
716
-
717
- @_alwaysEmitIntoClient
718
- @lifetime( borrow pointer)
719
- public init(
720
- _initializing pointer: UnsafeMutablePointer < Element > ,
721
- capacity: Int,
722
- initialized: Int = 0
723
- ) {
724
- precondition ( capacity >= 0 , " Capacity must be 0 or greater " )
725
- let buffer = UnsafeMutableBufferPointer ( start: pointer, count: capacity)
726
- let os = OutputSpan ( _initializing: buffer, initialized: initialized)
727
- self = _overrideLifetime ( of: os, to: pointer)
728
- }
729
- }
730
-
731
- @available( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , visionOS 9999 , * )
732
- extension OutputSpan {
733
-
734
- @_alwaysEmitIntoClient
735
- @lifetime ( borrow buffer)
736
- public init(
737
- _initializing buffer: borrowing Slice < UnsafeMutableBufferPointer < Element > > ,
738
- initialized: Int = 0
739
- ) {
740
- let rebased = UnsafeMutableBufferPointer ( rebasing: buffer)
741
- let os = OutputSpan ( _initializing: rebased, initialized: 0 )
742
- self = _overrideLifetime ( of: os, to: buffer)
743
- }
744
- }
745
-
746
- @available( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , visionOS 9999 , * )
747
- extension OutputSpan where Element: BitwiseCopyable {
748
-
749
- @_alwaysEmitIntoClient
750
- @lifetime ( borrow bytes)
751
- public init(
752
- _initializing bytes: UnsafeMutableRawBufferPointer ,
753
- initialized: Int = 0
754
- ) {
755
- precondition (
756
- ( ( Int ( bitPattern: bytes. baseAddress) &
757
- ( MemoryLayout < Element > . alignment&- 1 ) ) == 0 ) ,
758
- " baseAddress must be properly aligned to access Element "
759
- )
760
- let ( byteCount, stride) = ( bytes. count, MemoryLayout< Element> . stride)
761
- let ( count, remainder) = byteCount. quotientAndRemainder ( dividingBy: stride)
762
- precondition ( remainder == 0 , " Span must contain a whole number of elements " )
763
- let pointer = bytes. baseAddress
764
- let os = OutputSpan (
765
- _unchecked: pointer, capacity: count, initialized: initialized
766
- )
767
- self = _overrideLifetime ( of: os, to: bytes)
768
- }
769
-
770
- @_alwaysEmitIntoClient
771
- @lifetime ( borrow pointer)
772
- public init(
773
- _initializing pointer: UnsafeMutableRawPointer,
774
- capacity: Int,
775
- initialized: Int = 0
776
- ) {
777
- precondition ( capacity >= 0 , " Capacity must be 0 or greater " )
778
- let buffer = UnsafeMutableRawBufferPointer ( start: pointer, count: capacity)
779
- let os = OutputSpan ( _initializing: buffer, initialized: initialized)
780
- self = _overrideLifetime ( of: os, to: pointer)
781
- }
782
-
783
- @_alwaysEmitIntoClient
784
- @lifetime( borrow buffer)
785
- public init(
786
- _initializing buffer: borrowing Slice< UnsafeMutableRawBufferPointer > ,
787
- initialized: Int = 0
788
- ) {
789
- let rebased = UnsafeMutableRawBufferPointer ( rebasing: buffer)
790
- let os = OutputSpan ( _initializing: rebased, initialized: initialized)
791
- self = _overrideLifetime ( of: os, to: buffer)
792
- }
793
- }
794
-
795
663
@available( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , visionOS 9999 , * )
796
664
extension OutputSpan where Element: ~ Copyable {
797
665
666
+ @available ( macOS 9999 , * )
667
+ @available ( macOS 9999 , * )
668
+ @available ( macOS 9999 , * )
798
669
@_alwaysEmitIntoClient
799
670
public mutating func append( _ value: consuming Element ) {
800
671
precondition ( _initialized < capacity, " Output buffer overflow " )
@@ -1000,7 +871,7 @@ extension OutputSpan where Element: ~Copyable {
1000
871
let pointer = _pointer? . assumingMemoryBound ( to: Element . self)
1001
872
let buffer = UnsafeBufferPointer ( start: pointer, count: _initialized)
1002
873
let span = Span ( _unsafeElements: buffer)
1003
- return _overrideLifetime ( of : span, to : self )
874
+ return _overrideLifetime ( span, borrowing : self )
1004
875
}
1005
876
}
1006
877
@@ -1011,7 +882,7 @@ extension OutputSpan where Element: ~Copyable {
1011
882
let pointer = _pointer? . assumingMemoryBound ( to: Element . self)
1012
883
let buffer = UnsafeMutableBufferPointer ( start: pointer, count: _initialized)
1013
884
let span = MutableSpan ( _unsafeElements: buffer)
1014
- return _overrideLifetime ( of : span, mutating: & self )
885
+ return _overrideLifetime ( span, mutating: & self )
1015
886
}
1016
887
}
1017
888
}
@@ -1050,7 +921,7 @@ extension Span {
1050
921
// get {
1051
922
// let nilBasedBuffer = UnsafeBufferPointer<Element>(start: nil, count: 0)
1052
923
// let span = Span(_unsafeElements: nilBasedBuffer)
1053
- // return _overrideLifetime(of: span, to: immortalThing)
924
+ // return _overrideLifetime(span, to: immortalThing)
1054
925
// }
1055
926
// }
1056
927
//
@@ -1059,7 +930,7 @@ extension Span {
1059
930
// public init() {
1060
931
// let nilBasedBuffer = UnsafeBufferPointer<Element>(start: nil, count: 0)
1061
932
// let span = Span(_unsafeElements: nilBasedBuffer)
1062
- // self = _overrideLifetime(of: span, to: immortalThing)
933
+ // self = _overrideLifetime(span, to: immortalThing)
1063
934
// }
1064
935
}
1065
936
0 commit comments