@@ -2316,12 +2316,23 @@ void swift::checkPropertyWrapperActorIsolation(
2316
2316
// / inference rules). Returns \c None if there were no attributes on this
2317
2317
// / declaration.
2318
2318
static Optional<ActorIsolation> getIsolationFromAttributes (
2319
- const Decl *decl, bool shouldDiagnose = true ) {
2319
+ const Decl *decl, bool shouldDiagnose = true , bool onlyExplicit = false ) {
2320
2320
// Look up attributes on the declaration that can affect its actor isolation.
2321
2321
// If any of them are present, use that attribute.
2322
2322
auto independentAttr = decl->getAttrs ().getAttribute <ActorIndependentAttr>();
2323
2323
auto nonisolatedAttr = decl->getAttrs ().getAttribute <NonisolatedAttr>();
2324
2324
auto globalActorAttr = decl->getGlobalActorAttr ();
2325
+
2326
+ // Remove implicit attributes if we only care about explicit ones.
2327
+ if (onlyExplicit) {
2328
+ if (independentAttr && independentAttr->isImplicit ())
2329
+ independentAttr = nullptr ;
2330
+ if (nonisolatedAttr && nonisolatedAttr->isImplicit ())
2331
+ nonisolatedAttr = nullptr ;
2332
+ if (globalActorAttr && globalActorAttr->first ->isImplicit ())
2333
+ globalActorAttr = None;
2334
+ }
2335
+
2325
2336
unsigned numIsolationAttrs =
2326
2337
(nonisolatedAttr ? 1 : 0 ) + (independentAttr ? 1 : 0 ) +
2327
2338
(globalActorAttr ? 1 : 0 );
@@ -2504,7 +2515,7 @@ static Optional<ActorIsolation> getIsolationFromConformances(
2504
2515
NominalTypeDecl *nominal) {
2505
2516
if (isa<ProtocolDecl>(nominal))
2506
2517
return None;
2507
-
2518
+
2508
2519
Optional<ActorIsolation> foundIsolation;
2509
2520
for (auto proto : nominal->getLocalProtocols ()) {
2510
2521
switch (auto protoIsolation = getActorIsolation (proto)) {
@@ -2884,8 +2895,12 @@ void swift::checkOverrideActorIsolation(ValueDecl *value) {
2884
2895
bool swift::contextUsesConcurrencyFeatures (const DeclContext *dc) {
2885
2896
while (!dc->isModuleScopeContext ()) {
2886
2897
if (auto closure = dyn_cast<AbstractClosureExpr>(dc)) {
2887
- // A closure with an explicit global actor uses concurrency features.
2898
+ // A closure with an explicit global actor or @actorIndependent
2899
+ // uses concurrency features.
2888
2900
if (auto explicitClosure = dyn_cast<ClosureExpr>(closure)) {
2901
+ if (explicitClosure->getAttrs ().hasAttribute <ActorIndependentAttr>())
2902
+ return true ;
2903
+
2889
2904
if (getExplicitGlobalActor (const_cast <ClosureExpr *>(explicitClosure)))
2890
2905
return true ;
2891
2906
}
@@ -2899,7 +2914,8 @@ bool swift::contextUsesConcurrencyFeatures(const DeclContext *dc) {
2899
2914
} else if (auto decl = dc->getAsDecl ()) {
2900
2915
// If any isolation attributes are present, we're using concurrency
2901
2916
// features.
2902
- if (getIsolationFromAttributes (decl, /* shouldDiagnose=*/ false ))
2917
+ if (getIsolationFromAttributes (
2918
+ decl, /* shouldDiagnose=*/ false , /* onlyExplicit=*/ true ))
2903
2919
return true ;
2904
2920
2905
2921
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
@@ -2915,7 +2931,9 @@ bool swift::contextUsesConcurrencyFeatures(const DeclContext *dc) {
2915
2931
// If we're in an accessor declaration, also check the storage
2916
2932
// declaration.
2917
2933
if (auto accessor = dyn_cast<AccessorDecl>(decl)) {
2918
- if (getIsolationFromAttributes (accessor->getStorage ()))
2934
+ if (getIsolationFromAttributes (
2935
+ accessor->getStorage (), /* shouldDiagnose=*/ false ,
2936
+ /* onlyExplicit=*/ true ))
2919
2937
return true ;
2920
2938
}
2921
2939
}
0 commit comments