Skip to content

engine: two offset machineries disagree on submodel size with a table-only variable (latent off-by-N) #644

@bpowers

Description

@bpowers

Problem

Two independent offset machineries size a module-typed body variable differently when the submodel contains a table-only (lookup-only) variable:

  • calc_flattened_offsets_incremental (src/simlin-engine/src/db/assemble.rs) sizes a module-typed body variable by the sum of its sub_offsets entry sizes, which excludes table-only / lookup-only variables (they are skipped from the offsets map).
  • compute_layout (src/simlin-engine/src/db/layout.rs) sizes the same submodule by the full sub_layout.n_slots, which does count table-only slots.

If a submodel contains a table-only variable (the standalone lookup-only kind from #606) and is instantiated as a module, the two machineries can disagree on the submodule's size, corrupting result-map slot offsets (an off-by-N in the result map).

Why it matters

This is a latent correctness bug: result-map slot offsets could silently point at the wrong slots for any model that instantiates such a submodel as a module. It produces wrong numbers, not a crash.

Current status

Components affected

  • src/simlin-engine/src/db/assemble.rs (calc_flattened_offsets_incremental)
  • src/simlin-engine/src/db/layout.rs (compute_layout)

Possible approach

Reconcile the two size computations so both either include or exclude table-only slots consistently. Add a regression test: a submodel containing a lookup-only variable, instantiated as a module, asserting the results-map offsets match the assembled layout (i.e. the two machineries agree).

Severity

medium / latent correctness bug.

Context

Identified during the salsa-pipeline-cleanup refactor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingengineIssues with the rust-based simulation enginerustPull requests that update Rust codetech debt

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions