Skip to content

Commit 1875c7f

Browse files
committed
fix(wasm): align typed-receiver CHA dispatch confidence to 0.8
The inline CHA expansion in buildCallEdges and buildChaPostPass used computeConfidence(relPath, t.file) - CHA_DISPATCH_PENALTY for all CHA targets, producing 0.6 for cross-directory interface dispatch (same-dir = 0.7, minus 0.1 penalty). runChaPostPass (helpers.ts) and runPostNativeCha (native-orchestrator.ts) both hardcode 0.8 for interface/CHA-dispatch edges. The deduplication in runChaPostPass uses the existing DB edge as-is and skips reinsertion, so the 0.6 edges from the inline pass were never upgraded to 0.8. Fix: typed-receiver (interface) dispatch branches now use hardcoded 0.8 matching the post-pass constants. The this/super branch keeps computeConfidence-based proximity scoring to remain aligned with runPostNativeThisDispatch. parity-compare.mjs --langs typescript --hybrid goes green (was 12 edge diffs). Closes #1470 docs check acknowledged
1 parent 7095ffe commit 1875c7f

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

src/domain/graph/builder/stages/build-edges.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ function buildChaPostPass(
709709

710710
const caller = findCaller(lookup, call, symbols.definitions, relPath, fileNodeRow);
711711
let chaTargets: ReadonlyArray<{ id: number; file: string }> = [];
712+
let isTypedReceiverDispatch = false;
712713

713714
if (call.receiver === 'this' || call.receiver === 'self' || call.receiver === 'super') {
714715
chaTargets = resolveThisDispatch(
@@ -727,13 +728,21 @@ function buildChaPostPass(
727728
: null;
728729
if (typeName) {
729730
chaTargets = resolveChaTargets(typeName, call.name, chaCtx, lookup);
731+
isTypedReceiverDispatch = true;
730732
}
731733
}
732734

733735
for (const t of chaTargets) {
734736
const edgeKey = `${caller.id}|${t.id}`;
735737
if (t.id !== caller.id && !seenByPair.has(edgeKey)) {
736-
const conf = computeConfidence(relPath, t.file, null) - CHA_DISPATCH_PENALTY;
738+
// Typed-receiver (interface/CHA) dispatch: use the same hardcoded 0.8 that
739+
// runChaPostPass (helpers.ts) and runPostNativeCha (native-orchestrator.ts)
740+
// use — file proximity is not meaningful for virtual dispatch confidence.
741+
// this/super dispatch keeps computeConfidence-based proximity scoring to
742+
// match runPostNativeThisDispatch (native-orchestrator.ts).
743+
const conf = isTypedReceiverDispatch
744+
? 0.8
745+
: computeConfidence(relPath, t.file, null) - CHA_DISPATCH_PENALTY;
737746
if (conf > 0) {
738747
seenByPair.add(edgeKey);
739748
allEdgeRows.push([caller.id, t.id, 'calls', conf, 0, 'cha']);
@@ -1278,6 +1287,7 @@ function buildFileCallEdges(
12781287
// For typed receiver calls: expand to all instantiated concrete implementations.
12791288
if (chaCtx && call.receiver) {
12801289
let chaTargets: ReadonlyArray<{ id: number; file: string }> = [];
1290+
let isTypedReceiverDispatch = false;
12811291
if (call.receiver === 'this' || call.receiver === 'self' || call.receiver === 'super') {
12821292
chaTargets = resolveThisDispatch(
12831293
call.name,
@@ -1295,12 +1305,20 @@ function buildFileCallEdges(
12951305
: null;
12961306
if (typeName) {
12971307
chaTargets = resolveChaTargets(typeName, call.name, chaCtx, lookup);
1308+
isTypedReceiverDispatch = true;
12981309
}
12991310
}
13001311
for (const t of chaTargets) {
13011312
const edgeKey = `${caller.id}|${t.id}`;
13021313
if (t.id !== caller.id && !seenCallEdges.has(edgeKey) && !ptsEdgeRows.has(edgeKey)) {
1303-
const conf = computeConfidence(relPath, t.file, null) - CHA_DISPATCH_PENALTY;
1314+
// Typed-receiver (interface/CHA) dispatch: use the same hardcoded 0.8 that
1315+
// runChaPostPass (helpers.ts) and runPostNativeCha (native-orchestrator.ts)
1316+
// use — file proximity is not meaningful for virtual dispatch confidence.
1317+
// this/super dispatch keeps computeConfidence-based proximity scoring to
1318+
// match runPostNativeThisDispatch (native-orchestrator.ts line 906).
1319+
const conf = isTypedReceiverDispatch
1320+
? 0.8
1321+
: computeConfidence(relPath, t.file, null) - CHA_DISPATCH_PENALTY;
13041322
if (conf > 0) {
13051323
seenCallEdges.add(edgeKey);
13061324
allEdgeRows.push([caller.id, t.id, 'calls', conf, 0, 'cha']);

0 commit comments

Comments
 (0)