Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lifetime Dependency Annotations for Non-escapable Types #2305

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

tbkka
Copy link
Contributor

@tbkka tbkka commented Feb 5, 2024

This is a companion proposal to "Non-Escapable Types".

It proposes a set of annotations that can be used to relate the lifetimes of two objects. For example, this can be used to ensure that a "slice" or "iterator" object that holds a pointer into some container does not outlive the container.

@tbkka tbkka changed the title Tbkka lifetime dependency Lifetime Dependency Annotations for Non-escapable Types Feb 5, 2024
@tbkka tbkka mentioned this pull request Feb 5, 2024
proposals/NNNN-lifetime-dependency.md Outdated Show resolved Hide resolved
proposals/NNNN-lifetime-dependency.md Outdated Show resolved Hide resolved
proposals/NNNN-lifetime-dependency.md Show resolved Hide resolved
proposals/NNNN-lifetime-dependency.md Outdated Show resolved Hide resolved
proposals/NNNN-lifetime-dependency.md Outdated Show resolved Hide resolved
proposals/NNNN-lifetime-dependency.md Outdated Show resolved Hide resolved
proposals/NNNN-lifetime-dependency.md Outdated Show resolved Hide resolved
proposals/NNNN-lifetime-dependency.md Outdated Show resolved Hide resolved
proposals/NNNN-lifetime-dependency.md Outdated Show resolved Hide resolved
proposals/NNNN-lifetime-dependency.md Outdated Show resolved Hide resolved
@tbkka
Copy link
Contributor Author

tbkka commented Mar 21, 2024

Overhauled to reflect a fundamentally different syntax. We now have a single @dependsOn(arg) marker that simply states the fact of the dependency rather than a set of borrow/mutate/consume/copy markers that state the type. This follows from conversation about the previous proposal: Since there is almost always only one type of dependency possible for any given function signature, we can simplify the syntax. This should also help users of libraries that expose nonescapable types: those users only need to know what values have dependencies; they generally do not need to be aware of the precise semantics underlying that dependency.

meg-gupta added a commit to meg-gupta/swift that referenced this pull request Mar 22, 2024
meg-gupta added a commit to meg-gupta/swift that referenced this pull request Mar 22, 2024
… pitch

Pitch - apple/swift-evolution#2305

Changes highlights:

@dependsOn(paramName) and @dependsOn(scoped argName) syntax

@dependsOn(paramName) -> copy lifetime dependence for all parameters/self except
                         when we have Escapable parameters/self, we assign scope
                         lifetime dependence.

Allow lifetime dependence on parameters without ownership modifier.

Always infer copy lifetime dependence except when we have
Escapable parameters/self, we infer scope lifetime dependence.

Allow lifetime dependence inference on parameters without ownership modifier.
meg-gupta added a commit to meg-gupta/swift that referenced this pull request Mar 22, 2024
… pitch

Pitch - apple/swift-evolution#2305

Changes highlights:

@dependsOn(paramName) and @dependsOn(scoped argName) syntax

@dependsOn(paramName) -> copy lifetime dependence for all parameters/self except
                         when we have Escapable parameters/self, we assign scope
                         lifetime dependence.

Allow lifetime dependence on parameters without ownership modifier.

Always infer copy lifetime dependence except when we have
Escapable parameters/self, we infer scope lifetime dependence.

Allow lifetime dependence inference on parameters without ownership modifier.
We need to separate description of the dependency itself --
which places a bound on when particular objects can be
destroyed -- from the syntax.
In particular, the syntax specifies a relationship between
two objects, but that relationship is not always a
lifetime dependency itself (because of "copied" dependencies).
meg-gupta added a commit to meg-gupta/swift that referenced this pull request Mar 24, 2024
… pitch

Pitch - apple/swift-evolution#2305

Changes highlights:

dependsOn(paramName) and dependsOn(scoped argName) syntax

dependsOn(paramName) -> copy lifetime dependence for all parameters/self except
                         when we have Escapable parameters/self, we assign scope
                         lifetime dependence.

Allow lifetime dependence on parameters without ownership modifier.

Always infer copy lifetime dependence except when we have
Escapable parameters/self, we infer scope lifetime dependence.

Allow lifetime dependence inference on parameters without ownership modifier.
@rjmccall rjmccall added LSG Contains topics under the domain of the Language Steering Group workgroup: blocked This proposal is blocked on some other consideration labels Apr 1, 2024
These would also be useable with methods that wish to declare a dependency on `self`.
To reduce the burden of manually adding such annotations, we also propose inferring lifetime dependencies in certain common cases without requiring any additional annotations.

This is a key requirement for the `StorageView` type (previously called `BufferView`) being discussed elsewhere, and is closely related to the proposal for `~Escapable` types.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have named this construct Span. Please let's avoid mentioning its deadnames; proposals are forever, and we really need to avoid indefinitely propagating these obsolete names.

Suggested change
This is a key requirement for the `StorageView` type (previously called `BufferView`) being discussed elsewhere, and is closely related to the proposal for `~Escapable` types.
This is a key requirement for the `Span` type that is being discussed elsewhere, and is closely related to the proposal for `~Escapable` types.

atrick and others added 2 commits May 2, 2024 19:45
Changed `StorageView` and `BufferReference` to `Span` to match the si…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LSG Contains topics under the domain of the Language Steering Group workgroup: blocked This proposal is blocked on some other consideration
Projects
None yet
5 participants