-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[5.9🍒] prevent reinitialization of self after discard #66352
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
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
his instruction is a marker for a following destroy instruction to suppress the call of the move-only type's deinitializer.
…eeded by a drop_deinit rdar://105798769
…ry-picked yet." This reverts commit 22a9c77.
As part of SE-390, you're required to write either: - `consume self` - pass self as a `consuming` parameter to a function - `discard self` before the function ends in a context that contains a `discard self` somewhere. This prevents people from accidentally invoking the deinit due to implicit destruction of `self` before exiting the function. rdar://106099027 (cherry picked from commit 88d35a0)
The value `self` is mutable (i.e., var-bound) in a `consuming` method. Since you're allowed to reinitialize a var after consuming, that means you were also naturally allowed to reinitialize self after `discard self`. But that capability was not intended; after you discard self you shouldn't be reinitializing it, as that's probably a mistake. This change makes reinitialization of `self` reachable from a `discard self` statement an error. rdar://106098163 (cherry picked from commit bd253c6)
I rebased this on top of #65449 since it depends on those changes. Only the last commit is new. |
@swift-ci please test |
gottesmm
approved these changes
Jun 6, 2023
@swift-ci clean test macOS platform |
tbkka
approved these changes
Jun 6, 2023
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.
• Description: Adds a missing piece of SE-390 where we want to prevent reinitialization of
self
after discarding it, since it doesn't make sense to permit that and can limit our ability to implementdiscard
more generally in the future.• Risk: Medium. Will introduce a source break in functions that are using discard self and reinitialize self at some point reachable afterwards. (see test/SILOptimizer/discard_checking.swift for examples). The set of programs using discard is probably quite small currently and we'd want to introduce this change early, though the error could be downgraded into a warning for 5.9 upon request.
• Original PR: #66351
• Reviewed By: @gottesmm
• Testing: regression tests included
• Resolves: rdar://106098163