package ir
import "github.com/open-policy-agent/opa/ir"
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.
Package ir defines an intermediate representation (IR) for Rego.
The IR specifies an imperative execution model for Rego policies similar to a query plan in traditional databases.
Index ¶
- Constants
- func Pretty(w io.Writer, x interface{}) error
- func Walk(vis Visitor, x interface{}) error
- type ArrayAppendStmt
- type AssignIntStmt
- type AssignVarOnceStmt
- type AssignVarStmt
- type Block
- type BlockStmt
- type Bool
- type BreakStmt
- type BuiltinFunc
- type CallDynamicStmt
- type CallStmt
- type DotStmt
- type EqualStmt
- type Func
- type Funcs
- type IsArrayStmt
- type IsDefinedStmt
- type IsObjectStmt
- type IsSetStmt
- type IsUndefinedStmt
- type LenStmt
- type Local
- type Location
- type MakeArrayStmt
- type MakeNullStmt
- type MakeNumberIntStmt
- type MakeNumberRefStmt
- type MakeObjectStmt
- type MakeSetStmt
- type NopStmt
- type NotEqualStmt
- type NotStmt
- type ObjectInsertOnceStmt
- type ObjectInsertStmt
- type ObjectMergeStmt
- type Operand
- type Plan
- type Plans
- type Policy
- type ResetLocalStmt
- type ResultSetAddStmt
- type ReturnLocalStmt
- type ScanStmt
- type SetAddStmt
- type Static
- type Stmt
- type StringConst
- type StringIndex
- type Val
- type Visitor
- type WithStmt
Constants ¶
const ( // Input is the local variable that refers to the global input document. Input = v1.Input // Data is the local variable that refers to the global data document. Data = v1.Data // Unused is the free local variable that can be allocated in a plan. Unused = v1.Unused )
Functions ¶
func Pretty ¶
Pretty writes a human-readable representation of an IR object to w.
func Walk ¶
Walk invokes the visitor for nodes under x.
Types ¶
type ArrayAppendStmt ¶
type ArrayAppendStmt = v1.ArrayAppendStmt
ArrayAppendStmt represents a dynamic append operation of a value onto an array.
type AssignIntStmt ¶
type AssignIntStmt = v1.AssignIntStmt
AssignIntStmt represents an assignment of an integer value to a local variable.
type AssignVarOnceStmt ¶
type AssignVarOnceStmt = v1.AssignVarOnceStmt
AssignVarOnceStmt represents an assignment of one local variable to another. If the target is defined, execution aborts with a conflict error.
TODO(tsandall): is there a better name for this?
type AssignVarStmt ¶
type AssignVarStmt = v1.AssignVarStmt
AssignVarStmt represents an assignment of one local variable to another.
type Block ¶
Block represents an ordered sequence of statements to execute. Blocks are executed until a return statement is encountered, a statement is undefined, or there are no more statements. If all statements are defined but no return statement is encountered, the block is undefined.
type BlockStmt ¶
BlockStmt represents a nested block. Nested blocks and break statements can be used to short-circuit execution.
type Bool ¶
Bool represents a constant boolean.
type BreakStmt ¶
BreakStmt represents a jump out of the current block. The index specifies how many blocks to jump starting from zero (the current block). Execution will continue from the end of the block that is jumped to.
type BuiltinFunc ¶
type BuiltinFunc = v1.BuiltinFunc
BuiltinFunc represents a built-in function that may be required by the policy.
type CallDynamicStmt ¶
type CallDynamicStmt = v1.CallDynamicStmt
CallDynamicStmt represents an indirect (data) function call. The result should be stored in the result local.
type CallStmt ¶
CallStmt represents a named function call. The result should be stored in the result local.
type DotStmt ¶
DotStmt represents a lookup operation on a value (e.g., array, object, etc.) The source of a DotStmt may be a scalar value in which case the statement will be undefined.
type EqualStmt ¶
EqualStmt represents an value-equality check of two local variables.
type Func ¶
Func represents a named plan (function) that can be invoked. Functions accept one or more parameters and return a value. By convention, the input document and data documents are always passed as the first and second arguments (respectively).
type Funcs ¶
Funcs represents a collection of planned functions to include in the policy.
type IsArrayStmt ¶
type IsArrayStmt = v1.IsArrayStmt
IsArrayStmt represents a dynamic type check on a local variable.
type IsDefinedStmt ¶
type IsDefinedStmt = v1.IsDefinedStmt
IsDefinedStmt represents a check of whether a local variable is defined.
type IsObjectStmt ¶
type IsObjectStmt = v1.IsObjectStmt
IsObjectStmt represents a dynamic type check on a local variable.
type IsSetStmt ¶
IsSetStmt represents a dynamic type check on a local variable.
type IsUndefinedStmt ¶
type IsUndefinedStmt = v1.IsUndefinedStmt
IsUndefinedStmt represents a check of whether local variable is undefined.
type LenStmt ¶
LenStmt represents a length() operation on a local variable. The result is stored in the target local variable.
type Local ¶
Local represents a plan-scoped variable.
TODO(tsandall): should this be int32 for safety?
type Location ¶
Location records the filen index, and the row and column inside that file that a statement can be connected to.
type MakeArrayStmt ¶
type MakeArrayStmt = v1.MakeArrayStmt
MakeArrayStmt constructs a local variable that refers to an array value.
type MakeNullStmt ¶
type MakeNullStmt = v1.MakeNullStmt
MakeNullStmt constructs a local variable that refers to a null value.
type MakeNumberIntStmt ¶
type MakeNumberIntStmt = v1.MakeNumberIntStmt
MakeNumberIntStmt constructs a local variable that refers to an integer value.
type MakeNumberRefStmt ¶
type MakeNumberRefStmt = v1.MakeNumberRefStmt
MakeNumberRefStmt constructs a local variable that refers to a number stored as a string.
type MakeObjectStmt ¶
type MakeObjectStmt = v1.MakeObjectStmt
MakeObjectStmt constructs a local variable that refers to an object value.
type MakeSetStmt ¶
type MakeSetStmt = v1.MakeSetStmt
MakeSetStmt constructs a local variable that refers to a set value.
type NopStmt ¶
NopStmt adds a nop instruction. Useful during development and debugging only.
type NotEqualStmt ¶
type NotEqualStmt = v1.NotEqualStmt
NotEqualStmt represents a != check of two local variables.
type NotStmt ¶
NotStmt represents a negated statement.
type ObjectInsertOnceStmt ¶
type ObjectInsertOnceStmt = v1.ObjectInsertOnceStmt
ObjectInsertOnceStmt represents a dynamic insert operation of a key/value pair into an object. If the key already exists and the value differs, execution aborts with a conflict error.
type ObjectInsertStmt ¶
type ObjectInsertStmt = v1.ObjectInsertStmt
ObjectInsertStmt represents a dynamic insert operation of a key/value pair into an object.
type ObjectMergeStmt ¶
type ObjectMergeStmt = v1.ObjectMergeStmt
ObjectMergeStmt performs a recursive merge of two object values. If either of the locals refer to non-object values this operation will abort with a conflict error. Overlapping object keys are merged recursively.
type Operand ¶
Operand represents a value that a statement operates on.
type Plan ¶
Plan represents an ordered series of blocks to execute. Plan execution stops when a return statement is reached. Blocks are executed in-order.
type Plans ¶
Plans represents a collection of named query plans to expose in the policy.
type Policy ¶
Policy represents a planned policy query.
type ResetLocalStmt ¶
type ResetLocalStmt = v1.ResetLocalStmt
ResetLocalStmt resets a local variable to 0.
type ResultSetAddStmt ¶
type ResultSetAddStmt = v1.ResultSetAddStmt
ResultSetAddStmt adds a value into the result set returned by the query plan.
type ReturnLocalStmt ¶
type ReturnLocalStmt = v1.ReturnLocalStmt
ReturnLocalStmt represents a return statement that yields a local value.
type ScanStmt ¶
ScanStmt represents a linear scan over a composite value. The source may be a scalar in which case the block will never execute.
type SetAddStmt ¶
type SetAddStmt = v1.SetAddStmt
SetAddStmt represents a dynamic add operation of an element into a set.
type Static ¶
Static represents a static data segment that is indexed into by the policy.
type Stmt ¶
Stmt represents an operation (e.g., comparison, loop, dot, etc.) to execute.
type StringConst ¶
type StringConst = v1.StringConst
StringConst represents a string value.
type StringIndex ¶
type StringIndex = v1.StringIndex
StringIndex represents the index into the plan's list of constant strings of a constant string.
type Val ¶
Val represents an abstract value that statements operate on. There are currently 3 types of values:
1. Local - a local variable that can refer to any type. 2. StringIndex - a string constant that refers to a compiled string. 3. Bool - a boolean constant.
type Visitor ¶
Visitor defines the interface for visiting IR nodes.
type WithStmt ¶
WithStmt replaces the Local or a portion of the document referred to by the Local with the Value and executes the contained block. If the Path is non-empty, the Value is upserted into the Local. If the intermediate nodes in the Local referred to by the Path do not exist, they will be created. When the WithStmt finishes the Local is reset to it's original value.
Source Files ¶
doc.go ir.go pretty.go walk.go
Directories ¶
Path | Synopsis |
---|---|
ir/encoding | 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. |
- Version
- v1.4.2 (latest)
- Published
- May 2, 2025
- Platform
- linux/amd64
- Imports
- 2 packages
- Last checked
- 5 hours ago –
Tools for package owners.