lang: unification: Add more partial knowledge to solved

This performs the same task as the previous commit, but it also adds
partial information when solving a list, map, or struct.
This commit is contained in:
James Shubin
2023-08-20 20:42:52 -04:00
parent f0e9af1cf5
commit 7d29efeb33

View File

@@ -381,6 +381,16 @@ Loop:
t, exists := listPartials[eq.Expr1][y] t, exists := listPartials[eq.Expr1][y]
if !exists { if !exists {
listPartials[eq.Expr1][y] = typ // learn! listPartials[eq.Expr1][y] = typ // learn!
// Even though this is only a partial learn, we should still add it to the solved information!
if newTyp, exists := solved[y]; !exists {
solved[y] = typ // yay, we learned something!
//used = append(used, i) // mark equality as used up when complete!
logf("%s: solved partial list val equality", Name)
} else if err := newTyp.Cmp(typ); err != nil {
return nil, errwrap.Wrapf(err, "can't unify, invariant illogicality with partial list val equality")
}
continue continue
} }
if err := t.Cmp(typ); err != nil { if err := t.Cmp(typ); err != nil {
@@ -440,6 +450,16 @@ Loop:
t, exists := mapPartials[eq.Expr1][y] t, exists := mapPartials[eq.Expr1][y]
if !exists { if !exists {
mapPartials[eq.Expr1][y] = typ // learn! mapPartials[eq.Expr1][y] = typ // learn!
// Even though this is only a partial learn, we should still add it to the solved information!
if newTyp, exists := solved[y]; !exists {
solved[y] = typ // yay, we learned something!
//used = append(used, i) // mark equality as used up when complete!
logf("%s: solved partial map key/val equality", Name)
} else if err := newTyp.Cmp(typ); err != nil {
return nil, errwrap.Wrapf(err, "can't unify, invariant illogicality with partial map key/val equality")
}
continue continue
} }
if err := t.Cmp(typ); err != nil { if err := t.Cmp(typ); err != nil {
@@ -516,6 +536,16 @@ Loop:
t, exists := structPartials[eq.Expr1][y] t, exists := structPartials[eq.Expr1][y]
if !exists { if !exists {
structPartials[eq.Expr1][y] = typ // learn! structPartials[eq.Expr1][y] = typ // learn!
// Even though this is only a partial learn, we should still add it to the solved information!
if newTyp, exists := solved[y]; !exists {
solved[y] = typ // yay, we learned something!
//used = append(used, i) // mark equality as used up when complete!
logf("%s: solved partial struct field equality", Name)
} else if err := newTyp.Cmp(typ); err != nil {
return nil, errwrap.Wrapf(err, "can't unify, invariant illogicality with partial struct field equality")
}
continue continue
} }
if err := t.Cmp(typ); err != nil { if err := t.Cmp(typ); err != nil {