Require convertibility to the type of the associated constant when checking a rewrite constraint. (#2321)

Per recent discussion, in `... where .A = B`, require that `B` is implicitly convertible to the type of `A` immediately, rather than treating that as part of the criteria that a type must satisfy to satisfy the resulting constraint. Extend the implementation of implicit conversion so that conversion of a type to a constraint checks that the type satisfies the constraint.

As part of implementing this, stop duplicating rewrite constraints as equality constraints. Instead, when checking that a constraint is satisfied, check both its equality constraints and its rewrite constraints. This fixes an infinite recursion that would otherwise be caused by this change, and is also a necessary prerequisite for applying rewrite constraints to equality constraints, where we would otherwise collapse the implied equality constraints to a tautological `V == V` constraint.

In passing, make ErrorBuilder support building the error message more incrementally and use that to improve diagnostics for mismatched values with equality constraints.
This commit is contained in:
Richard Smith
2022-10-20 16:18:26 -07:00
committed by GitHub
parent 4601a9cce8
commit 374bf9f853
17 changed files with 572 additions and 233 deletions
+6 -4
View File
@@ -434,9 +434,11 @@ void Value::Print(llvm::raw_ostream& out) const {
llvm::ListSeparator sep(" and ");
for (const ConstraintType::RewriteConstraint& rewrite :
constraint.rewrite_constraints()) {
out << sep << ".(" << *rewrite.interface << "."
<< *GetName(*rewrite.constant)
<< ") = " << rewrite.replacement->value();
out << sep << ".(";
PrintNameWithBindings(out, &rewrite.constant->interface().declaration(),
rewrite.constant->interface().args());
out << "." << *GetName(rewrite.constant->constant())
<< ") = " << *rewrite.unconverted_replacement;
}
for (const ConstraintType::ImplConstraint& impl :
constraint.impl_constraints()) {
@@ -515,7 +517,7 @@ void Value::Print(llvm::raw_ostream& out) const {
out << "(" << assoc.base() << ").(";
PrintNameWithBindings(out, &assoc.interface().declaration(),
assoc.interface().args());
out << "." << assoc.constant().binding().name() << ")";
out << "." << *GetName(assoc.constant()) << ")";
break;
}
case Value::Kind::ContinuationValue: {