Skip to content

Commit 2274f7e

Browse files
committed
Fix the computation of default-actor-ness for resilient classes.
Tested in a follow-up.
1 parent be8d2c8 commit 2274f7e

File tree

5 files changed

+41
-6
lines changed

5 files changed

+41
-6
lines changed

include/swift/AST/Decl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3766,14 +3766,19 @@ class ClassDecl final : public NominalTypeDecl {
37663766

37673767
/// Whether the class is (known to be) a default actor.
37683768
bool isDefaultActor() const;
3769+
bool isDefaultActor(ModuleDecl *M, ResilienceExpansion expansion) const;
37693770

37703771
/// Whether the class is known to be a *root* default actor,
37713772
/// i.e. the first class in its hierarchy that is a default actor.
37723773
bool isRootDefaultActor() const;
3774+
bool isRootDefaultActor(ModuleDecl *M, ResilienceExpansion expansion) const;
37733775

37743776
/// Whether the class was explicitly declared with the `actor` keyword.
37753777
bool isExplicitActor() const { return Bits.ClassDecl.IsActor; }
37763778

3779+
/// Get the closest-to-root superclass that's an actor class.
3780+
const ClassDecl *getRootActorClass() const;
3781+
37773782
/// Does this class explicitly declare any of the methods that
37783783
/// would prevent it from being a default actor?
37793784
bool hasExplicitCustomActorMethods() const;

include/swift/AST/TypeCheckRequests.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -938,15 +938,16 @@ class IsActorRequest :
938938
/// Determine whether the given class is a default actor.
939939
class IsDefaultActorRequest :
940940
public SimpleRequest<IsDefaultActorRequest,
941-
bool(ClassDecl *),
941+
bool(ClassDecl *, ModuleDecl *, ResilienceExpansion),
942942
RequestFlags::Cached> {
943943
public:
944944
using SimpleRequest::SimpleRequest;
945945

946946
private:
947947
friend SimpleRequest;
948948

949-
bool evaluate(Evaluator &evaluator, ClassDecl *classDecl) const;
949+
bool evaluate(Evaluator &evaluator, ClassDecl *classDecl,
950+
ModuleDecl *M, ResilienceExpansion expansion) const;
950951

951952
public:
952953
// Caching

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ SWIFT_REQUEST(TypeChecker, CanBeAsyncHandlerRequest, bool(FuncDecl *),
9999
Cached, NoLocationInfo)
100100
SWIFT_REQUEST(TypeChecker, IsActorRequest, bool(NominalTypeDecl *),
101101
Cached, NoLocationInfo)
102-
SWIFT_REQUEST(TypeChecker, IsDefaultActorRequest, bool(ClassDecl *),
102+
SWIFT_REQUEST(TypeChecker, IsDefaultActorRequest,
103+
bool(ClassDecl *, ModuleDecl *, ResilienceExpansion),
103104
Cached, NoLocationInfo)
104105
SWIFT_REQUEST(TypeChecker, GlobalActorInstanceRequest,
105106
VarDecl *(NominalTypeDecl *),

lib/AST/Decl.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4251,12 +4251,29 @@ GetDestructorRequest::evaluate(Evaluator &evaluator, ClassDecl *CD) const {
42514251
}
42524252

42534253
bool ClassDecl::isDefaultActor() const {
4254+
return isDefaultActor(getModuleContext(), ResilienceExpansion::Minimal);
4255+
}
4256+
4257+
bool ClassDecl::isDefaultActor(ModuleDecl *M,
4258+
ResilienceExpansion expansion) const {
42544259
auto mutableThis = const_cast<ClassDecl *>(this);
42554260
return evaluateOrDefault(getASTContext().evaluator,
4256-
IsDefaultActorRequest{mutableThis},
4261+
IsDefaultActorRequest{mutableThis, M,
4262+
expansion},
42574263
false);
42584264
}
42594265

4266+
const ClassDecl *ClassDecl::getRootActorClass() const {
4267+
if (!isActor()) return nullptr;
4268+
auto cur = this;
4269+
while (true) {
4270+
auto super = cur->getSuperclassDecl();
4271+
if (!super || !super->isActor())
4272+
return cur;
4273+
cur = super;
4274+
}
4275+
}
4276+
42604277
bool ClassDecl::hasMissingDesignatedInitializers() const {
42614278
return evaluateOrDefault(
42624279
getASTContext().evaluator,
@@ -8056,7 +8073,12 @@ bool ClassDecl::hasExplicitCustomActorMethods() const {
80568073
}
80578074

80588075
bool ClassDecl::isRootDefaultActor() const {
8059-
if (!isDefaultActor()) return false;
8076+
return isRootDefaultActor(getModuleContext(), ResilienceExpansion::Minimal);
8077+
}
8078+
8079+
bool ClassDecl::isRootDefaultActor(ModuleDecl *M,
8080+
ResilienceExpansion expansion) const {
8081+
if (!isDefaultActor(M, expansion)) return false;
80608082
auto superclass = getSuperclassDecl();
80618083
return (!superclass || superclass->isNSObject());
80628084
}

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ bool IsActorRequest::evaluate(
299299
}
300300

301301
bool IsDefaultActorRequest::evaluate(
302-
Evaluator &evaluator, ClassDecl *classDecl) const {
302+
Evaluator &evaluator, ClassDecl *classDecl, ModuleDecl *M,
303+
ResilienceExpansion expansion) const {
303304
// If the class isn't an actor, it's not a default actor.
304305
if (!classDecl->isActor())
305306
return false;
@@ -319,6 +320,11 @@ bool IsDefaultActorRequest::evaluate(
319320
return false;
320321
}
321322

323+
// If the class is resilient from the perspective of the module
324+
// module, it's not a default actor.
325+
if (classDecl->isForeign() || classDecl->isResilient(M, expansion))
326+
return false;
327+
322328
// If the class has explicit custom-actor methods, it's not
323329
// a default actor.
324330
if (classDecl->hasExplicitCustomActorMethods())

0 commit comments

Comments
 (0)