-
Notifications
You must be signed in to change notification settings - Fork 10.6k
@_lifetime defaults #84010
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
Merged
Merged
@_lifetime defaults #84010
Conversation
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
5700395
to
7a7cbd9
Compare
@swift-ci test |
7a7cbd9
to
130cf4c
Compare
@swift-ci test |
1323928
to
f40c966
Compare
@swift-ci test |
Restructure the inference logic to allow the same function declaration to independently annotate or infer different lifetime targets. For example: @_lifetime(borrow a) /* DEFAULT: @_lifetime(b: copy b) func f(a: A, b: inout B) -> NE The fact that we prevented this was somewhat accidental and surprising. This restructuring simplifies the code but also gives us much more control over the inference logic. Fixes: rdar://159288750 ("A function cannot have a ~Escapable 'inout' parameter in addition to other ~Escapable parameters" is not actionable)
Infer @_lifetime(self: copy self) for mutating methods without requiring the experimental Lifetimes feature to be disabled. Treatment of mutating 'self' is now consistent with other 'inout' parameters. Example: extension MutableSpan { mutating func mutatingMethod() {...} }
Cleanup the tests so we can cross reference them with the documentation. Update the tests to allow multiple annotations and defaults.
f40c966
to
91ab0b7
Compare
@swift-ci test |
glessard
approved these changes
Sep 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
} | ||
|
||
// ========================================================================== | ||
// MARK: Inferrence rules |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
// MARK: Inferrence rules | |
// MARK: Inference rules |
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.
Lifetime inference: restructure to support multiple dependencies.
Restructure the inference logic to allow the same function declaration to
independently annotate or infer different lifetime targets.
For example:
@_lifetime(borrow a)
/* DEFAULT: @_lifetime(b: copy b)
func f(a: A, b: inout B) -> NE
The fact that we prevented this was somewhat accidental and surprising.
This restructuring simplifies the code but also gives us much more control over
the inference logic.
Lifetime inference: comment the change in 'inout' behavior.
Lifetime inference test case update.
Cleanup the tests so we can cross reference them with the documentation.
Document @_lifetime annotation