@@ -236,7 +236,31 @@ bool CanBeAsyncHandlerRequest::evaluate(
236
236
}
237
237
238
238
bool 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
+
240
264
bool isExplicitActor = classDecl->isExplicitActor () ||
241
265
classDecl->getAttrs ().getAttribute <ActorAttr>();
242
266
@@ -1362,12 +1386,14 @@ namespace {
1362
1386
}
1363
1387
1364
1388
// Retrieve the nearest enclosing actor context.
1365
- static ClassDecl *getNearestEnclosingActorContext (const DeclContext *dc) {
1389
+ static NominalTypeDecl *getNearestEnclosingActorContext (
1390
+ const DeclContext *dc) {
1366
1391
while (!dc->isModuleScopeContext ()) {
1367
1392
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;
1371
1397
}
1372
1398
}
1373
1399
@@ -1967,7 +1993,7 @@ namespace {
1967
1993
memberLoc, diag::actor_isolated_non_self_reference,
1968
1994
member->getDescriptiveKind (),
1969
1995
member->getName (),
1970
- isolation.getActorClass () ==
1996
+ isolation.getActorType () ==
1971
1997
getNearestEnclosingActorContext (getDeclContext ()),
1972
1998
useKind
1973
1999
);
@@ -2331,9 +2357,18 @@ static Optional<ActorIsolation> getIsolationFromWitnessedRequirements(
2331
2357
continue ;
2332
2358
2333
2359
auto requirementIsolation = getActorIsolation (requirement);
2334
- if (requirementIsolation.isUnspecified ())
2360
+ switch (requirementIsolation) {
2361
+ case ActorIsolation::ActorInstance:
2362
+ case ActorIsolation::Unspecified:
2335
2363
continue ;
2336
2364
2365
+ case ActorIsolation::GlobalActor:
2366
+ case ActorIsolation::GlobalActorUnsafe:
2367
+ case ActorIsolation::Independent:
2368
+ case ActorIsolation::IndependentUnsafe:
2369
+ break ;
2370
+ }
2371
+
2337
2372
auto witness = conformance->getWitnessDecl (requirement);
2338
2373
if (witness != value)
2339
2374
continue ;
@@ -2422,12 +2457,13 @@ ActorIsolation ActorIsolationRequest::evaluate(
2422
2457
}
2423
2458
}
2424
2459
2425
- // Check for instance members and initializers of actor classes ,
2460
+ // Check for instance members and initializers of actor types ,
2426
2461
// 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
+ }
2431
2467
}
2432
2468
2433
2469
// Function used when returning an inferred isolation.
0 commit comments