mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-12-03 00:07:21 +00:00
* docs(plans): add Java overload repair plan * fix(java): resolve overloads by JLS phases Select complete overload families before shared pruning so strict, loose and variable-arity applicability preserve Java call targets. Keep unsupported or ambiguous families terminal and persist their omission boundaries so impact counts cannot imply complete coverage. Preserve declared return types, synthetic members and bounded runtime dispatch. Memoize inheritance walks to avoid exponential diamond work. Fixes #3789 * refactor(java): simplify overload capture paths Reuse record accessor captures and require suppression identity context. Remove redundant cache-layout assertions and test-history comments. Populate real overload receipts in the accuracy fixture so its exact control matches the production metadata contract. * docs: remove implementation plan from PR Exclude the planning document from the published change. * fix(java): honor enclosing protected access * docs(mcp): qualify overload coverage (#3791) * perf(java): bound overload ingestion costs Index method facts and lexical bindings, and avoid repeated native child and callable-definition scans. Add measured cold, warm, and edited scaling checks at 128, 512, and 2048 units. Refs #3789 * refactor(java): simplify overload lookup state Index diagnostic candidates once to bound lookup work linearly, preserving scope and first-match precedence. Keep local bindings out of the field index and remove redundant metadata. Refs #3789 * fix(java): correct replay diagnostics and CI Repeated impact queries exhausted the persistence test's 128 MiB buffer pool. Give the reader 512 MiB and reject partial results before checking callers. Coalesce receiver replay diagnostics by full source-site identity while compacting resolved drops in one linear pass. This removes 51 duplicate receipts without merging distinct calls at the same start position. Refresh the Java capture fingerprints after attributing every difference to return types, var initializers, and seven new fixture files. Keep the 1.5 scaling budget. Receiver calls move 140 -> 141: two new fixture sites and one existing chain newly resolved. Shape states are unchanged; origin counts reflect selected return types instead of earlier guesses. Refs #3789 * ci(java): enforce overload scaling benchmark Run the 54-analysis correctness and scaling check in the existing scope-resolution benchmark job. Upload its report with that job's measurements so regressions fail CI instead of relying on manual runs. Refs #3789 * test(java): clarify overload coverage (#3791) Separate unmodeled call-argument coverage from Java accessibility and confirm the accessible Object overload with an executed javac oracle. Give incomplete-attribution cases distinct titles: JSON formatting drops undefined properties and made three test identities collide in CI. * perf(scope): skip unmatched value names Reject impossible callable names before parsing definition positions or allocating positional keys. Keep the exact file/line/name admission and ambiguity rules unchanged. The callable-value-flow benchmark overhead drops from 1.747-1.883 locally to 1.210-1.271, below the unchanged 1.9 budget. Target fingerprints and cardinalities are identical. Refs #3791 * fix(java): resolve types from static imports Map package-qualified model names to scope-index keys before resolving explicit static member-type imports. Preserve uncertainty for missing or conflicting imports. Verify Number selection after boxing long and preserve the imported source type identity, with an executed javac oracle for both targets. Refs #3791 --------- Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
199 lines
7.2 KiB
TypeScript
199 lines
7.2 KiB
TypeScript
/**
|
|
* #2699 / #2714 — the nested-callable id rule has ONE definition.
|
|
*
|
|
* Three phases in `parse-worker.ts` build the id of a callable nested inside
|
|
* another callable, independently: the definition phase
|
|
* (`callableOwnQualifiedName`), the caller-attribution phase
|
|
* (`findEnclosingFunctionId`), and the worker-path node-id derivation in
|
|
* `processFileGroup`. They must agree byte-for-byte, and when they do not the
|
|
* failure is SILENT — the caller id names a node that does not exist, so the
|
|
* edge is dropped rather than reported. "Zero dangling edges" is what that
|
|
* looks like from the outside, which is why it went unnoticed.
|
|
*
|
|
* Caller attribution really did omit the position suffix until #2714. The fix
|
|
* routed all three through `nestedCallableQualifiedName`; this file pins both
|
|
* halves of that — the rule's contract, and the fact that no call site has
|
|
* re-inlined it.
|
|
*
|
|
* The rule reads only `startPosition` off the node, so a positional stub is a
|
|
* complete input here; parsing real source would add a tree-sitter dependency
|
|
* without testing anything more of this function.
|
|
*
|
|
* The rules live in `callable-id.ts` rather than `parse-worker.ts` precisely so
|
|
* this file can exist: parse-worker posts a `ready` message to `parentPort` at
|
|
* import, so value-importing it from a unit test throws before any test runs.
|
|
*/
|
|
import { readFileSync } from 'node:fs';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { describe, expect, it } from 'vitest';
|
|
import {
|
|
boundCallableStartRow,
|
|
nestedCallableQualifiedName,
|
|
} from '../../src/core/ingestion/workers/callable-id.js';
|
|
import type { NodeLabel, SymbolDefinition } from 'gitnexus-shared';
|
|
import type { SyntaxNode } from '../../src/core/ingestion/utils/ast-helpers.js';
|
|
|
|
const nodeAt = (row: number, column: number): SyntaxNode =>
|
|
({ startPosition: { row, column } }) as unknown as SyntaxNode;
|
|
|
|
function stubNode(opts: {
|
|
type: string;
|
|
id: number;
|
|
row?: number;
|
|
column?: number;
|
|
endRow?: number;
|
|
endColumn?: number;
|
|
}): SyntaxNode {
|
|
return {
|
|
type: opts.type,
|
|
id: opts.id,
|
|
startPosition: { row: opts.row ?? 0, column: opts.column ?? 0 },
|
|
endPosition: {
|
|
row: opts.endRow ?? opts.row ?? 0,
|
|
column: opts.endColumn ?? opts.column ?? 0,
|
|
},
|
|
} as unknown as SyntaxNode;
|
|
}
|
|
|
|
const semanticDef = (
|
|
filePath: string,
|
|
type: NodeLabel,
|
|
name: string,
|
|
line: number,
|
|
column: number,
|
|
): SymbolDefinition => ({
|
|
nodeId: `def:${filePath}#${line}:${column}:${type}:${name}`,
|
|
filePath,
|
|
type,
|
|
qualifiedName: name,
|
|
});
|
|
|
|
describe('boundCallableStartRow - #2735 semantic position join', () => {
|
|
it('reads unrelated definition names only while building the per-file index', () => {
|
|
let reads = 0;
|
|
const defs = Array.from({ length: 128 }, (_, i) => {
|
|
const def = semanticDef('src/file.ext', 'Method', `Owner.method${i}`, i + 1, 0);
|
|
const qualifiedName = def.qualifiedName;
|
|
Object.defineProperty(def, 'qualifiedName', {
|
|
get() {
|
|
reads++;
|
|
return qualifiedName;
|
|
},
|
|
});
|
|
return def;
|
|
});
|
|
for (let i = 0; i < defs.length; i++) {
|
|
const wrapper = stubNode({ type: 'binding_wrapper', id: i, row: i, endColumn: 20 });
|
|
expect(boundCallableStartRow(wrapper, `method${i}`, 'Method', defs)).toBe(i);
|
|
}
|
|
expect(reads).toBeLessThanOrEqual(defs.length * 2);
|
|
});
|
|
|
|
it('keeps the wrapper row when no semantic definition is available', () => {
|
|
const wrapper = stubNode({
|
|
type: 'binding_wrapper',
|
|
id: 1,
|
|
row: 2,
|
|
column: 0,
|
|
endRow: 4,
|
|
endColumn: 1,
|
|
});
|
|
|
|
expect(boundCallableStartRow(wrapper, 'handler', 'Function', undefined)).toBe(2);
|
|
});
|
|
|
|
it('uses the matching semantic callable position inside the wrapper', () => {
|
|
const wrapper = stubNode({
|
|
type: 'binding_wrapper',
|
|
id: 1,
|
|
row: 1,
|
|
column: 0,
|
|
endRow: 5,
|
|
endColumn: 10,
|
|
});
|
|
const name = stubNode({ type: 'binding_name', id: 2, row: 1, column: 4 });
|
|
const defs = [semanticDef('src/file.ext', 'Function', 'handler', 4, 8)];
|
|
|
|
expect(boundCallableStartRow(wrapper, 'handler', 'Function', defs, name)).toBe(3);
|
|
});
|
|
|
|
it('selects by canonical name and label rather than grammar shape', () => {
|
|
const wrapper = stubNode({
|
|
type: 'binding_wrapper',
|
|
id: 1,
|
|
row: 1,
|
|
column: 0,
|
|
endRow: 8,
|
|
endColumn: 10,
|
|
});
|
|
const defs = [
|
|
semanticDef('src/file.ext', 'Function', 'sibling', 3, 4),
|
|
semanticDef('src/file.ext', 'Method', 'handler', 4, 4),
|
|
semanticDef('src/file.ext', 'Function', 'handler', 6, 4),
|
|
];
|
|
|
|
expect(boundCallableStartRow(wrapper, 'handler', 'Function', defs)).toBe(5);
|
|
});
|
|
|
|
it('ignores a same-named semantic definition outside the wrapper', () => {
|
|
const wrapper = stubNode({
|
|
type: 'binding_wrapper',
|
|
id: 1,
|
|
row: 4,
|
|
column: 0,
|
|
endRow: 6,
|
|
endColumn: 10,
|
|
});
|
|
const defs = [semanticDef('src/file.ext', 'Function', 'handler', 2, 0)];
|
|
|
|
expect(boundCallableStartRow(wrapper, 'handler', 'Function', defs)).toBe(4);
|
|
});
|
|
});
|
|
describe('nestedCallableQualifiedName — the shared nested-callable id rule', () => {
|
|
it('qualifies by the enclosing callable AND the declaration position', () => {
|
|
expect(nestedCallableQualifiedName('run', nodeAt(3, 2), 'save')).toBe('run.save@3:2');
|
|
});
|
|
|
|
it('takes the position from the node, never from the name', () => {
|
|
// Guards against a "fix" that formats the suffix from anything but the
|
|
// declaration site — the position is what makes the id unique.
|
|
expect(nestedCallableQualifiedName('outer', nodeAt(12, 9), 'fn')).toBe('outer.fn@12:9');
|
|
});
|
|
|
|
it('separates same-named siblings in different blocks', () => {
|
|
// The case names alone cannot express (#2699): two `pick` bindings in the
|
|
// if/else arms of one function are genuinely different bindings, and both
|
|
// are `outer.pick` by name.
|
|
const first = nestedCallableQualifiedName('outer', nodeAt(2, 4), 'pick');
|
|
const second = nestedCallableQualifiedName('outer', nodeAt(5, 4), 'pick');
|
|
|
|
expect(first).not.toBe(second);
|
|
});
|
|
|
|
it('carries a multi-level chain verbatim in the prefix', () => {
|
|
expect(nestedCallableQualifiedName('A.outer.mid', nodeAt(7, 0), 'inner')).toBe(
|
|
'A.outer.mid.inner@7:0',
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('no call site re-inlines the rule', () => {
|
|
it('parse-worker.ts contains no inlined `<prefix>.${localIdentity(...)}` template', () => {
|
|
// The structural half. The unit assertions above would still pass if a
|
|
// fourth phase appeared and spelled the rule out by hand — which is
|
|
// exactly how the divergence #2714 fixed came to exist.
|
|
//
|
|
// Scope, stated honestly: this matches ONE template spelling — the
|
|
// `${prefix}.${localIdentity(...)}` form the divergence actually took. A
|
|
// hand-rolled id built by string concatenation, or with the interpolation
|
|
// spelled differently, still slips past. It is a tripwire for the known
|
|
// shape, not a proof that no site reconstructs the id.
|
|
const source = readFileSync(
|
|
fileURLToPath(new URL('../../src/core/ingestion/workers/parse-worker.ts', import.meta.url)),
|
|
'utf8',
|
|
);
|
|
const inlined = source.match(/\}\.\$\{localIdentity\(/g) ?? [];
|
|
|
|
expect(inlined).toEqual([]);
|
|
});
|
|
});
|