refactor(native): consolidate barrel-trace-with-fallback duplication in import_edges.rs - #2563
Merged
Conversation
…in import_edges.rs crates/codegraph-core/src/domain/graph/builder/stages/import_edges.rs inlined the same "resolve through a barrel, falling back to the original file/name" pattern independently in three places (collect_symbol_lookup_pairs, emit_named_symbol_rows, emit_barrel_through_rows) -- the same class of divergence-prone duplication #2295 consolidated on the TS side onto traceBarrelTarget, but with no equivalent Rust helper to fall back on. Extracts trace_barrel_target(ctx, resolved_path, symbol_name) mirroring traceBarrelTarget's exact shape and rewrites all three call sites to use it. emit_barrel_through_rows's prior explicit None-continue branch (barrel resolution finds nothing) now flows through the same pre-existing actual_source == resolved_path self-reference check the other two branches already used -- verified behavior-preserving by running the new emit_barrel_through_rows tests against both the original and refactored implementations with identical results. docs check acknowledged -- internal Rust refactor only, no new language support, feature, or externally-visible behavior change to document.
Contributor
Greptile SummaryThe PR consolidates duplicated native barrel-resolution fallback logic into
Confidence Score: 5/5The PR appears safe to merge with no actionable defects identified. The shared helper preserves each call site's previous fallback semantics, and unresolved barrel exports still produce no through-edge because the existing self-reference check discards the identity fallback. Important Files Changed
Reviews (1): Last reviewed commit: "refactor(native): consolidate barrel-tra..." | Re-trigger Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
While fixing #2295 (consolidating TS's duplicate barrel-trace-with-fallback logic onto the shared
traceBarrelTargethelper from #2071), found that the Rust native engine has the identical duplication pattern incrates/codegraph-core/src/domain/graph/builder/stages/import_edges.rs— and, unlike TS, had no shared helper at all to consolidate onto.Three call sites each inlined the same "resolve through a barrel, falling back to the original file/name" pattern independently:
collect_symbol_lookup_pairsemit_named_symbol_rowsemit_barrel_through_rowsFix
Extracted
trace_barrel_target(ctx, resolved_path, symbol_name) -> BarrelResolution, mirroring TS'straceBarrelTarget(src/domain/graph/builder/stages/resolve-imports.ts) exactly: returns the resolved barrel target whenresolved_pathis a barrel and resolution succeeds, otherwise falls back toresolved_path/symbol_nameunchanged. Rewrote all three call sites to use it.emit_barrel_through_rowsneeded a closer look: unlike the other two, it didn't previously have anis_barrel_fileguard inline (redundant — the function's own top-level guard already established that) and treated "resolution failed" as an explicit earlycontinuerather than a fallback. After routing through the shared helper (which never returnsNone, only the fallback identity), that case now flows through the same pre-existingactual_source == resolved_pathself-reference check the function already used for a different purpose — same observable outcome, one fewer special case. Verified this is genuinely behavior-preserving by running the newemit_barrel_through_rowstests against both the original and refactored implementations with identical (all-passing) results.Test plan
trace_barrel_targetdirectly: falls back to identity for a non-barrel file, resolves through a barrel to the declaring file, falls back to identity when barrel resolution finds nothingemit_barrel_through_rows(previously had no dedicated unit test — only exercised indirectly through theemit_edges_for_importorchestrator): emits an edge to the actual definition file, emits nothing when barrel resolution finds no target, skips a barrel that resolves back to itselfemit_barrel_through_rowstests still pass unchanged against the pre-refactor code — proving the refactor doesn't alter observable behaviorcargo test --lib(full suite) — 1094 passed (up from 1088, +6 new)cargo clippy --lib -- -D warnings— clean.nodeaddon and rantests/integration/build-parity.test.ts(native vs WASM cross-engine parity, including the monorepo-workspace fixture) — 12/12 passednpm test(full suite) — 339 files, 5447 passednpx tsc --noEmit— clean (no TS files changed by this PR)Closes #2461