copypropagation

package
v0.63.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 4 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CopyPropagator

type CopyPropagator struct {
	// contains filtered or unexported fields
}

CopyPropagator implements a simple copy propagation optimization to remove intermediate variables in partial evaluation results.

For example, given the query: input.x > 1 where 'input' is unknown, the compiled query would become input.x = a; a > 1 which would remain in the partial evaluation result. The CopyPropagator will remove the variable assignment so that partial evaluation simply outputs input.x > 1.

In many cases, copy propagation can remove all variables from the result of partial evaluation which simplifies evaluation for non-OPA consumers.

In some cases, copy propagation cannot remove all variables. If the output of a built-in call is subsequently used as a ref head, the output variable must be kept. For example. sort(input, x); x[0] == 1. In this case, copy propagation cannot replace x[0] == 1 with sort(input, x)[0] == 1 as this is not legal.

func New

func New(livevars ast.VarSet) *CopyPropagator

New returns a new CopyPropagator that optimizes queries while preserving vars in the livevars set.

func (*CopyPropagator) Apply

func (p *CopyPropagator) Apply(query ast.Body) ast.Body

Apply executes the copy propagation optimization and returns a new query.

func (*CopyPropagator) WithCompiler added in v0.20.0

func (p *CopyPropagator) WithCompiler(c *ast.Compiler) *CopyPropagator

WithCompiler configures the compiler to read from while processing the query. This should be the same compiler used to compile the original policy.

func (*CopyPropagator) WithEnsureNonEmptyBody added in v0.9.2

func (p *CopyPropagator) WithEnsureNonEmptyBody(yes bool) *CopyPropagator

WithEnsureNonEmptyBody configures p to ensure that results are always non-empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL