Skip to content

Analyze and lint module graphs inside the large Rust crates #253

Open

Description

@zkochan

Follow-up to pnpm/pnpm#17615, which added the crate layer check (pnpm/tasks/crate-layers, crate-layers.toml). That check sees only the graph between crates. Most code sits inside a few large crates, and their module graphs are tangled.

Findings

An approximate module graph built from crate:: paths (it misses super:: references, so it undercounts):

Crate Code lines Largest module cycle
pnpm-resolving-deps-resolver 16k 11 modules, 95% of the code
pnpm-deps-restorer 26k 25 modules, 77%
pnpm-package-manager 40k 11 modules, 66%
pnpm-config 12k 7 modules, 57%

In pnpm-package-manager, install and optimistic_repeat_install depend on each other. install calls the fast path's validation and settings about 30 times, and the fast path uses install's StateWrite, StateProjects, and FreshnessCheckError. The rule "is the recorded install state still valid" is split across both. Since 2026-08-01, 66 of 111 commits to optimistic_repeat_install and 164 of 277 to install were fixes.

Plan

Analysis

Tooling

Refactors the analysis points to


Written by an agent (Claude Code, claude-opus-5-5).

Activity

  1. self-assigned this
    on Nov 3, 2026
  2. zkochan commented on Nov 5, 2026

    @zkochan
    MemberAuthor

    pnpm/pnpm#17743 covers the tooling item "Per-crate direct-dependency ratchet and a transitive-dependency budget for the model and service layers". It adds a [direct_dependencies] ratchet table to crate-layers.toml and a max_transitive_dependencies cap on the model layer (18) and the service layer (35), both set to today's maxima, plus a crate-layers dependencies report. The other open items are not part of it.


    Written by an agent (Claude Code, claude-opus-5-5).

  3. zkochan commented on Nov 5, 2026

    @zkochan
    MemberAuthor

    pnpm/pnpm#17748 covers the tooling item "Leaky-API check". crate-layers leaks lists each crate that names a dependency's items in its public signatures without re-exporting them, with the number of crates that depend on both. crate-layers check ratchets the count per crate through a new [leaked_dependencies] table. The candidate pnpm-network → pnpm-http shows up with 8 items and 16 shared dependents. The largest is pnpm-resolving-resolver-base → pnpm-lockfile with 21. Fixing the leaks themselves is not part of the PR.


    Written by an agent (Claude Code, claude-opus-5-5).

  4. zkochan commented on Nov 13, 2026

    @zkochan
    MemberAuthor

    On the remaining pnpm-config item: after pnpm/pnpm#18068 it has 20 direct and 40 transitive dependencies. The rest comes from pnpm-lockfile (18 transitive), pnpm-workspace (15), and pnpm-resolving-resolver-base (24, mostly through pnpm-lockfile). Those are the formats pnpm-config exists to read: the workspace manifest and the lockfile settings. The only edges that add crates nothing else adds are now single crates (for example pnpm-workspace-task-scheduler, which Rust's orphan rule pins to pnpm-config). Further cuts would each save one or two crates. I suggest closing this item unless a specific dependency becomes a build-time or layering problem.


    Written by an agent (Claude Code, claude-opus-5-5).

  5. zkochan commented on Nov 27, 2026

    @zkochan
    MemberAuthor

    pnpm/pnpm#18490 covers the tooling item "function-level call graph from a rust-analyzer SCIP index". It adds two reports that read the index:

    • crate-layers overlaps lists the groups of functions in different top-level modules that access the same fields. The call graph drops a pair when one function reaches the other.
    • crate-layers fields lists the types whose fields two top-level modules both access, and --type lists the functions per module.

    Checked against the case this issue started from: on the tree before pnpm/pnpm#17686, fields lists WorkspaceStateSettings third, with 51 fields accessed in optimistic_repeat_install (21 functions) and 10 in install (4 functions). On main the type is second: install_state reads 60 fields, and install (14 fields, 6 functions) and optimistic_repeat_install (10 fields, 7 functions) still read it directly.

    overlaps prints 112 groups on main. Two that look worth a follow-up: four functions build a NodeResolver from the same four Config fields, and five functions in pnpm-cli, pnpm-package-manager, and pnpr derive lockfile settings from the same six Config fields.

    The reports are not part of crate-layers check, and CI does not run them: making the index takes rust-analyzer about 3 minutes and 13 GB.

    The pnpm-config item is not part of the PR. Its count is now 22 direct and 49 transitive workspace dependencies, up from 20 and 40 after pnpm/pnpm#18068. All nine added crates were created since then: pnpm-ffi-process and pnpm-time are direct, and pnpm-ffi-fs, pnpm-ffi-security, pnpm-ffi-signal, pnpm-ffi-sqlite, pnpm-ffi-webcontainer, pnpm-signal-registry, and pnpm-webcontainer-sys come through other crates. All nine are in the foundation layer, so the earlier suggestion to close that item still holds.


    Written by an agent (Claude Code, claude-fable-5-2).

  6. zkochan commented on Nov 27, 2026

    @zkochan
    MemberAuthor

    pnpm/pnpm#18495 covers part of the item "Reduce what pnpm-config pulls in transitively". It takes pnpm-config from 49 to 45 workspace crates and pnpm-workspace from 22 to 17.

    My earlier comment looked only at the edges out of pnpm-config itself. Measuring every edge in its dependency graph found one deeper: pnpm-workspace → pnpm-workspace-projects-graph, which existed for a 62-line adapter (GraphPkg) and brought in the graph crate, pnpm-catalogs-resolver, pnpm-catalogs-protocol-parser, and pnpm-workspace-range-resolver. The PR moves the adapter to pnpm-package-manager. The crates that rebuild after an edit to the graph crate drop from 25 to 10.

    After it, no single edge removes more than three crates:

    Edge Crates it alone brings in What cutting it takes
    pnpm-config → pnpm-store-dir 3 (pnpm-store-dir, pnpm-ffi-sqlite, pnpm-shared-artifact-protocol) Splitting the StoreDir path type from the store index
    pnpm-config → pnpm-resolving-resolver-base 2 (and pnpm-registry) Moving the 15 items pnpm-config takes from it, mostly setting types, to a lower crate
    pnpm-config → pnpm-workspace-task-scheduler 2 (and pnpm-reporter) Replacing the TaskDeclaration trait, which TaskSettings implements, with something the callers pass
    pnpm-config → pnpm-package-is-installable 2 (and pnpm-platform-tags) A new home for SupportedArchitectures

    All four together would leave 36. Each needs a new crate or an API change, and none of the crates they remove is a layering problem, so I suggest closing the item when the PR merges. The one with the most rebuild effect is pnpm-store-dir: it had 57 commits in the last 60 days, and 32 crates rebuild after each.


    Written by an agent (Claude Code, claude-fable-5-2).

  7. zkochan commented on Nov 27, 2026

    @zkochan
    MemberAuthor

    pnpm/pnpm#18495 is merged. pnpm/pnpm#18504 takes the next edge from the table above: pnpm-config → pnpm-workspace-task-scheduler.

    pnpm-config depended on the scheduler only to implement its TaskDeclaration trait for TaskSettings. The trait becomes a struct that pnpm-cli, the only caller, fills through a function it passes. pnpm-config goes from 45 to 43 workspace crates. The crates that rebuild after an edit to the scheduler drop from 21 to 11.

    I read the code behind the other three edges. Each cut removes fewer crates than the table above says, because the types pnpm-config uses need a home it still depends on:

    Edge from pnpm-config Net crates removed What it takes
    pnpm-store-dir 2 A new crate for StoreDir. Its inherent methods sit in eight modules of pnpm-store-dir and would become extension traits or free functions for 32 dependent crates.
    pnpm-resolving-resolver-base 1 A new crate for the 15 items pnpm-config takes from it.
    pnpm-package-is-installable 1 SupportedArchitectures needs pnpm-platform-tags, so that dependency moves with it.

    I recommend closing the item when pnpm/pnpm#18504 merges, with pnpm-config at 43.


    Written by an agent (Claude Code, claude-fable-5-2).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions