Repository navigation
engine: make implicit-helper identity a name, not a hash-ordered position - #1006
Conversation
…tion A sub-model that instantiates a stdlib module over a bound input compiled or failed depending on the process's HashMap seed: across identical runs of one fixture, roughly one in five returned the unattributed "failed to compile fragments for variables: $/sm/0/arg1, $/sm/0/smth1". BuiltinVisitor accumulated its synthesized SMOOTH/DELAY/TREND/PREVIOUS helpers in a HashMap and every producer of implicit_vars emitted it with .values(). Rust draws a fresh RandomState key per map, so two parses of the SAME variable -- in one process, differing only in their ModuleIdentContext -- reported the helpers in two different orders. ImplicitVarMeta identified a helper by its POSITION in that vector, and a position is meaningful only against the exact vector it was taken from: model_implicit_var_info records it under the no-extra-idents context while assembly resolves it under the context widened by the instance's module-input names. When the two orders disagreed, the position named an aux where a module was expected or the reverse; both fail to lower, so the sub-model lost every helper fragment. Two fixes, kept together because they close different properties. IDENTITY: ImplicitVarMeta carries the helper's canonical name and resolves by it, so a helper resolves to itself or to nothing and a compile outcome no longer depends on any ordering. ORDER: BuiltinVisitor::vars is an IndexMap and elements_in_stable_order walks an Ast::Arrayed slot map -- itself a HashMap -- in a stable order, so the two salsa-cached vectors carrying that order (ParsedVariableResult::implicit_vars, VariableDeps::implicit_vars) equal their own recomputation. Without the second, salsa stops backdating and the compiled artifact is irreproducible, which no numeric result and no compile outcome would have shown. Which test gates which fix is measured rather than predicted: each was reverted alone and the suite re-run, and the results are recorded in the test module's header. Also deletes LtmImplicitVarMeta::index_in_parent, which nothing read -- the same footgun sitting next to the fixed one. One shape stays broken and is disclosed rather than implied: when the widened context synthesizes a genuinely DIFFERENT helper set (PREVIOUS over a bound input whose port carries no access="input"), the model's layout and its runlists disagree about which helpers exist and the project fails to compile. That is deterministic and pre-existing -- verified byte-identical at the parent commit -- and its fix is GH #372's explicit model-level parse context. What changes here is only that the mis-resolution is loud. C-LEARN compile+run is unmoved at 0.44s; the ignored tier still has exactly its seven pre-existing failures (#915), name for name.
Four corrections from an adversarial review of the parent commit, three of
which were wrong claims rather than wrong code.
The load-bearing one is a real coverage gap. `elements_in_stable_order`'s
rustdoc said its second call site -- the arm where one visitor spans every
slot -- was inert and reachable only when a declared dimension failed to
resolve. Both halves were false. A failed dimension lookup yields no AST at
all; the live route is an EMPTY dimension list, which `xmile::variables`
mints for any `<aux>` carrying `<element subscript=...>` children with no
`<dimensions>` sibling. Such a model compiles, and reverting that call site
re-binds which slot's equation each helper name carries. Nothing caught it:
the mutation left the whole 5551-test suite green.
It went uncaught because the probe compared helper NAMES, and names are the
one thing that arm keeps stable -- its counter is monotonic, so it emits
0, 1, 2 however the slots are walked, and only the BINDING moves. The probe
now renders each helper's equation too, and the mutation is caught 3 of 3.
The new fixture is read through the real XMILE reader rather than
hand-built, since the shape is only interesting because production mints it.
Two claims in the test module's mutation matrix were wrong, both because
the original mutation was over-strong (it made `find_in` return the first
helper unconditionally, where a faithful revert restores `index_in_parent`
and indexes with it). Re-measured, three runs each: reverting the IndexMap
reds all three order tests, not one; reverting identity reds ONE test, not
three. The corrected matrix now records why that is a property of the
problem rather than thin coverage -- with a stable order, a positional
index resolves correctly whenever the two parse contexts synthesize the
same helper set, so only a diverging-set fixture can tell the two identity
schemes apart.
The anti-vacuity guard on both sub-model tests was a tautology: it
round-tripped a literal `["port"]` through `ModuleInputSet` and compared it
to itself, reading nothing from the fixture. Both now take the input set
from production's own `enumerate_module_instances`, via a `#[cfg(test)]`
accessor mirroring `db::dep_graph`'s idiom. Verified by degrading the
fixture's wiring to `x_module("sub", &[], None)`: the old guard stayed
silent and every test passed, the new one reds both tests.
Also: `an_implicit_helper_resolves_to_its_own_name_...` was a single-sample
probabilistic detector in a file built on repetition, and missed the
pre-fix defect 45% of the time; it now runs REPEATS times. `find_in` grew
an index HINT, checked against the name before it is accepted, because the
scan alone is O(k^2) per parent and k is not small on ordinary models -- an
apply-to-all SMTH1 over N elements mints ~2N helpers on one variable, and
at N=800 the scan cost 2.13s against the parent's 1.12s. With the hint,
1.16s. Dropping the hint's name check restores positional identity and reds
the identity test, so the optimization is gated. Corrects a dangling
reference to a `walk_module_call` that does not exist, and drops a
`dedup_vars_by_ident` parenthetical that was still wrong after the parent
commit edited it -- layout iterates a name-keyed map, so duplicate names
collapse to one slot rather than colliding into several.
Writing a tripwire for the index hint's soundness argument disproved the argument. The hint is still correct; the reason stated for it was not. The claim was that at most one helper in a parse can carry a given name, so accepting a name-checked hint must return what a scan would. That is false: `parse_var_with_module_context` runs `parse_and_lower_eqn` twice over one variable -- dt phase and initial phase -- and each appends to the same vector. A `Scalar`/`ApplyToAll` initial pass returns nothing unless the variable carries an ACTIVE INITIAL, so those do not repeat; the `Arrayed` arm has no such early-out and re-parses every slot, so each helper of a per-element variable appears exactly twice. What that means here is narrow and now written down where it belongs. `find_in` is sound regardless -- the name check makes it structurally unable to return another helper. Where hint and scan can diverge is between EQUALLY-named entries: the hint takes the last (which is what the name-keyed, last-wins `model_implicit_var_info` recorded, and what `index_in_parent` selected before this branch), the scan takes the first. They are interchangeable exactly while repeated names carry identical helpers, so that is what the test asserts, over five fixtures covering all five routes into `implicit_vars`. Worth stating because the branch briefly got this wrong in the other direction: the parent commit's scan-only `find_in` selected the FIRST occurrence, silently reversing a choice main had made. The hint restores main's selection, so the shipped behaviour is unchanged either way -- but that was luck rather than design until now. Two pre-existing shapes can make a repeated name carry DIFFERENT helpers, and both are disclosed on the test rather than fixed here: an `Arrayed` element with its own init equation, and a variable with `compat.active_initial`. Both make the initial pass parse a different equation while the helper-naming counter restarts at zero, so two bodies can claim one name -- which `model_implicit_var_info` collapses to one entry and `compute_layout` gives one slot. The fix for that is a phase discriminator in the synthesized name, not a change to `find_in`, and it is a defect of its own rather than part of GH #1002.
[P3] Doc comment for
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1006 +/- ##
==========================================
- Coverage 91.86% 91.86% -0.01%
==========================================
Files 247 247
Lines 159174 159225 +51
==========================================
+ Hits 146224 146267 +43
- Misses 12950 12958 +8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 07e46f5402
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| &self, | ||
| parsed: &'a ParsedVariableResult, | ||
| ) -> Option<&'a datamodel::Variable> { | ||
| let is_mine = |v: &datamodel::Variable| canonicalize(v.get_ident()) == self.name; |
There was a problem hiding this comment.
Make helper names independent of synthesis counters
When the instance context inserts a helper before an existing expression helper—for example, PREVIOUS(port, 0) + SMTH1(port + 1, 3) with port bound as a module input—the no-input SMTH argument and the widened PREVIOUS capture are both named $⁚sm⁚0⁚arg0. This predicate therefore accepts the newly inserted capture as the metadata's helper, returning the wrong fragment instead of the promised self-or-none result. Use a context-stable structural identity (or verify the stored helper content), and cover this name-collision arm in the determinism tests.
AGENTS.md reference: AGENTS.md:L97-L99
Useful? React with 👍 / 👎.
| /// Two shapes could break it, both PRE-EXISTING and neither in scope here: an | ||
| /// `Arrayed` element carrying its own `<init_eqn>`, and a `Scalar`/`ApplyToAll` | ||
| /// variable carrying `compat.active_initial`. Both make the initial pass parse | ||
| /// a DIFFERENT equation while `BuiltinVisitor`'s `n` counter restarts at zero, | ||
| /// so the two passes can mint the same helper NAME for different bodies -- |
There was a problem hiding this comment.
Give initial-phase helpers distinct names
For an Arrayed element with its own <init_eqn> or a variable using compat.active_initial, the flow and initial passes parse different equations while restarting the naming counter, so different helpers receive the same name; model_implicit_var_info then collapses them to one slot and one phase can silently execute the other phase's helper body. The new test deliberately excludes exactly these rows that falsify its universal invariant, so phase-qualify the synthesized names and add both cases rather than leaving this known result-corruption path green.
AGENTS.md reference: AGENTS.md:L97-L99
Useful? React with 👍 / 👎.
…e-stability claim Three findings from automated review of the branch. Two are real defects in what the branch CLAIMED; one is a pre-existing silent-corruption path the claim led straight to. **A variable's two parse phases could mint one helper name for two bodies.** `parse_var_with_module_context` runs `parse_and_lower_eqn` twice -- dt phase and initial phase -- and both name their helpers from a counter that restarts at zero. When the initial pass reads a DIFFERENT equation (an `Arrayed` element's own init equation, or `compat.active_initial`) the two passes mint the same name for different bodies. `model_implicit_var_info` is name-keyed and `compute_layout` allocates one slot per name, so one body was discarded in silence and a phase ran the other phase's helper. Verified silent, not theoretical: an aux with equation `SMTH1(driver * 2, 3)` and ACTIVE INITIAL `SMTH1(driver * 100, 7)` COMPILED, keeping only the initial pass's `$⁚v⁚0⁚arg0`, so the dt phase smoothed the wrong expression. The append is now a MERGE with `dedup_vars_by_ident`'s rule applied across the phases: a byte-identical repeat collapses (the `Arrayed` arm re-parses every slot on the initial pass, so that is the common case and it also halves the redundant entries), and a genuine collision is a loud `DuplicateVariable`. Refusal rather than repair -- making the shape WORK needs a phase discriminator in every synthesized helper name, which changes every helper's identity and is its own change. Loud rejection is the choice `dedup_vars_by_ident` already makes for the within-one-pass twin. Blast radius measured, not assumed: the whole engine suite is green, `simulates_clearn` included, and ACTIVE INITIAL appears in both C-LEARN and WRLD3 -- so the shape the merge refuses does not occur in the corpus. **A helper name is not the context-stable identity the branch claimed.** "Resolves to itself or to nothing, never to another helper" is false. Names embed the visitor's walk counter, so a context that inserts an EARLIER helper renames every later one: for `PREVIOUS(port, 0) + SMTH1(port + 1, 3)` over a bound `port`, the no-extra-idents parse calls `$⁚sm⁚0⁚arg0` the SMTH argument and the widened parse calls it the PREVIOUS capture. The claim is corrected wherever it was made, and the residual is bounded instead of hand-waved: such a collision REQUIRES the two parses to synthesize different helper sequences, which is the same condition that makes layout disagree with runlists, so the project fails to compile before a mis-resolved fragment could run. Both halves -- the collision and the failing compile -- are pinned in one test, so if the compile ever starts succeeding the mis-resolution stops being harmless and something says so. Context-stable naming is GH #372's. The test whose premise this changes flipped with it: helper names within one parse are unique again, now because the merge enforces it rather than because it was assumed. Also moves `enumerate_module_instances`' rustdoc back onto it -- inserting the test-only accessor above it had left the doc on the accessor and the function undocumented.
|
All three findings were real. Verified each against a fixture before changing anything; two of them falsified claims this PR was making. P1 — phase-collided helper names (confirmed, and it was silent). An aux with equation Fixed by merging helpers across the two phases instead of appending, with Refusal rather than repair, deliberately. Phase-qualifying every synthesized helper name changes every helper's identity and its layout slot; that is its own change. Loud rejection is the choice One note on the fixture, since it nearly fooled me: my first version used a different variable in each equation, and that failed to compile even before the fix — for an unrelated reason (the discarded helper's dependency was missing from the survivor's dep set). It would have passed against the defect it was meant to catch. The committed fixture has both equations reference the same variable. P2 — names are not context-stable (confirmed; the PR's claim was wrong). Reproduced exactly as described: for I did not adopt the suggested structural identity, and here is the reasoning rather than a dismissal. The collision requires the two parses to synthesize different helper sequences — which is the same condition that makes the model's layout disagree with its runlists, so the project fails to compile before any mis-resolved fragment can run. I verified that: the fixture returns P3 (from the other reviewer) — Also worth recording against an earlier round: a reviewer reported a perf regression on @codex review |
Code review findings[P2] Broken doc reference and stale premise in
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7ba78dc9ec
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| /// and is its own change. A loud error is the same choice `dedup_vars_by_ident` | ||
| /// already makes for the within-one-pass twin of this collision. | ||
| #[test] | ||
| fn an_active_initial_that_collides_a_helper_name_is_refused() { |
There was a problem hiding this comment.
Cover all cross-phase collision routes
Fresh evidence in this target is that this regression test constructs only a scalar aux using compat.active_initial, while parse_equation has distinct ApplyToAll active-initial and Arrayed per-element init_eqn routes, both explicitly identified as collision sources in the added documentation. implicit_helper_names_are_unique_within_one_parse exercises those variants only with identical phase bodies, so it cannot prove the new DuplicateVariable refusal for them; a regression limited to either route could restore silent phase-body substitution while the suite remains green. Add collision rows for both remaining equation variants or document where each is covered.
AGENTS.md reference: AGENTS.md:L97-L97
Useful? React with 👍 / 👎.
| match implicit_vars | ||
| .iter() | ||
| .find(|v| Ident::<Canonical>::new(v.get_ident()) == ident) |
There was a problem hiding this comment.
Keep cross-phase deduplication linear
When an arrayed equation synthesizes k distinct helpers—for example, SMTH1 over an N-element dimension yields roughly 2N—this lookup scans every previously inserted helper for every new helper. The first phase therefore already performs O(k²) identifier canonicalizations, and the initial phase repeats the scan for its duplicates, replacing the previous linear append path with quadratic parsing before the layout-size guard runs. This becomes prohibitive for dimensions in the thousands; maintain a name-to-index map or reuse a hash-based linear deduplication pass instead.
Useful? React with 👍 / 👎.
| module_ident_context, | ||
| ); | ||
| let implicit_dm_var = parsed.implicit_vars.get(meta.index_in_parent)?; | ||
| let implicit_dm_var = meta.find_in(parsed)?; |
There was a problem hiding this comment.
Update the remaining positional-identity documentation
The name-based lookup introduced here leaves this function's production contract describing parent → parsed.implicit_vars[index] and saying that None means an implicit index is absent; the corresponding comments in assemble.rs still describe the same positional relation. Those statements are now false because find_in verifies the hint and may scan by canonical name, with None meaning that name is absent from the selected parse. Update these nearby contracts so future callers do not reintroduce positional assumptions while following the documented lowering path.
AGENTS.md reference: AGENTS.md:L118-L118
Useful? React with 👍 / 👎.
Round-2 review, on top of the cross-phase merge that the reviewer had not seen. Two of its three items were already closed by that merge but left the docs asserting the opposite; the third is a real blind spot in a test probe. The `index_hint` rustdoc claimed a wrong hint "cannot change the answer", then immediately qualified it with a paragraph saying a name is NOT unique within a parse -- so the claim was false and the qualification was the reason. The merge made the claim true, and both halves of the doc were stale: it still described the duplicates it now prevents, and cited the uniqueness test by a name that no longer exists. It now states the PRECONDITION (no two entries of one parse share a name), says what establishes it, and names the test that checks it -- and it separates that WITHIN-parse property from the cross-parse residual on `name`, which is a different thing and stays. The same review re-ran the performance question with three genuinely distinct binaries, having found that its earlier retraction came from sharing one `CARGO_TARGET_DIR` across worktrees -- cargo never rebuilt, so every "interleaved" number was one binary measured against itself. Its clean run reproduces the regression and its instrumentation settles the algorithmic claim without a clock: at N=800 the scan examines 17,289,600 entries against the hint's 14,400, a 1200x reduction, at a 100% hit rate on C-LEARN, WRLD3, scirev7 and the synthetic. That is now the doc's evidence, with the wall clock kept as the secondary number it is. `implicit_helper_signatures` rendered `get_equation()`, which is `None` for a `Variable::Module` -- so for exactly the helper kind carrying the WIRING the signature degenerated to the bare name, and a mutation re-binding which module reads which argument helper would have been invisible. Modules now render their model name and references. The doc also records what the probe is still weaker than (the compiled artifact, which differs on 21 of 23 repeats under the same mutation) so the next person can reach for the stronger one deliberately. `an_active_initial_that_collides_a_helper_name_is_refused` grew the reviewer's spelling as a second arm. Only the same-dependency arm gates the merge -- the disjoint-dependency one fails without it too, for an unrelated dep-set reason -- and the doc now says which is which, so nobody later deletes the arm that does the work. `ImplicitVarMeta`'s `Debug` renders `index_hint`, since a wrong hint is precisely what someone reads that for.
|
Follow-up review round landed as The The Adopted: On the performance disagreement, now settled — and the resolution is worth recording for anyone doing A/B work in this repo. The earlier retraction came from sharing one Better still, it settles the algorithmic claim without a clock: instrumenting the scan, N=800 examines 17,289,600 entries without the hint and 14,400 with it — a 1200x reduction — at a 100% hit rate on C-LEARN, WRLD3, scirev7 and the synthetic. That is now the doc's primary evidence, with wall-clock kept as the secondary number it is. Full pre-commit gate green on each commit; heavy @codex review |
Review of PR #1006I traced through the four production edits ( Correctness checks I completed:
Overall correctness verdict: correct. The fix is well-scoped, the measured gating matrix in the test module header persuasively shows each edit is load-bearing, and the honest disclosure of the two residuals ( |
…utes Three more findings from automated review, all real, and one of them a regression the previous commit introduced. **The cross-phase merge was O(k^2) -- the same shape it had just removed elsewhere.** Scanning `implicit_vars` for each incoming helper costs a canonicalize-and-intern per comparison, and `k` is ~2N for an apply-to-all `SMTH1` over an N-element dimension. Worse, `model::ModelStage0` threads ONE vector across every variable of a model, so each variable paid for every helper minted before it. Measured against the previous commit with separate target directories: N=800 went 1.18s -> 1.51s, about +30%. A name->index map, seeded empty and grown as helpers are pushed, brings it back to 1.14s. Seeded empty rather than from the caller's vector, and that is the point: only helpers of the same PARENT can collide, since a synthesized name embeds its parent's ident and two parents sharing a canonical name is already a `DuplicateVariable` model error. Seeding from the shared vector would have reproduced the model-wide quadratic the map exists to remove. **The collision test covered one of three routes.** `parse_equation` has exactly three arms that can make the initial pass read a different equation than the dt pass -- `Scalar`+`active_initial`, `ApplyToAll`+`active_initial`, and `Arrayed` with a per-element init equation -- and the test had only the first. Enumerating the arms rather than sampling one was not academic: with the merge reverted, THREE of the four rows now present compile and silently drop a helper body. A regression confined to the `ApplyToAll` or `Arrayed` route would have left the old test green. The doc records which row gates what, since `scalar_disjoint_dep` fails without the merge too for an unrelated dep-set reason and must not be mistaken for one that does the work. The loop also reports every failing row at once instead of stopping at the first, because the routes are independent and which one regressed is the signal. **Stale positional contracts.** `lower_implicit_var`'s rustdoc still described the chain as `parent -> parsed.implicit_vars[index]` and said `None` meant an absent index; `assemble.rs` carried the same prose in two more places. All three now describe resolution by name, so nobody reintroduces a positional assumption by following the documented path.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 60d14d2538
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Identity makes a helper resolve to itself or to nothing, so no compile | ||
| // outcome depends on any ordering. Order makes the two salsa-cached vectors |
There was a problem hiding this comment.
Correct the identity guarantee in the test header
This still says name-based identity can resolve only the intended helper or nothing, but a_cross_context_helper_name_collision_is_confined_to_a_failing_compile and the updated ImplicitVarMeta::name docs establish that, when a widened module context inserts an earlier capture, the same counter-derived name can resolve a different helper; the existing compile failure merely bounds the damage. Restate that residual here so future mutation work does not rely on the false invariant.
AGENTS.md reference: AGENTS.md:L115-L118
Useful? React with 👍 / 👎.
|
All three findings were real, and one of them was a regression the previous commit introduced. Fixed in P2 — the cross-phase merge was O(k²), the same shape it had just removed elsewhere. Confirmed by measurement. Scanning Measured against the previous commit, separate target dirs, interleaved:
A name→index map, seeded empty and grown as helpers are pushed, removes it. Seeded empty deliberately: only helpers of the same parent can collide (a synthesized name embeds its parent's ident, and two parents sharing a canonical name is already a P1 — the collision test covered one of three routes. This was the most valuable of the three findings. The doc now records which row gates what, because P1 — stale positional contracts. Full pre-commit gate green; heavy One note on methodology, since it bit an earlier round of this review badly enough to invert a conclusion: worktree A/B in this repo needs a separate @codex review |
ReviewI reviewed the three production changes and the test coverage. Findings: none. The change is correct on the axes I examined:
The revert matrix in the test module header, cross-checked against each edit, is unusually thorough — including the enumeration of the three phase-collision routes ( Overall verdict: correct. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 28a262184f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| /// names a different variable in the widened parse than it did in the parse | ||
| /// identity was derived from, deterministically. Positional identity therefore | ||
| /// produced a fragment whose `ident` was `$⁚sm⁚0⁚arg0` filed under the key | ||
| /// `$⁚sm⁚0⁚arg1`. A name resolves to its own helper or to nothing. |
There was a problem hiding this comment.
Remove the remaining self-or-none identity claim
Fresh evidence after the earlier header correction is the new a_cross_context_helper_name_collision_is_confined_to_a_failing_compile test: when two parse contexts assign the same counter-derived name to different bodies, find_in checks only that name and can return the unintended helper. Thus this sentence still states the false self-or-none contract; the order-test failure text at line 774 likewise still says identity is positional. Update both to describe the actual bounded guarantee so future work does not rely on an invariant this commit disproves.
AGENTS.md reference: AGENTS.md:L115-L118
Useful? React with 👍 / 👎.
|
Two verifications worth recording, both reproduced independently after a reviewer raised them. No code changes; The branch carries no net regression against main. All the performance numbers in this thread so far have been commit-to-commit (1.18 → 1.51 → 1.14), which shows each step is sound but structurally cannot see cumulative drift — four commits each landing "back to about where we were" can still sit above
The new refusal rejects nothing in the corpus — checked the strong way. "The engine suite is green" was the weaker evidence for this, because the suite only compiles a subset of On landing that census as a test: deliberately not doing it, and the reason is #915. Nothing in pre-commit or CI runs the One methodology note that inverted a conclusion earlier in this review and is worth the next person not rediscovering: worktree A/B in this repo needs a separate |
Correcting a false claim at the site it was argued is not the same as correcting it. Three copies of "resolves to itself or to nothing, never to another helper" outlived the commit that disproved it -- the test module's header, one assertion message, and one comment -- and a fourth statement, in the order test's failure text, still described identity as positional, which it stopped being two commits earlier. The header now says what name-based identity actually buys (no compile outcome depends on the vector's ORDER) and, in its own paragraph, what it does not: a name embeds the visitor's walk counter, so two parse contexts can attach one name to two different helpers. It names the test that builds that case and the failing compile that bounds it, and says outright not to build mutation work on the stronger invariant. The assertion message was the worst of the three, because it fires while someone is debugging: it told them a helper "must resolve to itself or to nothing" at exactly the moment that is the thing in question. It now states the property the check actually verifies -- a fragment carries the name it was resolved by -- and points at the test that owns the rest. The order test's failure text described the mechanism as it was BEFORE the identity fix. It now leads with the reason the order still matters (two salsa-cached values with derived `PartialEq`, so an unstable order defeats backdating) and keeps the positional history as history, which is where the seed-dependence came from and is worth a reader knowing. No behaviour change; every one of these is a string.
|
Both real, both fixed in Correcting a false claim at the site where it was argued is not the same as correcting it, and that is the mistake here. When I corrected "resolves to itself or to nothing, never to another helper" on The assertion message was the worst of the four, because it fires while someone is debugging: it told them a helper "must resolve to itself or to nothing" at precisely the moment that is the thing in question. It now states what the check actually verifies — a fragment carries the name it was resolved by — and points at the test that owns the rest. The header now separates what name-based identity buys (no compile outcome depends on the vector's order) from what it does not, in its own paragraph, naming the test that builds the collision and the failing compile that bounds it, and saying outright not to build mutation work on the stronger invariant. The order test's failure text described the pre-fix mechanism. It now leads with why the order still matters — two salsa-cached values with derived Verified no copies remain: |
Review SummaryI reviewed the PR carefully, tracing the identity/order fixes and the cross-phase merge through their call sites. Key checks performed:
Overall correctness verdict: correct. No blocking issues found. The two-part fix (order via |
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Fixes #1002
A sub-model that instantiates a stdlib module over a bound input compiled or
failed depending on the process's HashMap seed. On a 30-line fixture, roughly
one run in five returned the unattributed
failed to compile fragments for variables: $⁚sm⁚0⁚arg1, $⁚sm⁚0⁚smth1.Root cause
Not the one the issue proposed.
BuiltinVisitoraccumulated its synthesizedSMOOTH/DELAY/TREND/PREVIOUS helpers in a
HashMapand every producer ofParsedVariableResult::implicit_varsemitted it with.values(). Rust draws afresh
RandomStatekey per map, so two parses of one variable -- in the sameprocess, differing only in their
ModuleIdentContext-- reported the helpers intwo different ORDERS.
ImplicitVarMetaidentified a helper by its POSITION inthat vector, and a position is meaningful only against the exact vector it was
taken from:
model_implicit_var_inforecords it under the no-extra-identscontext while assembly resolves it under the context widened by the instance's
module-input names. When the two orders disagreed the position named an aux
where a module was expected, or the reverse; both fail to lower, so the
sub-model lost every helper fragment.
The fix
Two changes, in three production edits, kept together because they close
different properties.
Identity.
ImplicitVarMeta::namereplacesindex_in_parent. A helperresolves to itself or to nothing, never to another helper.
find_incarries anindex_hintchecked against the name before it is accepted, so the common casestays O(1) (see Performance).
Order.
BuiltinVisitor::varsis anIndexMap, and a newelements_in_stable_orderwalksAst::Arrayed's per-element slot map -- itselfa
HashMap-- at both expansion sites. Without this the two salsa-cachedvectors carrying that order (
ParsedVariableResult::implicit_vars,VariableDeps::implicit_vars) still differ run to run, salsa stops backdating,and the compiled artifact stops being reproducible -- the #595 class, invisible
in numeric results and in the compile outcome alike.
Also deletes
LtmImplicitVarMeta::index_in_parent, which nothing read.What gates what
Measured, not predicted: each edit was reverted alone, faithfully, and the suite
re-run three times. The matrix is in the test module header.
IndexMapelements_in_stable_order, per-element siteper_element_…aloneelements_in_stable_order, shared-visitor siteundimensioned_arrayed_…alonean_implicit_helper_declines_…alonean_implicit_helper_declines_…The identity fix having one gating test is a property of the problem, not thin
coverage: with a stable order a positional index resolves correctly whenever
the two contexts synthesize the same helper set, so only a diverging-set fixture
can tell the two schemes apart.
Performance
find_inreplaces an index lookup with a name match, which is O(k^2) per parentvariable, and k is not small on ordinary models -- an apply-to-all
SMTH1overan N-element dimension mints ~2N helpers on ONE variable. Measured with two
release binaries (worktree at the parent commit vs. the branch), interleaved, on
x[Dim] = SMTH1(y[Dim], 3):C-LEARN is unmoved throughout (0.39s), which is why a C-LEARN-only check missed
the regression and why the synthetic is in the record.
Verification
Full pre-commit gate green on each commit. 5553 lib + 647 integration. The
#[ignore]d tier has exactly its seven pre-existing failures, name for nameagainst #915. The original reproduction is 0/12.
Three adversarial review rounds; the first found a live coverage gap this
originally shipped with (the shared-visitor call site had no test, and a
name-only probe was structurally blind to it because that arm keeps names
stable and moves only the binding), a tautological anti-vacuity guard, and two
wrong cells in the mutation matrix. All fixed, each with the demonstration in
the commit message.
Not closed by this PR
randomising implicit-helper diagnostics) does not reproduce, and the reason is
structural:
collect_all_diagnosticsprobes helpers with the empty input setAND derives them from
model_implicit_var_info, which uses the same context,so no second context exists on that path. Kept as a guard test with that
reasoning recorded, so it starts working if the probe is ever changed to use
real instantiation input sets.
synthesizes genuinely different helpers (
PREVIOUSover a bound input whoseport lacks
access="input"), a model's layout and its runlists disagree aboutwhich helpers exist and the project fails to compile. Deterministic,
pre-existing (verified byte-identical at the parent commit), and engine: decouple module-aware parse context from per-variable parse cache #372's
territory. This PR only makes the mis-resolution loud instead of silent.
Arrayedelement with itsown init equation, or a variable with
compat.active_initial, makes theinitial parse read a different equation while the helper-naming counter
restarts at zero -- so two bodies can claim one name, which
model_implicit_var_infocollapses andcompute_layoutgives one slot. Foundwhile writing the tripwire, pre-existing, and disclosed on
repeated_implicit_helper_names_carry_identical_helpersrather than fixed:the fix is a phase discriminator in the synthesized name.
🤖 Generated with Claude Code
https://claude.ai/code/session_01S3vQ72pUeYXdMgCv7sSjaB