Skip to content

Commit d2b2a50

Browse files
committed
[Constraint system] Record application targets for statement conditions.
We’ll need this to generate constraints for statement conditions within the constraint system. This is unused boilerplate at the moment.
1 parent d81161a commit d2b2a50

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ Solution ConstraintSystem::finalize() {
172172
solution.contextualTypes.assign(
173173
contextualTypes.begin(), contextualTypes.end());
174174

175+
solution.stmtConditionTargets = stmtConditionTargets;
176+
175177
for (auto &e : CheckedConformances)
176178
solution.Conformances.push_back({e.first, e.second});
177179

@@ -243,6 +245,12 @@ void ConstraintSystem::applySolution(const Solution &solution) {
243245
}
244246
}
245247

248+
// Register the statement condition targets.
249+
for (const auto &stmtConditionTarget : solution.stmtConditionTargets) {
250+
if (!getStmtConditionTarget(stmtConditionTarget.first))
251+
setStmtConditionTarget(stmtConditionTarget.first, stmtConditionTarget.second);
252+
}
253+
246254
// Register the conformances checked along the way to arrive to solution.
247255
for (auto &conformance : solution.Conformances)
248256
CheckedConformances.push_back(conformance);
@@ -455,6 +463,7 @@ ConstraintSystem::SolverScope::SolverScope(ConstraintSystem &cs)
455463
numResolvedOverloads = cs.ResolvedOverloads.size();
456464
numInferredClosureTypes = cs.ClosureTypes.size();
457465
numContextualTypes = cs.contextualTypes.size();
466+
numStmtConditionTargets = cs.stmtConditionTargets.size();
458467

459468
PreviousScore = cs.CurrentScore;
460469

@@ -532,6 +541,9 @@ ConstraintSystem::SolverScope::~SolverScope() {
532541
// Remove any contextual types.
533542
truncate(cs.contextualTypes, numContextualTypes);
534543

544+
// Remove any statement condition types.
545+
truncate(cs.stmtConditionTargets, numStmtConditionTargets);
546+
535547
// Reset the previous score.
536548
cs.CurrentScore = PreviousScore;
537549

lib/Sema/ConstraintSystem.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,10 @@ class Solution {
868868
/// Contextual types introduced by this solution.
869869
std::vector<std::pair<const Expr *, ContextualTypeInfo>> contextualTypes;
870870

871+
/// Maps statement condition entries to their solution application targets.
872+
llvm::MapVector<const StmtConditionElement *, SolutionApplicationTarget>
873+
stmtConditionTargets;
874+
871875
std::vector<std::pair<ConstraintLocator *, ProtocolConformanceRef>>
872876
Conformances;
873877

@@ -1487,6 +1491,10 @@ class ConstraintSystem {
14871491
llvm::DenseMap<std::pair<const KeyPathExpr *, unsigned>, TypeBase *>
14881492
KeyPathComponentTypes;
14891493

1494+
/// Maps statement condition entries to their solution application targets.
1495+
llvm::MapVector<const StmtConditionElement *, SolutionApplicationTarget>
1496+
stmtConditionTargets;
1497+
14901498
/// Contextual type information for expressions that are part of this
14911499
/// constraint system.
14921500
llvm::MapVector<const Expr *, ContextualTypeInfo> contextualTypes;
@@ -2068,6 +2076,9 @@ class ConstraintSystem {
20682076
/// The length of \c contextualTypes.
20692077
unsigned numContextualTypes;
20702078

2079+
/// The length of \c stmtConditionTargets.
2080+
unsigned numStmtConditionTargets;
2081+
20712082
/// The previous score.
20722083
Score PreviousScore;
20732084

@@ -2355,6 +2366,22 @@ class ConstraintSystem {
23552366
return CTP_Unused;
23562367
}
23572368

2369+
void setStmtConditionTarget(
2370+
const StmtConditionElement *element, SolutionApplicationTarget target) {
2371+
assert(element != nullptr && "Expected non-null condition element!");
2372+
assert(stmtConditionTargets.count(element) == 0 &&
2373+
"Already set this condition target");
2374+
stmtConditionTargets.insert({element, target});
2375+
}
2376+
2377+
Optional<SolutionApplicationTarget> getStmtConditionTarget(
2378+
const StmtConditionElement *element) const {
2379+
auto known = stmtConditionTargets.find(element);
2380+
if (known == stmtConditionTargets.end())
2381+
return None;
2382+
return known->second;
2383+
}
2384+
23582385
/// Retrieve the constraint locator for the given anchor and
23592386
/// path, uniqued.
23602387
ConstraintLocator *

0 commit comments

Comments
 (0)