-
Notifications
You must be signed in to change notification settings - Fork 10.5k
SILOptimizer: add a diagnostics pass to warn about lifetime issues with weak references. #35918
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
@swift-ci test |
Build failed |
Build failed |
514bd26
to
d37a352
Compare
@swift-ci test |
Build failed |
@eeckstein We should probably have another iteration of this diagnostic after you merge this that recurses through all ForwardingConsumes, not just Enum. There is a |
We may also want to be more conservative in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm concerned about false positive warnings in two case: ForwardingConsume and DestroyingConsume. For forwarding operations, we should be able to recognize most and look through them. For DestroyingConsume, the question is how conservative we want to be for stores, calls, and things we don't recognize. It may be good enough to just warn when the only destroys are actual Destroys.
I spent most of my time reviewing just trying to figure out what the Demangle nodes really mean. I could not find documentation anywhere in the source. I can guess what they mean but it would be helpful if you add comments with precise definitions.
It's up to you whether you want to address improvements in another PR later.
@eeckstein in general this looks really great! |
@swift-ci smoke test linux |
@swift-ci smoke test windows |
Update: Actually that's the case right now. Everything else than |
@swift-ci smoke test linux |
1 similar comment
@swift-ci smoke test linux |
@eeckstein I'm referring to cases like this
or
|
…th weak references. The DiagnoseLifetimeIssuesPass pass prints a warning if an object is stored to a weak property (or is weakly captured) and destroyed before the property (or captured reference) is ever used again. This can happen if the programmer relies on the lexical scope to keep an object alive, but copy-propagation can shrink the object's lifetime to its last use. For example: func test() { let k = Klass() // k is deallocated immediately after the closure capture (a store_weak). functionWithClosure({ [weak k] in // crash! k!.foo() }) } Unfortunately this pass can only catch simple cases, but it's better than nothing. rdar://73910632
d37a352
to
a17f8c2
Compare
Ah, you are right. I fixed this. |
@swift-ci smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. It would be pretty easy to handle casts at some point.
The DiagnoseLifetimeIssuesPass pass prints a warning if an object is stored to a weak property (or is weakly captured) and destroyed before the property (or captured reference) is ever used again.
This can happen if the programmer relies on the lexical scope to keep an object alive, but copy-propagation can shrink the object's lifetime to its last use.
For example:
Unfortunately this pass can only catch simple cases, but it's better than nothing.
rdar://73910632