ir

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 16 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Checked execution IR

The ir package defines the production execution representation for Effectus. The representation uses effectus/v1/ir.proto and contains no Go callbacks.

ir.Check validates a protobuf artifact against an immutable declaration environment. ir.Parse treats stored or received protobuf bytes as untrusted input. Both functions return an opaque ir.Checked value.

The checker validates these properties:

  • Plan order follows list priority order, then flow priority order.
  • Plan IDs and step IDs are unique.
  • Step ordinals start at zero and have no gaps.
  • Result slots start at zero and have no gaps.
  • A result reference only uses a slot from an earlier step.
  • Argument names are unique and use lexical order.
  • Required and optional arguments follow the verb contract.
  • Fact paths, verb contracts, functions, and types match the environment.
  • Predicate functions are declared pure and total.
  • Predicate results have the bool type.
  • Literal, fact, and result values keep distinct protobuf variants.
  • Structural and value limits apply before execution.
  • Unknown protobuf fields cause rejection.

Use EnvironmentDigest for RuleArtifact.environment_digest. Use ContractHash for each Step.contract_hash. The checker recalculates both values and rejects a mismatch.

Use Checked.Marshal to store deterministic protobuf bytes. Use Checked.Digest as the artifact content digest. Checked.CloneArtifact returns an unchecked copy for inspection. Pass a changed copy to Check before use.

Legacy flow.Program values and Go continuations are not valid checked IR. Do not put them in a production generation.

Documentation

Overview

Package ir defines Effectus's callback-free, checked execution representation.

Index

Constants

View Source
const FormatVersion uint32 = 1

FormatVersion is the only artifact format accepted by this package.

Variables

View Source
var (
	// ErrInvalidArtifact identifies a structural or semantic IR failure.
	ErrInvalidArtifact = errors.New("invalid checked IR artifact")
	// ErrLimitExceeded identifies a configured structural or value limit.
	ErrLimitExceeded = errors.New("checked IR limit exceeded")
)
View Source
var DefaultLimits = ValidationDefaults()

DefaultLimits is a compatibility copy of the production defaults. Mutating this variable has no effect on checking. Removal requires compatibility review and an approved breaking release. Deprecated: use ValidationDefaults. Removal deadline: 2027-09-01.

Functions

func CanonicalPlanOrder

func CanonicalPlanOrder(plans []*effectusv1.Plan)

CanonicalPlanOrder sorts a mutable artifact into the only accepted plan order. Callers must still pass the result to Check.

func ContractHash

func ContractHash(contract VerbContract) (string, error)

ContractHash returns the canonical SHA-256 digest of a verb contract.

func EnvironmentDigest

func EnvironmentDigest(environment Environment) (string, error)

EnvironmentDigest returns the canonical SHA-256 digest used by artifacts.

func NormalizeValue added in v0.5.0

func NormalizeValue(environment Environment, typeName string, value any) (any, error)

NormalizeValue validates a value against a closed checked type and returns an owned, JSON-safe copy. Integers are signed int64, floats are finite float64, and bytes are canonical padded base64 strings (raw []byte is also accepted). Lists accept Go slices/arrays; maps and objects require string keys. Null is accepted only by the null type. Values deeper than 64 levels are rejected. The environment is declarations only; no callbacks are invoked.

Types

type Checked

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

Checked is an opaque, immutable execution plan. It contains no callbacks.

func Check

func Check(artifact *effectusv1.RuleArtifact, environment Environment, limits Limits) (*Checked, error)

Check validates an artifact and stores only its deterministic protobuf form. The input and environment may be mutated after this call without changing the returned Checked value.

func Parse

func Parse(data []byte, environment Environment, limits Limits) (*Checked, error)

Parse decodes untrusted protobuf bytes and rechecks every reference.

func (*Checked) CloneArtifact

func (c *Checked) CloneArtifact() *effectusv1.RuleArtifact

CloneArtifact returns a mutable copy for compatibility and inspection. The returned value is not checked state and must be passed through Check again.

func (*Checked) Digest

func (c *Checked) Digest() string

Digest returns the SHA-256 digest of Marshal.

func (*Checked) Marshal

func (c *Checked) Marshal() []byte

Marshal returns a copy of the deterministic protobuf representation.

func (*Checked) PlanCount

func (c *Checked) PlanCount() int

func (*Checked) Size

func (c *Checked) Size() int

func (*Checked) StepCount

func (c *Checked) StepCount() int

type Environment

type Environment struct {
	Facts     map[string]string           `json:"facts"`
	Verbs     map[string]VerbContract     `json:"verbs"`
	Functions map[string]FunctionContract `json:"functions"`
	Types     map[string]TypeDefinition   `json:"types"`
}

Environment is immutable input to checking. Check copies it before use. It contains declarations only; checking never calls executors or user code.

type FunctionContract

type FunctionContract struct {
	ArgumentTypes []string `json:"argument_types"`
	ReturnType    string   `json:"return_type"`
	Pure          bool     `json:"pure"`
	Total         bool     `json:"total"`
}

FunctionContract describes an expression function. Checked predicates may reference only functions explicitly declared pure and total.

type IdempotencyPolicy

type IdempotencyPolicy string

IdempotencyPolicy states which retry guarantee an executor binding provides.

const (
	IdempotencyNone           IdempotencyPolicy = "none"
	IdempotencyKeyRequired    IdempotencyPolicy = "key_required"
	IdempotencySinkGuaranteed IdempotencyPolicy = "sink_guaranteed"
)

type Limits

type Limits struct {
	MaxArtifactBytes    int
	MaxPlans            int
	MaxSteps            int
	MaxStepsPerPlan     int
	MaxArgumentsPerStep int
	MaxPredicateNodes   int
	MaxLiteralNodes     int
	MaxDepth            int
	MaxStringBytes      int
	MaxBytesValue       int
	MaxCollectionItems  int
	MaxObjectFields     int
	MaxTotalStringBytes int
}

Limits bounds untrusted artifacts. Zero fields use fixed production defaults; negative fields are invalid.

func ValidationDefaults added in v0.5.0

func ValidationDefaults() Limits

ValidationDefaults returns an independent copy of the fixed production bounds. Zero-valued Limits use these same bounds without reading mutable globals.

type RetryPolicy

type RetryPolicy struct {
	MaxAttempts          uint32 `json:"max_attempts"`
	InitialBackoffMillis uint64 `json:"initial_backoff_millis"`
	MaxBackoffMillis     uint64 `json:"max_backoff_millis"`
}

RetryPolicy is frozen into every checked step that invokes the verb.

type TypeDefinition

type TypeDefinition struct {
	Kind           TypeKind          `json:"kind"`
	ElementType    string            `json:"element_type,omitempty"`
	Fields         map[string]string `json:"fields,omitempty"`
	RequiredFields []string          `json:"required_fields,omitempty"`
}

TypeDefinition declares a named structural type. Object fields not present in Fields are rejected. Maps always have string keys.

type TypeKind

type TypeKind string

TypeKind identifies a named type definition.

const (
	TypeKindObject TypeKind = "object"
	TypeKindList   TypeKind = "list"
	TypeKindMap    TypeKind = "map"
)

type VerbContract

type VerbContract struct {
	Arguments         map[string]string `json:"arguments"`
	RequiredArgs      []string          `json:"required_args"`
	ResultType        string            `json:"result_type"`
	InverseVerb       string            `json:"inverse_verb,omitempty"`
	RetryPolicy       RetryPolicy       `json:"retry_policy"`
	IdempotencyPolicy IdempotencyPolicy `json:"idempotency_policy"`
	FencingRequired   bool              `json:"fencing_required"`
}

VerbContract describes the serializable part of a verb contract.

Jump to

Keyboard shortcuts

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