Skip to content

Rust resolve_call_targets_core has no barrel-hop resolution tier for call edges (TS has one) #2083

Closed

Description

@carlos-alm

Discovered while addressing a Greptile PR #2028 review finding (constructor-call attribution through a renaming barrel export).

Context: PR #2028 fixed a bug in the TypeScript engine where attachConstructorTargets used the call site's (possibly barrel-aliased) name instead of the barrel-resolved true declared name when building the qualified constructor-method lookup key. That fix only touches src/domain/graph/builder/call-resolver.ts.

While verifying whether the Rust engine (crates/codegraph-core/src/domain/graph/builder/stages/build_edges.rs) needed an equivalent mirrored fix, I found the underlying mechanism is architecturally different — and the Rust side appears to be missing barrel-hop resolution for call edges entirely, not just for the new constructor-attribution feature:

  • TypeScript's resolveCallTargets has an explicit fallback: when the direct (name, importedFrom) lookup misses and lookup.isBarrel(importedFrom) is true, it calls lookup.resolveBarrel(importedFrom, targetName) to find the name/file actually declared in the barrel's re-export chain, then re-queries with that resolved name/file.
  • Rust's resolve_call_targets_core (build_edges.rs, spans roughly lines 1019–1337) has no equivalent step anywhere in its tiers. Its "1. Import-aware resolution" tier does a single direct ctx.nodes_by_name_and_file.get(&(target_name, imp_file)) lookup with no barrel fallback if that misses. ctx.nodes_by_name_and_file itself (built in EdgeContext::new) is keyed purely by each node's own declared (name, file) — no barrel-alias entries are pre-seeded either.
  • Rust does have substantial barrel-handling code (barrel_resolution module, resolve_barrel_export, emit_barrel_through_edges, etc.), but on inspection this is used for import-edge emission (the file-level import graph), a different edge kind from the calls edges resolve_call_targets_core produces.

Suspected impact: a call site that constructs (or calls a method on) a class imported through a barrel that renames the export (export { Foo as Bar } from './foo'; ... new Bar()) may not resolve to any calls edge at all in the native/Rust engine, whereas the WASM/TypeScript engine resolves it correctly via the resolveBarrel fallback. This would be a pre-existing engine-parity gap, not something introduced by PR #2028 — that PR's own constructor-attribution addition just uses the same imported_original_names primitive the rest of Rust's call resolution already relies on, so it doesn't add a new divergence beyond whatever already exists here.

Not yet verified: I have not confirmed with an end-to-end repro (only via static code reading) that this actually produces a missing/divergent edge for a real barrel-renamed construction call under the native engine — that would be the first step of investigating this. If confirmed, the fix would add a genuine barrel-hop tier to resolve_call_targets_core, mirroring the TS isBarrel/resolveBarrel fallback, which is a non-trivial, separate change from the narrow constructor-attribution fix in PR #2028.

Activity

  1. added
    follow-upDeferred work from PR reviews that needs tracking
    on Jul 11, 2026
  2. carlos-alm commented on Aug 7, 2026

    @carlos-alm
    ContributorAuthor

    Investigated with concrete repros as part of a `/fixer` pass — the suspected gap does not actually exist. Closing as not reproducible / already correctly handled.

    What I tested: three scenarios against both engines (WASM and a locally rebuilt native addon), each with a barrel that renames the export (`export { Foo as Bar } from './foo.js'`) and a call site that constructs through the renamed binding:

    1. Single-hop rename barrel (`new Bar()` → `Foo`/`Foo.method`)
    2. Two-hop rename chain (`barrel1` renames `Foo→Mid`, `barrel2` renames `Mid→Bar`, consumer imports `Bar`)
    3. Wildcard barrel (`export * from './foo.js'`)

    All three resolved correctly in both engines — identical `calls` edges, same target file, same constructor-method attribution.

    Why the static-reading suspicion didn't hold up: the issue's diagnosis of `resolve_call_targets_core` itself (no `isBarrel`/`resolveBarrel` fallback tier) is accurate, but the conclusion doesn't follow — that resolution already happens upstream, before Rust ever sees the call. `ImportedName` (the struct the NAPI boundary passes into Rust) is populated by `buildImportedNamesForNative` in `src/domain/graph/builder/stages/build-edges.ts`, which calls the exact same `traceBarrelTarget`/`resolveBarrelExportCached`/`isBarrelFile` helpers the WASM path's `resolveCallTargets` uses (unified under `traceBarrelTarget`, #2071, specifically to prevent this kind of divergence). By the time `resolve_call_targets_core`'s import-aware tier runs, `imported_from`/`target_name` are already the fully barrel-dereferenced file and declared name — confirmed directly by temporarily instrumenting `resolve_call_targets_core` and tracing the two-hop repro: `call.name="Bar" target_name="Foo" imported_from="foo.ts"`, i.e. already resolved through both hops before the Rust function's first lookup.

    So Rust doesn't need its own barrel-hop tier because the TypeScript orchestration layer that prepares its input already did the hop — a different architecture from the WASM path's inline fallback, but not a parity gap. No code change made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    follow-upDeferred work from PR reviews that needs tracking

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions