Skip to content

Commit 34cda51

Browse files
authored
Merge pull request #13 from atrick/tbkka-non-escapable
Update Future direction: Initializers and Lifetime Dependencies
2 parents 135caf7 + 96c1f19 commit 34cda51

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

proposals/NNNN-non-escapable.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,6 @@ Nonescapable function parameters may not outlive the function scope.
293293
Consequently, nonescapable values can never be returned from a function.
294294
Nonescapable values come into existence within the body of the initializer.
295295
Naturally, the initializer must return its value, and this creates an exception to the rule.
296-
Without further language support, implementing a nonescapable initializer requires an unsafe construct.
297-
That unsafe handling is not covered by this proposal because we don't want to surface unnecessary unsafety in the language.
298-
Instead, a subsequent proposal will support safe initialization by allowing the initializer to specify lifetime dependencies on its parameters.
299296
The parameters to the initializer typically indicate a lifetime that the nonescapable value cannot outlive.
300297
An initializer may, for example, create a nonescapable value that depends on a container variable that is bound to an object with its own lifetime:
301298
```swift
@@ -309,9 +306,10 @@ consume container // `container` lifetime ends here
309306
use(iterator) // 🛑 'iterator' outlives `container`
310307
```
311308

312-
Lifetime dependencies will make this and similar misuses into compile-time errors.
313-
This will allow developers to safely define and use values that contain pointers into
314-
other values, ensuring that the pointers never outlive the underlying storage.
309+
Specifying a dependency from a function parameter to its nonescapable result currently requires an experimental lifetime dependency feature.
310+
With lifetime dependencies, initialization of nonescapable types is safe: misuses similar to the one shown above are compile-time errors.
311+
Adopting new syntax for lifetime dependencies merits a separate, focussed review.
312+
Until then, initialization of nonescapable values remains experimental.
315313

316314
#### Expanding standard library types
317315

0 commit comments

Comments
 (0)