Skip to content

Commit 3b6f859

Browse files
committed
Cleanup Future directions
Remove Lifetime Dependencies for Computed Properties Remove Lifetime Dependencies between arguments
1 parent adfe8a0 commit 3b6f859

File tree

1 file changed

+4
-32
lines changed

1 file changed

+4
-32
lines changed

proposals/NNNN-lifetime-dependency.md

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -761,43 +761,15 @@ This was changed after we realized that there was in practice almost always a si
761761

762762
## Future Directions
763763

764-
#### Lifetime Dependencies for Computed Properties
765-
766-
It would be useful to allow lifetime dependencies between `self` and the value returned by a computed property.
767-
There is some ambiguity here, since resilience hides the distinction between a computed and stored property.
768-
In particular, the resilience concern might prevent us from inferring lifetime dependencies for properties across module boundaries.
769-
The notation for an explicit lifetime dependency on a property might look like the following:
770-
771-
```swift
772-
struct Container {
773-
var view: dependsOn(self) ReturnType { get }
774-
}
775-
776-
struct Type1: ~Escapable {
777-
var childView: dependsOn(self) Type1 { get }
778-
}
779-
```
780-
781-
We expect that the lifetime notation would be mandatory for any property that provided a `~Escapable` value.
782-
783-
#### Lifetime Dependencies for Escapable Types
764+
### Lifetime Dependencies for Escapable Types
784765

785766
This proposal has deliberately limited the application of lifetime dependencies to return types that are nonescapable.
786767
This simplifies the model by identifying nonescapable types as exactly those types that can carry such dependencies.
787768
It also helps simplify the enforcement of lifetime constraints by guaranteeing that constrained values cannot escape before being returned.
788769
Most importantly, this restriction helps ensure that the new semantics (especially lifetime dependency inference) cannot accidentally break existing code.
789770
We expect that in the future, additional investigation can reveal a way to relax this restriction.
790771

791-
#### Lifetime Dependencies between arguments
792-
793-
A caller may need assurance that a callee will honor a lifetime dependency between two arguments.
794-
For example, if a function is going to destroy a container and a reference to that container in the process of computing some result,
795-
it needs to guarantee that the reference is destroyed before the container:
796-
```swift
797-
func f(container: consuming ContainerType, ref: dependsOn(container) consuming RefType) -> ResultType
798-
```
799-
800-
#### Lifetime Dependencies for Tuples
772+
### Lifetime Dependencies for Tuples
801773

802774
It should be possible to return a tuple where one part has a lifetime dependency.
803775
For example:
@@ -806,7 +778,7 @@ func f(a: consume A, b: B) -> (consume(a) C, B)
806778
```
807779
We expect to address this in the near future in a separate proposal.
808780

809-
#### Lifetime Dependencies for containers and their elements
781+
### Lifetime Dependencies for containers and their elements
810782

811783
It should be possible to return containers with collections of lifetime-constrained elements.
812784
For example, a container may want to return a partition of its contents:
@@ -815,7 +787,7 @@ borrowing func chunks(n: Int) -> dependsOn(self) SomeList<dependsOn(self) Span<U
815787
```
816788
We're actively looking into ways to support these more involved cases and expect to address this in a future proposal.
817789

818-
#### Parameter index for lifetime dependencies
790+
### Parameter index for lifetime dependencies
819791

820792
Internally, the implementation records dependencies based on the parameter index.
821793
This could be exposed as an alternate spelling if there were sufficient demand.

0 commit comments

Comments
 (0)