Skip to content

[6.0] Consistently mark borrowing and consuming parameters for move-only checking when captured. #73395

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 May 2, 2024

Explanation: Fixes a miscompile when a borrowing or consuming parameter is captured by a closure and incorrectly consumed or modified in the closure body, by diagnosing the error instead of letting it slip by.
Scope: Fixes a miscompile
Issue: rdar://127382105
Original PR: #73380
Risk: Medium-low. This may cause existing code to be rejected, but the existing code would be getting miscompiled with previous compilers.
Testing: Swift CI, test case from bug report
Reviewer: @kavon

…y checking when captured.

When a `borrowing` or `consuming` parameter is captured by a closure,
we emit references to the binding within the closure as if it is non-implicitly
copyable, but we didn't mark the bindings inside the closure for move-only
checking to ensure the uses were correct, so improper consumes would go
undiagnosed and lead to assertion failures, compiler crashes, and/or
miscompiles. Fixes rdar://127382105
@jckarter jckarter requested a review from a team as a code owner May 2, 2024 18:55
@jckarter
Copy link
Contributor Author

jckarter commented May 2, 2024

@swift-ci Please test

Comment on lines -1992 to +1994
classUseMoveOnlyWithoutEscaping(x2)
classConsume(x2)
print(x2)
classUseMoveOnlyWithoutEscaping(copy x2)
classConsume(copy x2)
print(copy x2)
Copy link
Member

Choose a reason for hiding this comment

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

nice!

@jckarter jckarter merged commit 04e2629 into swiftlang:release/6.0 May 13, 2024
@@ -645,7 +646,7 @@ struct LoadableSelfTest {
consuming func testCallEscapingClosure() {
var f: () -> () = {}
f = {
let _ = self
let _ = copy self
Copy link
Member

Choose a reason for hiding this comment

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

here

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