-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Disable stack promotion for classes with isolated deinit #76995
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
Disable stack promotion for classes with isolated deinit #76995
Conversation
@swift-ci please 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.
Hah, great observation, fix sounds good to me.
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.
lgtm
Thinking about this again, a better fix would be to make this check in
Though, it's a bit more complicated because it also needs to handle structs/tuples/enums which contain a class reference. This can be done by adding a flag in |
@eeckstein @nickolas-pohilets shall we merge this to resolve the crashes and investigate the follow up alternative approach you’re suggesting, or hold off merging and do the alternative approach instead immediately — wdyt @eeckstein? |
I'm fine with merging this and doing it the right way in a follow-up. But it would be nice to first file a github issue and reference it in a to-do comment in the stack promotion |
I'm still reading the code of the My vague understanding so far is that reference to objects with isolated deinit inside structs/tuples/enums is not a very big issue - current check in StackPromotion.swift will catch it. By vice versa can be a more serious issue - if non-escaping value is stored in a seemings non-escaping object with isolated deinit, then it will escape, and check in StackPromotion.swift won't do anything about it. Also type erasure can be an issue. When destroying type-erased reference we have to be conservative and assume that object has isolated deinit. Is this an issue, or escape analysis already conservatively assumes that any uses of the type-erased values can be escaping? |
Another interesting challenge: class ClassNoOp {
@AnotherActor
deinit {
}
}
class Holder {
var ref: ClassNoOp?
}
func testClass() {
let a = ClassNoOp()
let b = Holder()
b.ref = a
} In this example
So if |
Thinking about it again (2nd try), I think it's sufficient to do the check in stack promotion. An isolated deinit does not actually let
No, |
And what is the difference between "escaping" and "extending the lifetime"? |
"Escaping" - how we define it - means that a value (in this case an object reference) is visible at some other place. And "place" depends on the context in which escape analysis is used. For stack promotion this means: Is the object reference visible after the current function has returned?
|
I'm concerned about the following scenario: let x = SomeClass()
let y = ClassWithIsolatedDeinit()
y.prop = x Here neither |
Good example! You are right that this needs to be handled.
|
I've added unit tests and seems that it works even without with change, because escape analysis of the explicit deinit is very conservative and assumes and anything getting there can escape. But if this changes in the future, it may break. But added unit test should catch it. So I guess PR should be good as it is now. |
@swift-ci please smoke test |
1745443
to
8848411
Compare
@swift-ci please smoke test |
This time not related to PR changes. Let's wait until https://github.com/swiftlang/swift-corelibs-foundation is fixed. |
I see a few green pipelines in https://ci-external.swift.org/job/swift-PR-windows/. Let's try again. |
8848411
to
e201aa3
Compare
@swift-ci please smoke test |
Failing test has been disabled - swiftlang/swift-corelibs-foundation@974106b |
@swift-ci please smoke test Windows |
1 similar comment
@swift-ci please smoke test Windows |
Nice work! Looks good to me, merging and if anything pops up in additional testing I’ll keep an eye out |
This provides a proper fix of the issue, reverting workaround implemented in #76960