Skip to content

Commit 54066b2

Browse files
authored
Merge pull request #77548 from glessard/rdar139668469-not-immortal-vincible
[span] express correct lifetimes for initializers
2 parents 53e8db8 + 76d22cc commit 54066b2

File tree

2 files changed

+26
-46
lines changed

2 files changed

+26
-46
lines changed

stdlib/public/core/Span/RawSpan.swift

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ public struct RawSpan: ~Escapable, Copyable, BitwiseCopyable {
6161
@_disallowFeatureSuppression(NonescapableTypes)
6262
@_alwaysEmitIntoClient
6363
@inline(__always)
64-
//FIXME: should be @lifetime(borrow pointer) rdar://138672380
65-
@lifetime(immortal)
64+
@lifetime(borrow pointer)
6665
internal init(
6766
_unchecked pointer: borrowing UnsafeRawPointer?,
6867
byteCount: Int
@@ -90,8 +89,7 @@ extension RawSpan {
9089
/// - buffer: an `UnsafeRawBufferPointer` to initialized memory.
9190
@_disallowFeatureSuppression(NonescapableTypes)
9291
@_alwaysEmitIntoClient
93-
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
94-
@lifetime(immortal)
92+
@lifetime(borrow buffer)
9593
public init(
9694
_unsafeBytes buffer: borrowing UnsafeRawBufferPointer
9795
) {
@@ -110,8 +108,7 @@ extension RawSpan {
110108
/// - buffer: an `UnsafeRawBufferPointer` to initialized memory.
111109
@_disallowFeatureSuppression(NonescapableTypes)
112110
@_alwaysEmitIntoClient
113-
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
114-
@lifetime(immortal)
111+
@lifetime(borrow buffer)
115112
public init(
116113
_unsafeBytes buffer: borrowing Slice<UnsafeRawBufferPointer>
117114
) {
@@ -128,8 +125,7 @@ extension RawSpan {
128125
/// - buffer: an `UnsafeRawBufferPointer` to initialized memory.
129126
@_disallowFeatureSuppression(NonescapableTypes)
130127
@_alwaysEmitIntoClient
131-
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
132-
@lifetime(immortal)
128+
@lifetime(borrow buffer)
133129
public init(
134130
_unsafeBytes buffer: borrowing UnsafeMutableRawBufferPointer
135131
) {
@@ -138,8 +134,7 @@ extension RawSpan {
138134

139135
@_disallowFeatureSuppression(NonescapableTypes)
140136
@_alwaysEmitIntoClient
141-
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
142-
@lifetime(immortal)
137+
@lifetime(borrow buffer)
143138
public init(
144139
_unsafeBytes buffer: borrowing Slice<UnsafeMutableRawBufferPointer>
145140
) {
@@ -158,8 +153,7 @@ extension RawSpan {
158153
/// - byteCount: the number of initialized bytes in the span.
159154
@_disallowFeatureSuppression(NonescapableTypes)
160155
@_alwaysEmitIntoClient
161-
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
162-
@lifetime(immortal)
156+
@lifetime(borrow pointer)
163157
public init(
164158
_unsafeStart pointer: borrowing UnsafeRawPointer,
165159
byteCount: Int
@@ -178,8 +172,7 @@ extension RawSpan {
178172
/// - buffer: an `UnsafeRawBufferPointer` to initialized memory.
179173
@_disallowFeatureSuppression(NonescapableTypes)
180174
@_alwaysEmitIntoClient
181-
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
182-
@lifetime(immortal)
175+
@lifetime(borrow buffer)
183176
public init<T: BitwiseCopyable>(
184177
_unsafeElements buffer: borrowing UnsafeBufferPointer<T>
185178
) {
@@ -196,8 +189,7 @@ extension RawSpan {
196189
/// - buffer: an `UnsafeRawBufferPointer` to initialized memory.
197190
@_disallowFeatureSuppression(NonescapableTypes)
198191
@_alwaysEmitIntoClient
199-
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
200-
@lifetime(immortal)
192+
@lifetime(borrow buffer)
201193
public init<T: BitwiseCopyable>(
202194
_unsafeElements buffer: borrowing Slice<UnsafeBufferPointer<T>>
203195
) {
@@ -216,8 +208,7 @@ extension RawSpan {
216208
/// - buffer: an `UnsafeRawBufferPointer` to initialized memory.
217209
@_disallowFeatureSuppression(NonescapableTypes)
218210
@_alwaysEmitIntoClient
219-
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
220-
@lifetime(immortal)
211+
@lifetime(borrow buffer)
221212
public init<T: BitwiseCopyable>(
222213
_unsafeElements buffer: borrowing UnsafeMutableBufferPointer<T>
223214
) {
@@ -234,8 +225,7 @@ extension RawSpan {
234225
/// - buffer: an `UnsafeRawBufferPointer` to initialized memory.
235226
@_disallowFeatureSuppression(NonescapableTypes)
236227
@_alwaysEmitIntoClient
237-
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
238-
@lifetime(immortal)
228+
@lifetime(borrow buffer)
239229
public init<T: BitwiseCopyable>(
240230
_unsafeElements buffer: borrowing Slice<UnsafeMutableBufferPointer<T>>
241231
) {
@@ -256,8 +246,7 @@ extension RawSpan {
256246
/// - byteCount: the number of initialized bytes in the span.
257247
@_disallowFeatureSuppression(NonescapableTypes)
258248
@_alwaysEmitIntoClient
259-
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
260-
@lifetime(immortal)
249+
@lifetime(borrow pointer)
261250
public init<T: BitwiseCopyable>(
262251
_unsafeStart pointer: borrowing UnsafePointer<T>,
263252
count: Int
@@ -275,8 +264,10 @@ extension RawSpan {
275264
/// `RawSpan`'s lifetime and the memory it represents.
276265
@_disallowFeatureSuppression(NonescapableTypes)
277266
@_alwaysEmitIntoClient
278-
@lifetime(span)
279-
public init<Element: BitwiseCopyable>(_elements span: consuming Span<Element>) {
267+
@lifetime(borrow span)
268+
public init<Element: BitwiseCopyable>(
269+
_elements span: borrowing Span<Element>
270+
) {
280271
self.init(
281272
_unchecked: span._pointer,
282273
byteCount: span.count &* MemoryLayout<Element>.stride

stdlib/public/core/Span/Span.swift

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ public struct Span<Element: ~Copyable & ~Escapable>
6363
@_disallowFeatureSuppression(NonescapableTypes)
6464
@_alwaysEmitIntoClient
6565
@inline(__always)
66-
//FIXME: should be @lifetime(borrow pointer) rdar://138672380
67-
@lifetime(immortal)
66+
@lifetime(borrow pointer)
6867
internal init(
6968
_unchecked pointer: borrowing UnsafeRawPointer?,
7069
count: Int
@@ -92,8 +91,7 @@ extension Span where Element: ~Copyable {
9291
/// - buffer: an `UnsafeBufferPointer` to initialized elements.
9392
@_disallowFeatureSuppression(NonescapableTypes)
9493
@_alwaysEmitIntoClient
95-
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
96-
@lifetime(immortal)
94+
@lifetime(borrow buffer)
9795
public init(
9896
_unsafeElements buffer: borrowing UnsafeBufferPointer<Element>
9997
) {
@@ -116,8 +114,7 @@ extension Span where Element: ~Copyable {
116114
/// - buffer: an `UnsafeMutableBufferPointer` to initialized elements.
117115
@_disallowFeatureSuppression(NonescapableTypes)
118116
@_alwaysEmitIntoClient
119-
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
120-
@lifetime(immortal)
117+
@lifetime(borrow buffer)
121118
public init(
122119
_unsafeElements buffer: borrowing UnsafeMutableBufferPointer<Element>
123120
) {
@@ -136,8 +133,7 @@ extension Span where Element: ~Copyable {
136133
/// - count: the number of initialized elements in the span.
137134
@_disallowFeatureSuppression(NonescapableTypes)
138135
@_alwaysEmitIntoClient
139-
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
140-
@lifetime(immortal)
136+
@lifetime(borrow pointer)
141137
public init(
142138
_unsafeStart pointer: borrowing UnsafePointer<Element>,
143139
count: Int
@@ -161,8 +157,7 @@ extension Span {
161157
/// - buffer: an `UnsafeBufferPointer` to initialized elements.
162158
@_disallowFeatureSuppression(NonescapableTypes)
163159
@_alwaysEmitIntoClient
164-
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
165-
@lifetime(immortal)
160+
@lifetime(borrow buffer)
166161
public init(
167162
_unsafeElements buffer: borrowing Slice<UnsafeBufferPointer<Element>>
168163
) {
@@ -179,8 +174,7 @@ extension Span {
179174
/// - buffer: an `UnsafeMutableBufferPointer` to initialized elements.
180175
@_disallowFeatureSuppression(NonescapableTypes)
181176
@_alwaysEmitIntoClient
182-
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
183-
@lifetime(immortal)
177+
@lifetime(borrow buffer)
184178
public init(
185179
_unsafeElements buffer: borrowing Slice<UnsafeMutableBufferPointer<Element>>
186180
) {
@@ -206,8 +200,7 @@ extension Span where Element: BitwiseCopyable {
206200
/// - buffer: a buffer to initialized elements.
207201
@_disallowFeatureSuppression(NonescapableTypes)
208202
@_alwaysEmitIntoClient
209-
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
210-
@lifetime(immortal)
203+
@lifetime(borrow buffer)
211204
public init(
212205
_unsafeBytes buffer: borrowing UnsafeRawBufferPointer
213206
) {
@@ -239,8 +232,7 @@ extension Span where Element: BitwiseCopyable {
239232
/// - buffer: a buffer to initialized elements.
240233
@_disallowFeatureSuppression(NonescapableTypes)
241234
@_alwaysEmitIntoClient
242-
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
243-
@lifetime(immortal)
235+
@lifetime(borrow buffer)
244236
public init(
245237
_unsafeBytes buffer: borrowing UnsafeMutableRawBufferPointer
246238
) {
@@ -263,8 +255,7 @@ extension Span where Element: BitwiseCopyable {
263255
/// - byteCount: the number of initialized elements in the span.
264256
@_disallowFeatureSuppression(NonescapableTypes)
265257
@_alwaysEmitIntoClient
266-
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
267-
@lifetime(immortal)
258+
@lifetime(borrow pointer)
268259
public init(
269260
_unsafeStart pointer: borrowing UnsafeRawPointer,
270261
byteCount: Int
@@ -287,8 +278,7 @@ extension Span where Element: BitwiseCopyable {
287278
/// - buffer: a buffer to initialized elements.
288279
@_disallowFeatureSuppression(NonescapableTypes)
289280
@_alwaysEmitIntoClient
290-
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
291-
@lifetime(immortal)
281+
@lifetime(borrow buffer)
292282
public init(
293283
_unsafeBytes buffer: borrowing Slice<UnsafeRawBufferPointer>
294284
) {
@@ -309,8 +299,7 @@ extension Span where Element: BitwiseCopyable {
309299
/// - buffer: a buffer to initialized elements.
310300
@_disallowFeatureSuppression(NonescapableTypes)
311301
@_alwaysEmitIntoClient
312-
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
313-
@lifetime(immortal)
302+
@lifetime(borrow buffer)
314303
public init(
315304
_unsafeBytes buffer: borrowing Slice<UnsafeMutableRawBufferPointer>
316305
) {

0 commit comments

Comments
 (0)