[CS] Unify failed constraint recording

Rename `addNewFailingConstraint` to
`recordFailedConstraint`, and call into it
whenever a constraint fails, instead of setting
`failedConstraint`. This ensures that
`-debug-constraints` will always log the constraint
that failed a given scope.

In addition, introduce `retireFailedConstraint`
to cover the common case of retiring a constraint
that just failed.
This commit is contained in:
Hamish Knight
2020-04-09 20:19:57 -07:00
parent 992f035228
commit c39c4e8aad
4 changed files with 40 additions and 39 deletions

View File

@@ -9639,12 +9639,12 @@ ConstraintSystem::addKeyPathApplicationConstraint(Type keypath,
TMF_GenerateConstraints,
locator)) {
case SolutionKind::Error:
if (shouldAddNewFailingConstraint()) {
if (shouldRecordFailedConstraint()) {
auto c = Constraint::create(*this, ConstraintKind::KeyPathApplication,
keypath, root, value,
getConstraintLocator(locator));
if (isFavored) c->setFavored();
addNewFailingConstraint(c);
recordFailedConstraint(c);
}
return;
@@ -9668,13 +9668,13 @@ ConstraintSystem::addKeyPathConstraint(
TMF_GenerateConstraints,
locator)) {
case SolutionKind::Error:
if (shouldAddNewFailingConstraint()) {
if (shouldRecordFailedConstraint()) {
auto c = Constraint::create(*this, ConstraintKind::KeyPath,
keypath, root, value,
getConstraintLocator(locator),
componentTypeVars);
if (isFavored) c->setFavored();
addNewFailingConstraint(c);
recordFailedConstraint(c);
}
return;
@@ -9731,11 +9731,11 @@ void ConstraintSystem::addConstraint(ConstraintKind kind, Type first,
switch (addConstraintImpl(kind, first, second, locator, isFavored)) {
case SolutionKind::Error:
// Add a failing constraint, if needed.
if (shouldAddNewFailingConstraint()) {
if (shouldRecordFailedConstraint()) {
auto c = Constraint::create(*this, kind, first, second,
getConstraintLocator(locator));
if (isFavored) c->setFavored();
addNewFailingConstraint(c);
recordFailedConstraint(c);
}
return;
@@ -9838,11 +9838,11 @@ void ConstraintSystem::addFixConstraint(ConstraintFix *fix, ConstraintKind kind,
switch (simplifyFixConstraint(fix, first, second, kind, subflags, locator)) {
case SolutionKind::Error:
// Add a failing constraint, if needed.
if (shouldAddNewFailingConstraint()) {
if (shouldRecordFailedConstraint()) {
auto c = Constraint::createFixed(*this, kind, fix, first, second,
getConstraintLocator(locator));
if (isFavored) c->setFavored();
addNewFailingConstraint(c);
recordFailedConstraint(c);
}
return;
@@ -10085,8 +10085,7 @@ void ConstraintSystem::simplifyDisjunctionChoice(Constraint *choice) {
// Simplify this term in the disjunction.
switch (simplifyConstraint(*choice)) {
case ConstraintSystem::SolutionKind::Error:
if (!failedConstraint)
failedConstraint = choice;
recordFailedConstraint(choice);
break;
case ConstraintSystem::SolutionKind::Solved: