Skip to content

Commit a79855e

Browse files
committed
fix(perf): broaden Gate B to cover constructor/function-kind RTA fallback schema
Gate B previously checked only `tgt.kind = 'class'`, but the RTA seed has a fallback that matches `tgt.kind IN ('constructor', 'function')` when no class-kind constructor edges exist (older native engine schemas). On codebases where the fallback path is always active, Gate B would never fire, causing scopeToChangedFiles to be set incorrectly and silently dropping CHA edges for unchanged callers whose RTA evidence lives in the fallback-schema rows. Broaden Gate B to `tgt.kind IN ('class', 'constructor', 'function')` to mirror the full two-shape RTA seed. Also fix formatter violation on the .all() cast.
1 parent d70a9ab commit a79855e

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

src/domain/graph/builder/stages/native-orchestrator.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,11 @@ async function runPostNativeAnalysis(
406406
* - array → incremental; two cheap gate queries decide scope:
407407
* Gate A: any class/interface/trait/struct/record nodes in changed files?
408408
* If yes, a new implementor may have appeared — full scan required.
409-
* Gate B: any `calls` edges from changed-file sources targeting class-kind
410-
* nodes? If yes, the RTA set may have grown, enabling previously
411-
* filtered expansions in unchanged caller files — full scan required.
409+
* Gate B: any `calls` edges from changed-file sources targeting
410+
* class/constructor/function-kind nodes? If yes, the RTA set may
411+
* have grown (also covers the older-schema fallback where
412+
* constructor calls target `constructor`/`function` nodes instead
413+
* of `class` nodes) — full scan required.
412414
* If neither gate fires: scope `callToMethods` to `src.file IN changedFiles`
413415
* (safe because no hierarchy or RTA evidence changed).
414416
*
@@ -498,9 +500,10 @@ function runPostNativeCha(
498500
// valid expansions, so the full scan is required.
499501
//
500502
// Gate B: did a changed file add new RTA evidence (`new ConcreteX()`)?
501-
// A new `calls` edge to a class-kind target means the instantiated set grew —
502-
// previously RTA-filtered expansions in unchanged caller files become
503-
// admissible, so the full scan is required.
503+
// A new `calls` edge to a class/constructor/function-kind target means the
504+
// instantiated set grew — previously RTA-filtered expansions in unchanged
505+
// caller files become admissible, so the full scan is required.
506+
// (`constructor`/`function` cover the older native engine fallback schema.)
504507
//
505508
// If neither gate fires, the hierarchy and RTA set are unchanged for all files
506509
// outside changedFiles, so restricting to changed-file sources is safe.
@@ -523,7 +526,13 @@ function runPostNativeCha(
523526
if (row) gateAFired = true;
524527
}
525528

526-
// Gate B: calls from changed-file sources to class-kind targets?
529+
// Gate B: calls from changed-file sources to class-kind targets (or
530+
// constructor/function-kind targets in the older native engine fallback schema)?
531+
// Mirrors the two-shape RTA seed: primary checks `tgt.kind = 'class'`; older
532+
// native engine schemas record constructor calls against `constructor`/`function`
533+
// kinds instead. Including all three kinds here prevents Gate B from silently
534+
// passing on older-schema DBs, which would incorrectly set scopeToChangedFiles
535+
// and miss CHA edges whose RTA evidence lives in the fallback-schema rows.
527536
let gateBFired = false;
528537
if (!gateAFired) {
529538
for (let i = 0; i < changedFiles.length && !gateBFired; i += CHUNK_SIZE) {
@@ -534,7 +543,8 @@ function runPostNativeCha(
534543
`SELECT 1 FROM edges e
535544
JOIN nodes src ON e.source_id = src.id
536545
JOIN nodes tgt ON e.target_id = tgt.id
537-
WHERE e.kind = 'calls' AND tgt.kind = 'class'
546+
WHERE e.kind = 'calls'
547+
AND tgt.kind IN ('class', 'constructor', 'function')
538548
AND src.file IN (${ph})
539549
LIMIT 1`,
540550
)
@@ -577,7 +587,11 @@ function runPostNativeCha(
577587
AND INSTR(tgt.name, '.') > 0
578588
AND src.file IN (${ph})`,
579589
)
580-
.all(...chunk) as Array<{ source_id: number; method_name: string; caller_file: string | null }>;
590+
.all(...chunk) as Array<{
591+
source_id: number;
592+
method_name: string;
593+
caller_file: string | null;
594+
}>;
581595
rows.push(...chunkRows);
582596
}
583597
callToMethods = rows;

0 commit comments

Comments
 (0)