Skip to content

Commit d9a0130

Browse files
committed
[TypeChecker] Distributed: rework checkDistributedAccess
Only distributed functions and computed properties should be accepted, everything else is invalid.
1 parent 8d9962e commit d9a0130

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
@@ -2302,35 +2302,12 @@ namespace {
23022302
}
23032303
}
23042304

2305-
// Cannot reference subscripts, or stored properties.
2306-
auto var = dyn_cast<VarDecl>(decl);
2307-
if (isa<SubscriptDecl>(decl) || var) {
2308-
// But computed distributed properties are okay,
2309-
// and treated the same as a distributed func.
2310-
if (var && var->isDistributed()) {
2311-
bool explicitlyThrowing = false;
2312-
if (auto getter = var->getAccessor(swift::AccessorKind::Get)) {
2313-
explicitlyThrowing = getter->hasThrows();
2314-
}
2315-
return std::make_pair(
2316-
/*setThrows*/!explicitlyThrowing,
2317-
/*isDistributedThunk=*/true);
2318-
}
2319-
2320-
// otherwise, it was a normal property or subscript and therefore illegal
2321-
ctx.Diags.diagnose(
2322-
declLoc, diag::distributed_actor_isolated_non_self_reference,
2323-
decl->getDescriptiveKind(), decl->getName());
2324-
noteIsolatedActorMember(decl, context);
2325-
return None;
2326-
}
2327-
23282305
// Check that we have a distributed function or computed property.
23292306
if (auto afd = dyn_cast<AbstractFunctionDecl>(decl)) {
23302307
if (!afd->isDistributed()) {
2331-
ctx.Diags.diagnose(declLoc,
2332-
diag::distributed_actor_isolated_method)
2333-
.fixItInsert(decl->getAttributeInsertionLoc(true), "distributed ");
2308+
ctx.Diags.diagnose(declLoc, diag::distributed_actor_isolated_method)
2309+
.fixItInsert(decl->getAttributeInsertionLoc(true),
2310+
"distributed ");
23342311

23352312
noteIsolatedActorMember(decl, context);
23362313
return None;
@@ -2341,7 +2318,24 @@ namespace {
23412318
/*isDistributedThunk=*/true);
23422319
}
23432320

2344-
return std::make_pair(/*setThrows=*/false, /*distributedThunk=*/false);
2321+
if (auto *var = dyn_cast<VarDecl>(decl)) {
2322+
if (var->isDistributed()) {
2323+
bool explicitlyThrowing = false;
2324+
if (auto getter = var->getAccessor(swift::AccessorKind::Get)) {
2325+
explicitlyThrowing = getter->hasThrows();
2326+
}
2327+
return std::make_pair(
2328+
/*setThrows*/ !explicitlyThrowing,
2329+
/*isDistributedThunk=*/true);
2330+
}
2331+
}
2332+
2333+
// This is either non-distributed variable, subscript, or something else.
2334+
ctx.Diags.diagnose(declLoc,
2335+
diag::distributed_actor_isolated_non_self_reference,
2336+
decl->getDescriptiveKind(), decl->getName());
2337+
noteIsolatedActorMember(decl, context);
2338+
return None;
23452339
}
23462340

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

0 commit comments

Comments
 (0)