Skip to content

[6.0] Alternative noncopyable switch design based on expression kind. #72954

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

jckarter
Copy link
Contributor

@jckarter jckarter commented Apr 10, 2024

Explanation: Pre-review discussion of the noncopyable borrowing switch feature raised a preference for an alternative design where the ownership of a switch is driven by what the expression refers to: If an expression refers to noncopyable storage, then default to performing a borrowing switch, where let bindings in patterns borrow out of the matched value. If an expression refers to a temporary value or explicitly uses the consume keyword, then perform a consuming switch, where let bindings take ownership of corresponding parts of the matched value. Allow _borrowing to still be used to explicitly bind a pattern variable as a borrow, with no-implicit-copy semantics for copyable values.

Scope: Changes behavior of a pre-release experimental feature.
Issue: rdar://126212597
Original PR: #72647
Risk: Low. This should have no effect on code using released features only. For early adopters of the feature, the necessary source changes are also minimal; one only needs to explicitly write switch consume x when x is a local variable binding that would otherwise be borrowed by default.
Testing: Swift CI
Reviewer: @kavon

If an expression refers to noncopyable storage, then default to performing
a borrowing switch, where `let` bindings in patterns borrow out of the
matched value. If an expression refers to a temporary value or explicitly
uses the `consume` keyword, then perform a consuming switch, where
`let` bindings take ownership of corresponding parts of the matched value.
Allow `_borrowing` to still be used to explicitly bind a pattern variable
as a borrow, with no-implicit-copy semantics for copyable values.
@jckarter jckarter requested a review from a team as a code owner April 10, 2024 16:51
@jckarter
Copy link
Contributor Author

@swift-ci Please test

@jckarter
Copy link
Contributor Author

@swift-ci Please test Linux

@jckarter jckarter merged commit 34c2f92 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.

3 participants