You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: proposals/NNNN-lifetime-dependency.md
+32-1Lines changed: 32 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -389,7 +389,9 @@ extension Optional {
389
389
}
390
390
```
391
391
392
-
Once the escapable instance is constructed, it is limited in scope to the caller's function body since the caller only sees the static nonescapable type. If a dynamically escapable value needs to be returned further up the stack, that can be done by chaining multiple `dependsOn(immortal)` functions.
392
+
The constructed instance is returned to the caller without any lifetime dependence. The caller can pass that instance
393
+
along as an argument to other functions, but those functions cannot escape it. The instance can only be returned further
394
+
up the call stack by chaining multiple `dependsOn(immortal)` functions.
We could run into the same problem with any transient value, like a file descriptor, or even a class object:
430
+
431
+
```swift
432
+
init() dependsOn(immortal) {
433
+
self.value=Object() // 🛑 Incorrect
434
+
}
435
+
```
436
+
406
437
### Depending on an escapable `BitwiseCopyable` value
407
438
408
439
The source of a lifetime depenence may be an escapable `BitwiseCopyable` value. This is useful in the implementation of data types that internally use `UnsafePointer`:
0 commit comments