Merge pull request #18484 from xedin/diag-req-failures-via-fixes

[ConstraintSystem] Diagnose missing conformance requirements via "fixes"
This commit is contained in:
Pavel Yaskevich
2018-08-03 19:23:06 -07:00
committed by GitHub
25 changed files with 248 additions and 87 deletions

View File

@@ -2766,6 +2766,28 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
}
return result;
}
// If this is a generic requirement let's try to record that
// conformance is missing and consider this a success, which
// makes it much easier to diagnose problems like that.
{
SmallVector<LocatorPathElt, 4> path;
auto *anchor = locator.getLocatorParts(path);
if (!path.empty() && path.back().getKind() ==
ConstraintLocator::PathElementKind::TypeParameterRequirement) {
auto typeRequirement = path.back();
std::pair<Expr *, unsigned> reqLoc = {anchor, typeRequirement.getValue()};
MissingConformances[reqLoc] = {type.getPointer(), protocol};
// Let's strip all of the unnecessary information from locator,
// diagnostics only care about anchor - to lookup type,
// and what was the requirement# which is not satisfied.
ConstraintLocatorBuilder requirement(getConstraintLocator(anchor));
if (!recordFix({FixKind::AddConformance},
requirement.withPathElement(typeRequirement)))
return SolutionKind::Solved;
}
}
// There's nothing more we can do; fail.
return SolutionKind::Error;
@@ -5004,6 +5026,7 @@ ConstraintSystem::simplifyFixConstraint(Fix fix, Type type1, Type type2,
case FixKind::ExplicitlyEscapingToAny:
case FixKind::CoerceToCheckedCast:
case FixKind::RelabelArguments:
case FixKind::AddConformance:
llvm_unreachable("handled elsewhere");
}