From d8287db6536fe90ac16ec7476d48e9cec94bf5f9 Mon Sep 17 00:00:00 2001 From: Torin Sandall Date: Mon, 24 May 2021 10:36:23 -0400 Subject: [PATCH] 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 --- ast/compile.go | 10 +++++----- compile/compile.go | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/ast/compile.go b/ast/compile.go index 098f30f674..811838054f 100644 --- a/ast/compile.go +++ b/ast/compile.go @@ -1794,7 +1794,7 @@ func getComprehensionIndex(dbg debug.Debug, arity func(Ref) int, candidates VarS unsafe := body.Vars(SafetyCheckVisitorParams).Diff(outputs).Diff(ReservedVars) if len(unsafe) > 0 { - dbg.Printf("%s: unsafe vars: %v", expr.Location, unsafe) + dbg.Printf("%s: comprehension index: unsafe vars: %v", expr.Location, unsafe) return nil } @@ -1804,7 +1804,7 @@ func getComprehensionIndex(dbg debug.Debug, arity func(Ref) int, candidates VarS regressionVis := newComprehensionIndexRegressionCheckVisitor(candidates) regressionVis.Walk(body) if regressionVis.worse { - dbg.Printf("%s: output vars intersect candidates", expr.Location) + dbg.Printf("%s: comprehension index: output vars intersect candidates", expr.Location) return nil } @@ -1814,7 +1814,7 @@ func getComprehensionIndex(dbg debug.Debug, arity func(Ref) int, candidates VarS nestedVis := newComprehensionIndexNestedCandidateVisitor(candidates) nestedVis.Walk(body) if nestedVis.found { - dbg.Printf("%s: nested comprehensions close over candidates", expr.Location) + dbg.Printf("%s: comprehension index: nested comprehensions close over candidates", expr.Location) return nil } @@ -1824,7 +1824,7 @@ func getComprehensionIndex(dbg debug.Debug, arity func(Ref) int, candidates VarS // empty, there is no indexing to do. indexVars := candidates.Intersect(outputs) if len(indexVars) == 0 { - dbg.Printf("%s: no index vars", expr.Location) + dbg.Printf("%s: comprehension index: no index vars", expr.Location) return nil } @@ -1846,7 +1846,7 @@ func getComprehensionIndex(dbg debug.Debug, arity func(Ref) int, candidates VarS debugRes[i] = r } } - dbg.Printf("%s: comprehension index built with keys: %v", expr.Location, debugRes) + dbg.Printf("%s: comprehension index: built with keys: %v", expr.Location, debugRes) return &ComprehensionIndex{Term: term, Keys: result} } diff --git a/compile/compile.go b/compile/compile.go index 5dfc71269f..5797125c99 100644 --- a/compile/compile.go +++ b/compile/compile.go @@ -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