Skip to content

Commit e0bd269

Browse files
committed
Cleanup check for whether a context uses concurrency features
1 parent 21fb139 commit e0bd269

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,12 +2316,23 @@ void swift::checkPropertyWrapperActorIsolation(
23162316
/// inference rules). Returns \c None if there were no attributes on this
23172317
/// declaration.
23182318
static Optional<ActorIsolation> getIsolationFromAttributes(
2319-
const Decl *decl, bool shouldDiagnose = true) {
2319+
const Decl *decl, bool shouldDiagnose = true, bool onlyExplicit = false) {
23202320
// Look up attributes on the declaration that can affect its actor isolation.
23212321
// If any of them are present, use that attribute.
23222322
auto independentAttr = decl->getAttrs().getAttribute<ActorIndependentAttr>();
23232323
auto nonisolatedAttr = decl->getAttrs().getAttribute<NonisolatedAttr>();
23242324
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+
23252336
unsigned numIsolationAttrs =
23262337
(nonisolatedAttr ? 1 : 0) + (independentAttr ? 1 : 0) +
23272338
(globalActorAttr ? 1 : 0);
@@ -2504,7 +2515,7 @@ static Optional<ActorIsolation> getIsolationFromConformances(
25042515
NominalTypeDecl *nominal) {
25052516
if (isa<ProtocolDecl>(nominal))
25062517
return None;
2507-
2518+
25082519
Optional<ActorIsolation> foundIsolation;
25092520
for (auto proto : nominal->getLocalProtocols()) {
25102521
switch (auto protoIsolation = getActorIsolation(proto)) {
@@ -2884,8 +2895,12 @@ void swift::checkOverrideActorIsolation(ValueDecl *value) {
28842895
bool swift::contextUsesConcurrencyFeatures(const DeclContext *dc) {
28852896
while (!dc->isModuleScopeContext()) {
28862897
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.
28882900
if (auto explicitClosure = dyn_cast<ClosureExpr>(closure)) {
2901+
if (explicitClosure->getAttrs().hasAttribute<ActorIndependentAttr>())
2902+
return true;
2903+
28892904
if (getExplicitGlobalActor(const_cast<ClosureExpr *>(explicitClosure)))
28902905
return true;
28912906
}
@@ -2899,7 +2914,8 @@ bool swift::contextUsesConcurrencyFeatures(const DeclContext *dc) {
28992914
} else if (auto decl = dc->getAsDecl()) {
29002915
// If any isolation attributes are present, we're using concurrency
29012916
// features.
2902-
if (getIsolationFromAttributes(decl, /*shouldDiagnose=*/false))
2917+
if (getIsolationFromAttributes(
2918+
decl, /*shouldDiagnose=*/false, /*onlyExplicit=*/true))
29032919
return true;
29042920

29052921
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
@@ -2915,7 +2931,9 @@ bool swift::contextUsesConcurrencyFeatures(const DeclContext *dc) {
29152931
// If we're in an accessor declaration, also check the storage
29162932
// declaration.
29172933
if (auto accessor = dyn_cast<AccessorDecl>(decl)) {
2918-
if (getIsolationFromAttributes(accessor->getStorage()))
2934+
if (getIsolationFromAttributes(
2935+
accessor->getStorage(), /*shouldDiagnose=*/false,
2936+
/*onlyExplicit=*/true))
29192937
return true;
29202938
}
29212939
}

0 commit comments

Comments
 (0)