Repository navigation
Description
Problem
After #966 landed the cached stage queries, src/simlin-engine/src/db/ carries two different "is this a stdlib model" predicates about 60 lines apart in the same call path, and they disagree on a real input.
check_model_units' skip gate (src/simlin-engine/src/db/units.rs:189) tests the bare prefix:
if model.name(db).starts_with("stdlib\u{205A}") {
return;
}db::stages::model_is_stdlib (src/simlin-engine/src/db/stages.rs:107), which decides ModelStage0::implicit for the stage check_model_units then reads, additionally requires the suffix to name a real stdlib model:
pub(super) fn model_is_stdlib(canonical_model_name: &str) -> bool {
canonical_model_name
.strip_prefix("stdlib\u{205A}")
.is_some_and(|suffix| crate::stdlib::MODEL_NAMES.contains(&suffix))
}They disagree for a model named with the stdlib prefix but a suffix that is not in MODEL_NAMES -- e.g. an imported stdlib⁚bogus. The bare-prefix gate silently skips unit-checking it (treating it as a template), while the stage query treats it as an ordinary user model (implicit: false).
Why it matters
stdlib⁚ uses U+205A (TWO DOT PUNCTUATION), which ordinary model creation never produces -- but an import can carry any model name, so a prefixed-but-unknown model is reachable input, not a hypothetical. Whichever answer is right, having the two questions answered differently by adjacent code is the drift the #966 work set out to remove: a reader who finds one predicate has no signal that the other exists.
Both sites currently carry comments explaining that the divergence is deliberate (units.rs: "This is deliberately the BARE prefix test... The two answer different questions... Do not unify them without deciding that."), so this is a documented inconsistency awaiting an explicit decision, not an unnoticed bug. It was left alone during #966 specifically because unifying it is a behaviour change and #966 needed to be behaviour-preserving.
The two readings really are different questions:
- units.rs asks "is this model worth unit-checking on its own?" -- a model sitting under the stdlib namespace is arguably a generic template regardless of its suffix, and unit-checking it would produce spurious errors.
- stages.rs asks "is this one of the templates
db::syncsplices in?" -- flagging a bare-prefix importimplicitwould mark a user model as a generic template, which affectsextra_module_idents(and therefore whichModuleIdentContextits variables parse under).
So "just unify them" is not obviously correct in either direction.
Components affected
src/simlin-engine/src/db/units.rs(check_model_units, the skip gate)src/simlin-engine/src/db/stages.rs(model_is_stdlib,extra_module_idents,model_stage0)src/simlin-engine/src/db/ltm/loops.rs:147-- a third bare-prefix site (model.name(db).starts_with("stdlib\u{205A}")), which should be included in whatever decision is madesrc/simlin-engine/src/db/units.rs:302-- a fourth bare-prefix test, on submodel names
Possible approaches
- Decide the two questions are genuinely distinct and name them as such. Give each predicate a name that states its question (
model_is_stdlib_namespacevsmodel_is_stdlib_template), put both in one module, and have every site call one of the two by name. No behaviour change; the drift becomes impossible to reintroduce silently because there is no barestarts_withliteral left to copy. - Decide they are the same question and unify on the strict form. A prefixed-but-unknown model then starts getting unit-checked. Needs a call for whether that is desirable.
- Decide they are the same question and unify on the bare form. A prefixed-but-unknown model then gets marked
implicit, changing itsModuleIdentContext. Less attractive -- the strict form's rustdoc argues explicitly against marking a user model a template.
Approach 1 is the cheapest and preserves current behaviour; it should probably be paired with a test that pins whichever behaviour each site is supposed to have on a stdlib⁚bogus input (today only the strict predicate is pinned, by stages_tests::model_is_stdlib_requires_a_known_stdlib_suffix).
Related (not a duplicate)
- engine: three look-alike separator characters are written as literals #565 -- the three visually-indistinguishable separator characters (U+205A / U+00B7 / ASCII
.) being load-bearing with no type-level guard. That is about the characters; this is about two predicates over the same character disagreeing on the suffix. A fix for engine: three look-alike separator characters are written as literals #565 (a typed stdlib-name newtype) would be a natural home for a single canonical predicate, but neither issue subsumes the other.
Severity
Low -- no wrong simulation results; a narrow input is either unit-checked or not depending on which of two adjacent predicates you read.
Context
Identified while implementing #966 (caching ModelStage0/ModelStage1 as salsa-tracked queries) on branch roundtrips-track-b. Deliberately left as a documented inconsistency in that change because unifying it is a behaviour change that needs its own decision.
Activity