Skip to content

refactor(uffs-core): demote DirCacheExt to free fn dir_cache_with_capacity (Phase 7b, refs #287)#289

Merged
githubrobbi merged 3 commits into
mainfrom
chore/phase-7b-dircache-ext-demote
May 19, 2026
Merged

refactor(uffs-core): demote DirCacheExt to free fn dir_cache_with_capacity (Phase 7b, refs #287)#289
githubrobbi merged 3 commits into
mainfrom
chore/phase-7b-dircache-ext-demote

Conversation

@githubrobbi
Copy link
Copy Markdown
Collaborator

Phase 7b — the only trait demotion from the Phase 7 justification audit (issue #287).

Background

The Phase 7 trait justification audit classified 13 prod traits against the playbook §879-886 J1/J2/J3/J4 taxonomy:

  • 12 KEEP (J1 / J2 / J3): FileReader, FormatRow, RuntimeDir, JournalSource, plus 9 uffs-daemon::cache lifecycle hooks (BodyLoader, CacheCleaner, PatchSink, CursorStore, Prefetch, PressureSignal, WorkingSetTrim, BackgroundIoPriority).
  • 1 DEMOTE: DirCacheExt.

The demotion

DirCacheExt was a single-method pub(crate) extension trait providing with_capacity(n) -> Self over the DirCache = FxHashMap<u32, String> type alias. It satisfied none of the four justification criteria:

Criterion Verdict
J1 multiple meaningful impls ❌ 1 impl (for DirCache only)
J2 test-substitution boundary ❌ no test fakes
J3 stable extension surface pub(crate); rustdoc claims no extensibility
J4 high-level/infra decoupling ❌ single-method ergonomic constructor

The trait forced every caller to write use … DirCacheExt as _; just to spell DirCache::with_capacity(n), and the indirection made the call site easy to misread as an inherent method on the DirCache type alias (which is not legal — type aliases cannot have inherent methods).

What changed

  • crates/uffs-core/src/search/tree.rs: deleted the trait + impl (15 LOC); added a free pub(crate) fn dir_cache_with_capacity(capacity: usize) -> DirCache with the same body (FxHashMap::with_capacity_and_hasher(n, FxBuildHasher)). Doc-comment documents the playbook §879-886 rationale inline.
  • crates/uffs-core/src/search/query/mod.rs: dropped DirCacheExt as _ from the use line; switched 2 call sites.
  • crates/uffs-core/src/search/query/numeric_top_n.rs: same — 1 call site.
  • crates/uffs-core/src/search/query/path_only_top_n.rs: same — 2 call sites.
  • crates/uffs-core/src/search/query/path_sorted_top_n.rs: same — 2 call sites.

Behavior preserved bit-for-bit; the function body is the exact same expression the trait impl had.

API impact

Zero. DirCacheExt was pub(crate); no external code could reference it.

Verification

  • cargo check -p uffs-core — ✅ clean
  • cargo clippy -p uffs-core --all-targets -- -D warnings — ✅ clean
  • cargo nextest run -p uffs-core — ✅ 817/817 passing, 3 skipped (2.7 s)
  • Pre-push gate (lint-pre-push) — ✅ green (94 s)
  • Commit signed: 3628BD817A687030E83025A8E406D32B4736D09F

Diff summary

 5 files changed, 24 insertions(+), 21 deletions(-)

Findings doc (local-only, gitignored)

docs/dev/baseline/2026-05-19/phase_7_trait_justification_findings.md records every J1-J4 verdict for all 13 prod traits, with full per-trait justification text.

Next: 7c — generic-function audit (129 prod-path fn<…> sites).

Refs: #287

…acity (Phase 7b, refs #287)

`DirCacheExt` was a single-method `pub(crate)` extension trait providing
`with_capacity(n) -> Self` over the `DirCache = FxHashMap<u32, String>`
type alias.  Per the Phase 7 trait-justification audit (playbook §879-886
J1/J2/J3/J4), it satisfied none of the four criteria:

  * J1 multiple impls: ❌ 1 impl (for `DirCache` only)
  * J2 test substitution: ❌ no test fakes
  * J3 extension surface: ❌ `pub(crate)`, no rustdoc claim
  * J4 high-level/infra decoupling: ❌ single-method ergonomic constructor

The trait forced every caller to write `use … DirCacheExt as _;` just to
spell `DirCache::with_capacity(n)`, and the indirection made the call
site easy to misread as an inherent method on `DirCache`.

This refactor replaces the trait with a free
`pub(crate) fn dir_cache_with_capacity(capacity: usize) -> DirCache` and
updates the 7 call sites across 4 files in `uffs-core::search::query`.

Behavior preserved bit-for-bit: the new function body is the same
`FxHashMap::with_capacity_and_hasher(n, FxBuildHasher)` expression that
the trait impl had.

API impact: zero (trait + impl were `pub(crate)`).

Verification:

  * `cargo check -p uffs-core` — clean
  * `cargo clippy -p uffs-core --all-targets -- -D warnings` — clean
  * `cargo nextest run -p uffs-core` — 817/817 passing (3 skipped)

Findings doc (local-only):
docs/dev/baseline/2026-05-19/phase_7_trait_justification_findings.md
records all 13 prod traits classified J1-J4; `DirCacheExt` is the only
demotion.  The 12 other traits (9 `uffs-daemon::cache` hooks +
`FileReader` + `FormatRow` + `RuntimeDir`) are confirmed KEEP under
J1 / J2 / J3.

Refs: #287
@githubrobbi githubrobbi merged commit 33f22b5 into main May 19, 2026
26 checks passed
@githubrobbi githubrobbi deleted the chore/phase-7b-dircache-ext-demote branch May 19, 2026 17:51
githubrobbi added a commit that referenced this pull request May 19, 2026
The Phase 7g decisions-log row in `trait_policy.md:194` read 'this PR'
at the time of authoring (when PR #290 was open).  After PR #290 merged
the placeholder needed backfilling to '#290' to match the surrounding
rows (#288/#289/#291).

Companion to Phase 8e (PR #296), which already backfilled the sibling
'TBD' placeholder on row 193 (Phase 7f -> #291).  This 1-line edit
completes the decisions-log hygiene pass for Phase 7.
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