Skip to content

engine: salsa::Update on compiled bytecode uses PartialEq over f64/NaN (benign missed-backdate) #642

Closed

Description

@bpowers

Problem

CompiledModule / CompiledSimulation derive salsa::Update, which (via autoref specialization) falls back to the derived PartialEq for the bytecode side-channels. Those side-channels contain f64 values:

  • ByteCode.literals and ByteCodeContext.graphical_functions (src/simlin-engine/src/compiler/symbolic.rs)
  • crate::vm Specs (src/simlin-engine/src/results.rs)

NaN literals are reachable: out-of-range subscripts compile to Const(NaN). Because NaN != NaN under PartialEq, old == new can report "changed" on bit-identical output, defeating salsa's backdating for these outputs.

Why this is benign today

A cache hit is decided by the inputs' revisions, not by the output's PartialEq. The only consumer of these outputs (compile_project_incremental) is non-tracked, so an output that is never backdated costs at most one extra assemble_simulation re-exec -- never a wrong result and never a defeated cache hit.

It is also a pre-existing property of the already-tracked compile_var_fragment / PerVarBytecodes, so this change in framing does not introduce new risk.

Why it still matters

The derived PartialEq is a latent footgun: a future change that makes one of these outputs feed a tracked query would silently lose backdating on any model with NaN literals, with no compile error to flag it. Relying on "the only consumer happens to be non-tracked" is fragile.

Components affected

  • src/simlin-engine/src/compiler/symbolic.rs (ByteCode.literals, ByteCodeContext.graphical_functions)
  • src/simlin-engine/src/results.rs (crate::vm Specs)

Possible approach

Hand-write Update / PartialEq for the bytecode types using bit-pattern (f64::to_bits) float comparison, so NaN compares equal to itself and bit-identical bytecode backdates correctly.

Severity

low / cleanup.

Context

Identified during the salsa-pipeline-cleanup refactor.

Activity

  1. added
    engine
    rust
    on May 31, 2026
  2. bpowers commented on Jul 25, 2026

    @bpowers
    OwnerAuthor

    Cross-reference: #987 records the same f64-in-a-derived-PartialEq root for ModelStage0 / ModelStage1 / db::query::ParsedVariableResult (alongside #981 for the LTM types).

    The "benign because the only consumer is non-tracked" mitigation in this issue does not carry over there -- model_stage0, model_stage1, and parse_source_variable_with_module_context are all tracked and read by other tracked queries. A bit-pattern (f64::to_bits) equality at the Expr0/Expr2 Const level would address all three issues together.

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

    enginerusttech debt

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions