lang: unification: Improve type unification algorithm

The simple type unification algorithm suffered from some serious
performance and memory problems when used with certain code bases. This
adds some crucial optimizations that improve performance drastically.
This commit is contained in:
James Shubin
2019-04-23 20:31:29 -04:00
parent 97d60ac98d
commit d70bbfb5d0
17 changed files with 770 additions and 27 deletions

View File

@@ -19,6 +19,8 @@ package interfaces
import (
"fmt"
"github.com/purpleidea/mgmt/lang/types"
)
// Invariant represents a constraint that is described by the Expr's and Stmt's,
@@ -27,4 +29,11 @@ import (
type Invariant interface {
// TODO: should we add any other methods to this type?
fmt.Stringer
// ExprList returns the list of valid expressions in this invariant.
ExprList() []Expr
// Matches returns whether an invariant matches the existing solution.
// If it is inconsistent, then it errors.
Matches(solved map[Expr]*types.Type) (bool, error)
}