Skip to content

fix(native): CHA/RTA instantiation evidence lacks new_expressions - #2493

Merged
carlos-alm merged 1 commit into
mainfrom
fix/issue-2346-native-cha-rta-new-expressions
Aug 14, 2026
Merged

fix(native): CHA/RTA instantiation evidence lacks new_expressions#2493
carlos-alm merged 1 commit into
mainfrom
fix/issue-2346-native-cha-rta-new-expressions

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

  • Issue bug: native engine misses call edges when receiver's static type is an interface with multiple implementers (NativeDbProxy, TreeSitterNode, Repository) #2139 added CHA (Class Hierarchy Analysis) dispatch to the native engine, filtered by RTA (Rapid Type Analysis) instantiation evidence. The WASM/TS engine's evidence set (collectInstantiatedTypes, cha.ts) unions typeMap entries (confidence >= 0.9) with every raw new X() expression in the file (symbols.newExpressions), regardless of assignment shape.
  • The native engine's equivalent (collect_cha_instantiated_types, build_edges.rs) only had the typeMap half — there was no new_expressions list on the Rust side at all. A class instantiated ONLY via a pattern that doesn't produce a confidence>=0.9 typeMap entry (e.g. new X() as an object-literal property value, or a bare non-this. assignment) was invisible to native's RTA filter and never got CHA-expanded dispatch edges, even though WASM correctly produced them for identical code.
  • Fix: added new_expressions: Vec<String> to FileSymbols/FileEdgeInput, populated unconditionally in handle_new_expr (mirroring the TS extractor's existing newExpressions collection), and unioned into collect_cha_instantiated_types alongside the existing typeMap source — matching cha.ts's union exactly.
  • native-orchestrator.ts's DB-driven incremental path (buildChaRtaSet) already independently covers this via its own calls-edge query and does not go through build_edges.rs, so it needed no changes (confirmed via investigation before implementing).

Test plan

  • New fixture tests/fixtures/cha-dispatch/ObjWorker.ts — implements IWorker, instantiated ONLY via an object-literal property value ({ w: new ObjWorker() }), never as const x = new ObjWorker()
  • Extended tests/integration/phase-8.5-cha-dispatch.test.tsdescribe.each(['wasm','native']) now asserts both engines emit the CHA-expanded dispatch → ObjWorker.doWork edge
  • cargo test --workspace: 1011 passed
  • cargo fmt --check / cargo clippy --workspace --all-targets -- -D warnings: clean
  • Full test suite: 327 files / 5253 tests passed
  • npm run lint clean

Closes #2346

Native engine's collect_cha_instantiated_types only sourced typeMap
entries (confidence >= 0.9) as RTA instantiation evidence for CHA
dispatch, unlike WASM/TS's collectInstantiatedTypes (cha.ts) which
also unions every new_expressions entry regardless of assignment
shape. A class instantiated ONLY via an object-literal property value
or bare non-`this.` assignment never produced a confidence>=0.9
typeMap entry, so it was invisible to native's CHA/RTA filter even
after #2139's dispatch-edge fix — WASM already handled this correctly.

Adds new_expressions: Vec<String> to FileSymbols/FileEdgeInput,
populated unconditionally in handle_new_expr (mirroring the TS
extractor's newExpressions collection), and unions it into
collect_cha_instantiated_types alongside the existing typeMap source.

New fixture (ObjWorker.ts) instantiated only via an object-literal
property value, verified via describe.each(['wasm','native']) that
both engines now emit the CHA-expanded dispatch edge to it.

docs check acknowledged: this is an internal RTA-evidence parity fix
closing a narrow instantiation-evidence gap in one engine to match
the other's already-correct, already-documented CHA+RTA behavior — no
new feature, language, or architecture change, so README/CLAUDE/
ROADMAP do not need updates.

Closes #2346

Impact: 3 functions changed, 4 affected
@greptile-apps

greptile-apps Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR brings native CHA/RTA instantiation detection into parity with the WASM engine by collecting every supported JavaScript/TypeScript new expression and forwarding that evidence into native call-edge construction.

  • Adds newExpressions to the native extractor and edge-building data contracts.
  • Unions raw constructor evidence with high-confidence type-map evidence during native CHA filtering.
  • Adds a cross-engine integration fixture for constructor use inside an object-literal property.

Confidence Score: 5/5

The PR appears safe to merge, with the new native extraction and CHA/RTA evidence flow aligned with the existing WASM behavior.

The added field is initialized and propagated through all native constructors and marshaling points, both engines use equivalent constructor-name extraction and recursive traversal, and the integration test covers the targeted missing-edge scenario.

Important Files Changed

Filename Overview
crates/codegraph-core/src/extractors/javascript.rs Collects constructor type names for every traversed supported new expression using logic equivalent to the TypeScript extractor.
crates/codegraph-core/src/types.rs Adds and safely initializes the native FileSymbols.newExpressions FFI field.
crates/codegraph-core/src/domain/graph/builder/pipeline.rs Marshals extracted constructor evidence into native call-edge inputs.
crates/codegraph-core/src/domain/graph/builder/stages/build_edges.rs Unions raw new-expression evidence with high-confidence type-map entries before CHA/RTA filtering.
tests/integration/phase-8.5-cha-dispatch.test.ts Verifies both engines emit the expected CHA edge for an instantiation shape absent from the high-confidence type map.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Source["JavaScript / TypeScript source"] --> Extract["Native new-expression extraction"]
  Extract --> Symbols["FileSymbols.newExpressions"]
  Symbols --> Inputs["FileEdgeInput.newExpressions"]
  Inputs --> RTA["CHA/RTA instantiated-type union"]
  TypeMap["typeMap entries with confidence >= 0.9"] --> RTA
  RTA --> Filter["Filter hierarchy dispatch candidates"]
  Filter --> Edges["Persist CHA call edges"]
Loading

Reviews (1): Last reviewed commit: "fix(native): cha dispatch missing rta ev..." | Re-trigger Greptile

@carlos-alm
carlos-alm merged commit 8538339 into main Aug 14, 2026
34 checks passed
@carlos-alm
carlos-alm deleted the fix/issue-2346-native-cha-rta-new-expressions branch August 14, 2026 04:58
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

1 participant