Skip to content

6.0: [MoveOnlyAddressChecker] Fix enum representation. #72508

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

Conversation

nate-chandler
Copy link
Contributor

@nate-chandler nate-chandler commented Mar 22, 2024

Explanation: Fix a class of compiler crashes by teaching the move-only address checker to represent the elements of an enum.

The checker and its supporting infrastructure (FieldSensitivePrunedLiveness) track the indecomposable fields of an aggregate individually, checking that each which is non-copyable is consumed exactly once. Among other things, it uses this infrastructure to determine whether a node of the aggregate may be consumed on its own (which is not allowed if the node appears within an intermediary aggregate with a deinit). (In the future, it might be allowed so long as that intermediary aggregate had been discard'd.)

To allow this walk, it's necessary to identify which case of an enum is being consumed. (For example, one element but not another might have a payload with a deinit.)

Previously, the tracking for the indecomposable fields of an enum used the same bits to represent the different enum elements. That obstructed the walk up the tree from the consumed node.

Here, this is fixed by tracking the elements of an enum separately.
Scope: Affects move-only checking.
Issue: rdar://125113258
Original PR: #72469
Risk: Low.
Testing: Added test case that previously resulted in a crash.
Reviewer: Joe Groff ( @jckarter )

The visitor returns false to indicate an unknown/unhandled instruction.
Previously it returned true as a fallback.  This resulted in aberrant
behavior: e.g., in the test case committed here, the try_apply was
deleted.
The implementation of isUsableFromInline asserts that the function not
be public, so check that it's not before calling it.
Treat a take of a copyable value as a take.
Change FieldSensitive's enum representation to allow distinguishing
among the elements with associated value.  Consider
`unchecked_take_enum_data_addr` to consume all other fields than that
taken.

rdar://125113258
@nate-chandler nate-chandler requested a review from a team as a code owner March 22, 2024 01:33
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler merged commit 58ff4c2 into swiftlang:release/6.0 Mar 22, 2024
@nate-chandler nate-chandler deleted the cherrypick/release/6.0/rdar125113258 branch March 22, 2024 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants