Skip to content

Commit ff33665

Browse files
committed
[TypeChecker] Add getter/setter methods for retiredConstraints of SolverState
1 parent e546414 commit ff33665

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ bool ConstraintSystem::simplify(bool ContinueAfterFailures) {
359359
}
360360

361361
if (solverState)
362-
solverState->retiredConstraints.push_front(constraint);
362+
solverState->retireConstraint(constraint);
363363

364364
CG.removeConstraint(constraint);
365365
break;
@@ -369,7 +369,7 @@ bool ConstraintSystem::simplify(bool ContinueAfterFailures) {
369369
++solverState->NumSimplifiedConstraints;
370370

371371
// This constraint has already been solved; retire it.
372-
solverState->retiredConstraints.push_front(constraint);
372+
solverState->retireConstraint(constraint);
373373
}
374374

375375
// Remove the constraint from the constraint graph.
@@ -2396,11 +2396,11 @@ bool ConstraintSystem::solveSimplified(
23962396
case SolutionKind::Error:
23972397
if (!failedConstraint)
23982398
failedConstraint = constraint;
2399-
solverState->retiredConstraints.push_front(constraint);
2399+
solverState->retireConstraint(constraint);
24002400
break;
24012401

24022402
case SolutionKind::Solved:
2403-
solverState->retiredConstraints.push_front(constraint);
2403+
solverState->retireConstraint(constraint);
24042404
break;
24052405

24062406
case SolutionKind::Unsolved:

lib/Sema/ConstraintSystem.h

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,11 +1016,6 @@ class ConstraintSystem {
10161016
/// \brief Whether to record failures or not.
10171017
bool recordFixes = false;
10181018

1019-
/// The list of constraints that have been retired along the
1020-
/// current path, this list is used in LIFO fasion when constaints
1021-
/// are added back to the circulation.
1022-
ConstraintList retiredConstraints;
1023-
10241019
/// The current set of generated constraints.
10251020
SmallVector<Constraint *, 4> generatedConstraints;
10261021

@@ -1051,6 +1046,28 @@ class ConstraintSystem {
10511046
generatedConstraints.size()) });
10521047
}
10531048

1049+
/// \brief Check whether there are any retired constraints present.
1050+
bool hasRetiredConstraints() const {
1051+
return !retiredConstraints.empty();
1052+
}
1053+
1054+
/// \brief Mark given constraint as retired along current solver path.
1055+
///
1056+
/// \param constraint The constraint to retire temporarily.
1057+
void retireConstraint(Constraint *constraint) {
1058+
retiredConstraints.push_front(constraint);
1059+
}
1060+
1061+
/// \brief Iterate over all of the retired constraints registered with
1062+
/// current solver state.
1063+
///
1064+
/// \param processor The processor function to be applied to each of
1065+
/// the constraints retrieved.
1066+
void forEachRetired(std::function<void(Constraint &)> processor) {
1067+
for (auto &constraint : retiredConstraints)
1068+
processor(constraint);
1069+
}
1070+
10541071
/// \brief Restore all of the retired/generated constraints to the state
10551072
/// before given scope. This is required because retired constraints have
10561073
/// to be re-introduced to the system in order of arrival (LIFO) and list
@@ -1088,6 +1105,11 @@ class ConstraintSystem {
10881105
}
10891106

10901107
private:
1108+
/// The list of constraints that have been retired along the
1109+
/// current path, this list is used in LIFO fasion when constaints
1110+
/// are added back to the circulation.
1111+
ConstraintList retiredConstraints;
1112+
10911113
/// The collection which holds association between solver scope
10921114
/// and position of the last retired constraint and number of
10931115
/// constraints generated before registration of given scope,
@@ -1564,7 +1586,7 @@ class ConstraintSystem {
15641586
// Record this as a newly-generated constraint.
15651587
if (solverState) {
15661588
solverState->generatedConstraints.push_back(constraint);
1567-
solverState->retiredConstraints.push_front(constraint);
1589+
solverState->retireConstraint(constraint);
15681590
}
15691591
}
15701592

@@ -1588,7 +1610,7 @@ class ConstraintSystem {
15881610
InactiveConstraints.erase(constraint);
15891611

15901612
if (solverState)
1591-
solverState->retiredConstraints.push_front(constraint);
1613+
solverState->retireConstraint(constraint);
15921614
}
15931615

15941616
/// Retrieve the list of inactive constraints.

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2696,13 +2696,13 @@ void ConstraintSystem::print(raw_ostream &out) {
26962696
out << "\n";
26972697
}
26982698

2699-
if (solverState && !solverState->retiredConstraints.empty()) {
2699+
if (solverState && !solverState->hasRetiredConstraints()) {
27002700
out << "\nRetired Constraints:\n";
2701-
for (auto &constraint : solverState->retiredConstraints) {
2701+
solverState->forEachRetired([&](Constraint &constraint) {
27022702
out.indent(2);
27032703
constraint.print(out, &getTypeChecker().Context.SourceMgr);
27042704
out << "\n";
2705-
}
2705+
});
27062706
}
27072707

27082708
if (resolvedOverloadSets) {

0 commit comments

Comments
 (0)