Skip to content

SILGen: Separate borrow from consume phase for destructive pattern matches. #71231

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
Jan 30, 2024

Conversation

jckarter
Copy link
Contributor

We don't want the dispatch phase of a pattern match to invalidate the subject, because we don't define the order in which patterns are evaluated, and if a particular match attempt fails, we need to still have an intact subject value on hand to try a potentially arbitrary other pattern against it. For noncopyable types, this means we have to always emit the match phase as a borrow, including the variable bindings for a guard expression if any. For a consuming pattern match, end the borrow scope and reproject the variable bindings by using consuming destructuring operations on the subject in the match block.

For now, this new code path only handles single-case-label-per-block switches without fallthroughs.

…tches.

We don't want the dispatch phase of a pattern match to invalidate the subject,
because we don't define the order in which patterns are evaluated, and if a
particular match attempt fails, we need to still have an intact subject value
on hand to try a potentially arbitrary other pattern against it. For
noncopyable types, this means we have to always emit the match phase as a
borrow, including the variable bindings for a guard expression if any.
For a consuming pattern match, end the borrow scope and reproject the variable
bindings by using consuming destructuring operations on the subject in the
match block.

For now, this new code path only handles single-case-label-per-block switches
without fallthroughs.
@jckarter
Copy link
Contributor Author

@swift-ci Please test

@jckarter jckarter merged commit d3cd72f into swiftlang:main Jan 30, 2024
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.

1 participant