Skip to content

feat: port upstream overload, framework and dynamic-dispatch resolution - #7

Merged
NianJiuZst merged 2 commits into
mainfrom
claude/upstream-parity
Nov 1, 2026
Merged

NianJiuZst merged 2 commits into
mainfrom
claude/upstream-parity

Conversation

@NianJiuZst

Copy link
Copy Markdown
Owner

The Rust engine lagged upstream CodeGraph in three areas: overload and type resolution, framework understanding, and dynamic / cross-boundary calls. This ports upstream's rules for each (pinned oracle d2e0389, plus upstream's two later fixes for Java overload arguments and Go interface types), restructured for this engine's extract-sites-then-link model so that incremental sync still equals a full rebuild.

Changes

Types and overloads

  • Call sites record their argument shapes (Java, Kotlin, TS/JS) on the call reference. Overloads are chosen by arity, then by argument type (exact type, widening or boxing, project subtype, a lambda against a functional parameter). When nothing settles it, the first declared overload stands, as before.
  • Java/Kotlin calls on a field receiver (repo.find(), and this.repo.find(), which the kernel writes as repo.find) are typed by the field, through outer types. A field whose declared type is outside the project now resolves as external instead of a guessed project member.
  • Java/Kotlin same-package types resolve through the file's package namespace node, so qualified nested types such as Token.Tag resolve.
  • Go structural interfaces match by method key (package-scoped for unexported names), parameter/result counts and types, including defined types (type MatchPath []string) and promoted methods. True aliases and type parameters never rule a type out.
  • Interface → implementation edges follow upstream's per-type pass: each concrete type's direct supertypes, overloads paired by parameters, JS static/instance split, at most 40 per pair. This replaces skipping a method outright once it has more than 12 implementations.

Frameworks

  • Next.js routes follow upstream: pages named by path, [id] as :id, one route per exported method in route.ts, pages/api as ANY; parallel and intercepting routes are skipped.
  • Navigation → navigates edges to the page: router.push/replace/prefetch, redirect, NextResponse.redirect(new URL(..)), React Router navigate / history.push, TanStack navigate({ to }), and <Link href|to>, <NavLink>, <Navigate>, <LinkContainer>, internal <a href>. Conditional arms and a local const destination are read. A receiver-qualified Next push must name a router, so list.push('/about') is not navigation (upstream takes it).
  • Next.js middleware.ts / proxy.ts: config.matcher is compiled (parameters, groups, negative-lookahead exclusions) by a small matcher of its own, and every covered route calls the proxy entry.
  • React Router route tables from <Route> markup and route objects (nesting, index routes, layouts); TanStack Router file and code routes.
  • NestJS HTTP (controller prefix + method decorator), GraphQL (inside @Resolver), @MessagePattern / @EventPattern, @SubscribeMessage with the gateway namespace.
  • Express: the chained router.route('/x').get(..).put(..) form, and cross-file app.use('/prefix', router) mounts, composed at link time for HTTP matching (route node names are unchanged).
  • A decorator route whose bare handler name nothing else resolves falls back to the method declared right after the decorator. NestJS and Spring handler edges were missing.

Dynamic and cross-boundary calls (synthesized passes over persisted sites)

  • callback: a registrar stores a callback in a field that a same-file dispatcher iterates.
  • object-registry: handlers[action](..) through an object literal of functions.
  • http-client: fetch, axios, ky, got, useSWR and client instances (with base URLs, also imported ones) → the one route serving the method and path.
  • queue-job (Bull / BullMQ, Nest @Processor), event-bus (@OnEvent globs, sockets in both directions), celery-dispatch, spring-event.
  • Synthesized edges merge by (source, target) in upstream's pass order.

Engine

  • Engine rule version 4 → 5, so existing indexes rebuild on the next sync. The segment format is unchanged.
  • Incremental sync re-resolves names whose signatures changed, and recomputes the cross-file passes from persisted sites.
  • The new site scanners skip minified bundles, and facts compute columns incrementally: a 157 KB one-line bundle in caddy made extraction quadratic.

