Skip to content

engine: db.rs is 1 line from the 6000-line lint cap; split before it blocks an unrelated commit #518

@bpowers

Description

@bpowers

Problem

src/simlin-engine/src/db.rs is currently 5999 lines. The repo-wide lint scripts/lint-project.sh enforces a hard MAX_LINES=6000 threshold on Rust source files (rule 2 at scripts/lint-project.sh:38-52), and that lint runs in the pre-commit hook and CI. The file is effectively one line away from breaking pnpm lint: any future addition to db.rs of more than ~1 line will trip the threshold and force whoever is working there to do a tangential refactor before they can commit unrelated changes.

This is the same class of problem as #471 (vdf.rs at 6001 lines), but caught proactively — db.rs is right at the edge rather than already over it.

How it got here

The file crept up to 5999 during the LTM cross-element-aggregate-scoring work on branch ltm-503-cross-element-agg. Several commits on that branch had to actively manage headroom — de-duplicating helpers and moving LTM wiring into sibling modules (db_ltm.rs, ltm_agg.rs) — specifically to stay under the cap. There is no slack left.

Why it matters

  • The next non-trivial change to db.rs will fail pnpm lint / pre-commit / CI on an unrelated diff, the same way engine: vdf.rs exceeds MAX_LINES=6000 lint threshold (6001 lines), breaking pnpm lint #471 broke pnpm lint on main.
  • The hard threshold exists to force modularization of super-sized files; bumping it ad hoc would undermine the policy.
  • db.rs is the salsa-incremental-compilation hub and a high-traffic file (it's where most new compilation/analysis wiring lands), so the squeeze will recur often.

Component

  • src/simlin-engine/src/db.rs
  • Lint rule in scripts/lint-project.sh

What's in db.rs

The salsa machinery: SimlinDb; the SourceProject / SourceModel / SourceVariable salsa inputs; compile_project_incremental; the dependency graph; assemble_module (including a substantial block of LTM wiring in its pass 3); compute_layout; the diagnostic accumulator. It already uses the #[path = "..."] mod ...; pattern to host related code in db_analysis.rs, db_ltm.rs, and ltm_agg.rs.

Possible approaches

Following the existing #[path] submodule precedent (and the #471 fix pattern):

  • Move the assemble_module / compute_layout layout-and-assembly section — or specifically the LTM-wiring portion of assemble_module's pass 3 — into a new sibling submodule (e.g. db_assemble.rs or db_layout.rs) declared via #[path] mod ...; with pub(super) visibility, alongside db_analysis.rs / db_ltm.rs / ltm_agg.rs.
  • Or extract the dependency-graph construction into its own submodule.

The fix is mechanical: find a cohesive 200-500-line cluster and relocate it to a db_<name>.rs submodule. Doing it now (with headroom to spare) is lower-risk than doing it under duress when a feature commit is blocked.

Context

Identified during the LTM cross-element-aggregate-scoring work (docs/design-plans/2026-05-09-ltm-503-cross-element-agg.md / branch ltm-503-cross-element-agg), where keeping db.rs under the cap required repeated headroom management.

Related, lower priority

src/simlin-engine/tests/simulate_ltm.rs is 6652 lines — over the 6000-line threshold — but scripts/lint-project.sh excludes */tests/*, so it does not fail the lint. It is nonetheless a very large test file that would benefit from being split by topic (A2A loops, cross-element loops, polarity analysis, etc.).

Metadata

Metadata

Assignees

No one assigned

    Labels

    engineIssues with the rust-based simulation enginehygieneToil, but its useful to get get too behind on it

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions