Skip to content

[WIP] SILGen: Capture address-only lets with the in_guaranteed convention. #17047

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

Closed
wants to merge 1 commit into from

Conversation

jckarter
Copy link
Contributor

@jckarter jckarter commented Jun 7, 2018

Fixes rdar://problem/40828667. If we capture a let as inout_aliasable, then definite initialization mistakes capture of the let from a defer closure as an inappropriate inout use.

@jckarter jckarter requested a review from slavapestov June 7, 2018 16:13
@jckarter
Copy link
Contributor Author

jckarter commented Jun 7, 2018

@swift-ci Please smoke test

@jckarter
Copy link
Contributor Author

jckarter commented Jun 7, 2018

@swift-ci Please test source compatibility

Fixes rdar://problem/40828667. If we capture a `let` as inout_aliasable, then definite initialization mistakes capture of the `let` from a defer closure as an inappropriate inout use.
@jckarter jckarter force-pushed the defer-let-inout-bug branch from be494cf to f8b3541 Compare June 7, 2018 21:09
Copy link
Contributor

@slavapestov slavapestov left a comment

Choose a reason for hiding this comment

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

Looks good, just curious about the debuginfo change.

@@ -1925,8 +1925,12 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(

// There are variables without storage, such as "struct { func foo() {}
// }". Emit them as constant 0.
if (isa<llvm::UndefValue>(Piece))
Piece = llvm::ConstantInt::get(IGM.Int64Ty, 0);
if (isa<llvm::UndefValue>(Piece)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What was this change about?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The existing behavior is broken for an undef of any type that isn't 64 bits in size. I should break it out into its own commit.

@jckarter
Copy link
Contributor Author

jckarter commented Jun 8, 2018

Unfortunately this appears to cause a lot of downstream breakage in the optimizer I can't cleanly detangle. I might have to look for a more targeted fix for the DI regression.

@jckarter jckarter changed the title SILGen: Capture address-only lets with the in_guaranteed convention. [WIP] SILGen: Capture address-only lets with the in_guaranteed convention. Jun 8, 2018
jckarter added a commit to jckarter/swift that referenced this pull request Jun 11, 2018
Sema enforces that closures can't modify the let properties of their captured contexts, but we consider the capture argument to be @inout_aliasable at the SIL level. Add an exception to our normal handling so that this use is considered read-only. Fixes rdar://problem/40828667.

A more principled solution would be to treat let captures as @in_guaranteed (see swiftlang#17047), but that unfortunately leads to breakage elsewhere in the optimizer.
jckarter added a commit to jckarter/swift that referenced this pull request Jun 11, 2018
Sema enforces that closures can't modify the let properties of their captured contexts, but we consider the capture argument to be @inout_aliasable at the SIL level. Add an exception to our normal handling so that this use is considered read-only. Fixes rdar://problem/40828667.

A more principled solution would be to treat let captures as @in_guaranteed (see swiftlang#17047), but that unfortunately leads to breakage elsewhere in the optimizer.
@shahmishal
Copy link
Member

Please update the base branch to main by Oct 5th otherwise the pull request will be closed automatically.

  • How to change the base branch: (Link)
  • More detail about the branch update: (Link)

@shahmishal shahmishal closed this Oct 5, 2020
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