package copypropagation

import "github.com/open-policy-agent/opa/topdown/copypropagation"

Deprecated: This package is intended for older projects transitioning from OPA v0.x and will remain for the lifetime of OPA v1.x, but its use is not recommended. For newer features and behaviours, such as defaulting to the Rego v1 syntax, use the corresponding components in the github.com/open-policy-agent/opa/v1 package instead. See https://www.openpolicyagent.org/docs/latest/v0-compatibility/ for more information.

Index

Types

type CopyPropagator

type CopyPropagator = v1.CopyPropagator

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.

Source Files

copypropagation.go doc.go

Version
v1.1.0
Published
Jan 27, 2025
Platform
darwin/amd64
Imports
2 packages
Last checked
8 minutes ago

Tools for package owners.