Expand description
Static analysis passes over compiled Program IR.
Forward-flow analyses that produce abstract domains for each opcode position. Callers (compiler, planner, caller code) can use these to:
- emit specialised opcodes where a value’s type / nullness / cardinality is statically known,
- reject ill-typed expressions at compile time,
- enable further peephole passes that require type awareness.
The analyses run on the flat Arc<[Opcode]> IR and are intentionally
conservative — when uncertain, they return the Unknown top element of
the lattice.
Structs§
Enums§
- Cardinality
- Monotonicity
- Tracks ordering properties of array-like values through the pipeline.
- Nullness
- VType
Functions§
- collect_
accessed_ fields - Collect all field names directly accessed from a program. Used by projection-pushdown analysis: if an object is later accessed only via these fields, other fields can be trimmed early.
- count_
ident_ uses - Count
LoadIdent(name)references across an entire program (including sub-programs). - dedup_
subprograms - Walk
programand replace everyArc<Program>inside opcodes with a canonicalArckeyed byprogram_signature. Structurally-identical sub-programs end up pointing at the same allocation, reducing memory and enabling downstream caches to hit on the same key. - escapes_
doc - Simple escape check: does the program’s final value contain references to the input document (i.e. survive returning)? If not, the compiler may emit value-copying ops rather than Arc-sharing to free the original doc.
- expr_
is_ pure - True if the expression is pure — no side-effecting global calls or
unknown methods. Enables dropping unused
letinitialisers safely. - expr_
uses_ ident - True if any sub-expression references
nameas a bare identifier. Walks the AST without compiling. Shadowing by innerlet/lambda/ comprehension binders is respected: inner bindings with the same name hide the outer one. - find_
common_ subexprs - Find sub-programs (via
Arc<Program>pointers inside opcodes) that appear multiple times across the program tree. Returns a map ofsignature → countfor analysis / potential reuse. - fold_
kind_ check - When a
KindCheckis applied to a value with a statically-known type, the check can be constant-folded to true/false at compile time. - infer_
monotonicity - Walk program and determine monotonicity of the final result.
- infer_
result_ type - Walk opcodes of
programforward, simulating a stack ofAbstractVals. Returns the top-of-stack abstract value at program end (i.e. the result type). - infer_
result_ type_ with_ env - Same as
infer_result_typebut exposes the bindings environment after the program finishes — useful for debugging the interprocedural flow. - method_
result_ type - Static result-type mapping for builtin methods (conservative).
- opcode_
cost - Rough, ordinal cost estimate per opcode. Not a wall-clock number — only useful to compare relative cost (e.g. for AndOp operand reordering).
- program_
cost - Total cost of a program (sum of per-op costs).
- program_
signature - Hash a program’s opcode sequence into a stable identifier. Two programs
with the same opcodes hash to the same value — enables CSE across
letinitialisers or parallel->binds. - selectivity_
score - Rough selectivity estimate for AST predicates. Lower score → more
selective (filters out more rows). Used to reorder
andoperands so cheaper / more-selective predicate runs first (short-circuit friendly).