lang: Structurally refactor type unification

This will make it easier to add new solvers and also cleans up some
pending issues.
This commit is contained in:
James Shubin
2024-03-30 16:55:20 -04:00
parent 964bd8ba61
commit cede7e5ac0
10 changed files with 374 additions and 173 deletions

View File

@@ -76,13 +76,13 @@ func ExprContains(needle interfaces.Expr, haystack []interfaces.Expr) bool {
return false
}
// pairs is a simple list of pairs of expressions which can be used as a simple
// Pairs is a simple list of pairs of expressions which can be used as a simple
// undirected graph structure, or as a simple list of equalities.
type pairs []*interfaces.EqualityInvariant
type Pairs []*interfaces.EqualityInvariant
// Vertices returns the list of vertices that the input expr is directly
// connected to.
func (obj pairs) Vertices(expr interfaces.Expr) []interfaces.Expr {
func (obj Pairs) Vertices(expr interfaces.Expr) []interfaces.Expr {
m := make(map[interfaces.Expr]struct{})
for _, x := range obj {
if x.Expr1 == x.Expr2 { // skip circular
@@ -106,7 +106,7 @@ func (obj pairs) Vertices(expr interfaces.Expr) []interfaces.Expr {
}
// DFS returns a depth first search for the graph, starting at the input vertex.
func (obj pairs) DFS(start interfaces.Expr) []interfaces.Expr {
func (obj Pairs) DFS(start interfaces.Expr) []interfaces.Expr {
var d []interfaces.Expr // discovered
var s []interfaces.Expr // stack
found := false