Skip to content

[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

Merged
merged 1 commit into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions stdlib/public/Concurrency/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Copy link
Member

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.

metadata->getInstanceAlignMask());
}

void DefaultActorImpl::scheduleActorProcessJob(JobPriority priority, bool useInlineJob) {
Expand Down
35 changes: 35 additions & 0 deletions test/Interpreter/SDK/weak_objc_actor_interop.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// RUN: %empty-directory(%t)
//
// RUN: cp %s %t/main.swift
// RUN: %target-clang -fno-objc-arc %S/Inputs/ObjCWeak/ObjCWeak.m -c -o %t/ObjCWeak.o
// RUN: %target-build-swift %t/main.swift -I %S/Inputs/ObjCWeak/ -Xlinker %t/ObjCWeak.o -o %t/weak_objc_actor_interop -Xfrontend -disable-access-control
// RUN: %target-codesign %t/weak_objc_actor_interop
// RUN: %target-run %t/weak_objc_actor_interop 2>&1 | %FileCheck %s
// REQUIRES: executable_test
// REQUIRES: objc_interop
// REQUIRES: concurrency
// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime

import Foundation
import ObjCWeak

// Test that instances of Swift actors can be referenced using ObjC
// weak references.

@available(SwiftStdlib 5.1, *)
actor A {
@objc nonisolated var description: String {
return "Swift Actor"
}
}

// This availability check will always be true, so we don't need to provide
// FileCheck with fake output in an else branch.
if #available(SwiftStdlib 5.1, *) {
tryWeakReferencing { A() }
// CHECK: before giving up strong reference:
// CHECK-NEXT: Swift Actor
// CHECK-NEXT: after giving up strong reference:
// CHECK-NEXT: Gone
}