-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Concurrency] Fix ObjC weak references to actors. #42219
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
// Test that instances of Swift actors can be referenced using ObjC | ||
// weak references. | ||
|
||
actor A { |
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.
You will probably need some SwiftStdlib 5.1 availability guards on these
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.
Good point. I should probably move this to a separate file too so we can put REQUIRES: concurrency
only on this test.
@@ -1208,8 +1208,8 @@ void DefaultActorImpl::deallocateUnconditional() { | |||
if (JobStorageHeapObject.metadata != nullptr) | |||
JobStorage.~ProcessInlineJob(); | |||
auto metadata = cast<ClassMetadata>(this->metadata); | |||
swift_deallocObject(this, metadata->getInstanceSize(), | |||
metadata->getInstanceAlignMask()); | |||
swift_deallocClassInstance(this, metadata->getInstanceSize(), |
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.
Well, that's subtle! Very good catch.
Change actor destruction to call swift_deallocClassInstance instead of swift_deallocObject. When ObjC interop is enabled, swift_deallocClassInstance will check the "pure swift deallocation" bit and call into the ObjC runtime to destruct the instance when needed. This is what clears weak references and associated objects. rdar://91270492
@swift-ci please 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.
nice catch
Change actor destruction to call swift_deallocClassInstance instead of swift_deallocObject. When ObjC interop is enabled, swift_deallocClassInstance will check the "pure swift deallocation" bit and call into the ObjC runtime to destruct the instance when needed. This is what clears weak references and associated objects.
rdar://91270492