@@ -184,6 +184,7 @@ extension MutableSpan where Element: BitwiseCopyable {
184
184
extension Span where Element: ~ Copyable {
185
185
186
186
@_alwaysEmitIntoClient
187
+ @lifetime ( borrow mutableSpan)
187
188
public init( _unsafeMutableSpan mutableSpan: borrowing MutableSpan < Element > ) {
188
189
let pointer = mutableSpan. _pointer? . assumingMemoryBound ( to: Element . self)
189
190
let buffer = UnsafeBufferPointer ( start: pointer, count: mutableSpan. count)
@@ -215,6 +216,7 @@ extension MutableSpan where Element: ~Copyable {
215
216
extension RawSpan {
216
217
217
218
@_alwaysEmitIntoClient
219
+ @lifetime ( borrow mutableSpan)
218
220
public init< Element: BitwiseCopyable> (
219
221
_unsafeMutableSpan mutableSpan: borrowing MutableSpan< Element >
220
222
) {
@@ -286,7 +288,10 @@ extension MutableSpan where Element: BitwiseCopyable {
286
288
/// - Returns: a RawSpan over the memory represented by this span
287
289
@unsafe //FIXME: remove when the lifetime inference is fixed
288
290
@_alwaysEmitIntoClient
289
- public var _unsafeRawSpan : RawSpan { RawSpan ( _unsafeMutableSpan: self ) }
291
+ public var _unsafeRawSpan: RawSpan {
292
+ @lifetime ( borrow self)
293
+ get { RawSpan ( _unsafeMutableSpan: self ) }
294
+ }
290
295
}
291
296
292
297
@available( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , visionOS 9999 , * )
@@ -300,10 +305,12 @@ extension MutableSpan where Element: ~Copyable {
300
305
/// - Complexity: O(1)
301
306
@_alwaysEmitIntoClient
302
307
public subscript( _ position: Index ) -> Element {
308
+ @lifetime ( borrow self)
303
309
_read {
304
310
precondition ( indices. contains ( position) , " index out of bounds " )
305
311
yield self [ unchecked: position]
306
312
}
313
+ @lifetime ( borrow self)
307
314
_modify {
308
315
precondition ( indices. contains ( position) , " index out of bounds " )
309
316
yield & self [ unchecked: position]
@@ -323,6 +330,7 @@ extension MutableSpan where Element: ~Copyable {
323
330
unsafeAddress {
324
331
UnsafePointer ( _unsafeAddressOfElement ( unchecked: position) )
325
332
}
333
+ @lifetime ( self : copy self )
326
334
unsafeMutableAddress {
327
335
_unsafeAddressOfElement ( unchecked: position)
328
336
}
@@ -342,12 +350,14 @@ extension MutableSpan where Element: ~Copyable {
342
350
@available( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , visionOS 9999 , * )
343
351
extension MutableSpan where Element: ~ Copyable {
344
352
353
+ @lifetime ( self : copy self )
345
354
public mutating func swapAt( _ i: Index , _ j: Index ) {
346
355
precondition ( indices. contains ( Index ( i) ) )
347
356
precondition ( indices. contains ( Index ( j) ) )
348
357
swapAt ( unchecked: i, unchecked: j)
349
358
}
350
359
360
+ @lifetime ( self : copy self )
351
361
public mutating func swapAt( unchecked i: Index , unchecked j: Index ) {
352
362
let pi = _unsafeAddressOfElement ( unchecked: i)
353
363
let pj = _unsafeAddressOfElement ( unchecked: j)
@@ -372,6 +382,7 @@ extension MutableSpan where Element: BitwiseCopyable {
372
382
precondition ( indices. contains ( position) )
373
383
return self [ unchecked: position]
374
384
}
385
+ @lifetime ( self : copy self )
375
386
set {
376
387
precondition ( indices. contains ( position) )
377
388
self [ unchecked: position] = newValue
@@ -392,6 +403,7 @@ extension MutableSpan where Element: BitwiseCopyable {
392
403
let offset = position&* MemoryLayout< Element> . stride
393
404
return _start ( ) . loadUnaligned ( fromByteOffset: offset, as: Element . self)
394
405
}
406
+ @lifetime ( self : copy self )
395
407
set {
396
408
let offset = position&* MemoryLayout< Element> . stride
397
409
_start ( ) . storeBytes ( of: newValue, toByteOffset: offset, as: Element . self)
@@ -412,6 +424,7 @@ extension MutableSpan where Element: ~Copyable {
412
424
413
425
//FIXME: mark closure parameter as non-escaping
414
426
@_alwaysEmitIntoClient
427
+ @lifetime ( self : copy self )
415
428
public mutating func withUnsafeMutableBufferPointer< E: Error , Result: ~ Copyable> (
416
429
_ body: ( UnsafeMutableBufferPointer < Element > ) throws ( E ) -> Result
417
430
) throws ( E ) -> Result {
@@ -440,6 +453,7 @@ extension MutableSpan where Element: BitwiseCopyable {
440
453
441
454
//FIXME: mark closure parameter as non-escaping
442
455
@_alwaysEmitIntoClient
456
+ @lifetime ( self : copy self )
443
457
public mutating func withUnsafeMutableBytes< E: Error , Result: ~ Copyable> (
444
458
_ body: ( _ buffer: UnsafeMutableRawBufferPointer ) throws ( E ) -> Result
445
459
) throws ( E ) -> Result {
@@ -456,13 +470,15 @@ extension MutableSpan where Element: BitwiseCopyable {
456
470
extension MutableSpan {
457
471
458
472
@_alwaysEmitIntoClient
473
+ @lifetime ( self : copy self )
459
474
public mutating func update( repeating repeatedValue: Element ) {
460
475
_start ( ) . withMemoryRebound ( to: Element . self, capacity: count) {
461
476
$0. update ( repeating: repeatedValue, count: count)
462
477
}
463
478
}
464
479
465
480
@_alwaysEmitIntoClient
481
+ @lifetime ( self : copy self )
466
482
public mutating func update< S: Sequence > (
467
483
from source: S
468
484
) -> ( unwritten: S . Iterator , index: Index ) where S. Element == Element {
@@ -472,6 +488,7 @@ extension MutableSpan {
472
488
}
473
489
474
490
@_alwaysEmitIntoClient
491
+ @lifetime ( self : copy self )
475
492
public mutating func update(
476
493
from elements: inout some IteratorProtocol < Element >
477
494
) -> Index {
@@ -485,6 +502,7 @@ extension MutableSpan {
485
502
}
486
503
487
504
@_alwaysEmitIntoClient
505
+ @lifetime ( self : copy self )
488
506
public mutating func update(
489
507
fromContentsOf source: some Collection < Element >
490
508
) -> Index {
@@ -505,6 +523,7 @@ extension MutableSpan {
505
523
}
506
524
507
525
@_alwaysEmitIntoClient
526
+ @lifetime ( self : copy self )
508
527
public mutating func update( fromContentsOf source: Span < Element > ) -> Index {
509
528
guard !source. isEmpty else { return 0 }
510
529
precondition (
@@ -520,6 +539,7 @@ extension MutableSpan {
520
539
}
521
540
522
541
@_alwaysEmitIntoClient
542
+ @lifetime ( self : copy self )
523
543
public mutating func update(
524
544
fromContentsOf source: borrowing MutableSpan < Element >
525
545
) -> Index {
@@ -532,6 +552,7 @@ extension MutableSpan {
532
552
extension MutableSpan where Element: BitwiseCopyable {
533
553
534
554
@_alwaysEmitIntoClient
555
+ @lifetime ( self : copy self )
535
556
public mutating func update(
536
557
repeating repeatedValue: Element
537
558
) where Element: BitwiseCopyable {
@@ -544,6 +565,7 @@ extension MutableSpan where Element: BitwiseCopyable {
544
565
}
545
566
546
567
@_alwaysEmitIntoClient
568
+ @lifetime ( self : copy self )
547
569
public mutating func update< S: Sequence > (
548
570
from source: S
549
571
) -> ( unwritten: S . Iterator , index: Index )
@@ -554,6 +576,7 @@ extension MutableSpan where Element: BitwiseCopyable {
554
576
}
555
577
556
578
@_alwaysEmitIntoClient
579
+ @lifetime ( self : copy self )
557
580
public mutating func update(
558
581
from elements: inout some IteratorProtocol < Element >
559
582
) -> Index {
@@ -567,6 +590,7 @@ extension MutableSpan where Element: BitwiseCopyable {
567
590
}
568
591
569
592
@_alwaysEmitIntoClient
593
+ @lifetime ( self : copy self )
570
594
public mutating func update(
571
595
fromContentsOf source: some Collection < Element >
572
596
) -> Index where Element: BitwiseCopyable {
@@ -587,6 +611,7 @@ extension MutableSpan where Element: BitwiseCopyable {
587
611
}
588
612
589
613
@_alwaysEmitIntoClient
614
+ @lifetime ( self : copy self )
590
615
public mutating func update(
591
616
fromContentsOf source: Span < Element >
592
617
) -> Index where Element: BitwiseCopyable {
@@ -604,6 +629,7 @@ extension MutableSpan where Element: BitwiseCopyable {
604
629
}
605
630
606
631
@_alwaysEmitIntoClient
632
+ @lifetime ( self : copy self )
607
633
public mutating func update(
608
634
fromContentsOf source: borrowing MutableSpan < Element >
609
635
) -> Index where Element: BitwiseCopyable {
@@ -667,6 +693,7 @@ extension OutputSpan where Element: ~Copyable {
667
693
@available ( macOS 9999 , * )
668
694
@available ( macOS 9999 , * )
669
695
@_alwaysEmitIntoClient
696
+ @lifetime ( self : copy self )
670
697
public mutating func append( _ value: consuming Element ) {
671
698
precondition ( _initialized < capacity, " Output buffer overflow " )
672
699
let p = _start. advanced ( by: _initialized&* MemoryLayout< Element> . stride)
@@ -696,6 +723,7 @@ extension OutputSpan where Element: ~Copyable {
696
723
extension OutputSpan {
697
724
698
725
@_alwaysEmitIntoClient
726
+ @lifetime ( self : copy self )
699
727
public mutating func append( repeating repeatedValue: Element , count: Int ) {
700
728
let available = capacity &- _initialized
701
729
precondition (
@@ -711,6 +739,7 @@ extension OutputSpan {
711
739
}
712
740
713
741
@_alwaysEmitIntoClient
742
+ @lifetime ( self : copy self )
714
743
public mutating func append< S> (
715
744
from elements: S
716
745
) -> S . Iterator where S: Sequence , S. Element == Element {
@@ -720,6 +749,7 @@ extension OutputSpan {
720
749
}
721
750
722
751
@_alwaysEmitIntoClient
752
+ @lifetime ( self : copy self )
723
753
public mutating func append(
724
754
from elements: inout some IteratorProtocol < Element >
725
755
) {
@@ -732,6 +762,7 @@ extension OutputSpan {
732
762
}
733
763
734
764
@_alwaysEmitIntoClient
765
+ @lifetime ( self : copy self )
735
766
public mutating func append(
736
767
fromContentsOf source: some Collection < Element >
737
768
) {
@@ -762,6 +793,7 @@ extension OutputSpan {
762
793
}
763
794
764
795
//FIXME: remove once rdar://136838539 & rdar://136849171 are fixed
796
+ @lifetime ( self : copy self )
765
797
public mutating func append(
766
798
fromContentsOf source: UnsafeBufferPointer < Element >
767
799
) {
@@ -779,6 +811,7 @@ extension OutputSpan {
779
811
780
812
//FIXME: rdar://136838539 & rdar://136849171
781
813
@_alwaysEmitIntoClient
814
+ @lifetime ( self : copy self )
782
815
public mutating func append(
783
816
fromContentsOf source: Span < Element >
784
817
) {
@@ -797,6 +830,7 @@ extension OutputSpan {
797
830
}
798
831
799
832
@_alwaysEmitIntoClient
833
+ @lifetime ( self : copy self )
800
834
public mutating func append( fromContentsOf source: borrowing MutableSpan < Element > ) {
801
835
source. withUnsafeBufferPointer { append ( fromContentsOf: $0) }
802
836
}
@@ -806,6 +840,7 @@ extension OutputSpan {
806
840
extension OutputSpan where Element: ~ Copyable {
807
841
808
842
@_alwaysEmitIntoClient
843
+ @lifetime ( self : copy self )
809
844
public mutating func moveAppend(
810
845
fromContentsOf source: consuming Self
811
846
) {
@@ -824,6 +859,7 @@ extension OutputSpan where Element: ~Copyable {
824
859
}
825
860
826
861
@_alwaysEmitIntoClient
862
+ @lifetime ( self : copy self )
827
863
public mutating func moveAppend(
828
864
fromContentsOf source: UnsafeMutableBufferPointer < Element >
829
865
) {
@@ -849,6 +885,7 @@ extension OutputSpan where Element: ~Copyable {
849
885
extension OutputSpan {
850
886
851
887
@_alwaysEmitIntoClient
888
+ @lifetime ( self : copy self )
852
889
public mutating func moveAppend(
853
890
fromContentsOf source: Slice < UnsafeMutableBufferPointer < Element > >
854
891
) {
@@ -875,16 +912,19 @@ extension OutputSpan where Element: ~Copyable {
875
912
}
876
913
}
877
914
915
+ /* FIXME: rdar://147194789 ([nonescapable] 'mutating get' causes a
916
+ type checking error for non-existent _read accessor)
878
917
@_alwaysEmitIntoClient
879
918
public var mutableSpan: MutableSpan<Element> {
880
- // @lifetime(inout self) // this just crashes the compiler
919
+ @lifetime(borrow self)
881
920
mutating get { // the accessor must provide a mutable projection
882
921
let pointer = _pointer?.assumingMemoryBound(to: Element.self)
883
922
let buffer = UnsafeMutableBufferPointer(start: pointer, count: _initialized)
884
923
let span = MutableSpan(_unsafeElements: buffer)
885
924
return _overrideLifetime(span, mutating: &self)
886
925
}
887
926
}
927
+ */
888
928
}
889
929
890
930
@available( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , visionOS 9999 , * )
0 commit comments