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

@@ -50,6 +50,7 @@ import (
"github.com/purpleidea/mgmt/lang/interpret"
"github.com/purpleidea/mgmt/lang/parser"
"github.com/purpleidea/mgmt/lang/unification"
_ "github.com/purpleidea/mgmt/lang/unification/solvers" // import so the solvers register
"github.com/purpleidea/mgmt/pgraph"
"github.com/purpleidea/mgmt/util"
"github.com/purpleidea/mgmt/util/errwrap"
@@ -225,13 +226,18 @@ func (obj *Lang) Init(ctx context.Context) error {
}
}
obj.Logf("running type unification...")
timing = time.Now()
solver, err := unification.LookupDefault()
if err != nil {
return errwrap.Wrapf(err, "could not get default solver")
}
unifier := &unification.Unifier{
AST: obj.ast,
Solver: unification.SimpleInvariantSolverLogger(logf),
Solver: solver,
Debug: obj.Debug,
Logf: logf,
}
timing = time.Now()
// NOTE: This is the "real" Unify that runs. (This is not for deploy.)
unifyErr := unifier.Unify(ctx)
obj.Logf("type unification took: %s", time.Since(timing))