lang: unification, interfaces: Add a skip invariant

This is a cleaner way of telling the type unifier that we don't want
this particular expression in the solution set at the end.
This commit is contained in:
James Shubin
2023-12-17 21:41:20 -05:00
parent c2bf4ef7d4
commit 7cc231e8b9
3 changed files with 63 additions and 0 deletions

View File

@@ -72,7 +72,13 @@ func (obj *Unifier) Unify() error {
// build a list of what we think we need to solve for to succeed
exprs := []interfaces.Expr{}
skips := make(map[interfaces.Expr]struct{})
for _, x := range invariants {
if si, ok := x.(*interfaces.SkipInvariant); ok {
skips[si.Expr] = struct{}{}
continue
}
exprs = append(exprs, x.ExprList()...)
}
exprMap := ExprListToExprMap(exprs) // makes searching faster
@@ -137,6 +143,10 @@ func (obj *Unifier) Unify() error {
// programming error ?
return fmt.Errorf("unexpected invalid solution at: %p", x)
}
if _, exists := skips[x.Expr]; exists {
continue
}
if obj.Debug {
obj.Logf("solution: %p => %+v\t(%+v)", x.Expr, x.Type, x.Expr.String())
}