refactor: remove unreachable Partition delta-computation interface methods#1896
Conversation
…thods optimiser.ts's computeQualityGain (the only caller of CPM/modularity delta computation in the Leiden hot loop) calls the standalone diffCPM/diffModularity functions directly — it never calls partition.deltaCPM(...), partition.deltaModularityDirected(...), or partition.deltaModularityUndirected(...). Confirmed via repo-wide grep that these three Partition interface methods, plus getCandidateCommunityCount, have zero callers in src/, tests/, or scripts, and that Partition/makePartition are not part of the public API (src/index.ts). Verified dead empirically, not just statically: replaced each of the four functions' bodies with a throw and ran the full test suite (3549 tests) — all passed, proving no code path anywhere reaches them. This also revealed that the "directed modularity delta — exact regression" tests added by #1755 (pinning computeDeltaModularityDirected's assumed output) actually exercise a different function — diffModularityDirected in modularity.ts, reached via computeQualityGain — since detectClusters never calls the Partition interface method. Corrected that test's comment accordingly instead of leaving it pointing at a deleted function. Removed: - The four dead Partition interface methods (deltaCPM, deltaModularityDirected, deltaModularityUndirected, getCandidateCommunityCount) and their backing implementations (computeDeltaCPM, computeDeltaModularityDirected, computeDeltaModularityUndirected, and the CPM/directed-term helper functions extracted in #1755/phase-22 that existed solely to serve them). - fgetOrZero (typed-array-helpers.ts), which becomes fully unreachable once computeDeltaModularityDirected (its only caller) is gone — it was extracted in #1755 specifically for that function. Removed its direct unit-test block along with it. Chose removal over wiring computeQualityGain to the Partition methods (deduplicating diffCPM/diffModularity vs. computeDeltaCPM/computeDeltaModularityDirected/ computeDeltaModularityUndirected) because the two implementations read through different data-access layers (raw PartitionState typed arrays vs. the PartitionView getter interface) — swapping which one runs in the Leiden hot loop would need rigorous before/after numerical verification on real data to rule out subtle divergence, on a file with a track record of exactly that kind of bug (#1734, #1755). Removal of genuinely unreachable code carries none of that risk. Verified no behavioral change: built this repo's own dependency graph (920 files / 19285 function-level nodes) and ran detectClusters directly (bypassing louvainCommunities' native-Rust preference to exercise the changed JS path) at file- and function-level granularity, both modularity and CPM quality functions, 3 resolutions x 3 random seeds (36 combinations) — before/after membership + quality() output is byte-for-byte identical (matching SHA-256). Also confirmed `codegraph communities -T --json` and `npm run typecheck`/ `npm run lint`/`npm test` (216 files, 3545 passed, 30 skipped, 2 todo) are unaffected. Filed #1895 to track codegraph's own dead-code detector blind spot (an object-literal-property-value reference counts as liveness without checking whether the resulting property is ever invoked) — out of scope to fix here. diff-impact --staged: 1 function changed (makePartition) -> 4 transitive callers across 2 files, all of which only use surviving Partition methods. Fixes #1770 docs check acknowledged Impact: 1 functions changed, 4 affected
Greptile SummaryThis PR removes four dead interface methods (
Confidence Score: 5/5Safe to merge — removes verified dead code with no live callers; all 3549 tests pass and community detection output is byte-identical before and after. The deleted interface methods have zero callers in the codebase (confirmed by grepping src/), the actual hot-loop computation routes exclusively through standalone diffCPM/diffModularity functions in optimiser.ts, and the PR description documents an empirical proof (replacing the functions with throw left the full test suite green). The only change to surviving code is the test comment correction, which is accurate. No files require special attention — all three files are straightforward deletions or comment corrections with no logic changes to surviving code paths. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[optimiser.ts\ncomputeQualityGain] -->|quality === 'cpm'| B[cpm.ts\ndiffCPM]
A -->|quality === 'modularity'| C[modularity.ts\ndiffModularity]
C -->|graph.directed| D[modularity.ts\ndiffModularityDirected]
C -->|undirected| E[modularity.ts\ndiffModularityUndirected]
subgraph removed["Removed dead code (this PR)"]
F["Partition.deltaCPM()"]
G["Partition.deltaModularityDirected()"]
H["Partition.deltaModularityUndirected()"]
I["Partition.getCandidateCommunityCount()"]
J["fgetOrZero() in typed-array-helpers.ts"]
end
style removed fill:#fee2e2,stroke:#ef4444,color:#7f1d1d
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[optimiser.ts\ncomputeQualityGain] -->|quality === 'cpm'| B[cpm.ts\ndiffCPM]
A -->|quality === 'modularity'| C[modularity.ts\ndiffModularity]
C -->|graph.directed| D[modularity.ts\ndiffModularityDirected]
C -->|undirected| E[modularity.ts\ndiffModularityUndirected]
subgraph removed["Removed dead code (this PR)"]
F["Partition.deltaCPM()"]
G["Partition.deltaModularityDirected()"]
H["Partition.deltaModularityUndirected()"]
I["Partition.getCandidateCommunityCount()"]
J["fgetOrZero() in typed-array-helpers.ts"]
end
style removed fill:#fee2e2,stroke:#ef4444,color:#7f1d1d
Reviews (1): Last reviewed commit: "refactor: remove unreachable Partition d..." | Re-trigger Greptile |
Codegraph Impact Analysis1 functions changed → 4 callers affected across 2 files
|
Summary
Partition.deltaCPM/.deltaModularityDirected/.deltaModularityUndirected/getCandidateCommunityCountinterface methods have zero callers anywhere —computeQualityGain(the only caller of delta computation in the Leiden hot loop) calls standalonediffCPM/diffModularityfunctions directly instead. ConfirmedPartition/makePartitionaren't part of the public API (src/index.tsexports nothing from the leiden module).throwand ran the full suite; all 3549 tests still passed, proving leiden/partition.ts: computeDeltaModularityDirected exceeds cyclomatic threshold (cyc=11) #1755's "directed modularity delta" test actually exercises a different function (diffModularityDirectedinmodularity.ts) via the real call path. Corrected that misattributed test comment. Also removedfgetOrZero(added by leiden/partition.ts: computeDeltaModularityDirected exceeds cyclomatic threshold (cyc=11) #1755), now orphaned as a direct consequence — leaving it would ship newly-created dead code from this very change.Closes #1770
Test plan
npm test— full suite green (3545 passed, 0 failed)npm run lint/npm run typecheck— cleanFiled #1895 for codegraph's own dead-code detector blind spot found during investigation: object-literal property-value references count as liveness without checking if the property is ever invoked (not fixed here, out of scope).
Stacked on #1894 (base branch
fix/issue-1769-codegraph-method-attribution) — only the leiden/test diff is this issue's change.