Skip to content

Verify noescape closures for exclusivity diagnostics. #13898

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 3 commits into from
Jan 22, 2018
Merged

Verify noescape closures for exclusivity diagnostics. #13898

merged 3 commits into from
Jan 22, 2018

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Jan 12, 2018

Verify @inout_aliasable captures.

This is currently only done in DiagnoseStaticExclusivity because AllocBoxToStack
doesn't know how to set @NoEscape function types yet.

Negative test cases need to be added. This PR is currently just for SCK testing and review.

@atrick
Copy link
Contributor Author

atrick commented Jan 12, 2018

@swift-ci Test Source Compatibility.

@slavapestov
Copy link
Contributor

What are inout_aliasable captures actually used for these days?

@atrick
Copy link
Contributor Author

atrick commented Jan 12, 2018

@slavapestov @inout_aliasable is for any captured variable that's promoted to the stack (unboxed). SILGen emits them in the obvious cases. The reason they need to be verified is that exclusivity checking is completely different in those cases. There aren't any access markers in the SIL. Instead it is assumed that the diagnostic pass can detect all closure applications and analyze the body of the closure. So, this verification is required to guard against undefined behavior.

Incidentally, I was working on removing the @inout_aliasable convention on a branch, relying on the @NoEscape attribute instead, removing the special logic from SILGen, and unifying several passes, but I can't enable any of that until exclusivity is officially part of the language.

@atrick atrick changed the title [WIP] Verify inoutalias Verify noescape closures for exclusivity diagnostics. Jan 13, 2018
@atrick atrick requested a review from devincoughlin January 13, 2018 00:30
@atrick
Copy link
Contributor Author

atrick commented Jan 13, 2018

This passed SCK testing. I think we can enable this verification now by default in debug builds.

@atrick
Copy link
Contributor Author

atrick commented Jan 13, 2018

@swift-ci test.

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - cc42bbbdba67b3eaa6180b4d83d9683966769ddb

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - cc42bbbdba67b3eaa6180b4d83d9683966769ddb

@atrick
Copy link
Contributor Author

atrick commented Jan 13, 2018

@swift-ci test.

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 2bcf726d091b4d2d5bbf8a4460966f31003cb9e1

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 2bcf726d091b4d2d5bbf8a4460966f31003cb9e1

@slavapestov
Copy link
Contributor

@atrick What does it mean for exclusivity to be part of the language model? I thought it was already.

@atrick
Copy link
Contributor Author

atrick commented Jan 13, 2018

@slavapestov It's part of the language but the compiler can't make that assumption yet. We don't want to make it undefined behavior until there's some arbitrary level of confidence that code doesn't break it in practice.

@atrick
Copy link
Contributor Author

atrick commented Jan 13, 2018

The test failure is unrelated to this PR.

@slavapestov
Copy link
Contributor

@atrick I see, so basically once exclusivity checking is complete you plan on changing the optimizer to start assuming it?

@atrick
Copy link
Contributor Author

atrick commented Jan 13, 2018

@slavapestov We won't make assumptions that lead to memory unsafety or undefined behavior yet. Enforcement needs to be adequate in Swift 5 if we ever want to make those assumptions.

This is currently only done in DiagnoseStaticExclusivity because AllocBoxToStack
doesn't know how to set @NoEscape function types yet.
@atrick
Copy link
Contributor Author

atrick commented Jan 18, 2018

@devincoughlin Does this look ok?

@devincoughlin
Copy link
Contributor

Looks great!

@atrick
Copy link
Contributor Author

atrick commented Jan 22, 2018

@swift-ci test and merge.

@swift-ci swift-ci merged commit 7f8c59e into swiftlang:master Jan 22, 2018
@atrick atrick deleted the verify-inoutalias branch May 9, 2018 23:51
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.

4 participants