@colbymchenry/codegraph-win32-arm64 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/codegraph.cmd +1 -1
- package/lib/dist/bin/codegraph.js +106 -19
- package/lib/dist/bin/codegraph.js.map +1 -1
- package/lib/dist/bin/command-supervision.d.ts +38 -1
- package/lib/dist/bin/command-supervision.d.ts.map +1 -1
- package/lib/dist/bin/command-supervision.js +8 -2
- package/lib/dist/bin/command-supervision.js.map +1 -1
- package/lib/dist/context/index.d.ts.map +1 -1
- package/lib/dist/context/index.js +41 -11
- package/lib/dist/context/index.js.map +1 -1
- package/lib/dist/db/index.d.ts +142 -0
- package/lib/dist/db/index.d.ts.map +1 -1
- package/lib/dist/db/index.js +267 -6
- package/lib/dist/db/index.js.map +1 -1
- package/lib/dist/db/migrations.d.ts +1 -1
- package/lib/dist/db/migrations.d.ts.map +1 -1
- package/lib/dist/db/migrations.js +31 -1
- package/lib/dist/db/migrations.js.map +1 -1
- package/lib/dist/db/queries.d.ts +113 -4
- package/lib/dist/db/queries.d.ts.map +1 -1
- package/lib/dist/db/queries.js +398 -24
- package/lib/dist/db/queries.js.map +1 -1
- package/lib/dist/db/schema.sql +13 -1
- package/lib/dist/db/sqlite-adapter.d.ts +3 -1
- package/lib/dist/db/sqlite-adapter.d.ts.map +1 -1
- package/lib/dist/db/sqlite-adapter.js +22 -4
- package/lib/dist/db/sqlite-adapter.js.map +1 -1
- package/lib/dist/db/wal-valve.d.ts +15 -2
- package/lib/dist/db/wal-valve.d.ts.map +1 -1
- package/lib/dist/db/wal-valve.js +88 -6
- package/lib/dist/db/wal-valve.js.map +1 -1
- package/lib/dist/extraction/grammars.d.ts.map +1 -1
- package/lib/dist/extraction/grammars.js +63 -0
- package/lib/dist/extraction/grammars.js.map +1 -1
- package/lib/dist/extraction/index.d.ts +32 -3
- package/lib/dist/extraction/index.d.ts.map +1 -1
- package/lib/dist/extraction/index.js +313 -56
- package/lib/dist/extraction/index.js.map +1 -1
- package/lib/dist/extraction/kernel/decode.d.ts +9 -0
- package/lib/dist/extraction/kernel/decode.d.ts.map +1 -0
- package/lib/dist/extraction/kernel/decode.js +162 -0
- package/lib/dist/extraction/kernel/decode.js.map +1 -0
- package/lib/dist/extraction/kernel/index.d.ts +64 -0
- package/lib/dist/extraction/kernel/index.d.ts.map +1 -0
- package/lib/dist/extraction/kernel/index.js +279 -0
- package/lib/dist/extraction/kernel/index.js.map +1 -0
- package/lib/dist/extraction/kernel/layout.d.ts +101 -0
- package/lib/dist/extraction/kernel/layout.d.ts.map +1 -0
- package/lib/dist/extraction/kernel/layout.js +104 -0
- package/lib/dist/extraction/kernel/layout.js.map +1 -0
- package/lib/dist/extraction/kernel/loader.d.ts +103 -0
- package/lib/dist/extraction/kernel/loader.d.ts.map +1 -0
- package/lib/dist/extraction/kernel/loader.js +146 -0
- package/lib/dist/extraction/kernel/loader.js.map +1 -0
- package/lib/dist/extraction/languages/c-cpp.d.ts +14 -0
- package/lib/dist/extraction/languages/c-cpp.d.ts.map +1 -1
- package/lib/dist/extraction/languages/c-cpp.js +849 -12
- package/lib/dist/extraction/languages/c-cpp.js.map +1 -1
- package/lib/dist/extraction/parse-pool.d.ts +8 -0
- package/lib/dist/extraction/parse-pool.d.ts.map +1 -1
- package/lib/dist/extraction/parse-pool.js +15 -0
- package/lib/dist/extraction/parse-pool.js.map +1 -1
- package/lib/dist/extraction/parse-worker.js +35 -1
- package/lib/dist/extraction/parse-worker.js.map +1 -1
- package/lib/dist/extraction/store-worker.d.ts +24 -0
- package/lib/dist/extraction/store-worker.d.ts.map +1 -0
- package/lib/dist/extraction/store-worker.js +139 -0
- package/lib/dist/extraction/store-worker.js.map +1 -0
- package/lib/dist/extraction/store-writer.d.ts +63 -0
- package/lib/dist/extraction/store-writer.d.ts.map +1 -0
- package/lib/dist/extraction/store-writer.js +174 -0
- package/lib/dist/extraction/store-writer.js.map +1 -0
- package/lib/dist/extraction/tree-sitter.d.ts +22 -4
- package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.js +151 -6
- package/lib/dist/extraction/tree-sitter.js.map +1 -1
- package/lib/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
- package/lib/dist/extraction/wasm-runtime-flags.d.ts +15 -0
- package/lib/dist/extraction/wasm-runtime-flags.d.ts.map +1 -1
- package/lib/dist/extraction/wasm-runtime-flags.js +27 -3
- package/lib/dist/extraction/wasm-runtime-flags.js.map +1 -1
- package/lib/dist/index.d.ts +19 -6
- package/lib/dist/index.d.ts.map +1 -1
- package/lib/dist/index.js +233 -17
- package/lib/dist/index.js.map +1 -1
- package/lib/dist/installer/beta-signup.d.ts +54 -0
- package/lib/dist/installer/beta-signup.d.ts.map +1 -0
- package/lib/dist/installer/beta-signup.js +178 -0
- package/lib/dist/installer/beta-signup.js.map +1 -0
- package/lib/dist/installer/index.d.ts +42 -0
- package/lib/dist/installer/index.d.ts.map +1 -1
- package/lib/dist/installer/index.js +105 -1
- package/lib/dist/installer/index.js.map +1 -1
- package/lib/dist/mcp/index.d.ts.map +1 -1
- package/lib/dist/mcp/index.js +8 -0
- package/lib/dist/mcp/index.js.map +1 -1
- package/lib/dist/mcp/liveness-watchdog.d.ts +18 -1
- package/lib/dist/mcp/liveness-watchdog.d.ts.map +1 -1
- package/lib/dist/mcp/liveness-watchdog.js +73 -13
- package/lib/dist/mcp/liveness-watchdog.js.map +1 -1
- package/lib/dist/mcp/proxy.js +1 -1
- package/lib/dist/mcp/proxy.js.map +1 -1
- package/lib/dist/mcp/session.d.ts +14 -0
- package/lib/dist/mcp/session.d.ts.map +1 -1
- package/lib/dist/mcp/session.js +22 -1
- package/lib/dist/mcp/session.js.map +1 -1
- package/lib/dist/mcp/tools.d.ts.map +1 -1
- package/lib/dist/mcp/tools.js +76 -1
- package/lib/dist/mcp/tools.js.map +1 -1
- package/lib/dist/resolution/c-fnptr-synthesizer.d.ts +1 -1
- package/lib/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/c-fnptr-synthesizer.js +574 -132
- package/lib/dist/resolution/c-fnptr-synthesizer.js.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.d.ts +54 -10
- package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.js +249 -157
- package/lib/dist/resolution/callback-synthesizer.js.map +1 -1
- package/lib/dist/resolution/cooperative-yield.d.ts +10 -2
- package/lib/dist/resolution/cooperative-yield.d.ts.map +1 -1
- package/lib/dist/resolution/cooperative-yield.js +6 -4
- package/lib/dist/resolution/cooperative-yield.js.map +1 -1
- package/lib/dist/resolution/frameworks/go.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/go.js +29 -6
- package/lib/dist/resolution/frameworks/go.js.map +1 -1
- package/lib/dist/resolution/import-resolver.d.ts +2 -3
- package/lib/dist/resolution/import-resolver.d.ts.map +1 -1
- package/lib/dist/resolution/import-resolver.js +166 -7
- package/lib/dist/resolution/import-resolver.js.map +1 -1
- package/lib/dist/resolution/index.d.ts +97 -2
- package/lib/dist/resolution/index.d.ts.map +1 -1
- package/lib/dist/resolution/index.js +783 -124
- package/lib/dist/resolution/index.js.map +1 -1
- package/lib/dist/resolution/memory-budget.d.ts +48 -0
- package/lib/dist/resolution/memory-budget.d.ts.map +1 -0
- package/lib/dist/resolution/memory-budget.js +162 -0
- package/lib/dist/resolution/memory-budget.js.map +1 -0
- package/lib/dist/resolution/name-matcher.d.ts +12 -1
- package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
- package/lib/dist/resolution/name-matcher.js +517 -96
- package/lib/dist/resolution/name-matcher.js.map +1 -1
- package/lib/dist/resolution/resolver-pool.d.ts +106 -0
- package/lib/dist/resolution/resolver-pool.d.ts.map +1 -0
- package/lib/dist/resolution/resolver-pool.js +344 -0
- package/lib/dist/resolution/resolver-pool.js.map +1 -0
- package/lib/dist/resolution/resolver-worker.d.ts +17 -0
- package/lib/dist/resolution/resolver-worker.d.ts.map +1 -0
- package/lib/dist/resolution/resolver-worker.js +141 -0
- package/lib/dist/resolution/resolver-worker.js.map +1 -0
- package/lib/dist/resolution/types.d.ts +3 -0
- package/lib/dist/resolution/types.d.ts.map +1 -1
- package/lib/dist/sync/watcher.d.ts +25 -1
- package/lib/dist/sync/watcher.d.ts.map +1 -1
- package/lib/dist/sync/watcher.js +76 -3
- package/lib/dist/sync/watcher.js.map +1 -1
- package/lib/dist/types.d.ts +41 -2
- package/lib/dist/types.d.ts.map +1 -1
- package/lib/dist/types.js +26 -1
- package/lib/dist/types.js.map +1 -1
- package/lib/dist/ui/color.d.ts +21 -0
- package/lib/dist/ui/color.d.ts.map +1 -0
- package/lib/dist/ui/color.js +42 -0
- package/lib/dist/ui/color.js.map +1 -0
- package/lib/dist/ui/glyphs.d.ts +35 -10
- package/lib/dist/ui/glyphs.d.ts.map +1 -1
- package/lib/dist/ui/glyphs.js +59 -12
- package/lib/dist/ui/glyphs.js.map +1 -1
- package/lib/dist/ui/shimmer-progress.d.ts.map +1 -1
- package/lib/dist/ui/shimmer-progress.js +78 -4
- package/lib/dist/ui/shimmer-progress.js.map +1 -1
- package/lib/dist/ui/shimmer-worker.js +25 -17
- package/lib/dist/ui/shimmer-worker.js.map +1 -1
- package/lib/dist/ui/types.d.ts +0 -2
- package/lib/dist/ui/types.d.ts.map +1 -1
- package/lib/dist/upgrade/index.d.ts +39 -0
- package/lib/dist/upgrade/index.d.ts.map +1 -1
- package/lib/dist/upgrade/index.js +180 -19
- package/lib/dist/upgrade/index.js.map +1 -1
- package/lib/dist/upgrade/remove-binary.d.ts +87 -0
- package/lib/dist/upgrade/remove-binary.d.ts.map +1 -0
- package/lib/dist/upgrade/remove-binary.js +289 -0
- package/lib/dist/upgrade/remove-binary.js.map +1 -0
- package/lib/dist/upgrade/update-check.d.ts +92 -0
- package/lib/dist/upgrade/update-check.d.ts.map +1 -0
- package/lib/dist/upgrade/update-check.js +258 -0
- package/lib/dist/upgrade/update-check.js.map +1 -0
- package/lib/kernel/codegraph-kernel.node +0 -0
- package/lib/node_modules/.package-lock.json +1 -1
- package/lib/package.json +6 -1
- package/package.json +6 -2
|
@@ -47,6 +47,7 @@ const fs = __importStar(require("fs"));
|
|
|
47
47
|
const path = __importStar(require("path"));
|
|
48
48
|
const name_matcher_1 = require("./name-matcher");
|
|
49
49
|
const import_resolver_1 = require("./import-resolver");
|
|
50
|
+
const resolver_pool_1 = require("./resolver-pool");
|
|
50
51
|
const frameworks_1 = require("./frameworks");
|
|
51
52
|
const callback_synthesizer_1 = require("./callback-synthesizer");
|
|
52
53
|
const cooperative_yield_1 = require("./cooperative-yield");
|
|
@@ -68,6 +69,8 @@ const CHAIN_LANGUAGES = new Set(['java', 'kotlin', 'csharp', 'swift', 'rust', 'g
|
|
|
68
69
|
const SCOPED_CHAIN_LANGUAGES = new Set(['rust']);
|
|
69
70
|
/** The extractor's chained-receiver encoding: `<inner>().<method>`. */
|
|
70
71
|
const CHAIN_SHAPE = /^(.+)\(\)\.(\w+)$/;
|
|
72
|
+
/** PHP `$this->prop->method()` encoded as `this->prop.method` — no `()`, so CHAIN_SHAPE misses it. */
|
|
73
|
+
const PHP_PROP_SHAPE = /^this->\w+\.\w+$/;
|
|
71
74
|
/**
|
|
72
75
|
* Cache size limits. Each per-resolver cache is bounded so memory
|
|
73
76
|
* stays flat on large codebases (20k+ files). Sizes were chosen to
|
|
@@ -242,6 +245,32 @@ class ReferenceResolver {
|
|
|
242
245
|
qualifiedNameCache; // qualified_name → nodes cache
|
|
243
246
|
fileLinesCache; // file → split lines cache
|
|
244
247
|
methodMatchCache; // lang\0Type::method → matching method nodes
|
|
248
|
+
// Per-(language, methodName) owner index for getMethodMatches: buckets a
|
|
249
|
+
// method name's candidates by their qualifiedName's last two segments so a
|
|
250
|
+
// (type, method) query is a lookup instead of an O(candidates) filter per
|
|
251
|
+
// methodMatchCache miss. Derived purely from node rows (stable through the
|
|
252
|
+
// resolution loop, same window nameCache relies on); dropped in clearCaches.
|
|
253
|
+
methodOwnerIndexCache = new Map();
|
|
254
|
+
// Generation-tagged memo for getSupertypes. Supertype edges GROW during the
|
|
255
|
+
// resolution loop (batch k persists its implements/extends edges BEFORE
|
|
256
|
+
// batch k+1 fans out — the #1320 ordering), so a plain cache would freeze an
|
|
257
|
+
// early batch's emptier answer and change later batches' outcomes. Within
|
|
258
|
+
// one batch the edge state is fixed by that same ordering, so entries are
|
|
259
|
+
// tagged with a generation that advances at every batch entry point
|
|
260
|
+
// (resolveBatchYielding / resolveListForAdmission) — a stale-gen entry is
|
|
261
|
+
// recomputed, making the memo behavior-identical to no memo at every point
|
|
262
|
+
// in time. On the Swift compiler the unmemoized walk ran 971k times for
|
|
263
|
+
// 565s of combined worker time (~581µs each, recursion-multiplied).
|
|
264
|
+
supertypeGen = 0;
|
|
265
|
+
supertypeMemo = new Map();
|
|
266
|
+
/** Invalidate the getSupertypes memo — call when resolved edges may have advanced. */
|
|
267
|
+
advanceSupertypeGeneration() {
|
|
268
|
+
this.supertypeGen++;
|
|
269
|
+
// Lazy invalidation via the gen tag; bound the map so a long run over many
|
|
270
|
+
// batches doesn't accrete dead entries.
|
|
271
|
+
if (this.supertypeMemo.size > 50_000)
|
|
272
|
+
this.supertypeMemo.clear();
|
|
273
|
+
}
|
|
245
274
|
// Node kinds are a small fixed set (~24), so this is a plain Map, not an LRU.
|
|
246
275
|
// getNodesByKind returns the FULL node list for a kind; it was previously
|
|
247
276
|
// uncached — a per-ref `SELECT * FROM nodes WHERE kind=?` + row-mapping. Called
|
|
@@ -370,10 +399,19 @@ class ReferenceResolver {
|
|
|
370
399
|
this.qualifiedNameCache.clear();
|
|
371
400
|
this.fileLinesCache.clear();
|
|
372
401
|
this.methodMatchCache.clear();
|
|
402
|
+
this.methodOwnerIndexCache.clear();
|
|
403
|
+
this.supertypeMemo.clear();
|
|
404
|
+
this.supertypeGen++;
|
|
373
405
|
this.nodesByKindCache.clear();
|
|
374
406
|
this.knownNames = null;
|
|
375
407
|
this.knownFiles = null;
|
|
376
408
|
this.cachesWarmed = false;
|
|
409
|
+
// The import-resolver's and name-matcher's per-context memos assume the
|
|
410
|
+
// same stable window as the caches above — drop them together.
|
|
411
|
+
if (this.context) {
|
|
412
|
+
(0, import_resolver_1.clearImportResolverMemos)(this.context);
|
|
413
|
+
(0, name_matcher_1.clearNameMatcherMemos)(this.context);
|
|
414
|
+
}
|
|
377
415
|
}
|
|
378
416
|
/** `readFile` through the LRU content cache (null = read failed, also cached). */
|
|
379
417
|
readFileCached(filePath) {
|
|
@@ -422,15 +460,61 @@ class ReferenceResolver {
|
|
|
422
460
|
this.nameCache.set(methodName, candidates);
|
|
423
461
|
}
|
|
424
462
|
const want = `${typeName}::${methodName}`;
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
463
|
+
let matches;
|
|
464
|
+
if (typeName.includes('::') || methodName.includes(':')) {
|
|
465
|
+
// Legacy linear filter for the shapes the owner index below can't
|
|
466
|
+
// key exactly: a multi-segment typeName (the endsWith test then
|
|
467
|
+
// spans more than two `::` segments) and ObjC selectors (whose
|
|
468
|
+
// single/empty-keyword colons defeat the segment split). Tiny
|
|
469
|
+
// populations; the per-key memo above still amortizes them.
|
|
470
|
+
matches = [];
|
|
471
|
+
for (const m of candidates) {
|
|
472
|
+
if (m.kind !== 'method')
|
|
473
|
+
continue;
|
|
474
|
+
if (m.language !== language)
|
|
475
|
+
continue;
|
|
476
|
+
const qn = m.qualifiedName;
|
|
477
|
+
if (qn === want || qn.endsWith(`::${want}`))
|
|
478
|
+
matches.push(m);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
// Owner index: the linear filter above is O(all same-named methods)
|
|
483
|
+
// per CACHE MISS, and on overload-heavy landscapes the distinct
|
|
484
|
+
// (type, method) key space is so large the per-key memo never
|
|
485
|
+
// amortizes — Swift's `init` has tens of thousands of candidates
|
|
486
|
+
// and the compiler repo measured 732µs per failing call, most of it
|
|
487
|
+
// this scan (re-entered once per supertype recursion level, too).
|
|
488
|
+
// Bucket each (language, methodName)'s candidates ONCE by the
|
|
489
|
+
// qualifiedName's last two `::` segments — exactly the span the
|
|
490
|
+
// `qn === want || qn.endsWith('::' + want)` predicate tests for a
|
|
491
|
+
// segment-clean typeName — then every query is a map lookup.
|
|
492
|
+
// Bucket insertion follows candidate order, so each bucket is
|
|
493
|
+
// byte-identical to what the linear filter produced.
|
|
494
|
+
const idxKey = `${language} ${methodName}`;
|
|
495
|
+
let ownerIndex = this.methodOwnerIndexCache.get(idxKey);
|
|
496
|
+
if (!ownerIndex) {
|
|
497
|
+
ownerIndex = new Map();
|
|
498
|
+
for (const m of candidates) {
|
|
499
|
+
if (m.kind !== 'method')
|
|
500
|
+
continue;
|
|
501
|
+
if (m.language !== language)
|
|
502
|
+
continue;
|
|
503
|
+
const qn = m.qualifiedName;
|
|
504
|
+
const i2 = qn.lastIndexOf('::');
|
|
505
|
+
if (i2 < 0)
|
|
506
|
+
continue; // single-segment qn can never match `T::m`
|
|
507
|
+
const i1 = qn.lastIndexOf('::', i2 - 1);
|
|
508
|
+
const bucketKey = i1 < 0 ? qn : qn.slice(i1 + 2);
|
|
509
|
+
const bucket = ownerIndex.get(bucketKey);
|
|
510
|
+
if (bucket)
|
|
511
|
+
bucket.push(m);
|
|
512
|
+
else
|
|
513
|
+
ownerIndex.set(bucketKey, [m]);
|
|
514
|
+
}
|
|
515
|
+
this.methodOwnerIndexCache.set(idxKey, ownerIndex);
|
|
516
|
+
}
|
|
517
|
+
matches = ownerIndex.get(want) ?? [];
|
|
434
518
|
}
|
|
435
519
|
this.methodMatchCache.set(key, matches);
|
|
436
520
|
return matches;
|
|
@@ -522,20 +606,34 @@ class ReferenceResolver {
|
|
|
522
606
|
// Matching by simple name (not id) reconciles a type declared in one node
|
|
523
607
|
// (`KF::Builder`) with conformance declared in a separate extension node
|
|
524
608
|
// (`KF.Builder: KFOptionSetter`) — both have name `Builder`.
|
|
609
|
+
// Memoized per batch generation (see supertypeMemo): within a batch the
|
|
610
|
+
// edge state is fixed, and the conformance walk re-queries the same
|
|
611
|
+
// popular supertypes (Swift stdlib protocols especially) thousands of
|
|
612
|
+
// times per batch.
|
|
613
|
+
const memoKey = `${language} ${typeName}`;
|
|
614
|
+
const hit = this.supertypeMemo.get(memoKey);
|
|
615
|
+
if (hit && hit.gen === this.supertypeGen)
|
|
616
|
+
return hit.supers;
|
|
525
617
|
const typeNodes = this.context
|
|
526
618
|
.getNodesByName(typeName)
|
|
527
619
|
.filter((n) => SUPERTYPE_BEARING_KINDS.has(n.kind) && n.language === language);
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
620
|
+
let supers;
|
|
621
|
+
if (typeNodes.length === 0) {
|
|
622
|
+
supers = [];
|
|
623
|
+
}
|
|
624
|
+
else {
|
|
625
|
+
const supertypes = new Set();
|
|
626
|
+
for (const tn of typeNodes) {
|
|
627
|
+
for (const edge of this.queries.getOutgoingEdges(tn.id, ['implements', 'extends'])) {
|
|
628
|
+
const target = this.queries.getNodeById(edge.target);
|
|
629
|
+
if (target?.name && target.name !== typeName)
|
|
630
|
+
supertypes.add(target.name);
|
|
631
|
+
}
|
|
536
632
|
}
|
|
633
|
+
supers = [...supertypes];
|
|
537
634
|
}
|
|
538
|
-
|
|
635
|
+
this.supertypeMemo.set(memoKey, { gen: this.supertypeGen, supers });
|
|
636
|
+
return supers;
|
|
539
637
|
},
|
|
540
638
|
getImportMappings: (filePath, language) => {
|
|
541
639
|
const cacheKey = filePath;
|
|
@@ -613,12 +711,13 @@ class ReferenceResolver {
|
|
|
613
711
|
column: ref.column,
|
|
614
712
|
filePath: ref.filePath || this.getFilePathFromNodeId(ref.fromNodeId),
|
|
615
713
|
language: ref.language || this.getLanguageFromNodeId(ref.fromNodeId),
|
|
714
|
+
rowId: ref.rowId,
|
|
616
715
|
}));
|
|
617
716
|
const total = refs.length;
|
|
618
717
|
let lastReportedPercent = -1;
|
|
619
718
|
for (let i = 0; i < refs.length; i++) {
|
|
620
719
|
const ref = refs[i]; // Array index is guaranteed to be in bounds
|
|
621
|
-
const result = this.
|
|
720
|
+
const result = this.resolveOneTimed(ref);
|
|
622
721
|
if (result) {
|
|
623
722
|
resolved.push(result);
|
|
624
723
|
byMethod[result.resolvedBy] = (byMethod[result.resolvedBy] || 0) + 1;
|
|
@@ -780,10 +879,14 @@ class ReferenceResolver {
|
|
|
780
879
|
const existenceName = ref.language === 'arkts' && ref.referenceName.startsWith('.')
|
|
781
880
|
? ref.referenceName.slice(1)
|
|
782
881
|
: ref.referenceName;
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
882
|
+
const tPre = this.profileStages ? process.hrtime.bigint() : 0n;
|
|
883
|
+
const preFilterPass = (0, import_resolver_1.isNixPathImportRef)(ref) ||
|
|
884
|
+
this.hasAnyPossibleMatch(existenceName) ||
|
|
885
|
+
this.matchesAnyImport(ref) ||
|
|
886
|
+
this.frameworks.some((f) => f.claimsReference?.(ref.referenceName));
|
|
887
|
+
if (this.profileStages)
|
|
888
|
+
this.stageAdd('preFilter', ref, preFilterPass, tPre);
|
|
889
|
+
if (!preFilterPass) {
|
|
787
890
|
return null;
|
|
788
891
|
}
|
|
789
892
|
// Function-as-value refs (#756) get a dedicated, strictly-gated path:
|
|
@@ -809,7 +912,10 @@ class ReferenceResolver {
|
|
|
809
912
|
// JVM FQN imports skip framework/name-matcher: `import com.example.Bar`
|
|
810
913
|
// resolves directly through the qualifiedName index, which is unambiguous
|
|
811
914
|
// even when several `Bar` classes exist in different packages.
|
|
915
|
+
const tJvm = this.profileStages ? process.hrtime.bigint() : 0n;
|
|
812
916
|
const jvmImport = (0, import_resolver_1.resolveJvmImport)(ref, this.context);
|
|
917
|
+
if (this.profileStages)
|
|
918
|
+
this.stageAdd('jvmImport', ref, !!jvmImport, tJvm);
|
|
813
919
|
if (jvmImport)
|
|
814
920
|
return jvmImport;
|
|
815
921
|
// Razor/Blazor: a markup or `@code` type ref resolves through the file's
|
|
@@ -828,16 +934,27 @@ class ReferenceResolver {
|
|
|
828
934
|
// JS → native `calls`) — `gateFrameworkLanguage` only drops a type/import
|
|
829
935
|
// edge between two KNOWN families (see its doc), never a `calls` bridge or
|
|
830
936
|
// a config↔code edge.
|
|
937
|
+
const tFw = this.profileStages ? process.hrtime.bigint() : 0n;
|
|
938
|
+
let fwEarly = null;
|
|
831
939
|
for (const framework of this.frameworks) {
|
|
832
940
|
const result = this.gateFrameworkLanguage(framework.resolve(ref, this.context), ref);
|
|
833
941
|
if (result) {
|
|
834
|
-
if (result.confidence >= 0.9)
|
|
835
|
-
|
|
942
|
+
if (result.confidence >= 0.9) {
|
|
943
|
+
fwEarly = result; // High confidence, return immediately (below)
|
|
944
|
+
break;
|
|
945
|
+
}
|
|
836
946
|
candidates.push(result);
|
|
837
947
|
}
|
|
838
948
|
}
|
|
949
|
+
if (this.profileStages)
|
|
950
|
+
this.stageAdd('frameworks', ref, fwEarly !== null, tFw);
|
|
951
|
+
if (fwEarly)
|
|
952
|
+
return fwEarly;
|
|
839
953
|
// Strategy 2: Try import-based resolution
|
|
954
|
+
const tImp = this.profileStages ? process.hrtime.bigint() : 0n;
|
|
840
955
|
const importResult = this.gateLanguage((0, import_resolver_1.resolveViaImport)(ref, this.context), ref);
|
|
956
|
+
if (this.profileStages)
|
|
957
|
+
this.stageAdd('viaImport', ref, !!importResult, tImp);
|
|
841
958
|
if (importResult) {
|
|
842
959
|
if (importResult.confidence >= 0.9)
|
|
843
960
|
return importResult;
|
|
@@ -859,7 +976,10 @@ class ReferenceResolver {
|
|
|
859
976
|
: null;
|
|
860
977
|
}
|
|
861
978
|
// Strategy 3: Try name matching
|
|
979
|
+
const tName = this.profileStages ? process.hrtime.bigint() : 0n;
|
|
862
980
|
let nameResult = this.gateLanguage((0, name_matcher_1.matchReference)(ref, this.context), ref);
|
|
981
|
+
if (this.profileStages)
|
|
982
|
+
this.stageAdd('nameMatch', ref, !!nameResult, tName);
|
|
863
983
|
// Nix has no ambient cross-file namespace — a callee binds lexically
|
|
864
984
|
// (same file) or through explicit import/callPackage wiring (the import
|
|
865
985
|
// path above). A cross-file name match is wrong by construction: every
|
|
@@ -893,6 +1013,15 @@ class ReferenceResolver {
|
|
|
893
1013
|
CHAIN_SHAPE.test(ref.referenceName)) {
|
|
894
1014
|
this.deferredChainRefs.push(ref);
|
|
895
1015
|
}
|
|
1016
|
+
else if (
|
|
1017
|
+
// PHP `$this->prop->method()` (encoded `this->prop.method`): its method
|
|
1018
|
+
// may live on the property's declared supertype, resolvable only once
|
|
1019
|
+
// implements/extends edges exist — defer to the same conformance pass.
|
|
1020
|
+
ref.referenceKind === 'calls' &&
|
|
1021
|
+
ref.language === 'php' &&
|
|
1022
|
+
PHP_PROP_SHAPE.test(ref.referenceName)) {
|
|
1023
|
+
this.deferredChainRefs.push(ref);
|
|
1024
|
+
}
|
|
896
1025
|
return null;
|
|
897
1026
|
}
|
|
898
1027
|
// Return highest confidence candidate
|
|
@@ -939,6 +1068,18 @@ class ReferenceResolver {
|
|
|
939
1068
|
metadata: {
|
|
940
1069
|
confidence: ref.confidence,
|
|
941
1070
|
resolvedBy: ref.resolvedBy,
|
|
1071
|
+
// The ORIGINAL reference text (and kind, when edge-kind promotion
|
|
1072
|
+
// rewrote it — calls→instantiates, extends→implements,
|
|
1073
|
+
// function_ref→references). If this edge's target is later removed
|
|
1074
|
+
// by a re-index, the edge is resurrected as exactly this ref and
|
|
1075
|
+
// re-resolved (#1240 removal case) — a faithful resurrection, so
|
|
1076
|
+
// re-resolution can never bind anywhere a full re-index wouldn't.
|
|
1077
|
+
// Reconstruction from the target node's name instead would strip
|
|
1078
|
+
// receiver/qualifier context (`h.greet` → `greet`) and risk a
|
|
1079
|
+
// wrong rebind; edges without refName (pre-#1240, synthesized) are
|
|
1080
|
+
// deliberately NOT resurrected for the same reason.
|
|
1081
|
+
refName: ref.original.referenceName,
|
|
1082
|
+
...(ref.original.referenceKind !== kind ? { refKind: ref.original.referenceKind } : {}),
|
|
942
1083
|
// Uniform marker for function-as-value edges (#756), regardless of
|
|
943
1084
|
// which strategy resolved them (import vs matchFunctionRef) — lets
|
|
944
1085
|
// tooling label "callback registration" and lets validation diff
|
|
@@ -948,6 +1089,52 @@ class ReferenceResolver {
|
|
|
948
1089
|
};
|
|
949
1090
|
});
|
|
950
1091
|
}
|
|
1092
|
+
/**
|
|
1093
|
+
* Split resolved refs into rows deletable by id and hand-built refs that
|
|
1094
|
+
* must fall back to the key-tuple delete. Rows loaded from the database
|
|
1095
|
+
* carry their row id and are deleted by exactly that id; the key tuple
|
|
1096
|
+
* omits line/col, so it also removes SIBLING rows — the same caller calling
|
|
1097
|
+
* the same callee at other lines — that a later batch hadn't attempted yet:
|
|
1098
|
+
* when a batch boundary split a caller's same-named call sites, the later
|
|
1099
|
+
* sites' edges were silently never created (#1269).
|
|
1100
|
+
*/
|
|
1101
|
+
static partitionResolvedCleanup(resolved) {
|
|
1102
|
+
const rowIds = [];
|
|
1103
|
+
const legacyKeys = [];
|
|
1104
|
+
for (const r of resolved) {
|
|
1105
|
+
if (r.original.rowId != null)
|
|
1106
|
+
rowIds.push(r.original.rowId);
|
|
1107
|
+
else
|
|
1108
|
+
legacyKeys.push({
|
|
1109
|
+
fromNodeId: r.original.fromNodeId,
|
|
1110
|
+
referenceName: r.original.referenceName,
|
|
1111
|
+
referenceKind: r.original.referenceKind,
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
return { rowIds, legacyKeys };
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Same row-id precision for parking unresolvable refs as status='failed'
|
|
1118
|
+
* (#1240): the key-tuple fallback would flip same-key sibling rows in later
|
|
1119
|
+
* batches to 'failed' before they were ever attempted, and resolution
|
|
1120
|
+
* outcome can differ per call site (receiver-type inference reads the
|
|
1121
|
+
* ref's line), so a sibling must not inherit this row's failure (#1269).
|
|
1122
|
+
*/
|
|
1123
|
+
static partitionFailedCleanup(unresolved) {
|
|
1124
|
+
const byRowId = [];
|
|
1125
|
+
const legacyKeys = [];
|
|
1126
|
+
for (const r of unresolved) {
|
|
1127
|
+
if (r.rowId != null)
|
|
1128
|
+
byRowId.push({ rowId: r.rowId, referenceName: r.referenceName });
|
|
1129
|
+
else
|
|
1130
|
+
legacyKeys.push({
|
|
1131
|
+
fromNodeId: r.fromNodeId,
|
|
1132
|
+
referenceName: r.referenceName,
|
|
1133
|
+
referenceKind: r.referenceKind,
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
return { byRowId, legacyKeys };
|
|
1137
|
+
}
|
|
951
1138
|
/**
|
|
952
1139
|
* Resolve and persist edges to database
|
|
953
1140
|
*/
|
|
@@ -961,25 +1148,61 @@ class ReferenceResolver {
|
|
|
961
1148
|
}
|
|
962
1149
|
// Clean up resolved refs from unresolved_refs table so metrics are accurate
|
|
963
1150
|
if (result.resolved.length > 0) {
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
//
|
|
971
|
-
//
|
|
972
|
-
//
|
|
973
|
-
//
|
|
974
|
-
//
|
|
975
|
-
// still
|
|
976
|
-
//
|
|
1151
|
+
const { rowIds, legacyKeys } = ReferenceResolver.partitionResolvedCleanup(result.resolved);
|
|
1152
|
+
this.queries.deleteReferencesByRowIds(rowIds);
|
|
1153
|
+
this.queries.deleteSpecificResolvedReferences(legacyKeys);
|
|
1154
|
+
}
|
|
1155
|
+
// Park unresolvable refs as status='failed' — parity with
|
|
1156
|
+
// resolveAndPersistBatched. Deleting them was wrong (#1240): a ref whose
|
|
1157
|
+
// own file never changes is otherwise gone forever, so when a DIFFERENT
|
|
1158
|
+
// file later gains the export/symbol that would satisfy it, no sync can
|
|
1159
|
+
// recreate the edge — only a full re-index. Failed rows are excluded from
|
|
1160
|
+
// the pending readers, which preserves the #1187 orphan sweep's
|
|
1161
|
+
// invariant in status form: after a COMPLETED pass nothing it processed
|
|
1162
|
+
// is still 'pending', so any pending row at rest belongs to an
|
|
1163
|
+
// interrupted run and the sweep can key off the pending count.
|
|
977
1164
|
if (result.unresolved.length > 0) {
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
1165
|
+
const { byRowId, legacyKeys } = ReferenceResolver.partitionFailedCleanup(result.unresolved);
|
|
1166
|
+
this.queries.markReferencesFailedByRowIds(byRowId);
|
|
1167
|
+
this.queries.markReferencesFailed(legacyKeys);
|
|
1168
|
+
}
|
|
1169
|
+
return result;
|
|
1170
|
+
}
|
|
1171
|
+
/**
|
|
1172
|
+
* Yielding counterpart of {@link resolveAndPersist} for a caller-supplied
|
|
1173
|
+
* ref list — used by sync's failed-ref retry pass (#1240). Same persistence
|
|
1174
|
+
* semantics: resolved refs become edges and their rows are deleted;
|
|
1175
|
+
* still-unresolvable refs are (re-)marked failed (a no-op for rows already
|
|
1176
|
+
* in that status). Yields per-ref because sync can run on the daemon's
|
|
1177
|
+
* liveness-watchdog thread (#850/#1091) and a retry set is unbounded when
|
|
1178
|
+
* a large edit lands many popular symbol names at once.
|
|
1179
|
+
*/
|
|
1180
|
+
async resolveAndPersistListYielding(refs) {
|
|
1181
|
+
const maybeYield = (0, cooperative_yield_1.createYielder)();
|
|
1182
|
+
const result = await this.resolveBatchYielding(refs, maybeYield);
|
|
1183
|
+
const PERSIST_CHUNK = 1000;
|
|
1184
|
+
const edges = this.createEdges(result.resolved);
|
|
1185
|
+
for (let i = 0; i < edges.length; i += PERSIST_CHUNK) {
|
|
1186
|
+
this.queries.insertEdges(edges.slice(i, i + PERSIST_CHUNK));
|
|
1187
|
+
await maybeYield();
|
|
1188
|
+
}
|
|
1189
|
+
const resolvedCleanup = ReferenceResolver.partitionResolvedCleanup(result.resolved);
|
|
1190
|
+
for (let i = 0; i < resolvedCleanup.rowIds.length; i += PERSIST_CHUNK) {
|
|
1191
|
+
this.queries.deleteReferencesByRowIds(resolvedCleanup.rowIds.slice(i, i + PERSIST_CHUNK));
|
|
1192
|
+
await maybeYield();
|
|
1193
|
+
}
|
|
1194
|
+
for (let i = 0; i < resolvedCleanup.legacyKeys.length; i += PERSIST_CHUNK) {
|
|
1195
|
+
this.queries.deleteSpecificResolvedReferences(resolvedCleanup.legacyKeys.slice(i, i + PERSIST_CHUNK));
|
|
1196
|
+
await maybeYield();
|
|
1197
|
+
}
|
|
1198
|
+
const failedCleanup = ReferenceResolver.partitionFailedCleanup(result.unresolved);
|
|
1199
|
+
for (let i = 0; i < failedCleanup.byRowId.length; i += PERSIST_CHUNK) {
|
|
1200
|
+
this.queries.markReferencesFailedByRowIds(failedCleanup.byRowId.slice(i, i + PERSIST_CHUNK));
|
|
1201
|
+
await maybeYield();
|
|
1202
|
+
}
|
|
1203
|
+
for (let i = 0; i < failedCleanup.legacyKeys.length; i += PERSIST_CHUNK) {
|
|
1204
|
+
this.queries.markReferencesFailed(failedCleanup.legacyKeys.slice(i, i + PERSIST_CHUNK));
|
|
1205
|
+
await maybeYield();
|
|
983
1206
|
}
|
|
984
1207
|
return result;
|
|
985
1208
|
}
|
|
@@ -1011,11 +1234,15 @@ class ReferenceResolver {
|
|
|
1011
1234
|
const maybeYield = (0, cooperative_yield_1.createYielder)();
|
|
1012
1235
|
const resolved = [];
|
|
1013
1236
|
for (const ref of deferred) {
|
|
1014
|
-
//
|
|
1237
|
+
// PHP `this->prop.method` resolves via matchMethodCall (declared-type
|
|
1238
|
+
// inference + resolveMethodOnType conformance walk); `::`-receiver
|
|
1239
|
+
// languages (Rust) split on `::` (matchScopedCallChain); other
|
|
1015
1240
|
// dotted-receiver languages on `.` (matchDottedCallChain).
|
|
1016
|
-
const chainMatch =
|
|
1017
|
-
? (0, name_matcher_1.
|
|
1018
|
-
:
|
|
1241
|
+
const chainMatch = (ref.language === 'php' && PHP_PROP_SHAPE.test(ref.referenceName))
|
|
1242
|
+
? (0, name_matcher_1.matchMethodCall)(ref, this.context)
|
|
1243
|
+
: SCOPED_CHAIN_LANGUAGES.has(ref.language)
|
|
1244
|
+
? (0, name_matcher_1.matchScopedCallChain)(ref, this.context)
|
|
1245
|
+
: (0, name_matcher_1.matchDottedCallChain)(ref, this.context);
|
|
1019
1246
|
const match = this.gateLanguage(chainMatch, ref);
|
|
1020
1247
|
if (match)
|
|
1021
1248
|
resolved.push(match);
|
|
@@ -1045,6 +1272,7 @@ class ReferenceResolver {
|
|
|
1045
1272
|
*/
|
|
1046
1273
|
async resolveBatchYielding(batch, maybeYield) {
|
|
1047
1274
|
this.warmCaches();
|
|
1275
|
+
this.advanceSupertypeGeneration();
|
|
1048
1276
|
const resolved = [];
|
|
1049
1277
|
const unresolved = [];
|
|
1050
1278
|
const byMethod = {};
|
|
@@ -1057,8 +1285,9 @@ class ReferenceResolver {
|
|
|
1057
1285
|
column: raw.column,
|
|
1058
1286
|
filePath: raw.filePath || this.getFilePathFromNodeId(raw.fromNodeId),
|
|
1059
1287
|
language: raw.language || this.getLanguageFromNodeId(raw.fromNodeId),
|
|
1288
|
+
rowId: raw.rowId,
|
|
1060
1289
|
};
|
|
1061
|
-
const result = this.
|
|
1290
|
+
const result = this.resolveOneTimed(ref);
|
|
1062
1291
|
if (result) {
|
|
1063
1292
|
resolved.push(result);
|
|
1064
1293
|
byMethod[result.resolvedBy] = (byMethod[result.resolvedBy] || 0) + 1;
|
|
@@ -1066,7 +1295,11 @@ class ReferenceResolver {
|
|
|
1066
1295
|
else {
|
|
1067
1296
|
unresolved.push(ref);
|
|
1068
1297
|
}
|
|
1069
|
-
|
|
1298
|
+
// Fast-path the per-ref yield check: awaiting the async no-op costs a
|
|
1299
|
+
// microtask hop per ref, which dominates at ~10⁵ refs (see MaybeYield).
|
|
1300
|
+
const y = maybeYield();
|
|
1301
|
+
if (y)
|
|
1302
|
+
await y;
|
|
1070
1303
|
}
|
|
1071
1304
|
return {
|
|
1072
1305
|
resolved,
|
|
@@ -1079,12 +1312,144 @@ class ReferenceResolver {
|
|
|
1079
1312
|
},
|
|
1080
1313
|
};
|
|
1081
1314
|
}
|
|
1315
|
+
/**
|
|
1316
|
+
* Resolve a list of refs and return everything the ADMISSION side needs to
|
|
1317
|
+
* persist the outcome: resolutions, failures, the deferred post-pass refs
|
|
1318
|
+
* this run produced (drained, so the caller owns routing them), and stats.
|
|
1319
|
+
* This is the resolver-worker entry point — it runs the exact per-ref loop
|
|
1320
|
+
* of resolveBatchYielding, minus the main-thread yields (worker threads have
|
|
1321
|
+
* no watchdog heartbeat to starve). Results are in input order.
|
|
1322
|
+
*/
|
|
1323
|
+
/**
|
|
1324
|
+
* CODEGRAPH_RESOLVE_PROFILE=1: per-outcome wall-clock histogram of
|
|
1325
|
+
* resolveOne, keyed by the winning strategy (`resolvedBy`) or
|
|
1326
|
+
* `fail:<referenceKind>` — the §7a.2 "profile the per-ref path" probe. The
|
|
1327
|
+
* kernel-scale batch loop is ~430s and CORE-INVARIANT (835.9s pooled-4-on-8
|
|
1328
|
+
* ≈ 812.5s sequential-on-2 for the whole superphase), so the next lever is
|
|
1329
|
+
* which CLASS of ref the time belongs to, not more parallelism. Off by
|
|
1330
|
+
* default: the hrtime pair costs ~100ns/ref only when the env is set.
|
|
1331
|
+
*/
|
|
1332
|
+
resolveProfile = process.env.CODEGRAPH_RESOLVE_PROFILE ? new Map() : null;
|
|
1333
|
+
/**
|
|
1334
|
+
* CODEGRAPH_RESOLVE_PROFILE=2 additionally attributes time to the
|
|
1335
|
+
* STRATEGIES inside resolveOne (`stage:<name>|<refKind>|hit/miss` rows in
|
|
1336
|
+
* the same histogram) — i.e. WHICH machinery a failing class of refs pays
|
|
1337
|
+
* for, not just that it fails. =1 keeps the per-outcome rows only.
|
|
1338
|
+
*/
|
|
1339
|
+
profileStages = process.env.CODEGRAPH_RESOLVE_PROFILE === '2';
|
|
1340
|
+
stageAdd(stage, ref, hit, t0) {
|
|
1341
|
+
if (!this.resolveProfile)
|
|
1342
|
+
return;
|
|
1343
|
+
const dt = process.hrtime.bigint() - t0;
|
|
1344
|
+
const key = `stage:${stage}|${ref.referenceKind}|${hit ? 'hit' : 'miss'}`;
|
|
1345
|
+
const slot = this.resolveProfile.get(key);
|
|
1346
|
+
if (slot) {
|
|
1347
|
+
slot.n++;
|
|
1348
|
+
slot.ns += dt;
|
|
1349
|
+
}
|
|
1350
|
+
else {
|
|
1351
|
+
this.resolveProfile.set(key, { n: 1, ns: dt });
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
resolveOneTimed(ref) {
|
|
1355
|
+
if (!this.resolveProfile)
|
|
1356
|
+
return this.resolveOne(ref);
|
|
1357
|
+
const t0 = process.hrtime.bigint();
|
|
1358
|
+
const result = this.resolveOne(ref);
|
|
1359
|
+
const dt = process.hrtime.bigint() - t0;
|
|
1360
|
+
const key = result ? result.resolvedBy : `fail:${ref.referenceKind}`;
|
|
1361
|
+
const slot = this.resolveProfile.get(key);
|
|
1362
|
+
if (slot) {
|
|
1363
|
+
slot.n++;
|
|
1364
|
+
slot.ns += dt;
|
|
1365
|
+
}
|
|
1366
|
+
else {
|
|
1367
|
+
this.resolveProfile.set(key, { n: 1, ns: dt });
|
|
1368
|
+
}
|
|
1369
|
+
return result;
|
|
1370
|
+
}
|
|
1371
|
+
/** Dump the CODEGRAPH_RESOLVE_PROFILE histogram to stderr (no-op when off). */
|
|
1372
|
+
dumpResolveProfile(label) {
|
|
1373
|
+
if (!this.resolveProfile || this.resolveProfile.size === 0)
|
|
1374
|
+
return;
|
|
1375
|
+
const rows = [...this.resolveProfile.entries()]
|
|
1376
|
+
.map(([k, v]) => ({ k, n: v.n, ms: Number(v.ns / 1000000n) }))
|
|
1377
|
+
.sort((a, b) => b.ms - a.ms);
|
|
1378
|
+
for (const r of rows) {
|
|
1379
|
+
console.error(`[resolve-profile] ${label} ${r.k}: n=${r.n} total=${(r.ms / 1000).toFixed(1)}s avg=${((r.ms * 1000) / Math.max(1, r.n)).toFixed(0)}µs`);
|
|
1380
|
+
}
|
|
1381
|
+
// =2 only: this thread's matchReference sub-stage table rides along.
|
|
1382
|
+
(0, name_matcher_1.dumpNameMatcherProfile)(label);
|
|
1383
|
+
}
|
|
1384
|
+
resolveListForAdmission(refs) {
|
|
1385
|
+
this.warmCaches();
|
|
1386
|
+
this.advanceSupertypeGeneration();
|
|
1387
|
+
const resolved = [];
|
|
1388
|
+
const unresolved = [];
|
|
1389
|
+
const byMethod = {};
|
|
1390
|
+
for (const raw of refs) {
|
|
1391
|
+
const ref = {
|
|
1392
|
+
fromNodeId: raw.fromNodeId,
|
|
1393
|
+
referenceName: raw.referenceName,
|
|
1394
|
+
referenceKind: raw.referenceKind,
|
|
1395
|
+
line: raw.line,
|
|
1396
|
+
column: raw.column,
|
|
1397
|
+
filePath: raw.filePath || this.getFilePathFromNodeId(raw.fromNodeId),
|
|
1398
|
+
language: raw.language || this.getLanguageFromNodeId(raw.fromNodeId),
|
|
1399
|
+
rowId: raw.rowId,
|
|
1400
|
+
};
|
|
1401
|
+
const result = this.resolveOneTimed(ref);
|
|
1402
|
+
if (result) {
|
|
1403
|
+
resolved.push(result);
|
|
1404
|
+
byMethod[result.resolvedBy] = (byMethod[result.resolvedBy] || 0) + 1;
|
|
1405
|
+
}
|
|
1406
|
+
else {
|
|
1407
|
+
unresolved.push(ref);
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
return {
|
|
1411
|
+
resolved,
|
|
1412
|
+
unresolved,
|
|
1413
|
+
deferredChain: this.deferredChainRefs.splice(0),
|
|
1414
|
+
deferredThisMember: this.deferredThisMemberRefs.splice(0),
|
|
1415
|
+
byMethod,
|
|
1416
|
+
};
|
|
1417
|
+
}
|
|
1418
|
+
/**
|
|
1419
|
+
* The resolver's live ResolutionContext — resolver-pool workers use it to
|
|
1420
|
+
* run synthesis passes against their own read-only connection.
|
|
1421
|
+
*/
|
|
1422
|
+
getResolutionContext() {
|
|
1423
|
+
return this.context;
|
|
1424
|
+
}
|
|
1425
|
+
/**
|
|
1426
|
+
* Re-queue deferred post-pass refs produced by resolver workers, preserving
|
|
1427
|
+
* their admission order so resolveChainedCallsViaConformance /
|
|
1428
|
+
* resolveDeferredThisMemberRefs process them exactly as the sequential path
|
|
1429
|
+
* would have.
|
|
1430
|
+
*/
|
|
1431
|
+
appendDeferredFromWorkers(deferredChain, deferredThisMember) {
|
|
1432
|
+
this.deferredChainRefs.push(...deferredChain);
|
|
1433
|
+
this.deferredThisMemberRefs.push(...deferredThisMember);
|
|
1434
|
+
}
|
|
1082
1435
|
/**
|
|
1083
1436
|
* Resolve and persist in batches to keep memory bounded.
|
|
1084
1437
|
* Processes unresolved references in chunks, persisting edges and cleaning
|
|
1085
1438
|
* up resolved refs after each batch to avoid accumulating large arrays.
|
|
1086
1439
|
*/
|
|
1087
|
-
async resolveAndPersistBatched(onProgress, batchSize = 5000
|
|
1440
|
+
async resolveAndPersistBatched(onProgress, batchSize = 5000, onSynthesisProgress,
|
|
1441
|
+
// When provided, big batches fan out across a read-only resolver-worker
|
|
1442
|
+
// pool with results admitted in canonical order (see resolver-pool.ts).
|
|
1443
|
+
// Sequential fallback on any pool failure. CODEGRAPH_NO_PARALLEL_RESOLVE=1
|
|
1444
|
+
// disables entirely. bulkEdgeLoad hooks (when provided) bracket the batch
|
|
1445
|
+
// loop with drop/recreate of the non-unique edge indexes on big runs —
|
|
1446
|
+
// see DatabaseConnection.beginBulkEdgeLoad. backpressure (when provided)
|
|
1447
|
+
// is the WAL valve's writer-side backstop (WalCheckpointValve.backpressure):
|
|
1448
|
+
// called at pool-idle boundaries so a full backfill can actually complete —
|
|
1449
|
+
// the valve's timer-driven passive passes stay perpetually partial against
|
|
1450
|
+
// the pool's continuous reads, which is how a kernel-scale resolution grew
|
|
1451
|
+
// a 22GB WAL on a 4.6GB DB (migration plan §7a.1).
|
|
1452
|
+
parallel) {
|
|
1088
1453
|
// Resolution runs on the indexer's MAIN thread, and the #850 liveness
|
|
1089
1454
|
// watchdog SIGKILLs a process whose event loop stalls past its window (60s
|
|
1090
1455
|
// by default). A single dense batch's resolveAll — or the synthesis pass
|
|
@@ -1092,6 +1457,19 @@ class ReferenceResolver {
|
|
|
1092
1457
|
// (#1091). A shared yielder lets both give the watchdog heartbeat a regular
|
|
1093
1458
|
// window to fire; see ./cooperative-yield.
|
|
1094
1459
|
const maybeYield = (0, cooperative_yield_1.createYielder)();
|
|
1460
|
+
if (process.env.CODEGRAPH_SYNTH_TIMINGS) {
|
|
1461
|
+
console.error(`[pool-timing] backpressure hook: ${parallel?.backpressure ? 'present' : 'absent'}`);
|
|
1462
|
+
}
|
|
1463
|
+
// CODEGRAPH_RESOLVE_PROFILE loop-stage attribution: the §7a.2 kernel-scale
|
|
1464
|
+
// histogram showed resolveOne owns only ~93s of the ~436s batch loop —
|
|
1465
|
+
// these counters name where the other ~340s goes (reads, edge build+insert,
|
|
1466
|
+
// deletes/marks, the per-batch count guard).
|
|
1467
|
+
const loopProf = process.env.CODEGRAPH_RESOLVE_PROFILE
|
|
1468
|
+
? { read: 0, settle: 0, backpressure: 0, recycle: 0, createEdges: 0, insertEdges: 0, deletes: 0, marks: 0, countGuard: 0 }
|
|
1469
|
+
: null;
|
|
1470
|
+
const lp = (k, t0) => { if (loopProf)
|
|
1471
|
+
loopProf[k] = (loopProf[k] ?? 0) + (Date.now() - t0); };
|
|
1472
|
+
let tLp = 0;
|
|
1095
1473
|
await this.warmCachesYielding(maybeYield);
|
|
1096
1474
|
const total = this.queries.getUnresolvedReferencesCount();
|
|
1097
1475
|
let processed = 0;
|
|
@@ -1101,89 +1479,370 @@ class ReferenceResolver {
|
|
|
1101
1479
|
unresolved: 0,
|
|
1102
1480
|
byMethod: {},
|
|
1103
1481
|
};
|
|
1104
|
-
//
|
|
1105
|
-
//
|
|
1482
|
+
// Parallel pool, started immediately but never awaited up front: early
|
|
1483
|
+
// batches run sequentially while the workers boot (module load + readonly
|
|
1484
|
+
// DB open + framework detect + cache warm ≈ hundreds of ms), and the loop
|
|
1485
|
+
// switches to fan-out the moment the pool reports ready — so pool boot
|
|
1486
|
+
// costs zero wall-clock. Any failure downgrades to sequential permanently.
|
|
1487
|
+
let pool = null;
|
|
1488
|
+
let poolReady = false;
|
|
1489
|
+
// True once pool creation has been attempted by EITHER engage site (the
|
|
1490
|
+
// up-front ref-count gate or the adaptive projection below) — a pool that
|
|
1491
|
+
// failed or was destroyed must stay down (downgrade is permanent), and
|
|
1492
|
+
// tryCreate's sizing probes shouldn't re-run every batch on hosts that
|
|
1493
|
+
// declined.
|
|
1494
|
+
let poolEngageTried = false;
|
|
1495
|
+
const createPool = (t0, why) => {
|
|
1496
|
+
poolEngageTried = true;
|
|
1497
|
+
if (!parallel)
|
|
1498
|
+
return null;
|
|
1499
|
+
const p = resolver_pool_1.ResolverPool.tryCreate(parallel.dbPath, this.projectRoot);
|
|
1500
|
+
p?.ready().then(() => {
|
|
1501
|
+
poolReady = true;
|
|
1502
|
+
if (process.env.CODEGRAPH_SYNTH_TIMINGS)
|
|
1503
|
+
console.error(`[pool-timing] pool ready after ${Date.now() - t0}ms (${why})`);
|
|
1504
|
+
}, () => {
|
|
1505
|
+
void p.destroy().catch(() => undefined);
|
|
1506
|
+
if (pool === p)
|
|
1507
|
+
pool = null;
|
|
1508
|
+
});
|
|
1509
|
+
return p;
|
|
1510
|
+
};
|
|
1511
|
+
if (parallel && total >= (0, resolver_pool_1.minRefsForPool)()) {
|
|
1512
|
+
pool = createPool(Date.now(), 'ref-count');
|
|
1513
|
+
}
|
|
1514
|
+
// Adaptive engagement bar (see the batch-loop hook): projected remaining
|
|
1515
|
+
// sequential settle above this boots the pool mid-loop. Boot is async and
|
|
1516
|
+
// fan-out waits for ready, so a marginal engage costs background boot
|
|
1517
|
+
// only; the bar just needs to clear the fan-out's own overhead class.
|
|
1518
|
+
const ADAPTIVE_ENGAGE_SETTLE_MS = 400;
|
|
1519
|
+
let adaptiveSeqMs = 0;
|
|
1520
|
+
let adaptiveSeqRefs = 0;
|
|
1521
|
+
// Process in PIPELINED batches (double-buffer). The enumeration is the
|
|
1522
|
+
// head of the pending set in rowid order; every ref a persisted batch
|
|
1523
|
+
// processed leaves the pending set (resolved rows are deleted,
|
|
1524
|
+
// unresolvable ones flip to status='failed'), shifting the remaining
|
|
1525
|
+
// pending rows forward.
|
|
1106
1526
|
let prevRemaining = Number.POSITIVE_INFINITY;
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1527
|
+
// Cadence for the worker connection recycling below — ~8 batches
|
|
1528
|
+
// ≈ 40k refs between recycles keeps the WAL shallow at kernel scale
|
|
1529
|
+
// while a small sync never recycles at all. (25 recovered only half
|
|
1530
|
+
// the write tax — the WAL re-deepened between recycles; reopens are
|
|
1531
|
+
// sub-millisecond so the shorter cadence is ~free.)
|
|
1532
|
+
const RECYCLE_EVERY_BATCHES = 8;
|
|
1533
|
+
let batchesSinceRecycle = 0;
|
|
1534
|
+
// Begin one batch: fan out to the pool when it's ready and the batch is
|
|
1535
|
+
// big enough — workers then resolve batch k+1 WHILE the main thread
|
|
1536
|
+
// persists batch k (persist measured at ~58% of resolution wall on a
|
|
1537
|
+
// 255k-ref repo, all of it previously spent with the pool idle).
|
|
1538
|
+
// Sequential batches stay lazy: they run on the main thread at settle
|
|
1539
|
+
// time, where an early start would only contend with the persist.
|
|
1540
|
+
const beginBatch = (batch) => {
|
|
1541
|
+
if (pool && poolReady && resolver_pool_1.ResolverPool.worthParallel(batch.length)) {
|
|
1542
|
+
return {
|
|
1543
|
+
mode: 'pool',
|
|
1544
|
+
settled: pool.resolveBatch(batch).then((out) => ({ ok: true, out }), (err) => ({ ok: false, err })),
|
|
1545
|
+
};
|
|
1125
1546
|
}
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1547
|
+
return { mode: 'seq' };
|
|
1548
|
+
};
|
|
1549
|
+
// Settle an in-flight batch to a ResolutionResult. Deferred post-pass refs
|
|
1550
|
+
// are appended HERE, in loop order — never inside the fan-out promise — so
|
|
1551
|
+
// admission order stays exactly the sequential order even while a later
|
|
1552
|
+
// batch resolves concurrently. A pool failure downgrades to sequential
|
|
1553
|
+
// permanently and re-resolves this batch on the main thread.
|
|
1554
|
+
const settleBatch = async (inFlight, batch) => {
|
|
1555
|
+
if (inFlight.mode === 'pool') {
|
|
1556
|
+
const settled = await inFlight.settled;
|
|
1557
|
+
if (settled.ok) {
|
|
1558
|
+
this.appendDeferredFromWorkers(settled.out.deferredChain, settled.out.deferredThisMember);
|
|
1559
|
+
return {
|
|
1560
|
+
resolved: settled.out.resolved,
|
|
1561
|
+
unresolved: settled.out.unresolved,
|
|
1562
|
+
stats: {
|
|
1563
|
+
total: batch.length,
|
|
1564
|
+
resolved: settled.out.resolved.length,
|
|
1565
|
+
unresolved: settled.out.unresolved.length,
|
|
1566
|
+
byMethod: settled.out.byMethod,
|
|
1567
|
+
},
|
|
1568
|
+
};
|
|
1569
|
+
}
|
|
1570
|
+
(0, errors_1.logDebug)('Parallel resolution failed; falling back to sequential', {
|
|
1571
|
+
error: settled.err instanceof Error ? settled.err.message : String(settled.err),
|
|
1572
|
+
});
|
|
1573
|
+
if (pool)
|
|
1574
|
+
await pool.destroy().catch(() => undefined);
|
|
1575
|
+
pool = null;
|
|
1135
1576
|
}
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1577
|
+
return this.resolveBatchYielding(batch, maybeYield);
|
|
1578
|
+
};
|
|
1579
|
+
// Bulk edge load: on big runs, drop the non-unique edge indexes for the
|
|
1580
|
+
// duration of the batch loop (the identity index stays — OR IGNORE dedup
|
|
1581
|
+
// and the source-keyed supertype-walk reads both live on it). Recreated in
|
|
1582
|
+
// the inner finally BEFORE synthesis, whose passes read kind-keyed.
|
|
1583
|
+
// Measured on a 224k-edge resolution set: insert 2.8s → 1.1s + 0.3s
|
|
1584
|
+
// recreate. Same ref-count gate as the pool so small syncs never pay the
|
|
1585
|
+
// recreate cost.
|
|
1586
|
+
let bulkEdgesActive = false;
|
|
1587
|
+
if (parallel?.bulkEdgeLoad && total >= (0, resolver_pool_1.minRefsForPool)()) {
|
|
1588
|
+
try {
|
|
1589
|
+
parallel.bulkEdgeLoad.begin();
|
|
1590
|
+
bulkEdgesActive = true;
|
|
1145
1591
|
}
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1592
|
+
catch { /* keep the indexes; inserts just pay the per-row maintenance */ }
|
|
1593
|
+
}
|
|
1594
|
+
// Same gate for the ref-index window: the loop's deletes stop maintaining
|
|
1595
|
+
// the five sync-path unresolved_refs indexes, and the end-of-loop rebuild
|
|
1596
|
+
// is near-free (only failed refs survive the loop).
|
|
1597
|
+
let bulkRefsActive = false;
|
|
1598
|
+
if (parallel?.refIndexLoad && total >= (0, resolver_pool_1.minRefsForPool)()) {
|
|
1599
|
+
try {
|
|
1600
|
+
parallel.refIndexLoad.begin();
|
|
1601
|
+
bulkRefsActive = true;
|
|
1152
1602
|
}
|
|
1153
|
-
|
|
1154
|
-
onProgress?.(processed, total);
|
|
1155
|
-
// Yield so progress UI can render between batches
|
|
1156
|
-
await new Promise(resolve => setImmediate(resolve));
|
|
1157
|
-
// NOTE: there used to be an extra early break here when a batch resolved
|
|
1158
|
-
// nothing (`result.unresolved.length === batch.length`). That was wrong:
|
|
1159
|
-
// an all-unresolvable batch still DELETES its rows (progress), yet the
|
|
1160
|
-
// break abandoned every batch after it in the same run — on a repo whose
|
|
1161
|
-
// first 5000 refs are all external/stdlib calls, resolution stopped at
|
|
1162
|
-
// batch one and left the rest of the table as permanent orphans (#1187).
|
|
1163
|
-
// The count-based guard below catches the true no-progress case.
|
|
1164
|
-
// Non-progress guard (defense-in-depth). Because we re-read from offset 0
|
|
1165
|
-
// each pass, the unresolved_refs table MUST shrink every iteration — both
|
|
1166
|
-
// resolved and unresolved refs are deleted above. If it didn't shrink, a
|
|
1167
|
-
// resolver returned a match whose `original.referenceName` differs from the
|
|
1168
|
-
// stored row, so the keyed delete no-ops, and we'd re-read + re-resolve +
|
|
1169
|
-
// re-insert the same rows forever (the runaway that grew a 99-file repo to
|
|
1170
|
-
// 5M edges / 1.4 GB before the Go-fallback fix). Stop rather than grow the
|
|
1171
|
-
// graph without bound.
|
|
1172
|
-
const remaining = this.queries.getUnresolvedReferencesCount();
|
|
1173
|
-
if (remaining >= prevRemaining)
|
|
1174
|
-
break;
|
|
1175
|
-
prevRemaining = remaining;
|
|
1603
|
+
catch { /* keep the indexes; deletes just pay the per-row maintenance */ }
|
|
1176
1604
|
}
|
|
1177
|
-
// Dynamic-edge synthesis: now that all base `calls` edges are persisted,
|
|
1178
|
-
// synthesize observer/callback dispatch edges (dispatcher → registered
|
|
1179
|
-
// callbacks) that static parsing leaves out. Best-effort — never fail the
|
|
1180
|
-
// index on it. See docs/design/callback-edge-synthesis.md.
|
|
1181
1605
|
try {
|
|
1182
|
-
|
|
1606
|
+
try {
|
|
1607
|
+
tLp = Date.now();
|
|
1608
|
+
let batch = this.queries.getUnresolvedReferencesBatchAfter(0, batchSize);
|
|
1609
|
+
lp('read', tLp);
|
|
1610
|
+
let inFlight = batch.length > 0 ? beginBatch(batch) : null;
|
|
1611
|
+
while (batch.length > 0 && inFlight) {
|
|
1612
|
+
// Prefetch the NEXT batch before this one persists: this batch's rows
|
|
1613
|
+
// are still pending (nothing has mutated the table since they were
|
|
1614
|
+
// read), so seeking past this batch's last row id in the same rowid
|
|
1615
|
+
// enumeration yields the following batch (keyset — OFFSET re-walked the
|
|
1616
|
+
// accumulated failed prefix every read, 54.6s at kernel scale, §7a.2).
|
|
1617
|
+
tLp = Date.now();
|
|
1618
|
+
const nextBatch = this.queries.getUnresolvedReferencesBatchAfter(batch[batch.length - 1].rowId, batchSize);
|
|
1619
|
+
lp('read', tLp);
|
|
1620
|
+
const tBatch = Date.now();
|
|
1621
|
+
const result = await settleBatch(inFlight, batch);
|
|
1622
|
+
if (process.env.CODEGRAPH_SYNTH_TIMINGS)
|
|
1623
|
+
console.error(`[pool-timing] batch ${inFlight.mode}: ${batch.length} refs in ${Date.now() - tBatch}ms`);
|
|
1624
|
+
lp('settle', tBatch);
|
|
1625
|
+
// Adaptive pool engagement: the fixed ref-count gate can't see PER-REF
|
|
1626
|
+
// cost, and settle rates differ ~9× by language (56k Rust refs cost
|
|
1627
|
+
// more sequential settle than 154k Go refs — 36µs vs 4µs measured on
|
|
1628
|
+
// tokio/prometheus). After each sequential batch, project the remaining
|
|
1629
|
+
// settle from the observed rate and boot the pool mid-loop when it
|
|
1630
|
+
// clears the bar. The loop already switches to fan-out only when the
|
|
1631
|
+
// async boot reports ready, admission order is mode-independent, and
|
|
1632
|
+
// 2-core/low-memory hosts still decline inside tryCreate's sizing —
|
|
1633
|
+
// so the switch changes wall-clock, never the graph.
|
|
1634
|
+
if (inFlight.mode === 'seq' && parallel && pool === null && !poolEngageTried) {
|
|
1635
|
+
adaptiveSeqMs += Date.now() - tBatch;
|
|
1636
|
+
adaptiveSeqRefs += batch.length;
|
|
1637
|
+
const remaining = total - processed - batch.length;
|
|
1638
|
+
const projectedMs = (adaptiveSeqMs / Math.max(1, adaptiveSeqRefs)) * Math.max(0, remaining);
|
|
1639
|
+
if (projectedMs >= ADAPTIVE_ENGAGE_SETTLE_MS) {
|
|
1640
|
+
if (process.env.CODEGRAPH_SYNTH_TIMINGS) {
|
|
1641
|
+
console.error(`[pool-timing] adaptive engage: projected ${Math.round(projectedMs)}ms sequential settle over ${remaining} remaining refs`);
|
|
1642
|
+
}
|
|
1643
|
+
pool = createPool(Date.now(), 'adaptive');
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
// WAL-valve backstop at the ONE pool-idle boundary of the double-buffer
|
|
1647
|
+
// (this batch settled, the next not yet fanned out): past the hard cap
|
|
1648
|
+
// the writer parks for a full backfill here, where the pool's readers
|
|
1649
|
+
// are all between statements — so the backfill completes, readers
|
|
1650
|
+
// re-enter at SQLite's backfilled mark, and the next persist commit
|
|
1651
|
+
// WRAPS the WAL instead of growing it. No-op (one fstat) under the cap.
|
|
1652
|
+
tLp = Date.now();
|
|
1653
|
+
const bp = parallel?.backpressure?.();
|
|
1654
|
+
if (bp)
|
|
1655
|
+
await bp;
|
|
1656
|
+
lp('backpressure', tLp);
|
|
1657
|
+
// Recycle the workers' read connections periodically at this same
|
|
1658
|
+
// worker-idle boundary (batch k settled, batch k+1 not yet fanned
|
|
1659
|
+
// out): a long-lived reader pins WAL checkpoint progress, and the
|
|
1660
|
+
// deep WAL that accumulates behind it taxes the writer's OWN page
|
|
1661
|
+
// operations — the §7a.6 writes-under-readers finding (deletes
|
|
1662
|
+
// 42.6s → 118.8s from 0 to 4 attached readers; an aggressive valve
|
|
1663
|
+
// recovered the writes but paid +129s in full-park folds). Releasing
|
|
1664
|
+
// the read marks every ~25 batches lets the existing checkpoints
|
|
1665
|
+
// advance instead, at ~milliseconds of reopen cost. A failed recycle
|
|
1666
|
+
// downgrades to sequential permanently, same as a failed fan-out.
|
|
1667
|
+
if (pool && poolReady && ++batchesSinceRecycle >= RECYCLE_EVERY_BATCHES) {
|
|
1668
|
+
batchesSinceRecycle = 0;
|
|
1669
|
+
tLp = Date.now();
|
|
1670
|
+
try {
|
|
1671
|
+
await pool.recycleWorkers();
|
|
1672
|
+
}
|
|
1673
|
+
catch (err) {
|
|
1674
|
+
(0, errors_1.logDebug)('Worker connection recycle failed; falling back to sequential', {
|
|
1675
|
+
error: err instanceof Error ? err.message : String(err),
|
|
1676
|
+
});
|
|
1677
|
+
await pool.destroy().catch(() => undefined);
|
|
1678
|
+
pool = null;
|
|
1679
|
+
}
|
|
1680
|
+
lp('recycle', tLp);
|
|
1681
|
+
}
|
|
1682
|
+
// Persist in bounded sub-transactions with yields between: a whole
|
|
1683
|
+
// batch's edge insert / keyed deletes are otherwise one solid
|
|
1684
|
+
// synchronous span each on a multi-GB index, sitting BETWEEN the
|
|
1685
|
+
// per-ref yields — the last unyielded stretch of the resolution loop.
|
|
1686
|
+
// Crash semantics are unchanged (already several transactions): edges
|
|
1687
|
+
// land before their refs are deleted, so a kill mid-way re-resolves
|
|
1688
|
+
// the remainder idempotently on the next run/sweep (#1187).
|
|
1689
|
+
const PERSIST_CHUNK = 1000;
|
|
1690
|
+
const tPersist = Date.now();
|
|
1691
|
+
// Persist edges BEFORE fanning out the next batch: later batches read
|
|
1692
|
+
// this batch's edges — resolveMethodOnType walks supertype chains over
|
|
1693
|
+
// `extends`/`implements` edges that earlier batches resolved, so a
|
|
1694
|
+
// receiver typed as a subclass only reaches a method declared on its
|
|
1695
|
+
// base class if those edges are visible. (Validated on dubbo: fanning
|
|
1696
|
+
// out first downgraded exactly those supertype-method resolutions from
|
|
1697
|
+
// the 0.9 typed-receiver path to the 0.65 word-overlap fallback.)
|
|
1698
|
+
tLp = Date.now();
|
|
1699
|
+
const edges = this.createEdges(result.resolved);
|
|
1700
|
+
lp('createEdges', tLp);
|
|
1701
|
+
tLp = Date.now();
|
|
1702
|
+
for (let i = 0; i < edges.length; i += PERSIST_CHUNK) {
|
|
1703
|
+
this.queries.insertEdges(edges.slice(i, i + PERSIST_CHUNK));
|
|
1704
|
+
await maybeYield();
|
|
1705
|
+
}
|
|
1706
|
+
lp('insertEdges', tLp);
|
|
1707
|
+
// NOW fan the next batch out — workers see exactly the edge state the
|
|
1708
|
+
// sequential baseline would (every batch ≤ this one committed), while
|
|
1709
|
+
// the main thread spends the REST of the persist (ref deletes + failed
|
|
1710
|
+
// parking below) overlapped with their resolution — the double-buffer.
|
|
1711
|
+
const nextInFlight = nextBatch.length > 0 ? beginBatch(nextBatch) : null;
|
|
1712
|
+
// Clean up resolved refs so they don't appear in the next batch —
|
|
1713
|
+
// by row id, so a same-key sibling ref in a LATER batch (same caller
|
|
1714
|
+
// calling the same callee at another line) is left pending for its own
|
|
1715
|
+
// attempt instead of being swept out with this batch's rows (#1269).
|
|
1716
|
+
tLp = Date.now();
|
|
1717
|
+
let removedThisBatch = 0;
|
|
1718
|
+
const resolvedCleanup = ReferenceResolver.partitionResolvedCleanup(result.resolved);
|
|
1719
|
+
for (let i = 0; i < resolvedCleanup.rowIds.length; i += PERSIST_CHUNK) {
|
|
1720
|
+
removedThisBatch += this.queries.deleteReferencesByRowIds(resolvedCleanup.rowIds.slice(i, i + PERSIST_CHUNK));
|
|
1721
|
+
await maybeYield();
|
|
1722
|
+
}
|
|
1723
|
+
for (let i = 0; i < resolvedCleanup.legacyKeys.length; i += PERSIST_CHUNK) {
|
|
1724
|
+
removedThisBatch += this.queries.deleteSpecificResolvedReferences(resolvedCleanup.legacyKeys.slice(i, i + PERSIST_CHUNK));
|
|
1725
|
+
await maybeYield();
|
|
1726
|
+
}
|
|
1727
|
+
lp('deletes', tLp);
|
|
1728
|
+
// Park unresolvable refs from this batch as status='failed' so they
|
|
1729
|
+
// leave the pending set (the batch reader and non-progress guard below
|
|
1730
|
+
// only see pending rows) but stay retryable when a later sync adds a
|
|
1731
|
+
// symbol that could satisfy them (#1240).
|
|
1732
|
+
tLp = Date.now();
|
|
1733
|
+
const failedCleanup = ReferenceResolver.partitionFailedCleanup(result.unresolved);
|
|
1734
|
+
for (let i = 0; i < failedCleanup.byRowId.length; i += PERSIST_CHUNK) {
|
|
1735
|
+
removedThisBatch += this.queries.markReferencesFailedByRowIds(failedCleanup.byRowId.slice(i, i + PERSIST_CHUNK));
|
|
1736
|
+
await maybeYield();
|
|
1737
|
+
}
|
|
1738
|
+
for (let i = 0; i < failedCleanup.legacyKeys.length; i += PERSIST_CHUNK) {
|
|
1739
|
+
removedThisBatch += this.queries.markReferencesFailed(failedCleanup.legacyKeys.slice(i, i + PERSIST_CHUNK));
|
|
1740
|
+
await maybeYield();
|
|
1741
|
+
}
|
|
1742
|
+
lp('marks', tLp);
|
|
1743
|
+
if (process.env.CODEGRAPH_SYNTH_TIMINGS)
|
|
1744
|
+
console.error(`[pool-timing] batch persist: ${Date.now() - tPersist}ms`);
|
|
1745
|
+
// Aggregate stats
|
|
1746
|
+
aggregateStats.total += result.stats.total;
|
|
1747
|
+
aggregateStats.resolved += result.stats.resolved;
|
|
1748
|
+
aggregateStats.unresolved += result.stats.unresolved;
|
|
1749
|
+
for (const [method, count] of Object.entries(result.stats.byMethod)) {
|
|
1750
|
+
aggregateStats.byMethod[method] = (aggregateStats.byMethod[method] || 0) + count;
|
|
1751
|
+
}
|
|
1752
|
+
processed += batch.length;
|
|
1753
|
+
onProgress?.(processed, total);
|
|
1754
|
+
// Yield so progress UI can render between batches
|
|
1755
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
1756
|
+
// NOTE: there used to be an extra early break here when a batch resolved
|
|
1757
|
+
// nothing (`result.unresolved.length === batch.length`). That was wrong:
|
|
1758
|
+
// an all-unresolvable batch still DELETES its rows (progress), yet the
|
|
1759
|
+
// break abandoned every batch after it in the same run — on a repo whose
|
|
1760
|
+
// first 5000 refs are all external/stdlib calls, resolution stopped at
|
|
1761
|
+
// batch one and left the rest of the table as permanent orphans (#1187).
|
|
1762
|
+
// The count-based guard below catches the true no-progress case.
|
|
1763
|
+
// Non-progress guard (defense-in-depth). Each iteration enumerates from
|
|
1764
|
+
// the head of the pending set, so the PENDING population MUST shrink
|
|
1765
|
+
// every iteration — resolved refs are deleted and unresolvable ones are
|
|
1766
|
+
// marked failed above, and both leave the pending set the batch reader
|
|
1767
|
+
// sees. If it didn't shrink, a resolver returned a match whose
|
|
1768
|
+
// `original.referenceName` differs from the stored row, so the keyed
|
|
1769
|
+
// delete/update no-ops, and we'd re-read + re-resolve + re-insert the
|
|
1770
|
+
// same rows forever (the runaway that grew a 99-file repo to 5M edges /
|
|
1771
|
+
// 1.4 GB before the Go-fallback fix). Stop rather than grow the graph
|
|
1772
|
+
// without bound. (An in-flight prefetched batch is abandoned unsettled —
|
|
1773
|
+
// fan-out has no side effects until settleBatch appends its results.)
|
|
1774
|
+
// Non-progress signal, now O(1): `changes` summed across this batch's
|
|
1775
|
+
// deletes + failed-parks is the DIRECT evidence the guard's old count
|
|
1776
|
+
// diff inferred — a resolver returning a mismatched name makes the keyed
|
|
1777
|
+
// cleanup no-op, which shows up here as zero removals. The per-batch
|
|
1778
|
+
// COUNT(*) it replaces walked every remaining pending row — O(N²/batch)
|
|
1779
|
+
// over a run, 93.9s of the kernel-scale batch loop (§7a.2). A REAL count
|
|
1780
|
+
// runs only on the suspicious path (claimed-work batch removed nothing —
|
|
1781
|
+
// e.g. every row was a sibling a legacy-key sweep already consumed),
|
|
1782
|
+
// where it arbitrates stop-vs-continue exactly as before.
|
|
1783
|
+
if (removedThisBatch <= 0 && batch.length > 0) {
|
|
1784
|
+
tLp = Date.now();
|
|
1785
|
+
const remaining = this.queries.getUnresolvedReferencesCount();
|
|
1786
|
+
lp('countGuard', tLp);
|
|
1787
|
+
if (remaining >= prevRemaining)
|
|
1788
|
+
break;
|
|
1789
|
+
prevRemaining = remaining;
|
|
1790
|
+
}
|
|
1791
|
+
// Advance the pipeline: the prefetched batch (already fanned out when
|
|
1792
|
+
// the pool is on) becomes the current one.
|
|
1793
|
+
batch = nextBatch;
|
|
1794
|
+
inFlight = nextInFlight;
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
finally {
|
|
1798
|
+
// Recreate the edge indexes BEFORE synthesis (kind-keyed reads) and on
|
|
1799
|
+
// any error path. A crash before this line is healed by the next
|
|
1800
|
+
// DatabaseConnection open (schema.sql re-applies IF NOT EXISTS).
|
|
1801
|
+
if (bulkRefsActive) {
|
|
1802
|
+
const tRef = Date.now();
|
|
1803
|
+
await parallel.refIndexLoad.end();
|
|
1804
|
+
if (process.env.CODEGRAPH_SYNTH_TIMINGS)
|
|
1805
|
+
console.error(`[phase-timing] ref-index-recreate: ${Date.now() - tRef}ms`);
|
|
1806
|
+
}
|
|
1807
|
+
if (bulkEdgesActive) {
|
|
1808
|
+
const tIdx = Date.now();
|
|
1809
|
+
await parallel.bulkEdgeLoad.end();
|
|
1810
|
+
if (process.env.CODEGRAPH_SYNTH_TIMINGS)
|
|
1811
|
+
console.error(`[phase-timing] edge-index-recreate: ${Date.now() - tIdx}ms`);
|
|
1812
|
+
// The recreate just wrote every non-unique edge index into the WAL
|
|
1813
|
+
// (multi-GB at kernel scale) with the pool idle — fold before the
|
|
1814
|
+
// synthesis passes pin readers against it for minutes.
|
|
1815
|
+
const bp = parallel?.backpressure?.();
|
|
1816
|
+
if (bp)
|
|
1817
|
+
await bp;
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
// Dynamic-edge synthesis: now that all base `calls` edges are persisted,
|
|
1821
|
+
// synthesize observer/callback dispatch edges (dispatcher → registered
|
|
1822
|
+
// callbacks) that static parsing leaves out. Best-effort — never fail the
|
|
1823
|
+
// index on it. The pool (when it survived resolution) is REUSED to fan the
|
|
1824
|
+
// independent passes across its read-only workers — that's why its destroy
|
|
1825
|
+
// lives in the finally below, after synthesis, not at the end of the batch
|
|
1826
|
+
// loop. See docs/design/callback-edge-synthesis.md.
|
|
1827
|
+
const tSynth = Date.now();
|
|
1828
|
+
try {
|
|
1829
|
+
aggregateStats.byMethod['callback-synthesis'] = await (0, callback_synthesizer_1.synthesizeCallbackEdges)(this.queries, this.context, onSynthesisProgress, pool, parallel?.backpressure);
|
|
1830
|
+
}
|
|
1831
|
+
catch {
|
|
1832
|
+
// synthesis is additive and optional; ignore failures
|
|
1833
|
+
}
|
|
1834
|
+
if (process.env.CODEGRAPH_SYNTH_TIMINGS)
|
|
1835
|
+
console.error(`[phase-timing] callback-synthesis: ${Date.now() - tSynth}ms`);
|
|
1836
|
+
}
|
|
1837
|
+
finally {
|
|
1838
|
+
if (pool)
|
|
1839
|
+
await pool.destroy().catch(() => undefined);
|
|
1183
1840
|
}
|
|
1184
|
-
|
|
1185
|
-
|
|
1841
|
+
if (loopProf) {
|
|
1842
|
+
const parts = Object.entries(loopProf).map(([k, v]) => `${k}=${(v / 1000).toFixed(1)}s`).join(' ');
|
|
1843
|
+
console.error(`[resolve-profile] loop-stages ${parts}`);
|
|
1186
1844
|
}
|
|
1845
|
+
this.dumpResolveProfile('main');
|
|
1187
1846
|
return {
|
|
1188
1847
|
resolved: [],
|
|
1189
1848
|
unresolved: [],
|