Skip to content

engine: VECTOR ELM MAP(x[three], DimA - 1) fails to compile #578

Closed

Description

@bpowers

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.

Example

From test/sdeverywhere/models/vector/vector.mdl:

DimX: one, two, three, four, five
x[DimX] = 1, 2, 3, 4, 5
y[DimA] = VECTOR ELM MAP(x[three], (DimA - 1))

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)
  • src/simlin-engine/src/compiler/mod.rs (ELM MAP shape inference)
  • src/simlin-engine/tests/integration/simulate.rs (simulates_vector_xmile_genuine)

Activity

  1. added
    engine
    on Jun 8, 2026
  2. 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
  3. added
    bug
    compat
    on Oct 12, 2026
  4. bpowers commented on Oct 12, 2026

    @bpowers
    OwnerAuthor

    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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcompatengine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions