Skip to content

[5.9][move-only] Make it an error if we attempt to destructure/partially invalidate through a field with a deinit. #65131

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 1 commit into from
Apr 13, 2023

Conversation

gottesmm
Copy link
Contributor

@gottesmm gottesmm commented Apr 13, 2023

If one has a type with a deinit, if one were to partially invalidate the value, the checker will clean up the remaining parts of the value but not the actual underlying value. This then would cause the deinit of the actual type to not be called.

rdar://101651138
(cherry picked from commit 76e9382)


Explanation: If one has a type with a deinit, if one were to partially invalidate the value, the checker will clean up the remaining parts of the value but not the actual underlying value. This then would cause the deinit of the actual type to not be called.

Scope: Only affects noncopyable types since it only changes the move only checkers.

Risk: Low.

Testing: Added compiler tests

…nvalidate through a field with a deinit.

If one has a type with a deinit, if one were to partially invalidate the value,
the checker will clean up the remaining parts of the value but not the actual
underlying value. This then would cause the deinit of the actual type to be
called.

rdar://101651138
(cherry picked from commit 76e9382)
@gottesmm gottesmm requested a review from a team as a code owner April 13, 2023 04:16
@gottesmm
Copy link
Contributor Author

@swift-ci test

@gottesmm gottesmm changed the title [move-only] Make it an error if we attempt to destructure/partially invalidate through a field with a deinit. [5.9][move-only] Make it an error if we attempt to destructure/partially invalidate through a field with a deinit. Apr 13, 2023
@gottesmm
Copy link
Contributor Author

@tbkka

// cannot contain non-copyable types and that our parent root type must be
// an enum, tuple, or struct.
if (auto *nom = iterType.getNominalOrBoundGenericNominal()) {
if (mod.lookUpMoveOnlyDeinitFunction(nom)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be better to check nom->getValueTypeDestructor(), in case the type is from another module and the SIL-level deinit wasn't deserialized?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jckarter I can change that in a follow on commit. I'll also add a note saying deinit declared here.

@gottesmm gottesmm merged commit b0c990a into swiftlang:release/5.9 Apr 13, 2023
@gottesmm gottesmm deleted the release/5.9/101651138 branch April 13, 2023 18:42
@AnthonyLatsis AnthonyLatsis added the 🍒 release cherry pick Flag: Release branch cherry picks label May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants