Repository navigation
Description
Summary
A sub-model containing a stdlib module call (e.g. sm = SMTH1(port, 3) over a bound input port) compiles nondeterministically: across 8 identical runs of the same fixture, compile_project_incremental returned Ok on 2 and the unattributed
failed to compile fragments for variables: $⁚sm⁚0⁚arg1, $⁚sm⁚0⁚smth1, ...
error on the other 6. Whether the project compiles at all depends on the process's HashMap seed.
Root cause
A HashMap-order-dependent index misalignment between the empty-context implicit-var registry and the with-module-inputs parse of the same parent:
model_implicit_var_infokeys implicit vars by (parent,index_in_parent), computed under one parse context.- When the parent is instantiated with bound inputs, the module-input names widen
model_module_ident_context, which changes the parent's parse and hence the implicit-var set/order. ImplicitVarMeta.index_in_parentcomputed under one context is then resolved under the other, so the identity of a sub-model implicit var is not stable across contexts, and which helper a given index resolves to depends on hash iteration order.
Observable consequences (both verified with fixtures)
- An ordinary sub-model-with-bound-inputs whose implicit helper fails compiles or fails depending on hash seed (the 2/8-vs-6/8 fixture above).
- A phantom module-input dst binding (parent binds
sub.phantomwherephantomis undeclared — itself warned asBadModuleInputDst) makescollect_all_diagnosticsreport implicit-helper Error rows on runs where the project nevertheless compiles.
Why it matters
Same nondeterminism class as #595 / #633 / #859 / #999 (unordered collection order reaching an observable), but here the observable decides compile success, not just which diagnostic is worded how or which variable a warning names. Any test, CI gate, or user workflow touching sub-models with stdlib calls over bound inputs is seed-flaky.
Components
src/simlin-engine/src/db/query.rs—model_implicit_var_info,model_module_ident_contextsrc/simlin-engine/src/db/fragment_compile.rs—lower_implicit_var/index_in_parentresolutionsrc/simlin-engine/src/db/assemble.rs—build_module_inputs
Reproduce
Build a two-model project where main instantiates sub with a bound input, and sub's body is SMTH1(<bound port>, 3); run compile_project_incremental across several fresh processes and observe divergent outcomes (fresh processes get fresh HashMap seeds; within a single process the result is stable).
Distinct from existing issues
- engine: decouple module-aware parse context from per-variable parse cache #372 (decouple module-aware parse context from the per-variable parse cache): tracks the architectural tension between module-aware parsing and salsa cache granularity. This issue is a concrete correctness defect that tension produces — implicit-var identity computed under one context and resolved under another. Fixing engine: decouple module-aware parse context from per-variable parse cache #372's proposed explicit model-level parse-context input would likely be the principled fix here too, so this may resolve alongside it, but the defect stands on its own.
- engine: recurrence inside a module with wired inputs reports a false cycle #573 (dt-recurrence SCC resolution uses no-input
build_var_infowiring): same shape (empty-inputs vs with-inputs divergence within the salsa path) but a different code path (db_dep_graph.rsSCC resolution /element_order), a different consumer, and no nondeterminism component. - engine: C-LEARN fails with "failed to compile fragments" #580 (C-LEARN post-cycle-gate fragment-compile failure on temp-arg helpers): a deterministic fragment-compile failure with a different mechanism.
- engine: parse errors in SMOOTH/DELAY helper variables are hidden #666 / engine: compile_implicit_var_phase_bytecodes still swallows its codegen error (unattributed helper failures) #1000: error attribution/swallowing on the implicit-helper path — those make the failure unattributed; this issue is about the failure (or success) itself being seed-dependent.
Discovery context
Found during adversarial review of the #1000 fix (branch ltm-995-burndown, commit 8608f25). The defect pre-exists that branch — verified identical behavior at parent commit de321e5.
Activity