Skip to content

Commit 4aced08

Browse files
committed
fix: use setTypeMapEntry in cpp/cuda extractors and extract CHA_DISPATCH_CONFIDENCE constant
Switch handleCppDeclaration and handleCudaDeclaration from last-wins ctx.typeMap.set() to first-wins setTypeMapEntry(), fixing the same flat typeMap pollution bug this PR corrects in java.ts. Extract the CHA dispatch confidence value to a named CHA_DISPATCH_CONFIDENCE constant in helpers.ts so runChaPostPass and the native orchestrator share a single source of truth instead of two synchronized magic numbers.
1 parent 7095ffe commit 4aced08

4 files changed

Lines changed: 11 additions & 10 deletions

File tree

src/domain/graph/builder/helpers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,9 @@ export function batchInsertEdges(db: BetterSqlite3Database, rows: unknown[][]):
361361
}
362362
}
363363

364+
/** Confidence assigned to CHA-expanded interface/abstract dispatch edges. */
365+
export const CHA_DISPATCH_CONFIDENCE = 0.8;
366+
364367
/**
365368
* CHA (Class Hierarchy Analysis) post-pass.
366369
*
@@ -514,7 +517,7 @@ export function runChaPostPass(db: BetterSqlite3Database): number {
514517
const key = `${source_id}|${methodNode.id}`;
515518
if (seen.has(key)) continue;
516519
seen.add(key);
517-
newEdges.push([source_id, methodNode.id, 'calls', 0.8, 0, 'cha']);
520+
newEdges.push([source_id, methodNode.id, 'calls', CHA_DISPATCH_CONFIDENCE, 0, 'cha']);
518521
}
519522
}
520523

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import type { PipelineContext } from '../context.js';
4949
import {
5050
batchInsertEdges,
5151
batchInsertNodes,
52+
CHA_DISPATCH_CONFIDENCE,
5253
collectFiles as collectFilesUtil,
5354
fileHash,
5455
fileStat,
@@ -557,7 +558,7 @@ function runPostNativeCha(
557558

558559
// Find existing call edges targeting qualified methods (e.g., 'IWorker.doWork').
559560
// Include caller_file and method_file so affectedFiles can be populated for
560-
// incremental role reclassification; confidence is hardcoded 0.8 matching runChaPostPass.
561+
// incremental role reclassification; confidence is CHA_DISPATCH_CONFIDENCE matching runChaPostPass.
561562
// When scopeToChangedFiles is true, restrict to call sites in the changed files
562563
// (safe because no hierarchy or RTA evidence changed outside those files).
563564
let callToMethods: Array<{ source_id: number; method_name: string; caller_file: string | null }>;
@@ -653,10 +654,7 @@ function runPostNativeCha(
653654
const key = `${source_id}|${methodNode.id}`;
654655
if (seen.has(key)) continue;
655656
seen.add(key);
656-
// Use the same hardcoded 0.8 that runChaPostPass (helpers.ts) uses for
657-
// DB-level CHA dispatch edges. This aligns the native orchestrator path
658-
// with the WASM and hybrid paths, which both go through runChaPostPass.
659-
const conf = 0.8;
657+
const conf = CHA_DISPATCH_CONFIDENCE;
660658
newEdges.push([source_id, methodNode.id, 'calls', conf, 0, 'cha']);
661659
newEdgeCount++;
662660
if (caller_file) affectedFiles.add(caller_file);

src/extractors/cpp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
TreeSitterNode,
66
TreeSitterTree,
77
} from '../types.js';
8-
import { extractModifierVisibility, findChild, nodeEndLine } from './helpers.js';
8+
import { extractModifierVisibility, findChild, nodeEndLine, setTypeMapEntry } from './helpers.js';
99

1010
/**
1111
* Extract symbols from C++ files.
@@ -232,7 +232,7 @@ function handleCppDeclaration(node: TreeSitterNode, ctx: ExtractorOutput): void
232232
if (!nameNode) continue;
233233
const varName = unwrapCppDeclaratorName(nameNode);
234234
if (varName) {
235-
ctx.typeMap.set(varName, { type: typeName, confidence: 0.9 });
235+
setTypeMapEntry(ctx.typeMap, varName, typeName, 0.9);
236236
}
237237
}
238238
}

src/extractors/cuda.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
TreeSitterNode,
66
TreeSitterTree,
77
} from '../types.js';
8-
import { extractModifierVisibility, findChild, nodeEndLine } from './helpers.js';
8+
import { extractModifierVisibility, findChild, nodeEndLine, setTypeMapEntry } from './helpers.js';
99

1010
/**
1111
* Extract symbols from CUDA files.
@@ -232,7 +232,7 @@ function handleCudaDeclaration(node: TreeSitterNode, ctx: ExtractorOutput): void
232232
if (!nameNode) continue;
233233
const varName = extractCudaFieldName(nameNode);
234234
if (varName) {
235-
ctx.typeMap.set(varName, { type: typeName, confidence: 0.9 });
235+
setTypeMapEntry(ctx.typeMap, varName, typeName, 0.9);
236236
}
237237
}
238238
}

0 commit comments

Comments
 (0)