Skip to content

Commit 6a7dbb0

Browse files
committed
[stdlib] update lifetime annotations for Mutable[Raw]Span
1 parent 51db21a commit 6a7dbb0

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

stdlib/public/core/Span/MutableRawSpan.swift

+11-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ extension MutableRawSpan {
102102
}
103103

104104
@_alwaysEmitIntoClient
105-
@lifetime(elements)
105+
@lifetime(copy elements)
106106
public init<Element: BitwiseCopyable>(
107107
_elements elements: consuming MutableSpan<Element>
108108
) {
@@ -143,6 +143,7 @@ extension MutableRawSpan {
143143
}
144144

145145
@_alwaysEmitIntoClient
146+
@lifetime(self: copy self)
146147
public mutating func withUnsafeMutableBytes<E: Error, Result: ~Copyable>(
147148
_ body: (UnsafeMutableRawBufferPointer) throws(E) -> Result
148149
) throws(E) -> Result {
@@ -315,6 +316,7 @@ extension MutableRawSpan {
315316
}
316317

317318
@_alwaysEmitIntoClient
319+
@lifetime(self: copy self)
318320
public mutating func storeBytes<T: BitwiseCopyable>(
319321
of value: T, toByteOffset offset: Int = 0, as type: T.Type
320322
) {
@@ -328,6 +330,7 @@ extension MutableRawSpan {
328330

329331
@unsafe
330332
@_alwaysEmitIntoClient
333+
@lifetime(self: copy self)
331334
public mutating func storeBytes<T: BitwiseCopyable>(
332335
of value: T, toUncheckedByteOffset offset: Int, as type: T.Type
333336
) {
@@ -340,6 +343,7 @@ extension MutableRawSpan {
340343
extension MutableRawSpan {
341344

342345
@_alwaysEmitIntoClient
346+
@lifetime(self: copy self)
343347
public mutating func update<S: Sequence>(
344348
from source: S
345349
) -> (unwritten: S.Iterator, byteOffset: Int) where S.Element: BitwiseCopyable {
@@ -349,6 +353,7 @@ extension MutableRawSpan {
349353
}
350354

351355
@_alwaysEmitIntoClient
356+
@lifetime(self: copy self)
352357
public mutating func update<Element: BitwiseCopyable>(
353358
from elements: inout some IteratorProtocol<Element>
354359
) -> Int {
@@ -364,6 +369,7 @@ extension MutableRawSpan {
364369
}
365370

366371
@_alwaysEmitIntoClient
372+
@lifetime(self: copy self)
367373
public mutating func update<C: Collection>(
368374
fromContentsOf source: C
369375
) -> Int where C.Element: BitwiseCopyable {
@@ -382,6 +388,7 @@ extension MutableRawSpan {
382388
}
383389

384390
@_alwaysEmitIntoClient
391+
@lifetime(self: copy self)
385392
public mutating func update<Element: BitwiseCopyable>(
386393
fromContentsOf source: Span<Element>
387394
) -> Int {
@@ -392,6 +399,7 @@ extension MutableRawSpan {
392399
}
393400

394401
@_alwaysEmitIntoClient
402+
@lifetime(self: copy self)
395403
public mutating func update<Element: BitwiseCopyable>(
396404
fromContentsOf source: borrowing MutableSpan<Element>
397405
) -> Int {
@@ -402,6 +410,7 @@ extension MutableRawSpan {
402410
}
403411

404412
@_alwaysEmitIntoClient
413+
@lifetime(self: copy self)
405414
public mutating func update(
406415
fromContentsOf source: RawSpan
407416
) -> Int {
@@ -413,6 +422,7 @@ extension MutableRawSpan {
413422
}
414423

415424
@_alwaysEmitIntoClient
425+
@lifetime(self: copy self)
416426
public mutating func update(
417427
fromContentsOf source: borrowing MutableRawSpan
418428
) -> Int {

stdlib/public/core/Span/MutableSpan.swift

+22
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ extension MutableSpan where Element: ~Copyable {
258258
_precondition(indices.contains(position), "index out of bounds")
259259
return unsafe UnsafePointer(_unsafeAddressOfElement(unchecked: position))
260260
}
261+
@lifetime(self: copy self)
261262
unsafeMutableAddress {
262263
_precondition(indices.contains(position), "index out of bounds")
263264
return unsafe _unsafeAddressOfElement(unchecked: position)
@@ -278,6 +279,7 @@ extension MutableSpan where Element: ~Copyable {
278279
unsafeAddress {
279280
unsafe UnsafePointer(_unsafeAddressOfElement(unchecked: position))
280281
}
282+
@lifetime(self: copy self)
281283
unsafeMutableAddress {
282284
unsafe _unsafeAddressOfElement(unchecked: position)
283285
}
@@ -298,6 +300,7 @@ extension MutableSpan where Element: ~Copyable {
298300
extension MutableSpan where Element: ~Copyable {
299301

300302
@_alwaysEmitIntoClient
303+
@lifetime(self: copy self)
301304
public mutating func swapAt(_ i: Index, _ j: Index) {
302305
_precondition(indices.contains(Index(i)))
303306
_precondition(indices.contains(Index(j)))
@@ -306,6 +309,7 @@ extension MutableSpan where Element: ~Copyable {
306309

307310
@unsafe
308311
@_alwaysEmitIntoClient
312+
@lifetime(self: copy self)
309313
public mutating func swapAt(unchecked i: Index, unchecked j: Index) {
310314
let pi = unsafe _unsafeAddressOfElement(unchecked: i)
311315
let pj = unsafe _unsafeAddressOfElement(unchecked: j)
@@ -330,6 +334,7 @@ extension MutableSpan where Element: BitwiseCopyable {
330334
_precondition(indices.contains(position), "index out of bounds")
331335
return unsafe self[unchecked: position]
332336
}
337+
@lifetime(self: copy self)
333338
set {
334339
_precondition(indices.contains(position), "index out of bounds")
335340
unsafe self[unchecked: position] = newValue
@@ -353,6 +358,7 @@ extension MutableSpan where Element: BitwiseCopyable {
353358
fromByteOffset: offset, as: Element.self
354359
)
355360
}
361+
@lifetime(self: copy self)
356362
set {
357363
let offset = position&*MemoryLayout<Element>.stride
358364
unsafe _start().storeBytes(
@@ -375,6 +381,7 @@ extension MutableSpan where Element: ~Copyable {
375381

376382
//FIXME: mark closure parameter as non-escaping
377383
@_alwaysEmitIntoClient
384+
@lifetime(self: copy self)
378385
public mutating func withUnsafeMutableBufferPointer<
379386
E: Error, Result: ~Copyable
380387
>(
@@ -405,6 +412,7 @@ extension MutableSpan where Element: BitwiseCopyable {
405412

406413
//FIXME: mark closure parameter as non-escaping
407414
@_alwaysEmitIntoClient
415+
@lifetime(self: copy self)
408416
public mutating func withUnsafeMutableBytes<E: Error, Result: ~Copyable>(
409417
_ body: (_ buffer: UnsafeMutableRawBufferPointer) throws(E) -> Result
410418
) throws(E) -> Result {
@@ -421,13 +429,15 @@ extension MutableSpan where Element: BitwiseCopyable {
421429
extension MutableSpan {
422430

423431
@_alwaysEmitIntoClient
432+
@lifetime(self: copy self)
424433
public mutating func update(repeating repeatedValue: consuming Element) {
425434
unsafe _start().withMemoryRebound(to: Element.self, capacity: count) {
426435
unsafe $0.update(repeating: repeatedValue, count: count)
427436
}
428437
}
429438

430439
@_alwaysEmitIntoClient
440+
@lifetime(self: copy self)
431441
public mutating func update<S: Sequence>(
432442
from source: S
433443
) -> (unwritten: S.Iterator, index: Index) where S.Element == Element {
@@ -437,6 +447,7 @@ extension MutableSpan {
437447
}
438448

439449
@_alwaysEmitIntoClient
450+
@lifetime(self: copy self)
440451
public mutating func update(
441452
from elements: inout some IteratorProtocol<Element>
442453
) -> Index {
@@ -450,6 +461,7 @@ extension MutableSpan {
450461
}
451462

452463
@_alwaysEmitIntoClient
464+
@lifetime(self: copy self)
453465
public mutating func update(
454466
fromContentsOf source: some Collection<Element>
455467
) -> Index {
@@ -472,6 +484,7 @@ extension MutableSpan {
472484
}
473485

474486
@_alwaysEmitIntoClient
487+
@lifetime(self: copy self)
475488
public mutating func update(fromContentsOf source: Span<Element>) -> Index {
476489
guard !source.isEmpty else { return 0 }
477490
_precondition(
@@ -489,6 +502,7 @@ extension MutableSpan {
489502
}
490503

491504
@_alwaysEmitIntoClient
505+
@lifetime(self: copy self)
492506
public mutating func update(
493507
fromContentsOf source: borrowing MutableSpan<Element>
494508
) -> Index {
@@ -517,6 +531,7 @@ extension MutableSpan where Element: ~Copyable {
517531
// }
518532

519533
@_alwaysEmitIntoClient
534+
@lifetime(self: copy self)
520535
public mutating func moveUpdate(
521536
fromContentsOf source: UnsafeMutableBufferPointer<Element>
522537
) -> Index {
@@ -532,6 +547,7 @@ extension MutableSpan where Element: ~Copyable {
532547
extension MutableSpan {
533548

534549
@_alwaysEmitIntoClient
550+
@lifetime(self: copy self)
535551
public mutating func moveUpdate(
536552
fromContentsOf source: Slice<UnsafeMutableBufferPointer<Element>>
537553
) -> Index {
@@ -543,6 +559,7 @@ extension MutableSpan {
543559
extension MutableSpan where Element: BitwiseCopyable {
544560

545561
@_alwaysEmitIntoClient
562+
@lifetime(self: copy self)
546563
public mutating func update(
547564
repeating repeatedValue: Element
548565
) where Element: BitwiseCopyable {
@@ -556,6 +573,7 @@ extension MutableSpan where Element: BitwiseCopyable {
556573
}
557574

558575
@_alwaysEmitIntoClient
576+
@lifetime(self: copy self)
559577
public mutating func update<S: Sequence>(
560578
from source: S
561579
) -> (unwritten: S.Iterator, index: Index)
@@ -566,6 +584,7 @@ extension MutableSpan where Element: BitwiseCopyable {
566584
}
567585

568586
@_alwaysEmitIntoClient
587+
@lifetime(self: copy self)
569588
public mutating func update(
570589
from elements: inout some IteratorProtocol<Element>
571590
) -> Index {
@@ -579,6 +598,7 @@ extension MutableSpan where Element: BitwiseCopyable {
579598
}
580599

581600
@_alwaysEmitIntoClient
601+
@lifetime(self: copy self)
582602
public mutating func update(
583603
fromContentsOf source: some Collection<Element>
584604
) -> Index where Element: BitwiseCopyable {
@@ -601,6 +621,7 @@ extension MutableSpan where Element: BitwiseCopyable {
601621
}
602622

603623
@_alwaysEmitIntoClient
624+
@lifetime(self: copy self)
604625
public mutating func update(
605626
fromContentsOf source: Span<Element>
606627
) -> Index where Element: BitwiseCopyable {
@@ -619,6 +640,7 @@ extension MutableSpan where Element: BitwiseCopyable {
619640
}
620641

621642
@_alwaysEmitIntoClient
643+
@lifetime(self: copy self)
622644
public mutating func update(
623645
fromContentsOf source: borrowing MutableSpan<Element>
624646
) -> Index where Element: BitwiseCopyable {

0 commit comments

Comments
 (0)