Skip to content

Commit 4963fda

Browse files
xedinktoso
authored andcommitted
[TypeChecker] Distributed: rework checkDistributedAccess
Only distributed functions and computed properties should be accepted, everything else is invalid.
1 parent 879bf58 commit 4963fda

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,35 +2252,12 @@ namespace {
22522252
}
22532253
}
22542254

2255-
// Cannot reference subscripts, or stored properties.
2256-
auto var = dyn_cast<VarDecl>(decl);
2257-
if (isa<SubscriptDecl>(decl) || var) {
2258-
// But computed distributed properties are okay,
2259-
// and treated the same as a distributed func.
2260-
if (var && var->isDistributed()) {
2261-
bool explicitlyThrowing = false;
2262-
if (auto getter = var->getAccessor(swift::AccessorKind::Get)) {
2263-
explicitlyThrowing = getter->hasThrows();
2264-
}
2265-
return std::make_pair(
2266-
/*setThrows*/!explicitlyThrowing,
2267-
/*isDistributedThunk=*/true);
2268-
}
2269-
2270-
// otherwise, it was a normal property or subscript and therefore illegal
2271-
ctx.Diags.diagnose(
2272-
declLoc, diag::distributed_actor_isolated_non_self_reference,
2273-
decl->getDescriptiveKind(), decl->getName());
2274-
noteIsolatedActorMember(decl, context);
2275-
return None;
2276-
}
2277-
22782255
// Check that we have a distributed function or computed property.
22792256
if (auto afd = dyn_cast<AbstractFunctionDecl>(decl)) {
22802257
if (!afd->isDistributed()) {
2281-
ctx.Diags.diagnose(declLoc,
2282-
diag::distributed_actor_isolated_method)
2283-
.fixItInsert(decl->getAttributeInsertionLoc(true), "distributed ");
2258+
ctx.Diags.diagnose(declLoc, diag::distributed_actor_isolated_method)
2259+
.fixItInsert(decl->getAttributeInsertionLoc(true),
2260+
"distributed ");
22842261

22852262
noteIsolatedActorMember(decl, context);
22862263
return None;
@@ -2291,7 +2268,24 @@ namespace {
22912268
/*isDistributedThunk=*/true);
22922269
}
22932270

2294-
return std::make_pair(/*setThrows=*/false, /*distributedThunk=*/false);
2271+
if (auto *var = dyn_cast<VarDecl>(decl)) {
2272+
if (var->isDistributed()) {
2273+
bool explicitlyThrowing = false;
2274+
if (auto getter = var->getAccessor(swift::AccessorKind::Get)) {
2275+
explicitlyThrowing = getter->hasThrows();
2276+
}
2277+
return std::make_pair(
2278+
/*setThrows*/ !explicitlyThrowing,
2279+
/*isDistributedThunk=*/true);
2280+
}
2281+
}
2282+
2283+
// This is either non-distributed variable, subscript, or something else.
2284+
ctx.Diags.diagnose(declLoc,
2285+
diag::distributed_actor_isolated_non_self_reference,
2286+
decl->getDescriptiveKind(), decl->getName());
2287+
noteIsolatedActorMember(decl, context);
2288+
return None;
22952289
}
22962290

22972291
/// Attempts to identify and mark a valid cross-actor use of a synchronous

0 commit comments

Comments
 (0)