Skip to content

resolve: close JS/TS, Rust and JVM graph gaps against upstream / 补齐与原版的图谱差距(JS/TS、Rust、JVM) - #18

Merged
NianJiuZst merged 8 commits into
NianJiuZst:mainfrom
columbia11:claude/graph-gap-fixes
Nov 3, 2026
Merged

NianJiuZst merged 8 commits into
NianJiuZst:mainfrom
columbia11:claude/graph-gap-fixes

Conversation

@columbia11

@columbia11 columbia11 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

概要

对照原版 CodeGraph d2e0389 的十二仓库图谱数据(#17),修补 cgr 解析中的缺陷,重点是 JS/TS。

  • 共 8 个提交,基于 33040e9。
  • 只改 cg-extract、cg-resolve、cg-store、cg-sync 和测试,不动 vendored 的 cg-kernel。

通用、Rust、JVM(f78f346)

  • 多行 import:续行上的名字按语句首行解析(Python、TypeScript、Rust)。
  • JVM:Kotlin 属性或 Java 字段旁边有同名的唯一可调用成员时,调用连到该成员。
  • Kotlin 扩展函数(fun Lockable.awaitNanos())算作接收者类型及其子类型的成员。
  • Rust 泛型类型参数不再连到别处的同名 struct。
  • let (tx, rx) = f() 和 f()? 按被调函数返回的元组,给每个元素定类型。
  • use crate::…、self::…、super::… 不再额外产生指向 crate 根或父模块的文件级 imports 边。
  • Rust 路径成员(mio::Interest::AIO)按写出的路径解析,依赖里的类型不再连到同名的本地类型。
  • TS 的 new X() 解析到接口或类型别名时,改连旁边的同名值。

JS/TS

  • dc97f82:
    • export { a as b } from "m" 中的每个名字都连到定义;
    • var x = require("m").y 与 const { y } = require("m") 一样绑定。
  • 8492b90:调用用 var / let / const 声明的变量(如 const $ = django.jQuery; $(el))时,连到该变量或常量节点,与原版一致。
  • 9ead71e:
    • new X() 的 X 是参数时,不再连到别处的同名类;
    • core.output<T> 这类带命名空间的类型名,沿命名空间导入和 export * 解析,不再按尾名落到同名的 output 上。
  • adb8c7e:
    • 变量和类字段的类型注解也走上面的命名空间解析;
    • 类型位置的 ZodFirstPartyTypeKind.ZodLiteral 连到枚举成员,不再连到 class ZodLiteral。
  • 1d8913f:
    • 一个名字在文件里既声明为类型又声明为值(interface X 和 const X)时,导入连到先声明的那个,与原版一致;new X() 和调用仍连到值。增量同步在同名声明的顺序变化时,会重新解析导入方。
    • import x from "./m" 的绑定名也连到模块文件,与原版一致;调用 x 仍连到默认导出。
    • 一个脚本用 window.SelectFilter = { init: … } 定义全局对象时,另一个脚本里的 SelectFilter.init() 连到它的成员(Django admin)。
    • TS 类和函数的类型参数(T、Output)不再连到别处的同名声明。
    • JSX 渲染边改用渲染组件的首行作行号,与其他合成边一致。
  • c270e80、12d6fd0:
    • TS 里经类型已知的接收者调用重载方法(doc.write(…))时,连到方法的第一个声明,与原版一致。this.f(…) 仍按参数选重载。纯 JS 不受影响,同名方法重复定义时以最后一个为准。
    • new X() 只找到接口或类型别名、旁边没有同名的值时,不再连。例如测试里的 new File() 指的是 DOM 全局对象。
    • var express = require('..'); express.Router() 连到模块转出的变量(var Router = require('router'); exports.Router = Router),包根目录 module.exports = require('./lib/express') 转一层也能找到。

Summary

Fixes resolution gaps found by comparing against upstream CodeGraph d2e0389 on the twelve repositories from #17, mostly in JS/TS.

  • Eight commits on 33040e9.
  • Changes cg-extract, cg-resolve, cg-store, cg-sync and tests only; vendored cg-kernel is untouched.

General, Rust and JVM (f78f346)

  • Multi-line imports: names on continuation lines resolve through the statement's first line (Python, TypeScript, Rust).
  • JVM: a call takes the single callable member over a same-named Kotlin property or Java field.
  • Kotlin extension functions are members of their receiver type and its subtypes.
  • Rust generic type parameters no longer link to a same-named struct elsewhere.
  • let (tx, rx) = f() and f()? type each element from the callee's returned tuple.
  • use through a bare crate, self or super root no longer adds a file-level imports edge to the crate root or parent module.
  • Rust path members (mio::Interest::AIO) resolve by the path as written.
  • TS new X() that resolves to an interface or type alias goes to the same-named value beside it.

JS/TS

  • dc97f82: re-export lists (export { a as b } from "m") link each name; var x = require("m").y binds like const { y } = require("m").
  • 8492b90: a call of a var/let/const binding links that variable or constant node, as upstream does.
  • 9ead71e:
    • new X() with X a parameter no longer links a same-named class;
    • namespace-qualified type names (core.output<T>) resolve through the namespace import and its star exports.
  • adb8c7e:
    • variable and class-field annotations get the same namespace resolution;
    • Enum.Member in a type position links the enum member.
  • 1d8913f:
    • an import of a name declared as both a type and a value links the first declaration, as upstream does; new and calls still take the value. Sync re-resolves importers when the order changes;
    • import x from "./m" links the module file for the bound name too, as upstream does;
    • SelectFilter.init() reaches the member of a window.SelectFilter = {…} global from another script;
    • TS class and function type parameters no longer link same-named declarations;
    • JSX render edges sit on the rendering component's first line.
  • c270e80, 12d6fd0:
    • a TS call through a typed receiver links the method's first overload declaration, as upstream does; this.f(…) keeps argument matching; plain JS is unaffected;
    • new X() that only finds an interface or type alias with no value beside it links nothing;
    • express.Router() reaches the variable a CommonJS module forwards, also through a package root's module.exports = require(…).

结果 / Results

  • 严格边集,边键 (源稳定 ID, 目标稳定 ID, 类型, 行, 列),原版 d2e0389 作对照,基线 33040e9。
    Strict edge sets, key (src stable ID, dst stable ID, kind, line, col), upstream d2e0389 as the reference, baseline 33040e9.
  • 没有任何仓库的 P 或 R 下降。有变化的仓库如下;Gin、fmt、Alamofire、cJSON、MediatR、Slim、Sinatra 不变。
    No repository loses P or R. Changed repositories are below; Gin, fmt, Alamofire, cJSON, MediatR, Slim and Sinatra are unchanged.
仓库 / Repo P R
Express 64.18 → 65.00 87.75 → 92.07
Tokio 78.84 → 82.32 88.30 → 90.01
Django 94.21 → 94.35 89.82 → 92.14
Zod 87.24 → 89.08 92.86 → 95.73
OkHttp 88.47 → 89.10 82.24 → 83.28

imports 精确率 / imports precision: Tokio 50.91 → 64.55, Zod 96.59 → 97.83.

按源文件语言统计 / By source language:

范围 / Scope P R R(原版置信度 ≥ 0.85 / upstream confidence ≥ 0.85)
全部 JS / all JS 75.75 → 76.44 83.86 → 88.09 90.08 → 94.37
TS(Zod) 87.19 → 88.98 92.89 → 95.72 96.98 → 99.57
TSX(Zod) 90.03 → 96.67 89.57 → 95.93 89.57 → 95.93
Django JS 99.63 → 99.54 82.50 → 98.17 84.99 → 98.58
其他语言 / other languages 92.29 91.03 96.49

TS、TSX 的 R 已高于其他语言。全部 JS 的 P 偏低,主要是 Express 中有 825 条正确的 app.* 调用原版没有连。
TS and TSX recall are now above the other languages. All-JS precision stays low mainly because upstream leaves 825 correct app.* calls in Express unlinked.

验证 / Verification

  • 测试先行。 每项修复都先写测试:修复前失败,修复后通过。resolve_e2e 新增 21 个测试,另在已有的合成边测试里加了行号断言。
    Each fix has a test that fails before and passes after; 21 new resolve_e2e tests.

  • CI。 本 PR 在 12d6fd0 上的 9 项检查全部通过:rustfmt + clippy、三个平台的测试和端到端冒烟、musl 静态构建、vendored 内核校验。
    All 9 checks pass on 12d6fd0: rustfmt + clippy, tests and end-to-end smoke on three platforms, the static musl build, and the vendored-kernel check.

  • 增量同步。

    • incremental_parity 新增 CommonJS、barrel、同名类型和值、默认导入、window 全局对象、重载顺序、CommonJS 转出变量等文件,以及两侧的单侧编辑,都不走全量重建。
    • 在真实仓库上编辑后,增量同步的结果与全量索引一致,cgr debug diff 输出 identical:Tokio、OkHttp、Express、Django、Zod。其中包括改名接口 ZodISODate、交换 Doc.write 的重载、改名 SelectFilter.refresh_icons、改名 exports.Router。

    Incremental sync: new parity cases for each fix, and synced-vs-fresh parity on real repositories with semantic edits, cgr debug diff identical.

  • 人工抽样。 抽查只有 cgr 有、原版没有的边:

    • Express:48 条全部正确;
    • Zod:40 条中 39 条正确。唯一错边是测试里全局的 new File(),c270e80 已修复。

    Hand-checked samples of edges only cgr has: Express 48/48 correct, Zod 39/40; the one wrong edge (new File()) is fixed in c270e80.

需要注意 / Notes

  • 原版是对照,不是标准答案。 JS/TS 上 P 偏低,主要是原版漏边。剩下的原版独有边,很多是原版猜错的,本 PR 没有照搬:

    • Zod 中 417 条把 z.string()、z.number() 连到测试文件里的 Mocker::string 等 getter;
    • 521 条把类型位置的名字(如返回类型 ZodCustomStringFormat<"hostname">)连到同名的 const,cgr 连到接口;
    • Express 的 express.json() 被连到 createApplication,this.set() 被连到 app.set。

    Upstream is a reference, not ground truth. Many remaining upstream-only edges are wrong guesses, which this PR does not copy (Zod Mocker::* getters for z.string(), type positions linked to a same-named const, Express express.json() → createApplication).

  • 两处约定改为与原版一致:

    • 默认导入的绑定名连到模块文件,所以 import Scroller from "./scroller" 不再有指向 Scroller 函数的 imports 边;调用和 JSX 边仍连到函数;
    • TS 经接收者调用重载方法时连到第一个声明,查某个具体重载签名的调用者时看不到这些调用。

    Two conventions now follow upstream: a default import's bound name links the module file, and a TS receiver call links the method's first overload declaration.

  • 路由约定没有改。 路由 ID 和 file→route 的 contains 边保持原样。
    Route conventions (route IDs, file→route contains) are unchanged.

- Multi-line imports: names on continuation lines resolve through the
  statement's first line (Python, TypeScript, Rust).
- JVM calls take the single callable member over a same-named Kotlin
  property or Java field.
- Rust generic type parameters are TypeParam bindings and never link to a
  same-named struct elsewhere.
- Kotlin extension functions (`fun Lockable.awaitNanos()`) are members of
  their receiver type and its subtypes.
- TypeScript `new X()` that resolves to an interface or type alias goes to
  the same-named value beside it.
- Rust `let (tx, rx) = f()` / `f()?` types each element from the callee's
  returned tuple.
- Rust `use` through a bare `crate`/`self`/`super` root no longer adds a
  file-level imports edge to the crate root or parent module.
- Rust path members (`mio::Interest::AIO`) resolve by the path as written,
  so a dependency's type is not linked to a same-named local type.
- `export { a as b } from "m"` records one import per specifier, without a
  local binding, so each re-exported name links to its definition (the
  barrel files of TypeScript projects such as Zod).
- `var x = require("m").y` binds `x` to module m's export `y`, like
  `const { y } = require("m")`, and links the file to m.
- Incremental parity fixture covers both, with edits on the defining and
  the consuming side.
`const $ = django.jQuery; $(el)`, `Router = express.Router; new Router()`
and `const compiledFn = compile(s); compiledFn(x)` call what the
declaration's node holds. A call or `new` whose name is a var/let/const
binding (not a parameter) now links to that declaration's variable or
constant node; receivers of member calls are unchanged.
- `new Class(..)` where `Class` is a parameter or a local resolves through
  the binding, never to a same-named class elsewhere (Zod's
  `_nonoptional(Class: ..)` linked util's abstract `Class`).
- `core.output<T>` keeps its namespace: the kernel names a
  `nested_type_identifier` by its last segment, so a call-name fact gives
  the written path and qualified lookup walks the namespace import and its
  star exports, instead of a same-named `output` beside the reference.
  A path no walk enters (members of a TS `namespace`, which the kernel
  flattens into the file) falls back to the last segment.
…positions

A const's or class field's type annotation was never walked, so
`const decode: (.., _ctx?: core.ParseContext<..>) => ..` kept the bare
kernel name and fell to a same-named type elsewhere (v3's ParseContext,
a test file's `declare module` augmentation of ZodType). Walk it like a
parameter's.

`typeName: ZodFirstPartyTypeKind.ZodLiteral` names the enum's member, not
`class ZodLiteral`.
…ines

- An import of a name declared in its file as both a type and a value
  (`interface X` and `const X`) links the first declaration; `new X()` and
  calls still take the value. Sync re-resolves importers when the order
  of same-named declarations changes.
- `import x from "./m"` links the module file for the bound name too;
  calls of `x` still reach the default export.
- `X.m()` with no binding or import for `X` reaches the member of a
  `window.X = { m: .. }` global declared in another script.
- TS class and function type parameters are bound, so `T` / `Output`
  inside name no same-named declaration elsewhere.
- JSX render edges sit on the rendering component's first line, like the
  other synthesised edges.
…ommonJS forwarded exports

- A TS call through a typed receiver (`doc.write(..)`) links the method's
  first declaration, which stands for its overload signatures as upstream
  links it; `this.f(..)` keeps the overload its arguments fit.
- `new File([], name)` that only finds an interface or type alias, with no
  value beside it, links nothing: the value is a global's (the DOM's).
- `var express = require('..'); express.Router()` reaches the variable the
  module forwards (`var Router = require('router'); exports.Router =
  Router`), also through a package root's `module.exports = require(..)`.
Overload signatures exist only in TypeScript; a method defined twice in
plain JS is a redefinition, where the last definition wins.
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.

2 participants