Repository navigation
Description
Problem
Two latent unguarded-panic sites on the legacy Project::from_salsa dependency-resolution path crash with an "internal compiler error" / HashMap-index panic on user-controllable input (a module with an empty or dangling model_name, e.g. a freshly-drawn module or a reference to a deleted model).
1. model.rs:173 — unguarded HashMap index in module_deps
In the is_initial branch of module_deps (src/simlin-engine/src/model.rs):
if ctx.is_initial {
let model = ctx.models[model_name]; // <- panics if model_name not in ctx.modelsThis is an unguarded Index on ctx.models. If a Variable::Module references a model_name that is not present in ctx.models, this panics with "no entry found for key" / index panic.
The sibling at model.rs:241-244 (module_output_deps) already guards this correctly:
if !ctx.models.contains_key(model_name) {
return model_err!(BadModelName, model_name.to_string());
}
let model = ctx.models[model_name];Line 173 should do the same — use .get() and return BadModelName (or skip gracefully) rather than indexing unconditionally. The fix is a near-mechanical mirror of the guarded twin 70 lines below it.
2. common.rs:2659 — topo_sort panics on an unknown ident (lower priority, same class)
panic!("internal compiler error: unknown ident {}", ident.as_str());topo_sort panics when a runlist ident has no dependencies entry. This is reachable from the same legacy from_salsa path with a dangling module reference. Lower priority but the same class of latent crash on bad input — should surface as a proper error rather than a panic!.
Why it matters
- Unguarded panic on user-controllable input: an empty/dangling
model_nameis something the UI can produce (a module drawn but not yet wired up, or a reference to a model that was deleted). A panic here is an "internal compiler error" crash rather than a clean diagnostic. - Inconsistency:
model.rs:173is the unguarded twin of an already-guarded sibling (model.rs:241-244) in the same file. The guard pattern is established; line 173 simply was not updated to match. - WASM: under
panic = "abort"(WASM release builds) a panic aborts the entire runtime.
Currently latent (why it is tracked, not urgently fixed)
These sites are only reached via ModelStage1::set_dependencies -> Project::from_salsa, which the engine CLAUDE.md documents as a test-only / legacy path. Production uses db::compile_project_incremental, whose parallel logic at src/simlin-engine/src/db.rs:687 already uses .get(...)?:
let sub_model = project_models.get(sub_model_name.as_ref())?;So the production incremental path is safe; only the legacy monolithic path has the gap.
Components affected
src/simlin-engine/src/model.rs(module_deps, line 173)src/simlin-engine/src/common.rs(topo_sort, line 2659)
Possible approaches
model.rs:173: mirror the guarded twin —contains_key/.get()check returningBadModelName, or.get()and skip the module's deps gracefully.common.rs:2659: return aResult::Err(e.g. aGeneric/BadModelNamecompilation error) instead ofpanic!, so a dangling runlist ident degrades to a diagnostic.
Context / how discovered
Found while fixing a WASM panic with the same root cause in src/simlin-engine/src/units_infer.rs (an empty/dangling model_name caused self.models[model_name] to panic with "no entry found for key"). These two sibling sites share that root cause but were left unfixed because they are on the test-only/legacy from_salsa path. Filed for tracking; not fixed as part of the units_infer work.
Activity
engine: skip unit inference for a module referencing a missing model
engine: stop the legacy from_salsa path panicking on dangling module …
bpowers commentedon Sep 4, 2026
Re-scope, surfaced while writing the engine map for PR #1040 (compiler unification). Both code paths this issue names no longer exist, the panic sites it points at were removed before the code was deleted, and the crash class it describes is pinned by tests on
main. Recommendation: close as resolved. Details follow so the next reader does not have to redo the archaeology.What the named paths became
model.rs:173,module_deps, unguardedctx.models[model_name]40c85bff):ctx.models.get(model_name)with an early return, citing this issue. The whole function was then deleted in PR #991 (a42654bc).common.rs:2659,topo_sort,panic!("internal compiler error: unknown ident ...")if let Some(deps) = dependencies.get(ident)), with the trailingassert_eq!(runlist_len, result.len())downgraded todebug_assert!(result.len() <= runlist_len). The function was then deleted in6783dc01("engine: delete the test-only monolithic compile path", one of the Phase 7 commits of the compiler-unification plan; onmainand an ancestor of PR #1040's base).Project::from_salsa/ModelStage1::set_dependencies, the "legacy path" that reached both6783dc01together withproject.rs,enumerate_modules, and the stage-levelerrors/model_deps/instantiationsfields.db::compile_project_incrementalis the only compiler.None of
fn topo_sort,fn module_deps,fn from_salsa, orfn set_dependenciesexists onorigin/main(d04593e6) or at PR #1040's head (origin/compiler-unification-v2), so the reproduction steps in the description point at code a reader cannot find.What remains of the panic class: nothing reachable
The only topological sort left is the
topo_sort_strclosure insidemodel_dependency_graph_impl(src/simlin-engine/src/db/dep_graph.rs:2342onmain, enclosing fn at:1837;:2188at PR #1040's head). Itsaddlooks dependencies up withdeps.get(name)(:2410, and:2388for resolved-SCC members) and pushes a name only if it is inallowed, the runlist's own variable set. An ident with no dependency entry is visited, contributes no edges, and is not emitted: no panic and no phantom runlist entry.Every production lookup of a module's
model_nameis guarded (mainline numbers):db/diagnostic.rs:1086:let Some(child_model) = project_models.get(..) else { .. }, emitting an ErrorBadModelNameattributed to the module variable when the name is non-empty (added in6783dc01; an empty name, the freshly-drawn state, stays quiet by design).db/assemble.rs:1689-1693:contains_key, thenreturn Err(..).db/layout.rs:51and:206:.get(..)/.get(..).copied().db/layout.rs:399(module_dep_shape) resolves a missing model to an emptyModelShape, so a reference into it fails asDoesNotExist.db/query.rs:1021-1024:contains_key(module-cycle detection from PR Module editing: fix dangling/cyclic/mis-wired reference bugs found by adversarial audit #807).db.rs:872,db/ltm/mod.rs:610-614,db/analysis.rs:1545:?/if let Some.The remaining
panic!sites indep_graph.rsare a#[cfg(test)]helper (:1490-1525) and the SCC /CircularDependencyconsistency invariant (:644); neither is an identifier or model lookup.Current reproduction (already a test)
module_targeting_a_missing_model_errors_without_panicking(src/simlin-engine/src/db/module_cycle_tests.rs:646onmain,:649at PR #1040's head) builds a project withmodule_var("m", "nonexistent")and asserts thatcompile_project_incrementalreturnsErr, thatcollect_all_diagnosticsyields exactly oneBadModelNameError attributed tomain/m, and thatanalyze_modelreturns ananalysis_errorrather than panicking.module_with_an_empty_model_name_is_not_reported_as_dangling(:697) pins the empty-name arm (does not compile, noBadModelName). PR #807'sself_referential_module_errors_without_panickingandmutually_recursive_modules_error_without_panickingcover the cyclic cousin. These run under the pre-commit hook on every commit; I did not re-run them for this comment.Recommendation
Close. The two sites were fixed in #807 and then deleted (#991,
6783dc01); the production path has no unguarded lookup for a dangling modulemodel_name, and the class is pinned end to end. There is no residual scope to retitle this issue onto, so the title is left unchanged.bpowers commentedon Sep 4, 2026
Closing as resolved per the re-scope comment above: the panic sites were guarded in #807 and the code they lived in (
module_deps,topo_sort,Project::from_salsa) was deleted on main by #991 and6783dc01; the only topological sort left (db/dep_graph.rsmodel_dependency_graph_impl) cannot reach an unknown ident, andmodule_targeting_a_missing_model_errors_without_panickingpins the dangling-module case as aBadModelNameerror. Reopen if a current reproduction turns up.