Repository navigation
Description
Problem
The results-offset map (db/layout.rs::flattened_offsets) gives an arrayed
implicit helper one key, at its base slot, and nothing for the rest of its
slots. The only arrayed implicit helper that exists today is the GH #541
arrayed capture (PR #668): an ImplicitVar::Capture with non-empty dims,
minted when an apply-to-all equation puts a bare arrayed name inside a
nested PREVIOUS/INIT. It occupies product(dims) slots, and every slot
after the first has no name.
simlin simulate shows it directly. For
vals[region] = ...
x[region] = PREVIOUS(PREVIOUS(vals), 0)
the TSV header carries a $⁚x⁚0⁚arg0 column followed by one UNKNOWN
column per remaining element of region. Results::print_tsv_comparison
(src/simlin-engine/src/results.rs:96) labels every slot the offset map has
no key for UNKNOWN, so this is exactly the missing keys showing through.
Cause
flatten_model (src/simlin-engine/src/db/layout.rs) chooses
Flatten::Elements -- one key per element, name[e1,e2] in row-major order
-- only when the layout name is an explicit source variable with
entry.size > 1. Every implicit helper that is not a module instance falls
to Flatten::Series, one key at the base slot. The rustdoc on
flattened_offsets states that rule ("an arrayed implicit or LTM variable is
keyed once, by its bare name, at its base slot (readers widen it by the
variable's own dimensions)"), and the LTM readers do widen -- but the CLI's
TSV path and any other name-keyed reader of Results::offsets do not, and
nothing can widen a key it cannot see.
ImplicitVarMeta (src/simlin-engine/src/db/query.rs) already carries
size and dimensions for exactly this helper, so the layout has the
information in hand; it just does not use it for the implicit section.
Why it matters
- The CLI's TSV output is what the integration corpus and humans debugging a
model read. AnUNKNOWNcolumn is unlabelled data, and a reader cannot
tell whether it is a bug in the layout or a bug in the model. - Every name-keyed consumer of
CompiledSimulation::offsets/
Results::offsets--get_series, libsimlin's variable list, the
reference-comparison path inprint_tsv_comparison-- can address only the
first element of an arrayed capture. Explicit arrayed variables are
addressable per element; the helper the compiler synthesizes for them
should be too, or the results map is inconsistent with itself. - The
flattened_offsetsrustdoc documents "readers widen it" as the
contract, and the CLI reader does not. Either the contract or the reader is
wrong; today both stand.
Components affected
src/simlin-engine/src/db/layout.rs--flatten_model(the
Flatten::Seriesfall-through for implicit helpers) and the
flattened_offsetsrustdoc.src/simlin-engine/src/results.rs--print_tsv_comparison'sUNKNOWN
fallback is where it surfaces.src/simlin-engine/src/db/query.rs--ImplicitVarMeta::{size, dimensions}, the facts the fix consumes.
Possible approach
Give the implicit section of the layout the same per-element keys the
explicit section has: in flatten_model, when implicit_info.get(name)
reports size > 1 (equivalently non-empty dimensions), resolve those
dimension names through the project's dimension context and emit
Flatten::Elements(dims) so the keys are $⁚x⁚0⁚arg0[east],
$⁚x⁚0⁚arg0[west], ... in the same row-major order the VM stores them.
Update the flattened_offsets rustdoc to describe the new rule and say
which arrayed things (LTM synthetics) still rely on reader-side widening, if
any do after the change.
Test through flattened_offsets on a project built the way production builds
it (sync_from_datamodel from a datamodel with the bare-arrayed nested
PREVIOUS), asserting one key per element at consecutive slots, and a CLI
TSV header assertion with no UNKNOWN. A related but separate product
question is whether synthesized helpers should appear in the TSV at all;
this issue is only about the keys being wrong when they do.
Discovery
Identified during adversarial review of the compiler-unification Phase 7.3
work (branch compiler-unification-v2, engine crate); out of scope for that
branch. Follows on from GH #541 / PR #668, which introduced the arrayed
capture without extending the layout's key rule to cover it.
Activity
engine: print only the results map's columns as TSV
engine: element-scoped helpers; structural captures
engine: print only the results map's columns as TSV
engine: element-scoped helpers; structural captures