Skip to main content

Module runtime

Module runtime 

Source
Expand description

Runtime evaluator — walks an algebra Comprehension AST against a Lookup scope (a PolydatKernel or a Layered view) to produce typed coordinate tuples.

§Why this is separate from the static IR interpreter

The static IR interpreter (super::ir::interpreter) walks a compiled stack-machine program over fully-statically- resolvable Source variants (IntRange, Literal). It has no notion of a runtime parent kernel, which is correct for the consumption surfaces it serves (comprehension_forms.md §9.5).

Runtime comprehension evaluation is fundamentally different:

  • Source-text evaluation requires the parent kernel. Source::Generator { expr: "pre_{outer}" } and Source::WorkloadParamList { name } resolve against the parent kernel’s chain — {outer} substitution via interpolate_via_kernel, kernel.lookup(name) for workload params.
  • Cartesian is dependent-tuple, not independent. Clause N’s spec text may reference iter-vars from clauses 1..N-1. Prior-axis values are layered in front of the scope (Layered) so each clause evaluates against the correct context: the dependent product of comprehension_forms.md §3.2.
  • Filter predicates evaluate against per-tuple scopes. A CompiledPredicate parses the predicate once and tests each tuple: its boolean structure over the tuple’s values directly, and any richer sub-expression interpolated against a Layered view of the scope and evaluated as a Polydat expression, charged to the scope’s ledger.

All three rest on the kernel’s own primitives; this evaluator is the algebra-typed entry point to them.

§What this owns

evaluate_indexed is the public surface: (algebra AST + scope) → IndexedTuples, the tuples addressed by position and computed when asked for; evaluate_for_iteration computes them all. The tuples carry polydat Values, which the caller binds into a kernel over the body’s program, one per tuple. evaluate_for_iteration_materialized is the reference the index-addressed evaluator is held to: every node materializes.

Order modifiers route through Strategy::select (comprehension_forms.md §10.7.8): each node returns its tuples paired with the IndexFn they satisfy, and the Order node selects positions from that shape and the tuple count. An order over a filter selects through Strategy::select_surviving, ranking the survivors by their positions in the filter’s input (§5 V5). V4 fires again at this site, against the evaluated shape. An order’s own output is addressed through its selection, one axis as long as the selection (§3.6), so an order over an order selects from it.

§What this does NOT own

  • Per-iteration kernel construction. The evaluator returns tuples; the caller binds each into a kernel over the body’s program — TraversalStream for a for statement, the renderer for a tile’s projection.

Structs§

ClauseYield
Internal walker state — the scope the recursive walker resolves names against, so it does not thread it through every call. What one leaf clause yielded over a whole traversal.
EvaluatedIteration
A traversal’s tuples, and what each leaf clause yielded reaching them (ClauseYield), in the tree order of the comprehension.
IndexedTuples
A comprehension’s tuples addressed by position: each tuple is computed from its position when asked for (evaluate_indexed).

Enums§

RuntimeError
Errors the runtime evaluator surfaces.

Functions§

evaluate_for_iteration
Evaluate a comprehension against a scope and produce the typed coordinate-tuple list.
evaluate_for_iteration_materialized
The reference evaluator: every node materializes its tuples, and a cartesian evaluates each later axis once per tuple of the axes before it.
evaluate_for_iteration_reported
evaluate_for_iteration, and what each leaf clause yielded on the way (ClauseYield).
evaluate_indexed
Evaluate a comprehension against a scope to its tuples addressed by position (comprehension_forms.md §10.2 R2).

Type Aliases§

RuntimeTuple
Runtime tuple type — polydat-Value-based to preserve Ext typing (Partition / Json / etc.) through the iteration pipeline. The algebra layer’s Tuple uses TupleValue which is scalar-only; this RuntimeTuple is what the executor actually wants for per-iteration kernel binding via PolydatKernel::for_iteration.