@@ -236,7 +236,31 @@ bool CanBeAsyncHandlerRequest::evaluate(
236236}
237237
238238bool IsActorRequest::evaluate (
239- Evaluator &evaluator, ClassDecl *classDecl) const {
239+ Evaluator &evaluator, NominalTypeDecl *nominal) const {
240+ // Protocols are actors if their `Self` type conforms to `Actor`.
241+ if (auto protocol = dyn_cast<ProtocolDecl>(nominal)) {
242+ // Simple case: we have the Actor protocol itself.
243+ if (protocol->isSpecificProtocol (KnownProtocolKind::Actor))
244+ return true ;
245+
246+ auto actorProto = nominal->getASTContext ().getProtocol (
247+ KnownProtocolKind::Actor);
248+ if (!actorProto)
249+ return false ;
250+
251+ auto selfType = Type (protocol->getProtocolSelfType ());
252+ auto genericSig = protocol->getGenericSignature ();
253+ if (!genericSig)
254+ return false ;
255+
256+ return genericSig->requiresProtocol (selfType, actorProto);
257+ }
258+
259+ // Class declarations are actors if they were declared with "actor".
260+ auto classDecl = dyn_cast<ClassDecl>(nominal);
261+ if (!classDecl)
262+ return false ;
263+
240264 bool isExplicitActor = classDecl->isExplicitActor () ||
241265 classDecl->getAttrs ().getAttribute <ActorAttr>();
242266
@@ -1362,12 +1386,14 @@ namespace {
13621386 }
13631387
13641388 // Retrieve the nearest enclosing actor context.
1365- static ClassDecl *getNearestEnclosingActorContext (const DeclContext *dc) {
1389+ static NominalTypeDecl *getNearestEnclosingActorContext (
1390+ const DeclContext *dc) {
13661391 while (!dc->isModuleScopeContext ()) {
13671392 if (dc->isTypeContext ()) {
1368- if (auto classDecl = dc->getSelfClassDecl ()) {
1369- if (classDecl->isActor ())
1370- return classDecl;
1393+ // FIXME: Protocol extensions need specific handling here.
1394+ if (auto nominal = dc->getSelfNominalTypeDecl ()) {
1395+ if (nominal->isActor ())
1396+ return nominal;
13711397 }
13721398 }
13731399
@@ -1967,7 +1993,7 @@ namespace {
19671993 memberLoc, diag::actor_isolated_non_self_reference,
19681994 member->getDescriptiveKind (),
19691995 member->getName (),
1970- isolation.getActorClass () ==
1996+ isolation.getActorType () ==
19711997 getNearestEnclosingActorContext (getDeclContext ()),
19721998 useKind
19731999 );
@@ -2331,9 +2357,18 @@ static Optional<ActorIsolation> getIsolationFromWitnessedRequirements(
23312357 continue ;
23322358
23332359 auto requirementIsolation = getActorIsolation (requirement);
2334- if (requirementIsolation.isUnspecified ())
2360+ switch (requirementIsolation) {
2361+ case ActorIsolation::ActorInstance:
2362+ case ActorIsolation::Unspecified:
23352363 continue ;
23362364
2365+ case ActorIsolation::GlobalActor:
2366+ case ActorIsolation::GlobalActorUnsafe:
2367+ case ActorIsolation::Independent:
2368+ case ActorIsolation::IndependentUnsafe:
2369+ break ;
2370+ }
2371+
23372372 auto witness = conformance->getWitnessDecl (requirement);
23382373 if (witness != value)
23392374 continue ;
@@ -2422,12 +2457,13 @@ ActorIsolation ActorIsolationRequest::evaluate(
24222457 }
24232458 }
24242459
2425- // Check for instance members and initializers of actor classes ,
2460+ // Check for instance members and initializers of actor types ,
24262461 // which are part of actor-isolated state.
2427- auto classDecl = value->getDeclContext ()->getSelfClassDecl ();
2428- if (classDecl && classDecl->isActor () &&
2429- (value->isInstanceMember () || isa<ConstructorDecl>(value))) {
2430- defaultIsolation = ActorIsolation::forActorInstance (classDecl);
2462+ if (auto nominal = value->getDeclContext ()->getSelfNominalTypeDecl ()) {
2463+ if (nominal->isActor () &&
2464+ (value->isInstanceMember () || isa<ConstructorDecl>(value))) {
2465+ defaultIsolation = ActorIsolation::forActorInstance (nominal);
2466+ }
24312467 }
24322468
24332469 // Function used when returning an inferred isolation.
0 commit comments