Skip to content

Commit 9527413

Browse files
committed
carry the info into the solver
1 parent 7385fa7 commit 9527413

File tree

7 files changed

+26
-6
lines changed

7 files changed

+26
-6
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,9 @@ class Solution {
13121312
/// The set of parameters that have been inferred to be 'isolated'.
13131313
llvm::SmallVector<ParamDecl *, 2> isolatedParams;
13141314

1315+
/// The set of parameters that have been inferred to be '_local'.
1316+
llvm::SmallVector<ParamDecl *, 2> distributedKnownLocalParams;
1317+
13151318
/// The set of functions that have been transformed by a result builder.
13161319
llvm::MapVector<AnyFunctionRef, AppliedBuilderTransform>
13171320
resultBuilderTransformed;
@@ -2675,7 +2678,7 @@ class ConstraintSystem {
26752678
llvm::SmallSetVector<ParamDecl *, 2> isolatedParams;
26762679

26772680
/// The set of DistributedActor parameters that have been inferred
2678-
/// to be known to be local.
2681+
/// to be known to be '_local'.
26792682
llvm::SmallSetVector<ParamDecl *, 2> distributedKnownLocalParams;
26802683

26812684
/// Maps closure parameters to type variables.

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7963,7 +7963,8 @@ bool ExprRewriter::requiresDistributedThunk(Expr *base, SourceLoc memberLoc,
79637963
llvm::is_contained(solution.isolatedParams, P);
79647964
},
79657965
[&](ParamDecl *P) {
7966-
return P->isDistributedKnownToBeLocal(); // TODO: need the solution too?
7966+
return P->isDistributedKnownToBeLocal() ||
7967+
llvm::is_contained(solution.distributedKnownLocalParams, P);
79677968
});
79687969

79697970
// Adjust the declaration context to the innermost context that is neither

lib/Sema/CSClosure.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,12 @@ SolutionApplicationToFunctionResult ConstraintSystem::applySolution(
16561656
param->setIsolated(true);
16571657
}
16581658

1659+
// Find any '_local' parameters in this closure and mark them as isolated.
1660+
for (auto param : solution.distributedKnownLocalParams) {
1661+
if (param->getDeclContext() == closure)
1662+
param->setDistributedKnownToBeLocal(true);
1663+
}
1664+
16591665
// Coerce the result type, if it was written explicitly.
16601666
if (closure->hasExplicitResultType()) {
16611667
closure->setExplicitResultType(closureFnType->getResult());

lib/Sema/CSSimplify.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9870,8 +9870,9 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
98709870
// an 'isolated' param is also implicitly '_local',
98719871
// since in order to run "on" an actor, it must be a real local instance.
98729872
distributedKnownLocalParams.insert(paramDecl);
9873-
} else if (contextualParam->isDistributedKnownToBeLocal() &&
9874-
!flags.isDistributedKnownToBeLocal() && paramDecl) {
9873+
}
9874+
if (contextualParam->isDistributedKnownToBeLocal() &&
9875+
!flags.isDistributedKnownToBeLocal() && paramDecl) {
98759876
distributedKnownLocalParams.insert(paramDecl);
98769877
}
98779878

lib/Sema/CSSolver.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ Solution ConstraintSystem::finalize() {
182182
solution.solutionApplicationTargets = solutionApplicationTargets;
183183
solution.caseLabelItems = caseLabelItems;
184184
solution.isolatedParams.append(isolatedParams.begin(), isolatedParams.end());
185+
solution.distributedKnownLocalParams.append(distributedKnownLocalParams.begin(), distributedKnownLocalParams.end());
185186

186187
for (const auto &transformed : resultBuilderTransformed) {
187188
solution.resultBuilderTransformed.insert(transformed);
@@ -295,6 +296,10 @@ void ConstraintSystem::applySolution(const Solution &solution) {
295296
isolatedParams.insert(param);
296297
}
297298

299+
for (auto param : solution.distributedKnownLocalParams) {
300+
distributedKnownLocalParams.insert(param);
301+
}
302+
298303
for (const auto &transformed : solution.resultBuilderTransformed) {
299304
resultBuilderTransformed.insert(transformed);
300305
}
@@ -535,6 +540,7 @@ ConstraintSystem::SolverScope::SolverScope(ConstraintSystem &cs)
535540
numSolutionApplicationTargets = cs.solutionApplicationTargets.size();
536541
numCaseLabelItems = cs.caseLabelItems.size();
537542
numIsolatedParams = cs.isolatedParams.size();
543+
numDistributedKnownLocalParams = cs.distributedKnownLocalParams.size();
538544
numImplicitValueConversions = cs.ImplicitValueConversions.size();
539545
numArgumentLists = cs.ArgumentLists.size();
540546
numImplicitCallAsFunctionRoots = cs.ImplicitCallAsFunctionRoots.size();
@@ -646,6 +652,9 @@ ConstraintSystem::SolverScope::~SolverScope() {
646652
// Remove any isolated parameters.
647653
truncate(cs.isolatedParams, numIsolatedParams);
648654

655+
// Remove any distributed known-to-be-local parameters.
656+
truncate(cs.distributedKnownLocalParams, numDistributedKnownLocalParams);
657+
649658
// Remove any implicit value conversions.
650659
truncate(cs.ImplicitValueConversions, numImplicitValueConversions);
651660

lib/Sema/TypeCheckType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3706,7 +3706,7 @@ TypeResolver::resolveDistributedKnownToBeLocal(DistributedKnownToBeLocalTypeRepr
37063706

37073707
// TODO(distributed): more diagnosis here, prevent from use in props, enums etc
37083708

3709-
// isolated parameters must be of 'distributed actor' type
3709+
// '_local' parameters must be of 'distributed actor' type
37103710
if (!type->hasTypeParameter() &&
37113711
!type->isDistributedActor() &&
37123712
!type->hasError()) {

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5858
/// describe what change you made. The content of this comment isn't important;
5959
/// it just ensures a conflict if two people change the module format.
6060
/// Don't worry about adhering to the 80-column limit for this line.
61-
const uint16_t SWIFTMODULE_VERSION_MINOR = 694; // add @objc protocol methods to objc method tables
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 695; // add '_local' for distributed actors to mark "known to be local"
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///

0 commit comments

Comments
 (0)