Skip to content

refactor(solver): dedup factorization caching and cross-DB dep helpers#98

Merged
ccomb merged 2 commits into
advanced_haskellfrom
refactor/shared-solver-cleanup
May 28, 2026
Merged

refactor(solver): dedup factorization caching and cross-DB dep helpers#98
ccomb merged 2 commits into
advanced_haskellfrom
refactor/shared-solver-cleanup

Conversation

@ccomb
Copy link
Copy Markdown
Owner

@ccomb ccomb commented May 28, 2026

Summary

A readability pass over SharedSolver.hs that removes duplicated logic without changing behaviour.

  • Factorization caching deduped. The lazy MUMPS factorization was computed-and-cached in two near-identical blocks (solveWithSharedSolver, ensureFactorization). Extracted computeAndStoreFactorization so the precompute + store lives once; the dense-solver fallback stays scoped to the first-solve (cache-miss) path exactly as before.
  • Shared dep-demand helpers. The per-root dep-demand → demand-vector conversion was copied byte-for-byte in three resolvers (resolveDep, resolveDepContribs, and Service.resolveDepWithSubs). Extracted prepareDepDemandVecs, plus depDbsOf for the "DBs referenced at this level" set.
  • Semigroup CrossDBSolution. mergeSolutions is now foldl' (<>) — same summed inventory and base-first / BFS-ordered scalings as the hand-written version.
  • Named map types. Introduced SupplierDemands / DepDemands aliases in Matrix (where the type is produced) and used them across the affected signatures, replacing the verbose nested-Map spelling.

We deliberately stopped short of unifying the two dependency-graph walks (inventory vs. contributions) behind a generic interpreter: it barely reduces line count, would rely on a K=1 invariant the types don't enforce, and can't absorb the third walk in Service.hs.

Test plan

  • ./gen-version.sh && cabal build — clean (only two pre-existing, unrelated API/MCP.hs warnings).
  • cabal run lca-tests — 1107 examples, 0 failures, 1 pending.
  • Rebased onto current advanced_haskell; rebuilt and re-ran the full suite green on the rebased tree.

ccomb added 2 commits May 28, 2026 19:00
SharedSolver carried several copies of the same logic. Factor them out:

- Lazy MUMPS factorization was computed-and-cached in two near-identical
  blocks (solveWithSharedSolver, ensureFactorization). Extract
  computeAndStoreFactorization so the precompute+store lives once; the
  dense-solver fallback stays scoped to the first-solve (cache-miss) path.

- The per-root dep-demand -> demand-vector conversion was copied byte for
  byte in three resolvers (resolveDep, resolveDepContribs, and
  Service.resolveDepWithSubs). Extract prepareDepDemandVecs, plus depDbsOf
  for the "DBs referenced at this level" set.

- CrossDBSolution gains a Semigroup instance, so mergeSolutions is just
  foldl' (<>) — same summed inventory and BFS-ordered scalings as before.

- Name the cross-DB dep-demand map types in Matrix (SupplierDemands,
  DepDemands) and use them across the affected signatures.

No behaviour change; full test suite (1107 examples) green.
The factorization/merge dedup left modifyMVar (superseded by modifyMVar_)
and foldl' (provided by Prelude) unused, producing -Wall warnings.
@ccomb ccomb merged commit 9c5e1a6 into advanced_haskell May 28, 2026
@ccomb ccomb deleted the refactor/shared-solver-cleanup branch May 28, 2026 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant