Skip to content

Commit e595b4f

Browse files
committed
[SE-0306] Ban "open" and "required" on actors.
Because actors don't have inheritance, ban "open" and "required", which don't make sense. We will permit "final" which, although it doesn't have any semantic impact, is still used to determine whether the ABI of the actor itself might permit subclassing in the future. This leaves the door slightly ajar for actor inheritance should we need to revisit that decision. Fixes SR-14785 / rdar://79401150.
1 parent f5dc1a1 commit e595b4f

File tree

7 files changed

+9
-26
lines changed

7 files changed

+9
-26
lines changed

include/swift/AST/Decl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7560,7 +7560,8 @@ inline bool Decl::isPotentiallyOverridable() const {
75607560
isa<SubscriptDecl>(this) ||
75617561
isa<FuncDecl>(this) ||
75627562
isa<DestructorDecl>(this)) {
7563-
return getDeclContext()->getSelfClassDecl();
7563+
auto classDecl = getDeclContext()->getSelfClassDecl();
7564+
return classDecl && !classDecl->isActor();
75647565
} else {
75657566
return false;
75667567
}

lib/AST/Decl.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3349,9 +3349,6 @@ AccessLevel ValueDecl::getFormalAccess() const {
33493349
}
33503350

33513351
bool ValueDecl::hasOpenAccess(const DeclContext *useDC) const {
3352-
assert(isa<ClassDecl>(this) || isa<ConstructorDecl>(this) ||
3353-
isPotentiallyOverridable());
3354-
33553352
AccessLevel access =
33563353
getAdjustedFormalAccess(this, useDC,
33573354
/*treatUsableFromInlineAsPublic*/false);

lib/Sema/CodeSynthesisDistributedActor.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,6 @@ createDistributedActor_init_local(ClassDecl *classDecl,
223223
initDecl->setSynthesized();
224224
initDecl->setBodySynthesizer(&createBody_DistributedActor_init_transport);
225225

226-
// This constructor is 'required', all distributed actors MUST invoke it.
227-
auto *reqAttr = new (C) RequiredAttr(/*IsImplicit*/true);
228-
initDecl->getAttrs().add(reqAttr);
229-
230226
auto *nonIsoAttr = new (C) NonisolatedAttr(/*IsImplicit*/true);
231227
initDecl->getAttrs().add(nonIsoAttr);
232228

@@ -350,9 +346,6 @@ createDistributedActor_init_resolve(ClassDecl *classDecl,
350346
initDecl->setSynthesized();
351347
initDecl->setBodySynthesizer(&createDistributedActor_init_resolve_body);
352348

353-
// This constructor is 'required', all distributed actors MUST have it.
354-
initDecl->getAttrs().add(new (C) RequiredAttr(/*IsImplicit*/true));
355-
356349
auto *nonIsoAttr = new (C) NonisolatedAttr(/*IsImplicit*/true);
357350
initDecl->getAttrs().add(nonIsoAttr);
358351

lib/Sema/TypeCheckAttr.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,9 @@ void AttributeChecker::visitAccessControlAttr(AccessControlAttr *attr) {
799799
}
800800

801801
if (attr->getAccess() == AccessLevel::Open) {
802-
if (!isa<ClassDecl>(D) && !D->isPotentiallyOverridable() &&
802+
auto classDecl = dyn_cast<ClassDecl>(D);
803+
if (!(classDecl && !classDecl->isActor()) &&
804+
!D->isPotentiallyOverridable() &&
803805
!attr->isInvalid()) {
804806
diagnose(attr->getLocation(), diag::access_control_open_bad_decl)
805807
.fixItReplace(attr->getRange(), "public");
@@ -2085,7 +2087,8 @@ void AttributeChecker::visitRequiredAttr(RequiredAttr *attr) {
20852087
return;
20862088
}
20872089
// Only classes can have required constructors.
2088-
if (parentTy->getClassOrBoundGenericClass()) {
2090+
if (parentTy->getClassOrBoundGenericClass() &&
2091+
!parentTy->getClassOrBoundGenericClass()->isActor()) {
20892092
// The constructor must be declared within the class itself.
20902093
// FIXME: Allow an SDK overlay to add a required initializer to a class
20912094
// defined in Objective-C

test/Distributed/actor_protocols.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ actor A2: DistributedActor {
4949
fatalError()
5050
}
5151

52-
required init(transport: ActorTransport) {
52+
init(transport: ActorTransport) {
5353
fatalError()
5454
}
55-
required init(resolve address: ActorAddress, using transport: ActorTransport) throws {
55+
init(resolve address: ActorAddress, using transport: ActorTransport) throws {
5656
fatalError()
5757
}
5858
}

test/IRGen/async/Inputs/resilient_actor.swift

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/IRGen/async/default_actor.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -emit-module -enable-experimental-concurrency -enable-library-evolution -emit-module-path=%t/resilient_actor.swiftmodule -module-name=resilient_actor %S/Inputs/resilient_actor.swift
32
// RUN: %target-swift-frontend -I %t -emit-ir -enable-experimental-concurrency -enable-library-evolution %s | %IRGenFileCheck %s
43
// REQUIRES: concurrency
54

@@ -8,8 +7,6 @@
87
// 0x81810050: the same, but using a singleton metadata initialization
98
// CHECK-SAME: i32 {{-2122317744|-2122252208}},
109

11-
import resilient_actor
12-
1310
// CHECK-LABEL: define hidden swiftcc void @"$s13default_actor1ACfD"(%T13default_actor1AC* swiftself %0)
1411
// CHECK-NOT: ret void
1512
// CHECK: call swiftcc void @swift_defaultActor_deallocate(

0 commit comments

Comments
 (0)