Skip to content

[6.0] Use the BorrowingSwitch implementation for all noncopyable switches. #72966

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

Conversation

jckarter
Copy link
Contributor

Explanation: This changes the backend implementation of noncopyable pattern matches to always use the new implementation that supports borrowing switches, even if BorrowingSwitch itself is not enabled. This new implementation is more correct and robust even if a consuming switch is being performed. The experimental flag still enables the surface syntax until the final proposal is accepted.
Scope: New feature enablement.
Issue: rdar://126209276
Original PR: #72577
Risk: Low. Although this changes the implementation of an existing feature, the old implementation was limited in the situations it could actually handle correctly, and the adoption of noncopyable enums thus far has been limited. This is therefore unlikely to break existing code.
Testing: Swift CI, Swift compatibility suite
Reviewer: @eeckstein

…um_data`.

Under OSSA, the instruction may still be structurally responsible for consuming
its operand even if the result is dead, so we can't remove it without breaking
invariants.

More generally, this should probably apply to any instruction which consumes
one or more of its operands, has no side effects, and doesn't produce any
nontrivial results that require further consumption to keep the value alive.
I went with this targeted fix, since it addresses a problem that shows up
in practice (rdar://125381446) and the more general change appears to
disturb the optimizer pipeline while building the standard library.
It works well enough now that it should be an acceptable replacement for both
borrowing and consuming switches that works in more correct situations than the
previous implementation. This does however expose a few known issues that I'll
try to fix in follow ups:

- overconsumes cause verifier errors instead of raising diagnostics (rdar://125381446)
- cases with multiple pattern labels aren't yet supported (rdar://125188955)
- copyable types with the `borrowing` or `consuming` modifiers should probably use
  noncopyable pattern matching.

The `BorrowingSwitch` flag is still necessary to enable the surface-level syntax
changes (switches without `consume` and the `_borrowing` modifier, for instance).
@jckarter jckarter requested a review from a team as a code owner April 11, 2024 00:44
@jckarter
Copy link
Contributor Author

@swift-ci Please test

@jckarter jckarter merged commit bdb71e0 into swiftlang:release/6.0 Apr 11, 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.

2 participants