engine: replace base_from with from_salsa constructor#379
Conversation
Replace the monolithic `Project::base_from` with `from_salsa` which builds a Project from a pre-synced salsa database. All variable parsing comes from salsa-cached results instead of duplicating the parsing/DB-setup logic. The new constructor takes a salsa DB and SourceProject (already synced by the caller), eliminating the local DB creation and `cached_sources` parameter that `base_from` needed. A convenience wrapper `from_datamodel` handles the common case of creating a local DB and syncing. For stdlib (implicit) models, all variable names are passed as extra module idents so PREVIOUS expansion uses module expansion instead of LoadPrev. This matches the behavior of the old `ModelStage0::new()` for implicit models, where module inputs lack persistent slots in prev_values.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e9cfa24f5a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
src/simlin-engine/src/project.rs
Outdated
| models, | ||
| model_order: ordered_models, | ||
| errors: project_errors, | ||
| errors: vec![], |
There was a problem hiding this comment.
Preserve project-level unit definition errors
from_salsa now hardcodes errors: vec![], which drops the UnitDefinitionErrors that Project::base_from previously surfaced when Context::new_with_builtins failed. In the test/testing construction path (Project::from/from_datamodel), this means malformed project unit declarations are silently accepted because project_units_context only accumulates diagnostics in salsa and nothing copies them onto Project.errors; callers like TestProject::compile and build_sim check compiled.errors to reject invalid projects, so they can now incorrectly proceed with a default unit context.
Useful? React with 👍 / 👎.
Code Review: engine: replace base_from with from_salsa constructorSummaryThis PR replaces the monolithic
FindingsNo bugs found. Minor observations (non-blocking)
VerdictCorrect. The patch is a clean refactor that consolidates variable parsing through salsa-cached results. Existing code and tests should not break. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #379 +/- ##
==========================================
+ Coverage 76.79% 76.81% +0.01%
==========================================
Files 143 143
Lines 36171 36171
==========================================
+ Hits 27777 27784 +7
+ Misses 8394 8387 -7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
After calling project_units_context, collect accumulated CompilationDiagnostics for unit definition errors and convert them to Error instances stored in Project.errors. Without this, the from_salsa constructor always produced an empty errors vec, so callers inspecting compiled.errors (e.g. test_common helpers) would silently miss malformed unit definitions. Also restore the implicit-var recursion guard assertion that was present in ModelStage0::new but dropped in the from_salsa path, and rename the opaque "dummy" variable to "nested_implicit".
Code ReviewReviewed the replacement of AnalysisChanges reviewed:
Key areas verified:
FindingsNo bugs found. The refactoring correctly eliminates redundant parsing by leveraging salsa-cached results, simplifies the constructor API (removing the VerdictCorrect — The patch is free of bugs and blocking issues. Existing code and tests will not break. |
Use the canonical HashMap key (always lowercase) for the
starts_with("stdlib⁚") check instead of the raw model name,
so non-canonical spellings like Stdlib⁚Delay1 are handled
correctly. Also bind model_name once to reduce repeated
src_model.name(db) calls.
Code ReviewThis PR replaces the monolithic Project::base_from with two cleaner constructors: from_salsa (builds from a pre-synced salsa database) and from_datamodel (convenience wrapper). The refactoring eliminates duplicated parsing/DB-setup logic by reading all variable parsing results from salsa-cached tracked functions. Architecture: The split into from_salsa + from_datamodel is clean. from_salsa takes an already-synced DB and SourceProject, while from_datamodel handles the common create-and-sync pattern. This removes the awkward Option parameter from the old base_from. Stdlib module ident handling: Passing all variable names as extra_module_idents for stdlib models is well-motivated -- module inputs in submodules lack persistent slots in prev_values, so LoadPrev would be incorrect. Non-stdlib models correctly rely on model_module_ident_context to collect module idents from the model own variables. Error recovery from salsa accumulator: The pattern of recovering CompilationDiagnostic from project_units_context::accumulated and filtering for DiagnosticError::Unit is correct. Error detail formatting differs slightly from the old path (old code included unit_name in the message while the salsa accumulator drops it), but this is a pre-existing characteristic of the salsa path, not introduced by this PR. Implicit var parsing: The direct parse_var call for SMOOTH/DELAY expansion implicit vars with the debug_assert guard for nested implicit vars is consistent with the old behavior. Test coverage: The new test validates the error accumulation path. All unit inference tests are updated to the new API. No bugs found. The refactoring is mechanical and correct -- the behavioral semantics are preserved while eliminating code duplication. Verdict: Correct -- existing code and tests will not break. The patch is a clean refactoring with no bugs or blocking issues. |
Include the failing unit name in UnitDefinitionErrors details so
callers can identify which unit definition is broken. The salsa
accumulator in project_units_context now stores the unit name in
the Diagnostic.variable field; from_salsa recovers it and formats
errors as "{name}: {err}" matching the old base_from behavior.
Also tighten stdlib model detection to check against the known
crate::stdlib::MODEL_NAMES list instead of just the "stdlib⁚"
prefix, so user models with that prefix are not incorrectly
classified as implicit.
Code ReviewReviewed the replacement of the monolithic AnalysisThe refactoring is well-structured:
VerdictCorrect. No bugs found. The patch maintains behavioral equivalence with the old code while eliminating redundant parsing through salsa caching. Existing tests and the new test adequately cover the changes. |
Review SummaryThree review iterations addressed feedback from both automated reviewers: Iteration 1 fixed a P2 behavioral regression where Iteration 2 tightened stdlib model detection to use the canonical HashMap key instead of the raw model name, ensuring non-canonical spellings are handled correctly. Iteration 3 further improved the stdlib check to validate against the known Both reviewers passed with no actionable issues in the final iteration. |
Summary
Project::base_fromwithfrom_salsawhich builds a Project from a pre-synced salsa databasefrom_datamodelhandles the common case of creating a local DB and syncingFixes #376
Test plan