Skip to content

Collapse per-kind backend lookup to one call - #413

Open
Firehed wants to merge 18 commits into
mainfrom
slice/S3.8d
Open

Collapse per-kind backend lookup to one call#413
Firehed wants to merge 18 commits into
mainfrom
slice/S3.8d

Conversation

@Firehed

@Firehed Firehed commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Slice S3.8d — Plan 0002 Step 3b, §5.6; RFC 1 §5.1, §8.1.

SymbolBackend carried lookupClassLike and lookupFunction separately, so the same twenty lines of cache-then-build appeared twice in FilesystemBackend and BuiltinBackend, and OpenDocumentBackend held two parallel array pairs. Adding constants (S3.8b) would have tripled that. The backends now take one lookup(QualifiedName, NameKind): ?SymbolInfo.

SymbolSource is unchanged: it keeps a typed method per kind because §5.1 requires a concrete return type. The composite narrows the marker back once per kind, at one site — the O(kinds) narrowing §5.6 trades against O(kinds × backends) methods.

Kind dispatch lands in two factories, one per metadata route, rather than inline in a backend: DeclarationSymbolInfoFactory (parsed declarations) and ReflectionSymbolInfoFactory (the loaded runtime). §4.5 wants kind dispatch confined to a factory, and its static rule arrives in S4.1 — this puts the code in the shape that rule will expect. Moving reflection into the second factory relocates the Reflection* allowlist entry off BuiltinBackend rather than widening it.

Behaviour-preserving: every Step P golden is unchanged, and no golden was recaptured. The phpstan-baseline.neon diff is message text only, following the allowlist message edit — count unchanged at 43.

§8.1 mechanism

The slice also carries §8.1's mechanism for §5.1: SymbolCoverageGridTest, a backend × kind × query grid. Both axes are derived — rows from CompositeSymbolSource::$backends, columns from NameKind::cases() × GridQuery::cases() — so a new kind or backend adds cells that did not exist when the file was written. Every cell either answers over the fixtures or is registered against a named blocker; an unregistered cell fails, and a registration on a cell that now answers fails too, so a blocker cannot outlive its gap.

The grid found one gap on its first run, filed as manifest row SC.16: SymbolExtractor emits no SymbolKind::Constant, so an open document's global constants are never indexed and OpenDocumentBackend::childrenOf cannot enumerate them — while both on-disk and built-in enumeration report constants. WorkspaceNamespaceSource already maps the kind; only a hand-built index in a unit test ever reached that arm. Not fixed here (out of scope); the cell is registered against SC.16.

Acceptance criteria

  • SymbolBackend carries one kind-parameterized lookup, not a method per kind
  • SymbolSource keeps its typed per-kind methods (§5.1 concrete return types)
  • SymbolInfo marker on ClassInfo and FunctionInfo; Formattable not reused
  • Kind dispatch confined to factories, not backends
  • §5.1 grid with derived axes; unregistered cell fails; stale registration fails
  • Every not-applicable cell names a slice id or RFC section
  • Behaviour preserved — Step P goldens frozen, none recaptured
  • Baseline totals unchanged (43 → 43); no violation absorbed
  • 100% line and method coverage on every changed and new class

Sets up S3.8b, whose acceptance is that its diff touches no SymbolBackend implementation.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.62%. Comparing base (85c47fb) to head (04d0f1d).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #413      +/-   ##
============================================
- Coverage     98.62%   98.62%   -0.01%     
- Complexity     1810     1814       +4     
============================================
  Files           125      128       +3     
  Lines          4594     4571      -23     
============================================
- Hits           4531     4508      -23     
  Misses           63       63              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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