mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
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:
+5
-5
@@ -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}
|
||||
}
|
||||
|
||||
|
||||
+12
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user