Repository navigation
Description
Problem
The engine only performs the implicit WITH-LOOKUP lowering -- wrapping a tables-bearing variable's own equation as LOOKUP(self, input) -- for scalar equations. In src/simlin-engine/src/compiler/mod.rs (~line 800-825, the "WITH LOOKUP" comment), this happens exclusively in the Ast::Scalar branch of the Variable::Var arm. The Ast::ApplyToAll and Ast::Arrayed branches (expand_a2a_with_hoisting / expand_arrayed_with_hoisting) never consult tables, so a graphical function attached to an arrayed variable that also has a real input equation is silently ignored.
Stella applies the gf to the input equation per element; per the project's "Stella over XMILE spec" policy, Stella behavior is the target.
Concrete evidence
- An apply-to-all arrayed variable with a variable-level
<gf>AND a real input equation evaluates just the input equation; the gf is silently dropped (Stella computesgf(input)per element). - A non-A2A arrayed variable with per-element
<gf>s plus a shared top-level<eqn>-- the vendored fixturetest/test-models/samples/arrays/non-a2a/non-a2a-gf.stmx,Converter 1[Product]with<eqn>TIME</eqn>-- evaluates each element to the EXCEPT-default input (TIME) with the per-element tables latent, instead of Stella'sgf_elem(TIME)per element.
What DOES work today (not in scope here):
- The per-element tables are correctly compiled and reachable via explicit
LOOKUP(var[elem], x)call sites (well tested inper_element_gf_tests.rs). - A fully eqn-less arrayed gf holder correctly becomes a lookup-only static table.
The gap is only the implicit application of the gf to the variable's own input equation for arrayed shapes.
Current pinned behavior: simulate::opens_and_simulates_non_a2a_gf in src/simlin-engine/tests/integration/simulate.rs pins that Converter 1 == TIME per element and documents the divergence in its rustdoc. Update that test when fixing this.
Component
src/simlin-engine/src/compiler/mod.rs(Variable::Vararm:Ast::ApplyToAll/Ast::Arrayedbranches)src/simlin-engine/src/compiler/codegen.rs(extract_table_info, ~line 713)
Suggested disposition
The naive fix does not work: the scalar wrap passes Expr::Var(off) as the Lookup table expression, and codegen's extract_table_info resolves the table ident by matching the variable's BASE offset in module_offsets, so a per-element Expr::Var(off + i) would fail with BadTable. A real fix needs either a subscript-shaped table reference or an element-offset-aware wrap:
- For A2A with a variable-level gf: wrap each element's expanded equation as a Lookup against the shared table (base offset works, since there is one table).
- For per-element gfs (non-A2A): the wrap must select table index
base_gf + element_offset, i.e. teachextract_table_info(or the wrap itself) to carry the element offset rather than re-deriving the ident from the base offset.
Care is needed to interact correctly with #589 (per-element tables are laid out by sorted Arrayed-Vec position, not dimension index).
Context
Identified while fixing #907 (gf-only <element> entries failing whole-file parse) on branch conveyor-engine. Related: #904 (per-element <len> silently dropped), #606 (lookup-only static tables), #589 (per-element table ordering).
Activity
engine: accept XMILE elements without an eqn child
engine: accept XMILE elements without an eqn child