Repository navigation
Conversation
Contributor
|
FYI: SE-0073. |
… at-most once This proposal introduces a `@called(once)` attribute to model at-most once execution of a function. Making function execution behavior visible to the compiler has two advantages. First, it makes it possible to diagnose incorrect usage of such functions. But, it also allows the compiler to understand how closure captures could affect variable lifetimes. This can improve compatibility with non-Copyable types.
…y a closure are destroyed
…pyable` more prominent in 'Proposed solution' section
…once)` and `consuming` methods and `defer` blocks`
…ce)` from a parameter is source-breaking
- Rename the at-most-once attribute to `@callable(once)` and add the exactly-once `@once` attribute, modeled with a compiler-internal `Deinitable` protocol. - Add `withoutActuallyDiscarding(_:do:)`, storage rules, overriding, witness, and overloading rules, and C/ObjC interoperability. - Describe the limits of the exactly-once guarantee, runtime support, and the standard library adoption policy. - Add prior art, new alternatives considered, and future directions. - Address review feedback and make editorial fixes.
- Allow `borrowing` and `inout` parameters with `@once` and `@callable(once)` types. - Clarify that linear types suppress both `Copyable` and `Deinitable`, and show the declarations of the invertible protocols. - Describe the `async` and isolation behavior of `withoutActuallyDeiniting(_:do:)`. - Revise the overloading rules for execution semantics, and describe how libraries can offer overloads that closure literals resolve to. - Generalize narrowing and widening of execution semantics in Source compatibility. - Add alternatives considered for importing nullable `called_once` parameters as optional `@callable(once)`, give examples of APIs that need `@callable(once)`, and revise the arguments about attribute spellings.
xedin
marked this pull request as ready for review
November 13, 2026 23:12
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
… at-most once
This proposal introduces a
@called(once)attribute to model at-most once execution of a function. Making function execution behavior visible to the compiler has two advantages. First, it makes it possible to diagnose incorrect usage of such functions. But, it also allows the compiler to understand how closure captures could affect variable lifetimes. This can improve compatibility with non-Copyable types.