@@ -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