Skip to content

engine: Ident<State> doc comment claims a salsa::Update delegation the derive's State bound makes impossible #972

Closed

Description

@bpowers

Problem

The doc comment on Ident<State> in src/simlin-engine/src/common.rs (lines 2264-2273 at HEAD) says:

The derived PartialEq/Eq/Hash/Ord/PartialOrd/salsa::Update delegate to that handle's manual impls (value equality, value-based hash consistent with Borrow<str>, lexicographic ordering), preserving the previous String-backed semantics.

For salsa::Update this delegation cannot happen. Salsa 0.26's derive macro adds a salsa::Update bound to every type parameter (add_trait_bounds in salsa-macros' src/update.rs:154-158, verified in the vendored salsa-macros-0.26.2 source), so the generated impl is:

unsafe impl<State: salsa::Update> salsa::Update for Ident<State> { ... }

The Canonical marker type (common.rs ~2257) derives only Debug/Clone/Copy/PartialEq/Eq/Hash/PartialOrd/Ord -- no salsa::Update -- so Ident<Canonical>: salsa::Update is never satisfiable. A compile probe confirms: asserting the bound yields E0277 ("the trait bound common::Canonical: salsa::Update is not satisfied").

What actually happens (sound, but not what the comment says)

An Ident<Canonical> field inside a larger #[derive(salsa::Update)] type resolves through salsa's autoref-specialization fallback (salsa::update::helper::Dispatch<T> with the Fallback impl for T: 'static + PartialEq, which calls update_fallback: compare via PartialEq, overwrite, report changed iff different). Because Ident's derived PartialEq bottoms out in CanonicalStorage's value-correct pointer equality, the fallback is behaviorally equivalent to the manual CanonicalStorage::maybe_update -- so this is a documentation inaccuracy, not a correctness bug. But the comment claims a delegation path that does not exist.

Note the related claim on CanonicalStorage itself (common.rs ~204-208, "the public newtypes keep #[derive(salsa::Update)], whose per-field dispatch finds this impl") IS accurate for the non-generic newtypes -- only the generic Ident<State> is affected, because only it picks up the added type-parameter bound.

Why it matters

Anyone reasoning about salsa invalidation semantics from these docs (e.g. auditing maybe_update behavior for backdating) will be misled into thinking the manual impl runs for Ident<Canonical> fields. The soundness argument for the current behavior (PartialEq fallback is value-correct here) is real but undocumented.

Component

  • src/simlin-engine/src/common.rs (Ident<State>, Canonical/Raw markers)

Possible fixes (small doc/cleanup item)

  1. Correct the comment: state that the derived salsa::Update impl on Ident<State> is unsatisfiable for Canonical/Raw (no Update impl on the markers) and that containers resolve Ident<Canonical> fields through salsa's 'static + PartialEq compare-and-replace fallback, which is value-correct via CanonicalStorage's PartialEq; or
  2. Give the Canonical/Raw marker types trivial salsa::Update impls (sound: the only State-typed field is PhantomData<State>), making the derived impl genuinely usable so the delegation the comment describes actually happens. Then per-field dispatch on inner: CanonicalStorage does find the manual impl.

Option 2 plus a one-line comment tweak is probably cleanest; either way the comment should stop claiming a delegation that cannot occur.

Discovery context

Found during a review of salsa::Update derives on branch steelman-first-boxes (2026-07-17); the inaccuracy is pre-existing on main. Verified against vendored salsa-macros-0.26.2/salsa-0.26.2 sources and an E0277 compile probe.

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