Skip to content

Commit 97176fc

Browse files
authored
Merge pull request #38804 from varungandhi-apple/vg-5.5-objc-actors-took-2-weeks-of-my-life
[5.5] [AST] Treat actors inheriting from NSObject as SwiftNativeNSObjects.
2 parents 108cc64 + a955a0a commit 97176fc

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

lib/AST/Decl.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8222,8 +8222,13 @@ bool ClassDecl::isRootDefaultActor(ModuleDecl *M,
82228222

82238223
bool ClassDecl::isNativeNSObjectSubclass() const {
82248224
// @objc actors implicitly inherit from NSObject.
8225-
if (isActor() && getAttrs().hasAttribute<ObjCAttr>())
8226-
return true;
8225+
if (isActor()) {
8226+
if (getAttrs().hasAttribute<ObjCAttr>()) {
8227+
return true;
8228+
}
8229+
ClassDecl *superclass = getSuperclassDecl();
8230+
return superclass && superclass->isNSObject();
8231+
}
82278232

82288233
// For now, non-actor classes cannot use the native NSObject subclass.
82298234
// Eventually we should roll this out to more classes that directly

test/SILGen/objc_actor.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %target-swift-frontend -emit-silgen %s -swift-version 5 -disable-availability-checking | %FileCheck %s
2+
// REQUIRES: concurrency
3+
// REQUIRES: objc_interop
4+
5+
// rdar://80863853 - For an actor inheriting from NSObject and using '@objc'
6+
// should have the same effect: the effective superclass is SwiftNativeNSObject
7+
// (see 945011d39f8b271b8906bd509aac3aa954f4fc57) not NSObject.
8+
// Check that we don't treat any case as an ObjC class.
9+
10+
import Foundation
11+
12+
public actor MyClass1: NSObject {
13+
public var x: Int
14+
public init(_ x: Int) { self.x = x }
15+
}
16+
17+
// CHECK: alloc_ref $MyClass1
18+
// CHECK-NOT: alloc_ref [objc] $MyClass1
19+
20+
@objc public actor MyClass2 {
21+
public var x: Int
22+
public init(_ x: Int) { self.x = x }
23+
}
24+
25+
// CHECK: alloc_ref $MyClass2
26+
// CHECK-NOT: alloc_ref [objc] $MyClass2
27+
28+
@objc public actor MyClass3: NSObject {
29+
public var x: Int
30+
public init(_ x: Int) { self.x = x }
31+
}
32+
33+
// CHECK: alloc_ref $MyClass3
34+
// CHECK-NOT: alloc_ref [objc] $MyClass3

0 commit comments

Comments
 (0)