Repository navigation
Description
A link-score equation must hold a LOOKUP table's index at its previous value, like every other input: LOOKUP(g[idx], x) becomes LOOKUP(g[PREVIOUS(idx)], x).
That works, except when some dimension anywhere in the project has an element with the same name as the index variable.
Then the index is taken for a static element selector and left varying, with no diagnostic.
The index should be resolved against the table's own dimension at that position, the way the compiler does (an element of that axis first, else the variable).
Example
D: A1, A2
B: idx, spare <-- declared, used by no equation
g[A1]( (0,0),(1,10),(2,20) )
g[A2]( (0,0),(1,100),(2,200) )
idx = 1 + MODULO(Time, 2)
inflow = 1
src = INTEG(inflow, 1)
y = g[idx](src) + 0*idx
src -> y link-score equation |
score | |
|---|---|---|
B not declared |
lookup(g[PREVIOUS(idx, idx)], src) |
0, 0.053, 0, 0 |
B declared |
lookup(g[idx], src) |
0, 1.0, -1.0, 1.0 |
On the per-element path it is worse: the index is rewritten to bucket·ctr, an element of the unrelated dimension, and reads one fixed slot.
Why it matters
A silent wrong number, but only when a variable used as a table index shares its name with an element of some dimension.
Constructed; not seen in a real model.
Fix
Pass the table's declared dimension at each index position into the index pass, from db::variable_dimensions for the table variable.
The table is recorded in referenced_tables, beside the dependencies rather than in them (#606), which is why the existing axis lookup never finds it; freeze_lookup_table_indices passes a literal None and falls back to project-wide "is this an element of any dimension" checks.
generate_per_element_link_equation passes no axis table either.
Small.
Alternative: when the axis is unknown and the name is both a variable and an element, decline the link score with a warning.
Pointers
src/simlin-engine/src/ltm_augment.rs:freeze_lookup_table_indices,generate_per_element_link_equationsrc/simlin-engine/src/ltm_augment_index.rs:wrap_index_non_matching_in_previous,index_axis_verdictsrc/simlin-engine/src/dimensions.rs:resolve_axis_index_name,is_element_of_any_dimensionsrc/simlin-engine/src/db/ltm_char_tests.rs:arrayed_gf_lookup_mdl, a fixture to extend- Related: ltm: index of a held-fixed array read lags two steps instead of one #1060 (an index inside a held-fixed read is lagged twice)
Activity
engine: delete the LTM input-side round trip and the last Expr0 class…
bpowers commentedon Jul 28, 2026
Still open after the table-index freeze: the index resolution underneath it is project-wide
The wrap now freezes a
LOOKUPtable argument's subscript index (freeze_lookup_table_indices,landed on the round-trips burndown branch), which fixes the shape this issue's title describes. It
does not close the issue, because the freeze only fires for an index the wrap classifies as a
runtime read, and that classification is still made by two project-wide predicates. This comment
records the reproduction and the structural reason, so the next attempt starts here.
Two corrections to the record while I am here:
DoesNotExistfirst is wrong, not merely conservative. It is true only for an index thatappears nowhere else in the equation. Adding any second reference —
+ 0*idxis enough — buysthe index into
classify_dependencies' scope and the whole thing compiles.LOOKUPfixture to be tested at all. An ordinary subscriptedarrayed variable (
q[idx]) takes a different code path and does not exercise this one.Reproduction: compiles with zero diagnostics, score moves by 1.0
src→ypartialBnot declaredlookup(g[PREVIOUS(idx, idx)], src)[0, 0.05263, 0, 0]Bdeclaredlookup(g[idx], src)[0, 1.0, -1.0, 1.0]idxis a genuine runtime value. Declaring a dimension that no equation references leaves it liveinside a partial that is supposed to be ceteris-paribus, with no diagnostic in either model. The
same shape reproduces on the
PerElementemitter, where the failure is one step worse — the index isrewritten to
bucket·ctr, an element of a dimension the indexed variable is not declared over, whichcompiles and statically reads slot 1 forever:
pop[nyc,young]→growth[nyc]partialBucketnot declaredPREVIOUS(q[PREVIOUS(ctr, ctr)])[0, .7246, .98795, .94652, .99394, .96721]BucketdeclaredPREVIOUS(q[bucket·ctr])[0, .7246, .98795, **.80214**, .99394, **.81967**]Same diagnostic count both ways.
Why the GH #986 unification does not reach here
dimensions::resolve_axis_index_nameis the engine's single element-vs-dimension precedence rule andis what
compiler::subscript::normalize_subscripts3implements. GH #986 unifiedltm_agg::classify_axis_accessandltm_augment_post_transform::pin_dimension_name_indicesonto it;the wrap was the third consumer and has now been partially unified too
(
ltm_augment::index_axis_verdict). Partially, because resolving an index needs the axis — thedeclared
Dimensionat that index's position of the subscripted variable — and the wrap gets it fromIteratedDimCtx::dep_dims.A graphical-function table holder can never be in
dep_dims. That table is built fromvariable::classify_dependencies(..).all, and theBuiltinContents::LookupTablearm records theholder in
referenced_tablesand deliberately keeps it off the dependency graph (GH #606 — alookup-only holder is a static table, not a value-bearing variable, and a bare
Varreference to oneis a compile error, so there is no other route into
alleither). Soaxis_dim_atalways returnsNoneon this path,axis_unknownis always true, and the two project-wide predicates(
dimension_uniquely_containing_element,is_element_of_any_dimension) still decide every tableindex. Nothing in the test suite constrains it: deleting the call site outright leaves 5,435 tests
green, which is why it is now a literal
Nonewith a comment rather than a call that reads ascoverage.
generate_per_element_link_equationreaches the same fallbacks for a different reason — it threadsdep_dims: None, on a comment that was true whenother_dep_verdictwas that table's only consumer.What closing this needs
The wrap needs the subscripted variable's declared dimensions from the source of truth the compiler
uses (
db::variable_dimensions, or the project'sDimensionsContext), not from a table of thetarget's array dependencies. Those are different questions and the mismatch is exactly what bounds
the current fix: "absent from
dep_dims" is being read as "no axis exists", when it also means "thisemitter did not thread the table" and "this kind of reference is not a dependency by construction".
That is a decision about where this function family gets its dimension truth — it deliberately
carries none today, which
qualify_element_index's rustdoc has said honestly for a long time — so itis its own change rather than a rider. Both fixtures above are ready to become its tests; the second
one is four lines on top of the existing
arrayed_gf_lookup_mdlfixture insrc/simlin-engine/src/db/ltm_char_tests.rs.Related: the partial above is not fully ceteris-paribus even once every name resolves, because an
index frozen inside an already-frozen head is double-lagged (reads the head at
t-1indexed att-2, where thePREVIOUS(target)anchor indexed att-1). That is a separate semantics questionand is disclosed on the burndown PR.
bpowers commentedon Jul 30, 2026
Partial update from #994, and a correction to one premise in this issue's surrounding analysis. Not claiming this closes it — recording precisely what moved so someone can decide.
What #994 fixed: a
LOOKUPtable argument's dimension-name index is now element-pinned in a per-element partial. It previously survived into the scalar fragment and lowering rejected it withDimensionInScalarContext— 413 occurrences on C-LEARN, the largest single bucket of LTM fragment-compile failures.The premise that was wrong. The accepted explanation (repeated in
src/simlin-engine/CLAUDE.md) was that a graphical-function holder is "by construction absent fromdep_dims, soaxis_dim_atcan never resolve its axis." That conflates two things. The holder is deliberately kept out of the dependency graph —classify_dependencies'LookupTablearm records it inreferenced_tablesand keeps it offall(variable.rs:1150-1156, GH #606) so a table reference creates no runlist entry and no causal edge. Its dimensions were never unavailable:referenced_tablesrides the same struct returned by the same single AST pass asall, one field away.So the fix did not need any new plumbing. It widens the per-element pin candidate list with
referenced_tables, and deliberately leaves the wrap's dependency set alone — the separation is load-bearing for an attribution reason (a table cannot vary, so it earns no score and no edge, only an index).What this issue still covers, as far as I can tell: the runtime index case in the opening example —
LOOKUP(g[idx], x)whereidxis a genuine value read that should be frozen. That is a different thing from a dimension-name index needing to be pinned, and #994 did not touch it.freeze_lookup_table_indicesexists for the freezing half; whether it now covers the runtime case completely is not something I verified.Also worth knowing before further work here: a broader design alternative was measured and rejected. Putting table references into
allfor generality breaks 14 lib tests, and the first thing that breaks is compilation itself — a lookup-only holder has no value slot and is excluded from every runlist, so the fragment compiler cannot treat it as a dependency. Five consumer families see them; four must filter, one wants them. The safe default is the current one (absent, opt in), because the failure directions are asymmetric: a consumer that needs tables and does not get them fails loudly, while a forgotten opt-out mints a causal edge for a variable that cannot vary — a wrong number rather than a crash.variable.rs'sreferenced_tablesdoc now records all of this, including that the third consumer (dimension resolution) should read that field rather than expect it inall.[-]ltm: the ceteris-paribus wrap leaves a LOOKUP table argument's runtime index live in every link-score partial[/-][+]ltm: LOOKUP index is not held fixed if it shares an element's name[/+]