Skip to content

Commit 4399670

Browse files
authored
Merge pull request #42219 from mikeash/weak-actors
[Concurrency] Fix ObjC weak references to actors.
2 parents a0141bd + b00397c commit 4399670

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

stdlib/public/Concurrency/Actor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,8 +1208,8 @@ void DefaultActorImpl::deallocateUnconditional() {
12081208
if (JobStorageHeapObject.metadata != nullptr)
12091209
JobStorage.~ProcessInlineJob();
12101210
auto metadata = cast<ClassMetadata>(this->metadata);
1211-
swift_deallocObject(this, metadata->getInstanceSize(),
1212-
metadata->getInstanceAlignMask());
1211+
swift_deallocClassInstance(this, metadata->getInstanceSize(),
1212+
metadata->getInstanceAlignMask());
12131213
}
12141214

12151215
void DefaultActorImpl::scheduleActorProcessJob(JobPriority priority, bool useInlineJob) {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %empty-directory(%t)
2+
//
3+
// RUN: cp %s %t/main.swift
4+
// RUN: %target-clang -fno-objc-arc %S/Inputs/ObjCWeak/ObjCWeak.m -c -o %t/ObjCWeak.o
5+
// 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
6+
// RUN: %target-codesign %t/weak_objc_actor_interop
7+
// RUN: %target-run %t/weak_objc_actor_interop 2>&1 | %FileCheck %s
8+
// REQUIRES: executable_test
9+
// REQUIRES: objc_interop
10+
// REQUIRES: concurrency
11+
// UNSUPPORTED: use_os_stdlib
12+
// UNSUPPORTED: back_deployment_runtime
13+
14+
import Foundation
15+
import ObjCWeak
16+
17+
// Test that instances of Swift actors can be referenced using ObjC
18+
// weak references.
19+
20+
@available(SwiftStdlib 5.1, *)
21+
actor A {
22+
@objc nonisolated var description: String {
23+
return "Swift Actor"
24+
}
25+
}
26+
27+
// This availability check will always be true, so we don't need to provide
28+
// FileCheck with fake output in an else branch.
29+
if #available(SwiftStdlib 5.1, *) {
30+
tryWeakReferencing { A() }
31+
// CHECK: before giving up strong reference:
32+
// CHECK-NEXT: Swift Actor
33+
// CHECK-NEXT: after giving up strong reference:
34+
// CHECK-NEXT: Gone
35+
}

0 commit comments

Comments
 (0)