ast, compile: Update opa build --debug output

This commit tweaks the --debug output format to be slightly more
readable. The comprehension indexing messages now have a prefix to
make them more discernable and the optimizer output is now aggregated
so that it's more concise and clear what parameters are being passed
to partial evaluation.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
This commit is contained in:
Torin Sandall
2021-05-24 10:36:23 -04:00
parent a9c115c51d
commit d8287db653
2 changed files with 17 additions and 7 deletions
+12 -2
View File
@@ -629,10 +629,12 @@ func (o *optimizer) Do(ctx context.Context) error {
unknowns = o.findUnknowns()
}
required := o.findRequiredDocuments(e)
r := rego.New(
rego.ParsedQuery(ast.NewBody(ast.Equality.Expr(resultsym, e))),
rego.PartialNamespace(o.nsprefix),
rego.DisableInlining(o.findRequiredDocuments(e)),
rego.DisableInlining(required),
rego.ShallowInlining(o.shallow),
rego.SkipPartialNamespace(true),
rego.ParsedUnknowns(unknowns),
@@ -640,6 +642,15 @@ func (o *optimizer) Do(ctx context.Context) error {
rego.Store(store),
)
o.debug.Printf("optimizer: entrypoint: %v", e)
o.debug.Printf(" partial-namespace: %v", o.nsprefix)
o.debug.Printf(" disable-inlining: %v", required)
o.debug.Printf(" shallow-inlining: %v", o.shallow)
for i := range unknowns {
o.debug.Printf(" unknown: %v", unknowns[i])
}
pq, err := r.Partial(ctx)
if err != nil {
return err
@@ -738,7 +749,6 @@ func (o *optimizer) findUnknowns() []*ast.Term {
return true
}
if !refs.ContainsPrefix(prefix) {
o.debug.Printf("%s: marking %v as unknown", x[0].Location, prefix)
unknowns.AddPrefix(prefix)
}
return false