You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
engine: salsa::Update on compiled bytecode uses PartialEq over f64/NaN (benign missed-backdate) #642
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::vmSpecs (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.
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.
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/Expr2Const level would address all three issues together.
Activity
bpowers commentedon Jul 25, 2026
Cross-reference: #987 records the same
f64-in-a-derived-PartialEqroot forModelStage0/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, andparse_source_variable_with_module_contextare all tracked and read by other tracked queries. A bit-pattern (f64::to_bits) equality at theExpr0/Expr2Constlevel would address all three issues together.