Skip to main content

Module optimize

Module optimize 

Source

Modules§

bta
Binding-Time Analysis (BTA)
effects
egraph
The ARCHITECT — equality saturation over a compiler e-graph (EXODIA Phase 4, sprints 17–22).
partial_eval
supercompile
Supercompiler — a unified optimization pass that subsumes constant folding, propagation, dead code elimination, and compile-time function evaluation in a single framework.

Structs§

DecoratorGate
The file-level optimization-decorator contract (## No <opt> / ## Require <opt>) in ONE place, so no compile/run/emit tier can silently drop it — the drift that let the decorators be ignored on the C, VM, wasm and isa paths. Every tier does the same two steps: install_decorators(...) at scope entry, then gate.verify()? after compilation.
OracleFacts
EXODIA Phase 1’s DELIVERY layer: a product fact for every expression occurrence at its program point, keyed by ARENA ADDRESS (stable for the analyzed snapshot — record facts immediately before consuming them, and never across a pass that re-allocates expressions). Shared subtrees that appear at several program points JOIN their facts (sound; precision is lost exactly where sharing occurs).
VarProvenFacts
A variable’s program-wide PROVEN facts — the statically-verified summary the debugger shows beside its live value (distinct from the dynamic, observed-this-run invariants). All fields are sound over-approximations: present ⇒ proven.

Enums§

ScalarKind
Run the Oracle’s rich abstract interpretation, returning the (unchanged) statements together with the per-variable abstract facts. The scalar kinds downstream consumers (typed bytecode, JIT guard elision) act on.

Functions§

active_config
The current compile’s optimization config (all-on if unset).
begin_backend_trace
Begin a stage-separated trace for one concrete backend. The legacy FIRED union is opened too, preserving ## Require and existing tooling exactly.
begin_fired_trace
Begin recording which optimizations fire AND which they preempt for the current compile. Resets both accumulators; pair with end_fired_trace / end_preempted_trace.
end_backend_trace
Close a stage-separated trace. Always clears every accumulator, including after a failed compile, so a later compile on the same thread starts clean.
end_fired_trace
Stop recording and take the fired set (None if no trace was active).
end_preempted_trace
Stop recording and take the deduplicated set of (winner, loser) precedence decisions made during the trace (empty if no trace was active).
fired_trace_active
Whether a firing trace is currently active. Gates the cost of the before/after fingerprint in run_traced.
install_decorators
Merge the file’s ## No flags into env, install the result as the thread-local active config (so EVERY backend’s active_config().is_on(..) gate honors them — AOT codegen, the VM compiler, the JIT), and open a fired-trace when any ## Require was declared. Returns the merged config to hand to the optimizer/codegen plus the gate to verify() after the compile has run. When a trace is already active (a nested compile), the outer gate owns the verification, so this one is a no-op verify().
is_lifted_closure
Was f lifted out of a closure by defunctionalization?
lin_to_rust
Render an affine capacity LinExpr as a Rust i64 expression string — used to size a dense map’s direct-addressed array (with_bounds(0, (cap) + 1)) at its constructor site. None if any coefficient or the constant is non-integer (no clean rendering), in which case the dense gate declines and the map stays a hash table. Terms are emitted in symbol-index order for determinism.
mark_backend_decline
Record that the current backend deliberately declined one optimization. Outside a backend trace this is a no-op. Duplicate decisions are collapsed so a loop containing many equivalent candidates produces one audit reason.
mark_backend_fallback
Record an explicit backend fallback. Outside a backend trace this is a no-op, so production compilation pays neither allocation nor formatting.
mark_fired
Record that opt fired in the current compile. No-op when no trace is active.
mark_preempted
Record that winner took precedence over loser here — the exact spot the code skips one optimization for another (the conflict, traced at its source, the same way mark_fired traces firing). No-op when no trace is active, so the normal compile path and the benchmark scripts pay nothing. Self-gated on BOTH being enabled in the current config: a preemption is only meaningful when the two genuinely contest an instance — so toggling either off cleanly stops the edge from being reported.
memoize_for_explicit_lowering
The AOT optimizer — ONE pipeline. The Futamura residual (fold, propagate, polyvariant PE, CTFE) then the ARCHITECT: equality saturation over a kernel-certified e-graph, Oracle facts gating the conditional rewrites (value facts suppressed for loop-mutated variables — see egraph::convert); then defunctionalization, deforestation, interval analysis, DCE, and supercompilation. GVN/LICM/closed-form STILL run after the e-graph until it subsumes their cross-statement and loop-recurrence reach (the EG waves). Memoize the pure single-argument self-recursive functions of an already-optimized program for a lowering that has no native memoization construct. Rust emits its own cache during codegen; direct C and bytecode-derived backends instead consume this explicit Map-based residual. Keeping the transform here makes Memo one optimization with one eligibility rule and firing trace across those backends.
optimize_for_projection
Lighter optimization for Futamura P1: fold + propagate + PE + CTFE. Skips DCE, abstract interpretation, supercompilation, and structural transforms (LICM, closed-form, deforestation) that eliminate branches or restructure control flow. The residual preserves the program’s original control-flow structure while still folding constants, propagating values, specializing functions, and evaluating CTFE.
optimize_for_run
The RUN-PATH pipeline (EXODIA D1): the Futamura residual — fold, propagate, polyvariant PE, CTFE, GVN, LICM, closed-form, deforestation, interval analysis, DCE — everything except supercompilation (whose driving cost is unbounded; it stays AOT-only). Budgeted: programs beyond the statement gate run raw, and LOGOS_RUN_OPT=0 kills the pass entirely. Optimizer time lands inside the measured run, so the budget is part of the contract.
optimize_for_run_tiered
The run-path optimizer, gated by the unit’s hotness tier (HOTSWAP §4). Every pass runs in the SAME order as the un-tiered pipeline; tier decides WHICH passes run (via admits_pinned, a single cost comparison, with hs’s per-opt pins applied) and how many PE-fixpoint iterations to pay for. Tier::T3 with an all-on config and no pins reproduces optimize_for_run exactly — the compatibility + soundness anchor.
optimize_program
oracle_analyze
oracle_analyze_with
oracle_analyze with the interner, enabling declared-parameter type seeds inside function bodies. Used by every NON-AOT consumer (VM bytecode, copy-and-patch JIT, e-graph, UI) — these get NO entry-guard precondition, so the partition’s accesses stay behind a runtime RegionBoundsGuard rather than being statically elided on a precondition the bytecode never enforces.
oracle_analyze_with_entry_guards
oracle_analyze_with for the largo build AOT codegen ONLY. Enables the recursive-1-based-partition entry-guard precondition (1 <= lo, hi <= len) and alias length_def propagation — sound here because the AOT codegen emits the matching runtime assert! at the function entry. The VM/JIT path emits no such assert, so it must use oracle_analyze_with.
set_active_config
Record the optimization config for the current compile. Call at every compile entry (codegen / VM) so the deep codegen + VM toggle reads see it.
with_backend_lowering
Attribute every mark_fired in f to backend lowering rather than the shared optimizer. Outside a backend trace this is a zero-behavior wrapper.