mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-11-29 23:37:41 +00:00
* fix(java): emit wildcard import edges only for package files a file names `import pkg.*;` resolves to every file declaring `pkg`, and each resolved file became a File->File IMPORTS edge. That is importers x package size: 1,000 files importing a 1,000-file package wrote 1,000,005 edges. A 24,736-file Java repository produced 3,742,494 IMPORTS edges this way and ran out of heap writing them (#3695). A Java on-demand import only changes how simple names in the file are read (JLS 7.5.2), so a file depends on a package member only when it spells that member's name. `ScopeResolver.namesMentionedIn` lets a provider say so, and `emitImportEdges` then skips a wildcard edge whose bindable names the importer never mentions. Java opts in with an identifier scan of the source text. Name resolution is unchanged: the finalized import edges are the same, so CALLS, ACCESSES and EXTENDS edges do not move. The scan is a superset on purpose. A type used only in a declaration, cast, instanceof, throws clause or annotation produces no symbol edge, so the IMPORTS edge is the only record of that dependency and must survive. Missing source text or a missing target scope keeps the edge. Refs #3695 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * fix(java): bind wildcard imports to AST uses Resolve package dependencies through lexical scopes and declared packages. Carry use facts through worker/cache boundaries and retain unknown evidence conservatively. Refresh Java resolution together to keep incremental inherited calls consistent with full rebuilds. Refs #3875, #3695 Note: pre-existing failure in test/integration/setup-skills.test.ts not addressed by this PR. Note: pre-existing failure in test/unit/setup.test.ts not addressed by this PR. Note: pre-existing failure in test/unit/auto-sync.test.ts not addressed by this PR. * fix(java): resolve on-demand import uses in one linear AST pass Review 5862533172 on #3875 found one input that fails analysis and five that drop a real File->File IMPORTS edge, plus a path where narrowing did nothing. Capture (import-use-facts.ts) is now a single top-down traversal that carries the lexical scopes of JLS 6.3 instead of walking from every identifier to the root. Its cost no longer depends on expression depth: a file with a wildcard import and a 2,000-operand expression timed out the parse worker (exit 1 after 82 s) and now indexes in 4 s. The scope stack also fixes the scoping errors: - annotations on a package-info.java package declaration are uses; only the package name is skipped - a local declared in a constructor body, a varargs parameter, or a constant of a nested annotation type can no longer attach to an enclosing block or class body - a member type is in scope in the body of its declaring class only, so a same-named nested type elsewhere in the file, or the class's own header, no longer hides the imported type - `Type::new` names a type and is not hidden by a same-named variable The facts shrink from one record per identifier to the distinct names that nothing in the file binds (version 2). The hook resolves those names against explicit imports, the file's package and the wildcard packages, and no longer reads `parsed.scopes`, so narrowing also works when the scope tree is sealed to disk (GITNEXUS_DISK_SCOPE_INDEX=1). Cached facts of any other shape keep every wildcard edge. A type of the importer's package shadows a wildcard type only when it sits in the importer's own directory. The declared package name alone does not show that two files are compiled together (test source set, another build module, sample directories, the default package), and the earlier answer removed the edge in those layouts. The ScopeResolver hook contract now states that the returned set governs every wildcard-expanded edge of the file, and ARCHITECTURE.md lists the hook. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * fix(incremental): rewrite a resolution-group member only when its rows changed Java declares one resolution group for the whole language, so every Java edit put every Java file in the write set and, on a Java-majority repository, took the full wipe-and-bulk-COPY write plan even when no other file's graph rows changed (review 5862533172 on #3875, finding 8). The pipeline has already built the complete new graph when the write set is chosen, so whether an unchanged file needs rewriting has an exact answer. Each run now records a digest of the rows the index holds for every file (its nodes and the file-to-file relationships leaving them; graph-wide rows excluded) in meta.json as `fileRowDigests`, for repositories that have a resolution group. Group members and the files importing them are discovered exactly as before, but each is added to the write set only when its digest in the new graph differs from the recorded one. A file with no recorded digest counts as changed. A recorded digest moves to its new value only when that file's rows were written, so it always describes what the database holds. On a 300-file repository with explicit imports, a one-line edit is a surgical write again (0 of 299 candidates rewritten) instead of an escalated full write. The incremental parity test now compares IMPORTS as well as CALLS with a fresh full rebuild, adds and deletes a same-package type that shadows an on-demand import, and pins that a body edit rewrites no other file. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * fix(java): validate cached wildcard targets Retain dependencies when a target's facts are outdated or malformed. Pin deep-expression scaling and mixed wildcard/cache regressions; document resolution-group writes selected by graph-row changes. Refs #3875 Note: pre-existing failures in test/unit/setup.test.ts and test/integration/setup-skills.test.ts not addressed by this PR. --------- Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com> Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
63 lines
2.4 KiB
TypeScript
63 lines
2.4 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import {
|
|
collectResolutionGroupFiles,
|
|
hasResolutionGroups,
|
|
} from '../../src/core/incremental/resolution-groups.js';
|
|
|
|
describe('incremental resolution groups', () => {
|
|
it('refreshes Java across directories when an unmentioned package type changes or is deleted', () => {
|
|
const javaFiles = ['models/Foo.java', 'generated/Mid.java', 'app/A.java'];
|
|
const mixed = [...javaFiles, 'models/Other.kt', 'models/Other.ts'];
|
|
for (const changed of ['generated/Mid.java', 'removed/Base.java', 'New.java']) {
|
|
expect(collectResolutionGroupFiles([changed], mixed)).toEqual(new Set(javaFiles));
|
|
}
|
|
});
|
|
|
|
const files = [
|
|
'pkg/value_linux.go',
|
|
'pkg/method.go',
|
|
'pkg/internal_test.go',
|
|
'pkg/external_test.go',
|
|
'pkg/other.ts',
|
|
'pkg/sub/value.go',
|
|
'elsewhere/value.go',
|
|
];
|
|
|
|
it('includes current package siblings when the changed path was deleted', () => {
|
|
expect(collectResolutionGroupFiles(['pkg/value_windows.go'], files)).toEqual(
|
|
new Set(files.slice(0, 4)),
|
|
);
|
|
});
|
|
|
|
it('groups added and edited members without crossing directories or languages', () => {
|
|
const changed = ['pkg/value_linux.go', 'pkg/method.go', 'pkg/new.go', 'elsewhere/value.go'];
|
|
expect(collectResolutionGroupFiles(changed, [...files, 'pkg/new.go'])).toEqual(
|
|
new Set([...files.slice(0, 4), 'pkg/new.go', 'elsewhere/value.go']),
|
|
);
|
|
});
|
|
|
|
it('does not expand files whose provider has no resolution grouping hook', () => {
|
|
expect(collectResolutionGroupFiles(['pkg/other.ts', 'pkg/README.md'], files)).toEqual(
|
|
new Set(),
|
|
);
|
|
expect(collectResolutionGroupFiles([], files)).toEqual(new Set());
|
|
});
|
|
|
|
it('supports root packages and normalized directory keys for Windows paths', () => {
|
|
expect(collectResolutionGroupFiles(['removed.go'], ['method.go', 'sub/method.go'])).toEqual(
|
|
new Set(['method.go']),
|
|
);
|
|
expect(collectResolutionGroupFiles(['pkg\\removed.go'], files)).toEqual(
|
|
new Set(files.slice(0, 4)),
|
|
);
|
|
});
|
|
|
|
it.each([
|
|
['a Java file', ['web/app.ts', 'models/Foo.java'], true],
|
|
['a Go file', ['pkg/method.go'], true],
|
|
['only languages without a group', ['web/app.ts', 'models/Other.kt', 'README.md'], false],
|
|
['no files', [], false],
|
|
])('reports whether a repository with %s has a resolution group', (_label, paths, expected) => {
|
|
expect(hasResolutionGroups(paths)).toBe(expected);
|
|
});
|
|
});
|