Repository navigation
Description
Problem
An apply-to-all equation over a subrange that references a parent-dimensioned array by dimension name (out[Sub] = src[Sub], where src is declared over Parent and Sub is a subrange of Parent) reads src by the element's position within Sub instead of by its element name (equivalently, its position within Parent).
It is a silent wrong number: the model compiles and simulates with exit 0, and the wrong value propagates downstream with no diagnostic.
Reproduction
<dimensions>
<dim name="Parent"><elem name="A"/><elem name="B"/><elem name="C"/><elem name="D"/></dim>
<dim name="Sub"><elem name="A"/><elem name="C"/></dim>
</dimensions>
<model><variables>
<aux name="src">
<element subscript="A"><eqn>100</eqn></element>
<element subscript="B"><eqn>200</eqn></element>
<element subscript="C"><eqn>400</eqn></element>
<element subscript="D"><eqn>800</eqn></element>
<dimensions><dim name="Parent"/></dimensions>
</aux>
<aux name="q_dimref">
<eqn>src[Sub]</eqn>
<dimensions><dim name="Sub"/></dimensions>
</aux>
</variables></model>(sim_specs: Euler, start 0, stop 1, dt 1.)
| Variable | Expected | Observed |
|---|---|---|
q_dimref[a] |
100 (src[A]) |
100 |
q_dimref[c] |
400 (src[C]) |
200 (src[B]) |
src[C] sits at offset 2 in Parent but at offset 1 in Sub; the observed 200 is Parent[1], i.e. the read used the Sub-relative position.
Controls that ARE correct in the same model:
src[A]= 100 andsrc[C]= 400 (scalar element reads).SUM(src[*:Sub])= 500 = 100 + 400 -- the star-range path resolves throughSubdimensionRelation::parent_offsetsand is right.
Raw CLI output of the model above plus those controls (ctl_a = src[A], ctl_c = src[C], q_star = SUM(src[*:Sub])):
time dt initial_time final_time ctl_a ctl_c q_dimref[a] q_dimref[c] q_star src[a] src[b] src[c] src[d]
0 1 0 1 100 400 100 200 500 100 200 400 800
1 1 0 1 100 400 100 200 500 100 200 400 800
The four spellings of the same intent disagree
Also observed in the same family, and probably the same root-cause area:
out[Sub] = src(BARE, no subscript) is refused withmismatched_dimensions-- the loud arm. Verified:error in model 'main' variable 'q_bare': mismatched_dimensions.out[Sub] = src[Parent]is refused withmismatched_dimensions.
So of the four spellings, one is correct (*:Sub), two are refused, and one is silently wrong.
Where to look
src[Sub] normalizes through src/simlin-engine/src/compiler/subscript.rs::normalize_subscripts3 -- the IndexExpr3::Expr(Expr3::Var(..)) and IndexExpr3::Dimension(..) arms -- which find the ACTIVE dimension named sub and emit IndexOp::ActiveDimRef(active_idx). build_view_from_ops's ActiveDimRef arm then resolves the offset with config.dims[i].get_offset(subscript), where config.dims[i] is the SOURCE axis (Parent).
Read literally that should give Parent's offset for element c (2), not 1, so the positional 1 is arriving from somewhere else on the path and the arm that actually produces it must be found by tracing. The observed value is measured; the mechanism is not -- the reporter did not trace past normalize_subscripts3, and this paragraph is a starting point, not a diagnosis.
DimensionsContext::resolve_mapped_read and SubdimensionRelation::parent_offsets (src/simlin-engine/src/dimensions.rs) already state the correct rule, and the star-range path uses them. The fix is most likely to route this arm through the same shared rule rather than to invent a second one.
Why it matters
-
Silent wrong number on a legal, ordinary XMILE spelling. Subranges are the standard way to write a policy that applies to some regions/sectors, and
out[Sub] = src[Sub]is the natural way to spell "take the parent's values for those elements". -
It blocks a correctness improvement elsewhere. The compiler-unification Phase 6(a) work found that admitting a subdimension relation into the shared axis-matching precedence (
dimensions::match_axes) would compileout[Sub] = src-- currently a LOUDmismatched_dimensionsrefusal -- into exactly this positional read, converting a refusal into a silent wrong number. That rung is therefore opt-in (AxisRelations::is_subdimension, admitted only bySubdimensionRelations) with a rustdoc comment pointing at this issue.Whoever fixes this should revisit
AxisRelations::is_subdimensionand thea_subdimension_does_not_pair_for_a_caller_that_does_not_admit_the_rungrow indimensions::axis_match_tests-- the rung can become unconditional once the positional read is fixed.
Component
src/simlin-engine compiler -- subscript normalization / A2A view construction (compiler/subscript.rs, dimensions.rs).
Possible approaches
- Route the
ActiveDimRefresolution for a subdimension-of-source active axis throughDimensionsContext's existing rule (resolve_mapped_read/SubdimensionRelation::parent_offsets), so the name-based correspondence the star-range path already uses is the single answer for every spelling. - Whatever the fix, gate it with a regression test built from the probe above, and make the four spellings (
src[Sub], baresrc,src[Parent],src[*:Sub]) agree -- either all correct or loudly refused, never one silently wrong.
Context
Found while probing subrange/star-range shapes during the compiler-unification Phase 6(a) chunk (2026-08-26). Pre-existing -- not introduced by any compiler-unification commit; independently reproduced here with a simlin-cli release binary built 2026-08-07, well before that branch existed.
Sibling issues in the same "executed lowering resolves positionally" family, related but distinct (those concern explicit simlin:mapping element maps between distinct dimensions; this one concerns a subrange's implicit name-based correspondence with its parent): #756, #753.
Activity
engine: one dimension matcher and a decomposed subscript lowering
engine: one ordinal fallback for undeclared dimension pairs