Skip to content

Commit 955fe85

Browse files
authored
Sema: Simplify IsDistributedActor same as #37798 (#37811)
1 parent e6dabc1 commit 955fe85

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

include/swift/AST/Decl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3812,6 +3812,12 @@ class ClassDecl final : public NominalTypeDecl {
38123812
/// Whether the class was explicitly declared with the `actor` keyword.
38133813
bool isExplicitActor() const { return Bits.ClassDecl.IsActor; }
38143814

3815+
/// Whether the class was explicitly declared with the `distributed actor` keywords.
3816+
bool isExplicitDistributedActor() const {
3817+
return isExplicitActor() &&
3818+
getAttrs().hasAttribute<DistributedActorAttr>();
3819+
}
3820+
38153821
/// Get the closest-to-root superclass that's an actor class.
38163822
const ClassDecl *getRootActorClass() const;
38173823

lib/Sema/TypeCheckDistributed.cpp

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,20 @@ using namespace swift;
3333

3434
bool IsDistributedActorRequest::evaluate(
3535
Evaluator &evaluator, NominalTypeDecl *nominal) const {
36-
// Protocols are actors if their `Self` type conforms to `DistributedActor`.
36+
// Protocols are actors if they inherit from `DistributedActor`.
3737
if (auto protocol = dyn_cast<ProtocolDecl>(nominal)) {
38-
// Simple case: we have the `DistributedActor` protocol itself.
39-
if (protocol->isSpecificProtocol(KnownProtocolKind::DistributedActor))
40-
return true;
41-
42-
auto actorProto = nominal->getASTContext().getProtocol(
43-
KnownProtocolKind::DistributedActor);
44-
if (!actorProto)
45-
return false;
46-
47-
auto selfType = Type(protocol->getProtocolSelfType());
48-
auto genericSig = protocol->getGenericSignature();
49-
if (!genericSig)
50-
return false;
51-
52-
return genericSig->requiresProtocol(selfType, actorProto);
38+
auto &ctx = protocol->getASTContext();
39+
auto *distributedActorProtocol = ctx.getProtocol(KnownProtocolKind::DistributedActor);
40+
return (protocol == distributedActorProtocol ||
41+
protocol->inheritsFrom(distributedActorProtocol));
5342
}
5443

5544
// Class declarations are 'distributed actors' if they are declared with 'distributed actor'
56-
if(!dyn_cast<ClassDecl>(nominal))
45+
auto classDecl = dyn_cast<ClassDecl>(nominal);
46+
if(!classDecl)
5747
return false;
5848

59-
auto distributedAttr = nominal->getAttrs()
60-
.getAttribute<DistributedActorAttr>();
61-
return distributedAttr != nullptr;
49+
return classDecl->isExplicitDistributedActor();
6250
}
6351

6452
bool IsDistributedFuncRequest::evaluate(

0 commit comments

Comments
 (0)