@@ -426,35 +426,52 @@ static bool checkObjCInForeignClassContext(const ValueDecl *VD,
426
426
return true ;
427
427
}
428
428
429
+ // / Whether the given declaration can be exposed as Objective-C.
430
+ static bool canExposeActorIsolatedAsObjC (
431
+ const ValueDecl *value, const ActorIsolation &isolation) {
432
+ if (isAccessibleAcrossActors (
433
+ const_cast <ValueDecl *>(value), isolation, value->getDeclContext ()))
434
+ return true ;
435
+
436
+ // An async function can be exposed as Objective-C.
437
+ if (auto func = dyn_cast<AbstractFunctionDecl>( value))
438
+ return func->hasAsync ();
439
+
440
+ return false ;
441
+ }
442
+
429
443
// / Actor-isolated declarations cannot be @objc.
430
- static bool checkObjCActorIsolation (const ValueDecl *VD,
431
- ObjCReason Reason) {
444
+ static bool checkObjCActorIsolation (const ValueDecl *VD, ObjCReason Reason) {
432
445
// Check actor isolation.
433
- switch (auto restriction = ActorIsolationRestriction::forDeclaration (
434
- const_cast <ValueDecl *>(VD), VD->getDeclContext (),
435
- /* fromExpression=*/ false )) {
436
- case ActorIsolationRestriction::CrossActorSelf:
446
+ switch (auto isolation = getActorIsolation (const_cast <ValueDecl *>(VD))) {
447
+ case ActorIsolation::ActorInstance:
448
+ if (!canExposeActorIsolatedAsObjC (VD, isolation)) {
449
+ // Actor-isolated functions cannot be @objc.
450
+ VD->diagnose (diag::actor_isolated_objc, VD->getDescriptiveKind (),
451
+ VD->getName ());
452
+ Reason.describe (VD);
453
+ if (auto FD = dyn_cast<FuncDecl>(VD)) {
454
+ addAsyncNotes (const_cast <FuncDecl *>(FD));
455
+ }
456
+
457
+ return true ;
458
+ }
459
+
437
460
// FIXME: Substitution map?
438
461
diagnoseNonSendableTypesInReference (
439
462
const_cast <ValueDecl *>(VD), VD->getDeclContext (),
440
463
VD->getLoc (), SendableCheckReason::ObjC);
441
464
return false ;
442
- case ActorIsolationRestriction::ActorSelf:
443
- // Actor-isolated functions cannot be @objc.
444
- VD->diagnose (diag::actor_isolated_objc, VD->getDescriptiveKind (),
445
- VD->getName ());
446
- Reason.describe (VD);
447
- if (auto FD = dyn_cast<FuncDecl>(VD)) {
448
- addAsyncNotes (const_cast <FuncDecl *>(FD));
449
- }
450
- return true ;
451
465
452
- case ActorIsolationRestriction::GlobalActorUnsafe :
453
- case ActorIsolationRestriction::GlobalActor :
466
+ case ActorIsolation::GlobalActor :
467
+ case ActorIsolation::GlobalActorUnsafe :
454
468
// FIXME: Consider whether to limit @objc on global-actor-qualified
455
- // declarations.
456
- case ActorIsolationRestriction::Unrestricted:
457
- case ActorIsolationRestriction::Unsafe:
469
+ // declarations. Perhaps only allow main actor, which we can reflect
470
+ // in the generated header.
471
+ return false ;
472
+
473
+ case ActorIsolation::Independent:
474
+ case ActorIsolation::Unspecified:
458
475
return false ;
459
476
}
460
477
}
0 commit comments