@@ -699,7 +699,7 @@ static bool isAsyncCall(
699
699
if (lookup->isImplicitlyAsync ())
700
700
return true ;
701
701
702
- return isAsyncDecl ( lookup->getDecl ());
702
+ return lookup->getDecl (). getDecl ()-> isAsync ( );
703
703
}
704
704
705
705
// / Determine whether we should diagnose data races within the current context.
@@ -2042,24 +2042,6 @@ static ActorIsolation getInnermostIsolatedContext(
2042
2042
}
2043
2043
}
2044
2044
2045
- // / Determine whether this declaration is always accessed asynchronously.
2046
- bool swift::isAsyncDecl (ConcreteDeclRef declRef) {
2047
- auto decl = declRef.getDecl ();
2048
-
2049
- // An async function is asynchronously accessed.
2050
- if (auto func = dyn_cast<AbstractFunctionDecl>(decl))
2051
- return func->hasAsync ();
2052
-
2053
- // A computed property or subscript that has an 'async' getter
2054
- // is asynchronously accessed.
2055
- if (auto storageDecl = dyn_cast<AbstractStorageDecl>(decl)) {
2056
- if (auto effectfulGetter = storageDecl->getEffectfulGetAccessor ())
2057
- return effectfulGetter->hasAsync ();
2058
- }
2059
-
2060
- return false ;
2061
- }
2062
-
2063
2045
AbstractFunctionDecl *swift::enclosingUnsafeInheritsExecutor (
2064
2046
const DeclContext *dc) {
2065
2047
for (; dc; dc = dc->getParent ()) {
@@ -4443,7 +4425,7 @@ namespace {
4443
4425
// Make sure isolated conformances are formed in the right context.
4444
4426
checkIsolatedConformancesInContext (declRef, loc, getDeclContext ());
4445
4427
4446
- auto decl = declRef.getDecl ();
4428
+ auto * const decl = declRef.getDecl ();
4447
4429
4448
4430
// If this declaration is a callee from the enclosing application,
4449
4431
// it's already been checked via the call.
@@ -4500,7 +4482,7 @@ namespace {
4500
4482
4501
4483
// An escaping partial application of something that is part of
4502
4484
// the actor's isolated state is never permitted.
4503
- if (partialApply && partialApply->isEscaping && !isAsyncDecl (declRef )) {
4485
+ if (partialApply && partialApply->isEscaping && !decl-> isAsync ( )) {
4504
4486
ctx.Diags .diagnose (loc, diag::actor_isolated_partial_apply, decl);
4505
4487
return true ;
4506
4488
}
@@ -5612,9 +5594,9 @@ static OverrideIsolationResult validOverrideIsolation(
5612
5594
// It's okay to enter the actor when the overridden declaration is
5613
5595
// asynchronous (because it will do the switch) or is accessible from
5614
5596
// anywhere.
5615
- if (isAsyncDecl ( overridden) ||
5616
- isAccessibleAcrossActors (
5617
- overridden, refResult. isolation , declContext)) {
5597
+ if (overridden-> isAsync ( ) ||
5598
+ isAccessibleAcrossActors (overridden, refResult. isolation ,
5599
+ declContext)) {
5618
5600
return OverrideIsolationResult::Sendable;
5619
5601
}
5620
5602
@@ -7713,13 +7695,15 @@ ActorReferenceResult ActorReferenceResult::forReference(
7713
7695
std::optional<ActorIsolation> knownContextIsolation,
7714
7696
llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
7715
7697
getClosureActorIsolation) {
7698
+ auto *const decl = declRef.getDecl ();
7699
+
7716
7700
// If not provided, compute the isolation of the declaration, adjusted
7717
7701
// for references.
7718
7702
ActorIsolation declIsolation = ActorIsolation::forUnspecified ();
7719
7703
if (knownDeclIsolation) {
7720
7704
declIsolation = *knownDeclIsolation;
7721
7705
} else {
7722
- declIsolation = getActorIsolationForReference (declRef. getDecl () , fromDC);
7706
+ declIsolation = getActorIsolationForReference (decl , fromDC);
7723
7707
if (declIsolation.requiresSubstitution ())
7724
7708
declIsolation = declIsolation.subst (declRef.getSubstitutions ());
7725
7709
}
@@ -7731,7 +7715,7 @@ ActorReferenceResult ActorReferenceResult::forReference(
7731
7715
// FIXME: Actor constructors are modeled as isolated to the actor
7732
7716
// so that Sendable checking is applied to their arguments, but the
7733
7717
// call itself does not hop to another executor.
7734
- if (auto ctor = dyn_cast<ConstructorDecl>(declRef. getDecl () )) {
7718
+ if (auto ctor = dyn_cast<ConstructorDecl>(decl )) {
7735
7719
if (auto nominal = ctor->getDeclContext ()->getSelfNominalTypeDecl ()) {
7736
7720
if (nominal->isAnyActor ())
7737
7721
options |= Flags::OnlyArgsCrossIsolation;
@@ -7740,7 +7724,7 @@ ActorReferenceResult ActorReferenceResult::forReference(
7740
7724
7741
7725
// If the entity we are referencing is not a value, we're in the same
7742
7726
// concurrency domain.
7743
- if (isNonValueReference (declRef. getDecl () ))
7727
+ if (isNonValueReference (decl ))
7744
7728
return forSameConcurrencyDomain (declIsolation, options);
7745
7729
7746
7730
// Compute the isolation of the context, if not provided.
@@ -7757,9 +7741,10 @@ ActorReferenceResult ActorReferenceResult::forReference(
7757
7741
if (!declIsolation.isActorIsolated ()) {
7758
7742
// If the declaration is asynchronous and we are in an actor-isolated
7759
7743
// context (of any kind), then we exit the actor to the nonisolated context.
7760
- if (isAsyncDecl (declRef) && contextIsolation.isActorIsolated () &&
7761
- !declRef.getDecl ()->getAttrs ()
7762
- .hasAttribute <UnsafeInheritExecutorAttr>())
7744
+ if (decl->isAsync () && contextIsolation.isActorIsolated () &&
7745
+ !declRef.getDecl ()
7746
+ ->getAttrs ()
7747
+ .hasAttribute <UnsafeInheritExecutorAttr>())
7763
7748
return forExitsActorToNonisolated (contextIsolation, options);
7764
7749
7765
7750
// Otherwise, we stay in the same concurrency domain, whether on an actor
@@ -7788,11 +7773,9 @@ ActorReferenceResult ActorReferenceResult::forReference(
7788
7773
if ((declIsolation.isActorIsolated () && contextIsolation.isGlobalActor ()) ||
7789
7774
declIsolation.isGlobalActor ()) {
7790
7775
auto *init = dyn_cast<ConstructorDecl>(fromDC);
7791
- auto *decl = declRef.getDecl ();
7792
7776
if (init && init->isDesignatedInit () && isStoredProperty (decl) &&
7793
7777
(!actorInstance || actorInstance->isSelf ())) {
7794
- auto type =
7795
- fromDC->mapTypeIntoContext (declRef.getDecl ()->getInterfaceType ());
7778
+ auto type = fromDC->mapTypeIntoContext (decl->getInterfaceType ());
7796
7779
if (!type->isSendableType ()) {
7797
7780
// Treat the decl isolation as 'preconcurrency' to downgrade violations
7798
7781
// to warnings, because violating Sendable here is accepted by the
@@ -7806,16 +7789,14 @@ ActorReferenceResult ActorReferenceResult::forReference(
7806
7789
// If there is an instance and it is checked by flow isolation, treat it
7807
7790
// as being in the same concurrency domain.
7808
7791
if (actorInstance &&
7809
- checkedByFlowIsolation (
7810
- fromDC, *actorInstance, declRef.getDecl (), declRefLoc, useKind))
7792
+ checkedByFlowIsolation (fromDC, *actorInstance, decl, declRefLoc, useKind))
7811
7793
return forSameConcurrencyDomain (declIsolation, options);
7812
7794
7813
7795
// If we are delegating to another initializer, treat them as being in the
7814
7796
// same concurrency domain.
7815
7797
// FIXME: This has a lot of overlap with both the stored-property checks
7816
7798
// below and the flow-isolation checks above.
7817
- if (actorInstance && actorInstance->isSelf () &&
7818
- isa<ConstructorDecl>(declRef.getDecl ()) &&
7799
+ if (actorInstance && actorInstance->isSelf () && isa<ConstructorDecl>(decl) &&
7819
7800
isa<ConstructorDecl>(fromDC))
7820
7801
return forSameConcurrencyDomain (declIsolation, options);
7821
7802
@@ -7824,16 +7805,15 @@ ActorReferenceResult ActorReferenceResult::forReference(
7824
7805
// global-actor-qualified type, then we have problems if the stored property
7825
7806
// type is non-Sendable. Note that if we get here, the type must be Sendable.
7826
7807
if (actorInstance && actorInstance->isSelf () &&
7827
- isNonInheritedStorage (declRef.getDecl (), fromDC) &&
7828
- declIsolation.isGlobalActor () &&
7808
+ isNonInheritedStorage (decl, fromDC) && declIsolation.isGlobalActor () &&
7829
7809
(isa<ConstructorDecl>(fromDC) || isa<DestructorDecl>(fromDC)))
7830
7810
return forSameConcurrencyDomain (declIsolation, options);
7831
7811
7832
7812
// At this point, we are accessing the target from outside the actor.
7833
7813
// First, check whether it is something that can be accessed directly,
7834
7814
// without any kind of promotion.
7835
- if (isAccessibleAcrossActors (
7836
- declRef. getDecl (), declIsolation, fromDC, options, actorInstance))
7815
+ if (isAccessibleAcrossActors (decl, declIsolation, fromDC, options,
7816
+ actorInstance))
7837
7817
return forEntersActor (declIsolation, options);
7838
7818
7839
7819
// This is a cross-actor reference.
@@ -7843,7 +7823,7 @@ ActorReferenceResult ActorReferenceResult::forReference(
7843
7823
options |= Flags::Preconcurrency;
7844
7824
7845
7825
// If the declaration isn't asynchronous, promote to async.
7846
- if (!isAsyncDecl (declRef ))
7826
+ if (!decl-> isAsync ( ))
7847
7827
options |= Flags::AsyncPromotion;
7848
7828
7849
7829
// If the declaration is isolated to a distributed actor and we are not
0 commit comments