Skip to content

Commit 8208c94

Browse files
committed
[TypeChecker] Add getter/setter methods for generatedConstraints of SolverState
1 parent ff33665 commit 8208c94

File tree

3 files changed

+40
-23
lines changed

3 files changed

+40
-23
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2410,7 +2410,7 @@ bool ConstraintSystem::solveSimplified(
24102410
}
24112411

24122412
// Record this as a generated constraint.
2413-
solverState->generatedConstraints.push_back(constraint);
2413+
solverState->addGeneratedConstraint(constraint);
24142414

24152415
if (!solveRec(solutions, allowFreeTypeVariables)) {
24162416
firstSolvedConstraint = constraint;

lib/Sema/ConstraintGraph.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -740,23 +740,8 @@ void ConstraintGraph::removeEdge(Constraint *constraint) {
740740
}
741741
}
742742

743-
size_t index = 0;
744-
for (auto generated : CS.solverState->generatedConstraints) {
745-
if (generated == constraint) {
746-
unsigned last = CS.solverState->generatedConstraints.size()-1;
747-
auto lastConstraint = CS.solverState->generatedConstraints[last];
748-
if (lastConstraint == generated) {
749-
CS.solverState->generatedConstraints.pop_back();
750-
break;
751-
} else {
752-
CS.solverState->generatedConstraints[index] = lastConstraint;
753-
CS.solverState->generatedConstraints[last] = constraint;
754-
CS.solverState->generatedConstraints.pop_back();
755-
break;
756-
}
757-
}
758-
index++;
759-
}
743+
if (CS.solverState)
744+
CS.solverState->removeGeneratedConstraint(constraint);
760745

761746
removeConstraint(constraint);
762747
}

lib/Sema/ConstraintSystem.h

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

1019-
/// The current set of generated constraints.
1020-
SmallVector<Constraint *, 4> generatedConstraints;
1021-
10221019
/// \brief The set of type variable bindings that have changed while
10231020
/// processing this constraint system.
10241021
SavedTypeVariableBindings savedBindings;
@@ -1068,6 +1065,38 @@ class ConstraintSystem {
10681065
processor(constraint);
10691066
}
10701067

1068+
/// \brief Add new "generated" constraint along the current solver path.
1069+
///
1070+
/// \param constraint The newly generated constraint.
1071+
void addGeneratedConstraint(Constraint *constraint) {
1072+
generatedConstraints.push_back(constraint);
1073+
}
1074+
1075+
/// \brief Erase given constraint from the list of generated constraints
1076+
/// along the current solver path. Note that this operation doesn't
1077+
/// guarantee any ordering of the after it's application.
1078+
///
1079+
/// \param constraint The constraint to erase.
1080+
void removeGeneratedConstraint(Constraint *constraint) {
1081+
size_t index = 0;
1082+
for (auto generated : generatedConstraints) {
1083+
if (generated == constraint) {
1084+
unsigned last = generatedConstraints.size() - 1;
1085+
auto lastConstraint = generatedConstraints[last];
1086+
if (lastConstraint == generated) {
1087+
generatedConstraints.pop_back();
1088+
break;
1089+
} else {
1090+
generatedConstraints[index] = lastConstraint;
1091+
generatedConstraints[last] = constraint;
1092+
generatedConstraints.pop_back();
1093+
break;
1094+
}
1095+
}
1096+
index++;
1097+
}
1098+
}
1099+
10711100
/// \brief Restore all of the retired/generated constraints to the state
10721101
/// before given scope. This is required because retired constraints have
10731102
/// to be re-introduced to the system in order of arrival (LIFO) and list
@@ -1110,6 +1139,9 @@ class ConstraintSystem {
11101139
/// are added back to the circulation.
11111140
ConstraintList retiredConstraints;
11121141

1142+
/// The current set of generated constraints.
1143+
SmallVector<Constraint *, 4> generatedConstraints;
1144+
11131145
/// The collection which holds association between solver scope
11141146
/// and position of the last retired constraint and number of
11151147
/// constraints generated before registration of given scope,
@@ -1585,7 +1617,7 @@ class ConstraintSystem {
15851617

15861618
// Record this as a newly-generated constraint.
15871619
if (solverState) {
1588-
solverState->generatedConstraints.push_back(constraint);
1620+
solverState->addGeneratedConstraint(constraint);
15891621
solverState->retireConstraint(constraint);
15901622
}
15911623
}
@@ -1601,7 +1633,7 @@ class ConstraintSystem {
16011633

16021634
// Record this as a newly-generated constraint.
16031635
if (solverState)
1604-
solverState->generatedConstraints.push_back(constraint);
1636+
solverState->addGeneratedConstraint(constraint);
16051637
}
16061638

16071639
/// \brief Remove an inactive constraint from the current constraint graph.

0 commit comments

Comments
 (0)