You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
engine: VECTOR ELM MAP(x[three], DimA - 1) fails to compile #578
VECTOR ELM MAP with a single-element source and an arithmetic offset fails to compile, with no diagnostic on the variable.
It should compile and match Vensim.
Expected (Vensim, vector.dat): y[A1]=3, y[A2]=4, y[A3]=5.
Actual: NotSimulatable: "failed to compile fragments for variables: y".
Two things go wrong.
The source x[three] is widened back to all of x, dropping its starting element (harmless only when the element is the first one).
And the offset DimA - 1 is a per-element expression, while the ELM MAP implementation expects the offset to be an array it can index.
Why it matters
This is the ordinary Vensim idiom for "read x starting at element three".
It keeps vector.mdl from being a full Vensim-output regression test.
Fix
Keep a single-element source as a scalar that remembers its element's position.
When the offset is a constant per result element, compute the target element at compile time and read that slot directly (NaN if out of range), instead of going through the ELM MAP opcode.
Pointers
src/simlin-engine/src/compiler/context.rs (subscript lowering for the source)
changed the title [-]engine: VECTOR ELM MAP with scalar source + arithmetic (expression) offset fails to compile (no diagnostic) -- narrows the Phase 5 vector.xmile gate[/-][+]engine: VECTOR ELM MAP(x[three], DimA - 1) fails to compile[/+]on Oct 12, 2026
try_fold_scalar_source_elm_map / fold_scalar_source_elm_maps (src/simlin-engine/src/compiler/mod.rs:1663-1720) keep the scalar source's element offset and fold a constant per-element offset to a direct read (NaN if out of range). y is gated against vector.dat through both the XMILE and MDL readers (simulates_vector_xmile_genuine / simulates_vector_mdl_genuine, simulate.rs:2903/2920), plus unit tests scalar_source_dim_offset_* in src/array_tests.rs (~3443-3494).
Activity
engine: VECTOR ELM MAP genuine Vensim base+full-source (AC6)
engine: close out the VECTOR builtin issues (#576/#578/#579) (#736)
[-]engine: VECTOR ELM MAP with scalar source + arithmetic (expression) offset fails to compile (no diagnostic) -- narrows the Phase 5 vector.xmile gate[/-][+]engine: VECTOR ELM MAP(x[three], DimA - 1) fails to compile[/+]bpowers commentedon Oct 12, 2026
Closing: already fixed on main.
try_fold_scalar_source_elm_map / fold_scalar_source_elm_maps (src/simlin-engine/src/compiler/mod.rs:1663-1720) keep the scalar source's element offset and fold a constant per-element offset to a direct read (NaN if out of range). y is gated against vector.dat through both the XMILE and MDL readers (simulates_vector_xmile_genuine / simulates_vector_mdl_genuine, simulate.rs:2903/2920), plus unit tests scalar_source_dim_offset_* in src/array_tests.rs (~3443-3494).