Skip to content

engine: sub-model implicit-var identity is nondeterministic under module-input parse contexts (HashMap-order index misalignment) #1002

Closed

Description

@bpowers

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_info keys 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_parent computed 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)

  1. 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).
  2. A phantom module-input dst binding (parent binds sub.phantom where phantom is undeclared — itself warned as BadModuleInputDst) makes collect_all_diagnostics report 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_context
  • src/simlin-engine/src/db/fragment_compile.rs — lower_implicit_var / index_in_parent resolution
  • src/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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions