Repository navigation
engine: split ltm.rs into module directory - #498
Conversation
|
Reviewed the split of No findings. Verified:
Overall correctness: correct. Pure code movement plus an orthogonal env-sanitization fix; no behavior change observed. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #498 +/- ##
==========================================
- Coverage 82.39% 82.38% -0.01%
==========================================
Files 238 243 +5
Lines 61519 61531 +12
==========================================
+ Hits 50689 50693 +4
- Misses 10830 10838 +8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Move the 5837-line src/simlin-engine/src/ltm.rs into a module directory
at src/simlin-engine/src/ltm/ with submodules organised by logical area:
- types.rs: LinkPolarity, Link, Loop, LoopPolarity, TruncatedByBudget,
ModuleLtmRole and classify_module_for_ltm / normalize_module_ref
helpers (216 lines)
- partitions.rs: CyclePartitions plus the generic Tarjan SCC used by
compute_cycle_partitions (139 lines)
- polarity.rs: static polarity analysis on Expr2 ASTs --
analyze_link_polarity and the small expression predicates it leans
on (472 lines)
- indexed.rs: compact integer-indexed graph plus the Johnson 1975
elementary-circuit enumerator and iterative Tarjan SCC; Tiernan
1970 enumerator retained under cfg(test) as the equivalence oracle
(719 lines)
- graph.rs: public CausalGraph type owning model adjacency, stock
identity, variable AST references for polarity, and recursively
built sub-graphs for dynamic modules (939 lines)
- tests.rs: integration-style tests spanning all submodules
(3391 lines)
mod.rs re-exports every public item so crate::ltm::* paths are
unchanged for external callers. Pure code movement; no behaviour
change.
Motivation: ltm.rs was approaching the project's 6000-line lint
threshold with multiple in-flight LTM PRs adding to it. Splitting now
lets follow-on PRs land in narrower files with smaller, more focused
diffs against the specific submodule each touches.
Visibility changes: items previously private to ltm.rs that are now
accessed across submodule boundaries (IndexedGraph and its internals,
polarity helpers, get_variable_dependencies,
analyze_graphical_function_polarity) are widened to pub(super) so the
tests submodule and graph.rs can reach them; nothing is exposed beyond
the ltm module tree. The public API surface at crate::ltm::* is
unchanged.
24c51b9 to
7dc8620
Compare
bpowers
left a comment
There was a problem hiding this comment.
Rebased onto post-#489 main
- Dropped the redundant prep commit (older vars()-based GIT_* strip).
Main now carries the vars_os + as_encoded_bytes version from #489
which is strictly better. - Re-applied main's enumerate_module_pathways node-count bound
in the new src/simlin-engine/src/ltm/graph.rs location during the
rebase. Behavior on the refactor branch is unchanged from
pre-rebase: every existing test continues to pass, no expected
values modified.
mergeable: MERGEABLE / CLEAN after force-push.
|
Reviewed the refactor. Verified that this is pure code movement: re-exports in Overall correctness: correct. |
Summary
Move the 5837-line src/simlin-engine/src/ltm.rs into a module directory at src/simlin-engine/src/ltm/ with submodules organised by logical area.
Module layout
mod.rscrate::ltm::*, declares submodules, definesMAX_LTM_SCC_NODESand the top-leveldetect_loopshelper.types.rsLinkPolarity,Link,Loop,LoopPolarity,TruncatedByBudget,ModuleLtmRole, plusclassify_module_for_ltm/normalize_module_refhelpers.partitions.rsCyclePartitionsplus the generic Tarjan SCC used bycompute_cycle_partitions.polarity.rsExpr2ASTs:analyze_link_polarityand the small expression predicates it leans on (flip_polarity,expr_references_var,is_positive_constant, etc.).indexed.rscfg(test)as the equivalence oracle.graph.rsCausalGraphtype owning model adjacency, stock identity, variable AST references for polarity, and recursively-built sub-graphs for dynamic modules.tests.rsWhy now
ltm.rs was at 5837 lines, well into the project's 6000-line lint warning zone. Six in-flight LTM PRs (#489, #490, #491, #493, #494, #496 -- branches
ltm/312-module-pathway-depth,ltm/485-polarity-confidence,ltm/480-array-reducer-polarity,ltm/460-johnson-per-scc-alloc,ltm/308-canonical-cycle-dedup,ltm/482-variable-level-loops-first) all add to this file. Splitting first lets the follow-on PRs land in narrower, more focused files.API unchanged
mod.rsre-exports every public item; every existingcrate::ltm::Fooimport in the workspace continues to resolve. Pure code movement, no behaviour change.The only visibility widening is
pub(super)for items that are now accessed across submodule boundaries (IndexedGraphand its internals, polarity helpers,get_variable_dependencies,analyze_graphical_function_polarity). Nothing is exposed beyond theltmmodule tree.Stacking plan
After this lands, the six in-flight LTM PRs rebase onto the new layout. Each PR's diff against ltm.rs becomes a diff against the specific submodule it actually touches, dramatically reducing conflict surface.
Prep commit
The first commit (
serve: clear inherited GIT_* env in git probe and tests) is the same fix already onltm/312-module-pathway-depth, applied here so the project's pre-commit hook can pass on this branch. Without it, workspace tests inheritGIT_DIR/GIT_WORK_TREEfrom the outergit commitand thesimlin-serve::git::tests::invalidate_repo_cache_removes_cached_entries_for_that_repotest recursively invokes the parent pre-commit hook, blocking every subsequent commit on this and the other LTM branches that don't yet carry the fix.Test plan
cargo test -p simlin-enginecargo test -p simlin-engine --features file_iocargo clippy --workspace --all-targets -- -D warningscargo fmt --check