Validation

  • New tests: crates/cg-resolve/tests/upstream_parity.rs (10 end-to-end cases, each positive case with a negative twin) and unit tests for signature parsing, href and route matching, the proxy matcher and the scanners. crates/cg-sync/tests/incremental_parity.rs builds a fixture that draws every new edge kind, then applies 22 targeted one-sided edits and 80 random edits, comparing each sync with a full rebuild and requiring delta syncs.
  • Full workspace tests, cargo fmt --check on our crates and cargo clippy --workspace --exclude cg-kernel --all-targets -- -D warnings pass. The vendored kernel is untouched.
  • main vs this branch on real repositories (index p50 of 7 runs, release builds):
repository edges index p50
express, django identical 66 → 71 ms, 1779 → 1822 ms
tokio +173 trait → impl dispatch 400 → 446 ms (repeated phase timings within noise)
gin +14 go-implements, +102 interface-impl 84 → 85 ms
jsoup 3,241 call sites moved to the fitting overload, 822 newly resolved, 15 no longer resolved; +314 interface-impl 267 → 306 ms
caddy go-implements 226 → 399, interface-impl 188 → 433 598 → 523 ms
proshop_mern +19 route → screen, +31 links, +20 navigations, +23 axios → Express route, +44 handler refs —
  • Random samples on jsoup: 22/22 moved call sites and 22/22 newly resolved calls are correct against the signatures. 21 of 22 sampled losses were wrong targets before (calls into a field of the same name, ReentrantLock / Map / StringBuilder receivers matched to project methods); the other, a nested-type field receiver, is fixed in this branch. On caddy, sampled removed implementers had a different signature (TLS vs HTTP matchers) or came from methods of same-named types in other packages.
  • Peak RSS rises by a roughly fixed 10–14 MB (regex caches).

Reviewer notes

  • Next.js page routes change name (GET /cart → /cart, [id] → :id) and reach their component with calls instead of references.
  • Call references now carry an #args candidate list (the kernel never gives calls candidates); only resolution reads it.
  • Java bindings now record primitive types, and TS bindings string / number / boolean; a union still prefers its first non-primitive member.
  • Not measured against the upstream 1.6.2 binary: running it was not available in this session, so the agreement metrics of the earlier reports were not recomputed.
  • Not ported yet: NestJS RouterModule and global prefixes, React Router tables declared in another file, Go dispatch through promoted methods. README and quality-report docs are not updated.

🤖 Generated with Claude Code

NianJiuZst and others added 2 commits November 1, 2026 09:11
Close the gaps against upstream CodeGraph in three areas.

Types and overloads:
- Calls record their argument shapes (Java, Kotlin, TS/JS) and pick the
  overload whose arity and argument types fit, instead of the first declared.
- Java/Kotlin calls on a field receiver (`repo.find()`, `this.repo.find()`)
  are typed by the field; same-package Java types resolve through the
  package node, so `Token.Tag` names the nested type.
- Go structural interfaces match by method key, parameter/result counts and
  types; interface dispatch follows upstream's per-type override pass.

Frameworks:
- Next.js routes named by path with upstream segments; router.push,
  redirect and <Link href> navigation; middleware/proxy matcher coverage.
- React Router and TanStack Router route tables, links and navigation.
- NestJS HTTP, GraphQL, microservice and WebSocket routes.
- Express chained router.route() and cross-file mount prefixes.
- A decorator route's bare handler name falls back to the method it sits on.

Dynamic and cross-boundary calls:
- Callback collections, object registries, HTTP client -> route,
  queue job -> consumer, event bus and sockets, Celery tasks, Spring events.
- Synthesized edges merge by (source, target) in upstream pass order.

Engine rule version 5; segment format unchanged. Incremental sync recomputes
the cross-file passes and re-resolves names whose signatures changed.
Minified files are skipped by the new site scanners, and facts compute
columns incrementally so a one-line bundle no longer costs quadratic time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@NianJiuZst
NianJiuZst merged commit 9a68cf4 into main Nov 1, 2026
9 checks passed
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