Skip to content

Commit b08caff

Browse files
committed
Rename _unsafeLifetime to @unsafe _overrideLifetime and reformat.
Also, fix the _overrideLifetime doc comments.
1 parent 496296e commit b08caff

File tree

3 files changed

+42
-43
lines changed

3 files changed

+42
-43
lines changed

stdlib/public/core/LifetimeManager.swift

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -286,37 +286,36 @@ public func _copy<T>(_ value: T) -> T {
286286

287287
/// Unsafely discard any lifetime dependency on the `dependent` argument. Return
288288
/// a value identical to `dependent` with a lifetime dependency on the caller's
289-
/// borrow scope of the `borrows` argument.
290-
///
291-
/// TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence
292-
/// should be expressed by a builtin that is hidden within the function body.
289+
/// borrow scope of the `source` argument.
290+
@unsafe
293291
@_unsafeNonescapableResult
294292
@_alwaysEmitIntoClient
295293
@inline(__always)
296294
@lifetime(borrow source)
297-
internal func _unsafeLifetime<T: ~Copyable & ~Escapable,
298-
U: ~Copyable & ~Escapable>(
299-
dependent: consuming T, borrows source: borrowing U
295+
internal func _overrideLifetime<
296+
T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable
297+
>(
298+
_ dependent: consuming T, borrowing source: borrowing U
300299
) -> T {
300+
// TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence
301+
// should be expressed by a builtin that is hidden within the function body.
301302
dependent
302303
}
303304

304305
/// Unsafely discard any lifetime dependency on the `dependent` argument. Return
305306
/// a value identical to `dependent` that inherits all lifetime dependencies from
306-
/// the `dependsOn` argument.
307-
///
308-
/// Transferring generic lifetime dependencies from `dependsOn` requires the
309-
/// result to have the same type.
310-
///
311-
/// TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence
312-
/// should be expressed by a builtin that is hidden within the function body.
307+
/// the `source` argument.
308+
@unsafe
313309
@_unsafeNonescapableResult
314310
@_alwaysEmitIntoClient
315311
@inline(__always)
316312
@lifetime(source)
317-
internal func _unsafeLifetime<T: ~Copyable & ~Escapable,
318-
U: ~Copyable & ~Escapable>(
319-
dependent: consuming T, dependsOn source: borrowing U
313+
internal func _overrideLifetime<
314+
T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable
315+
>(
316+
_ dependent: consuming T, copying source: borrowing U
320317
) -> T {
318+
// TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence
319+
// should be expressed by a builtin that is hidden within the function body.
321320
dependent
322321
}

stdlib/public/core/Span/RawSpan.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ extension RawSpan {
101101
let span = RawSpan(_unchecked: baseAddress, byteCount: buffer.count)
102102
// As a trivial value, 'baseAddress' does not formally depend on the
103103
// lifetime of 'buffer'. Make the dependence explicit.
104-
self = _unsafeLifetime(dependent: span, borrows: buffer)
104+
self = _overrideLifetime(span, borrowing: buffer)
105105
}
106106

107107
/// Unsafely create a `RawSpan` over initialized memory.
@@ -121,7 +121,7 @@ extension RawSpan {
121121
let span = RawSpan(_unsafeBytes: rawBuffer)
122122
// As a trivial value, 'rawBuffer' does not formally depend on the
123123
// lifetime of 'buffer'. Make the dependence explicit.
124-
self = _unsafeLifetime(dependent: span, borrows: buffer)
124+
self = _overrideLifetime(span, borrowing: buffer)
125125
}
126126

127127
/// Unsafely create a `RawSpan` over initialized memory.
@@ -141,7 +141,7 @@ extension RawSpan {
141141
let span = RawSpan(_unsafeBytes: rawBuffer)
142142
// As a trivial value, 'rawBuffer' does not formally depend on the
143143
// lifetime of 'buffer'. Make the dependence explicit.
144-
self = _unsafeLifetime(dependent: span, borrows: buffer)
144+
self = _overrideLifetime(span, borrowing: buffer)
145145
}
146146

147147
@_alwaysEmitIntoClient
@@ -154,7 +154,7 @@ extension RawSpan {
154154
let span = RawSpan(_unsafeBytes: rawBuffer)
155155
// As a trivial value, 'rawBuffer' does not formally depend on the
156156
// lifetime of 'buffer'. Make the dependence explicit.
157-
self = _unsafeLifetime(dependent: span, borrows: buffer)
157+
self = _overrideLifetime(span, borrowing: buffer)
158158
}
159159

160160
/// Unsafely create a `RawSpan` over initialized memory.
@@ -194,7 +194,7 @@ extension RawSpan {
194194
let span = RawSpan(_unsafeBytes: rawBuffer)
195195
// As a trivial value, 'rawBuffer' does not formally depend on the
196196
// lifetime of 'buffer'. Make the dependence explicit.
197-
self = _unsafeLifetime(dependent: span, borrows: buffer)
197+
self = _overrideLifetime(span, borrowing: buffer)
198198
}
199199

200200
/// Unsafely create a `RawSpan` over initialized memory.
@@ -214,7 +214,7 @@ extension RawSpan {
214214
let span = RawSpan(_unsafeBytes: rawBuffer)
215215
// As a trivial value, 'rawBuffer' does not formally depend on the
216216
// lifetime of 'buffer'. Make the dependence explicit.
217-
self = _unsafeLifetime(dependent: span, borrows: buffer)
217+
self = _overrideLifetime(span, borrowing: buffer)
218218
}
219219

220220
/// Unsafely create a `RawSpan` over initialized memory.
@@ -234,7 +234,7 @@ extension RawSpan {
234234
let span = RawSpan(_unsafeBytes: rawBuffer)
235235
// As a trivial value, 'rawBuffer' does not formally depend on the
236236
// lifetime of 'buffer'. Make the dependence explicit.
237-
self = _unsafeLifetime(dependent: span, borrows: buffer)
237+
self = _overrideLifetime(span, borrowing: buffer)
238238
}
239239

240240
/// Unsafely create a `RawSpan` over initialized memory.
@@ -255,7 +255,7 @@ extension RawSpan {
255255
let span = RawSpan(_unsafeBytes: rawBuffer)
256256
// As a trivial value, 'rawBuffer' does not formally depend on the
257257
// lifetime of 'buffer'. Make the dependence explicit.
258-
self = _unsafeLifetime(dependent: span, borrows: buffer)
258+
self = _overrideLifetime(span, borrowing: buffer)
259259
}
260260

261261
/// Unsafely create a `RawSpan` over initialized memory.
@@ -374,7 +374,7 @@ extension RawSpan {
374374
public func _extracting(unchecked bounds: Range<Int>) -> Self {
375375
let newStart = _pointer?.advanced(by: bounds.lowerBound)
376376
let newSpan = RawSpan(_unchecked: newStart, byteCount: bounds.count)
377-
return _unsafeLifetime(dependent: newSpan, dependsOn: self)
377+
return _overrideLifetime(newSpan, copying: self)
378378
}
379379

380380
/// Constructs a new span over the bytes within the supplied range of
@@ -488,7 +488,7 @@ extension RawSpan {
488488
let newSpan = Span<T>(_unsafeBytes: rawBuffer)
489489
// As a trivial value, 'rawBuffer' does not formally depend on the
490490
// lifetime of 'self'. Make the dependence explicit.
491-
return _unsafeLifetime(dependent: newSpan, dependsOn: self)
491+
return _overrideLifetime(newSpan, copying: self)
492492
}
493493
}
494494

@@ -711,7 +711,7 @@ extension RawSpan {
711711
let newSpan = RawSpan(_unchecked: newStart, byteCount: newCount)
712712
// As a trivial value, 'newStart' does not formally depend on the
713713
// lifetime of 'self'. Make the dependence explicit.
714-
return _unsafeLifetime(dependent: newSpan, dependsOn: self)
714+
return _overrideLifetime(newSpan, copying: self)
715715
}
716716

717717
/// Returns a span over all but the given number of initial bytes.
@@ -737,6 +737,6 @@ extension RawSpan {
737737
let newSpan = RawSpan(_unchecked: newStart, byteCount: byteCount &- droppedCount)
738738
// As a trivial value, 'newStart' does not formally depend on the
739739
// lifetime of 'self'. Make the dependence explicit.
740-
return _unsafeLifetime(dependent: newSpan, dependsOn: self)
740+
return _overrideLifetime(newSpan, copying: self)
741741
}
742742
}

stdlib/public/core/Span/Span.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ extension Span where Element: ~Copyable {
109109
let span = Span(_unchecked: baseAddress, count: buffer.count)
110110
// As a trivial value, 'baseAddress' does not formally depend on the
111111
// lifetime of 'buffer'. Make the dependence explicit.
112-
self = _unsafeLifetime(dependent: span, borrows: buffer)
112+
self = _overrideLifetime(span, borrowing: buffer)
113113
}
114114

115115
/// Unsafely create a `Span` over initialized memory.
@@ -129,7 +129,7 @@ extension Span where Element: ~Copyable {
129129
let span = Span(_unsafeElements: buf)
130130
// As a trivial value, 'buf' does not formally depend on the
131131
// lifetime of 'buffer'. Make the dependence explicit.
132-
self = _unsafeLifetime(dependent: span, borrows: buffer)
132+
self = _overrideLifetime(span, borrowing: buffer)
133133
}
134134

135135
/// Unsafely create a `Span` over initialized memory.
@@ -153,7 +153,7 @@ extension Span where Element: ~Copyable {
153153
let span = Span(_unsafeElements: buf)
154154
// As a trivial value, 'buf' does not formally depend on the
155155
// lifetime of 'pointer'. Make the dependence explicit.
156-
self = _unsafeLifetime(dependent: span, borrows: pointer)
156+
self = _overrideLifetime(span, borrowing: pointer)
157157
}
158158
}
159159

@@ -177,7 +177,7 @@ extension Span {
177177
let span = Span(_unsafeElements: buf)
178178
// As a trivial value, 'buf' does not formally depend on the
179179
// lifetime of 'buffer'. Make the dependence explicit.
180-
self = _unsafeLifetime(dependent: span, borrows: buffer)
180+
self = _overrideLifetime(span, borrowing: buffer)
181181
}
182182

183183
/// Unsafely create a `Span` over initialized memory.
@@ -197,7 +197,7 @@ extension Span {
197197
let span = Span(_unsafeElements: buf)
198198
// As a trivial value, 'buf' does not formally depend on the
199199
// lifetime of 'buffer'. Make the dependence explicit.
200-
self = _unsafeLifetime(dependent: span, borrows: buffer)
200+
self = _overrideLifetime(span, borrowing: buffer)
201201
}
202202
}
203203

@@ -236,7 +236,7 @@ extension Span where Element: BitwiseCopyable {
236236
let span = Span(_unchecked: baseAddress, count: count)
237237
// As a trivial value, 'baseAddress' does not formally depend on the
238238
// lifetime of 'buffer'. Make the dependence explicit.
239-
self = _unsafeLifetime(dependent: span, borrows: buffer)
239+
self = _overrideLifetime(span, borrowing: buffer)
240240
}
241241

242242
/// Unsafely create a `Span` over initialized memory.
@@ -260,7 +260,7 @@ extension Span where Element: BitwiseCopyable {
260260
let span = Span(_unsafeBytes: rawBuffer)
261261
// As a trivial value, 'buf' does not formally depend on the
262262
// lifetime of 'buffer'. Make the dependence explicit.
263-
self = _unsafeLifetime(dependent: span, borrows: buffer)
263+
self = _overrideLifetime(span, borrowing: buffer)
264264
}
265265

266266
/// Unsafely create a `Span` over initialized memory.
@@ -288,7 +288,7 @@ extension Span where Element: BitwiseCopyable {
288288
let span = Span(_unsafeBytes: rawBuffer)
289289
// As a trivial value, 'rawBuffer' does not formally depend on the
290290
// lifetime of 'pointer'. Make the dependence explicit.
291-
self = _unsafeLifetime(dependent: span, borrows: pointer)
291+
self = _overrideLifetime(span, borrowing: pointer)
292292
}
293293

