Skip to content

Commit d4bbb82

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. (cherry picked from commit e595b4f)
1 parent 56dd749 commit d4bbb82

File tree

5 files changed

+7
-17
lines changed

5 files changed

+7
-17
lines changed

include/swift/AST/Decl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7532,7 +7532,8 @@ inline bool Decl::isPotentiallyOverridable() const {
75327532
isa<SubscriptDecl>(this) ||
75337533
isa<FuncDecl>(this) ||
75347534
isa<DestructorDecl>(this)) {
7535-
return getDeclContext()->getSelfClassDecl();
7535+
auto classDecl = getDeclContext()->getSelfClassDecl();
7536+
return classDecl && !classDecl->isActor();
75367537
} else {
75377538
return false;
75387539
}

lib/AST/Decl.cpp

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

33473347
bool ValueDecl::hasOpenAccess(const DeclContext *useDC) const {
3348-
assert(isa<ClassDecl>(this) || isa<ConstructorDecl>(this) ||
3349-
isPotentiallyOverridable());
3350-
33513348
AccessLevel access =
33523349
getAdjustedFormalAccess(this, useDC,
33533350
/*treatUsableFromInlineAsPublic*/false);

lib/Sema/TypeCheckAttr.cpp

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

829829
if (attr->getAccess() == AccessLevel::Open) {
830-
if (!isa<ClassDecl>(D) && !D->isPotentiallyOverridable() &&
830+
auto classDecl = dyn_cast<ClassDecl>(D);
831+
if (!(classDecl && !classDecl->isActor()) &&
832+
!D->isPotentiallyOverridable() &&
831833
!attr->isInvalid()) {
832834
diagnose(attr->getLocation(), diag::access_control_open_bad_decl)
833835
.fixItReplace(attr->getRange(), "public");
@@ -2099,7 +2101,8 @@ void AttributeChecker::visitRequiredAttr(RequiredAttr *attr) {
20992101
return;
21002102
}
21012103
// Only classes can have required constructors.
2102-
if (parentTy->getClassOrBoundGenericClass()) {
2104+
if (parentTy->getClassOrBoundGenericClass() &&
2105+
!parentTy->getClassOrBoundGenericClass()->isActor()) {
21032106
// The constructor must be declared within the class itself.
21042107
// FIXME: Allow an SDK overlay to add a required initializer to a class
21052108
// defined in Objective-C

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)