Skip to content

Commit ba3946c

Browse files
committed
New examples for Future Directions
1 parent 2992389 commit ba3946c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

proposals/NNNN-lifetime-dependency.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ We expect that the lifetime notation would be mandatory for any property that pr
446446
This proposal has deliberately limited the application of lifetime dependencies to return types that are `~Escapable`.
447447
This simplifies the model by identifying `~Escapable` types as exactly those types that can carry such dependencies.
448448
It also helps simplify the enforcement of lifetime constraints by guaranteeing that constrained values cannot escape before being returned.
449+
Most importantly, this restriction helps ensure that the new semantics (especially lifetime dependency inference) cannot accidentally break existing code.
449450
We expect that in the future, additional investigation can reveal a way to relax this restriction.
450451

451452
#### Downgraded Dependencies
@@ -468,3 +469,25 @@ it needs to guarantee that the reference is destroyed before the container:
468469
```
469470
func f(container: consuming ContainerType, ref: borrow(container) consuming RefType) -> ResultType
470471
```
472+
473+
#### Lifetime Dependencies for Tuples
474+
475+
It should be possible to return a tuple where one part has a lifetime dependency.
476+
For example:
477+
```swift
478+
func f(a: consume A, b: B) -> (consume(a) C, B)
479+
```
480+
We expect to address this in the near future in a separate proposal.
481+
482+
#### Lifetime Dependencies for containers and their elements
483+
484+
It should be possible to return containers with collections of lifetime-constrained elements.
485+
For example, a container may want to return a partition of its contents:
486+
```swift
487+
borrowing func chunks(n: Int) -> borrow(self) SomeList<borrow(self) BufferView<UInt8>>
488+
```
489+
We're actively looking into ways to support these more involved cases and expect to address this in a future proposal.
490+
491+
## Acknowledgements
492+
493+
Dima Galimzianov provided several examples for Future Directions.

0 commit comments

Comments
 (0)