Repository navigation
resolve: close JS/TS, Rust and JVM graph gaps against upstream / 补齐与原版的图谱差距(JS/TS、Rust、JVM) - #18
Merged
Conversation
- 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.
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
概要
对照原版 CodeGraph
d2e0389的十二仓库图谱数据(#17),修补cgr解析中的缺陷,重点是 JS/TS。33040e9。cg-extract、cg-resolve、cg-store、cg-sync和测试,不动 vendored 的cg-kernel。通用、Rust、JVM(
f78f346)fun Lockable.awaitNanos())算作接收者类型及其子类型的成员。let (tx, rx) = f()和f()?按被调函数返回的元组,给每个元素定类型。use crate::…、self::…、super::…不再额外产生指向 crate 根或父模块的文件级imports边。mio::Interest::AIO)按写出的路径解析,依赖里的类型不再连到同名的本地类型。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)。T、Output)不再连到别处的同名声明。c270e80、12d6fd0: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
d2e0389on the twelve repositories from #17, mostly in JS/TS.33040e9.cg-extract,cg-resolve,cg-store,cg-syncand tests only; vendoredcg-kernelis untouched.General, Rust and JVM (
f78f346)let (tx, rx) = f()andf()?type each element from the callee's returned tuple.usethrough a barecrate,selforsuperroot no longer adds a file-levelimportsedge to the crate root or parent module.mio::Interest::AIO) resolve by the path as written.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").ybinds likeconst { y } = require("m").8492b90: a call of a var/let/const binding links that variable or constant node, as upstream does.9ead71e:new X()withXa parameter no longer links a same-named class;core.output<T>) resolve through the namespace import and its star exports.adb8c7e:Enum.Memberin a type position links the enum member.1d8913f:newand 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 awindow.SelectFilter = {…}global from another script;c270e80,12d6fd0: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'smodule.exports = require(…).结果 / Results
(源稳定 ID, 目标稳定 ID, 类型, 行, 列),原版d2e0389作对照,基线33040e9。Strict edge sets, key
(src stable ID, dst stable ID, kind, line, col), upstreamd2e0389as the reference, baseline33040e9.No repository loses P or R. Changed repositories are below; Gin, fmt, Alamofire, cJSON, MediatR, Slim and Sinatra are unchanged.
imports精确率 /importsprecision: Tokio 50.91 → 64.55, Zod 96.59 → 97.83.按源文件语言统计 / By source language:
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_e2etests.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 diffidentical.人工抽样。 抽查只有
cgr有、原版没有的边:new File(),c270e80已修复。Hand-checked samples of edges only
cgrhas: Express 48/48 correct, Zod 39/40; the one wrong edge (new File()) is fixed inc270e80.需要注意 / Notes
原版是对照,不是标准答案。 JS/TS 上 P 偏低,主要是原版漏边。剩下的原版独有边,很多是原版猜错的,本 PR 没有照搬:
z.string()、z.number()连到测试文件里的Mocker::string等 getter;ZodCustomStringFormat<"hostname">)连到同名的const,cgr连到接口;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 forz.string(), type positions linked to a same-namedconst, Expressexpress.json()→createApplication).两处约定改为与原版一致:
import Scroller from "./scroller"不再有指向Scroller函数的imports边;调用和 JSX 边仍连到函数;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.