294294
/// Unsafely create a `Span` over initialized memory.
@@ -312,7 +312,7 @@ extension Span where Element: BitwiseCopyable {
312312
let span = Span(_unsafeBytes: rawBuffer)
313313
// As a trivial value, 'rawBuffer' does not formally depend on the
314314
// lifetime of 'buffer'. Make the dependence explicit.
315-
self = _unsafeLifetime(dependent: span, borrows: buffer)
315+
self = _overrideLifetime(span, borrowing: buffer)
316316
}
317317

318318
/// Unsafely create a `Span` over initialized memory.
@@ -336,7 +336,7 @@ extension Span where Element: BitwiseCopyable {
336336
let span = Span(_unsafeBytes: rawBuffer)
337337
// As a trivial value, 'rawBuffer' does not formally depend on the
338338
// lifetime of 'buffer'. Make the dependence explicit.
339-
self = _unsafeLifetime(dependent: span, borrows: buffer)
339+
self = _overrideLifetime(span, borrowing: buffer)
340340
}
341341

342342
/// Create a `Span` over the bytes represented by a `RawSpan`
@@ -352,7 +352,7 @@ extension Span where Element: BitwiseCopyable {
352352
let span = Span(_unsafeBytes: rawBuffer)
353353
// As a trivial value, 'rawBuffer' does not formally depend on the
354354
// lifetime of 'bytes'. Make the dependence explicit.
355-
self = _unsafeLifetime(dependent: span, dependsOn: bytes)
355+
self = _overrideLifetime(span, copying: bytes)
356356
}
357357
}
358358

@@ -526,7 +526,7 @@ extension Span where Element: ~Copyable {
526526
let newSpan = Span(_unchecked: newStart, count: bounds.count)
527527
// As a trivial value, 'newStart' does not formally depend on the
528528
// lifetime of 'self'. Make the dependence explicit.
529-
return _unsafeLifetime(dependent: newSpan, dependsOn: self)
529+
return _overrideLifetime(newSpan, copying: self)
530530
}
531531

532532
/// Constructs a new span over the items within the supplied range of
@@ -752,7 +752,7 @@ extension Span where Element: ~Copyable {
752752
let newSpan = Span(_unchecked: newStart, count: newCount)
753753
// As a trivial value, 'newStart' does not formally depend on the
754754
// lifetime of 'buffer'. Make the dependence explicit.
755-
return _unsafeLifetime(dependent: newSpan, dependsOn: self)
755+
return _overrideLifetime(newSpan, copying: self)
756756
}
757757

758758
/// Returns a span over all but the given number of initial elements.
@@ -779,6 +779,6 @@ extension Span where Element: ~Copyable {
779779
let newSpan = Span(_unchecked: newStart, count: count &- droppedCount)
780780
// As a trivial value, 'newStart' does not formally depend on the
781781
// lifetime of 'buffer'. Make the dependence explicit.
782-
return _unsafeLifetime(dependent: newSpan, dependsOn: self)
782+
return _overrideLifetime(newSpan, copying: self)
783783
}
784784
}

0 commit comments

Comments
 (0)