Skip to content

Commit 93ec343

Browse files
committed
refactor(resolver): confidence filter in class-scoped Rust lookup; runPostNativeCha returns count
- edge_builder.rs: align class-scoped lookup with WASM call-resolver.ts by adding compute_confidence >= 0.5 filter, matching all other lookup paths in the same block (#1403) - native-orchestrator.ts: change runPostNativeCha return type from Set<number> to number — caller only reads .size, individual IDs are never used; clearer intent and avoids the unused Set allocation (#1403)
1 parent 0831e36 commit 93ec343

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

crates/codegraph-core/src/edge_builder.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,10 @@ fn resolve_call_targets<'a>(
514514
let qualified = format!("{}.{}", class_prefix, call.name);
515515
let class_scoped: Vec<&NodeInfo> = ctx.nodes_by_name
516516
.get(qualified.as_str())
517-
.map(|v| v.iter().filter(|n| n.kind == "method").copied().collect())
517+
.map(|v| v.iter()
518+
.filter(|n| n.kind == "method"
519+
&& import_resolution::compute_confidence(rel_path, &n.file, None) >= 0.5)
520+
.copied().collect())
518521
.unwrap_or_default();
519522
if !class_scoped.is_empty() { return class_scoped; }
520523
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,12 @@ async function runPostNativeAnalysis(
406406
* can re-classify roles for the affected implementation files. An empty set
407407
* means no edges were added and role re-classification is unnecessary.
408408
*/
409-
function runPostNativeCha(db: BetterSqlite3Database): Set<number> {
409+
function runPostNativeCha(db: BetterSqlite3Database): number {
410410
// Fast guard: no hierarchy edges → no CHA work
411411
const hasHierarchy = db
412412
.prepare(`SELECT 1 FROM edges WHERE kind IN ('extends', 'implements') LIMIT 1`)
413413
.get();
414-
if (!hasHierarchy) return new Set();
414+
if (!hasHierarchy) return 0;
415415

416416
// Build implementors map: parent/interface name → [child/implementing class names]
417417
const hierarchyRows = db
@@ -433,7 +433,7 @@ function runPostNativeCha(db: BetterSqlite3Database): Set<number> {
433433
}
434434
if (!list.includes(row.child_name)) list.push(row.child_name);
435435
}
436-
if (implementors.size === 0) return new Set();
436+
if (implementors.size === 0) return 0;
437437

438438
// RTA: collect class names that are actually instantiated via `new X()`.
439439
// Primary query targets `class`-kind nodes (the canonical schema).
@@ -506,7 +506,7 @@ function runPostNativeCha(db: BetterSqlite3Database): Set<number> {
506506
`SELECT id, file AS method_file FROM nodes WHERE name = ? AND kind = 'method'`,
507507
);
508508
const newEdges: Array<[number, number, string, number, number, string]> = [];
509-
const newTargetIds = new Set<number>();
509+
let newEdgeCount = 0;
510510

511511
for (const { source_id, method_name, caller_file } of callToMethods) {
512512
const dotIdx = method_name.indexOf('.');
@@ -545,7 +545,7 @@ function runPostNativeCha(db: BetterSqlite3Database): Set<number> {
545545
CHA_DISPATCH_PENALTY;
546546
if (conf <= 0) continue;
547547
newEdges.push([source_id, methodNode.id, 'calls', conf, 0, 'cha']);
548-
newTargetIds.add(methodNode.id);
548+
newEdgeCount++;
549549
}
550550
}
551551

@@ -558,7 +558,7 @@ function runPostNativeCha(db: BetterSqlite3Database): Set<number> {
558558
if (newEdges.length > 0) {
559559
db.transaction(() => batchInsertEdges(db, newEdges))();
560560
}
561-
return newTargetIds;
561+
return newEdgeCount;
562562
}
563563

564564
/**
@@ -1555,8 +1555,8 @@ export async function tryNativeOrchestrator(
15551555
// pre-CHA might be near the median, but post-CHA the median is higher, changing
15561556
// its role from utility → core.) Using an incremental pass with a stale median
15571557
// cache would produce incorrect roles outside the CHA-affected file set.
1558-
const chaTargetIds = runPostNativeCha(ctx.db as unknown as BetterSqlite3Database);
1559-
if (chaTargetIds.size > 0) {
1558+
const chaEdgeCount = runPostNativeCha(ctx.db as unknown as BetterSqlite3Database);
1559+
if (chaEdgeCount > 0) {
15601560
try {
15611561
const db = ctx.db as unknown as BetterSqlite3Database;
15621562
const { classifyNodeRoles } = (await import('../../../../features/structure.js')) as {
@@ -1566,7 +1566,7 @@ export async function tryNativeOrchestrator(
15661566
) => Record<string, number>;
15671567
};
15681568
classifyNodeRoles(db);
1569-
debug(`CHA post-pass: full role re-classification after ${chaTargetIds.size} new CHA edges`);
1569+
debug(`CHA post-pass: full role re-classification after ${chaEdgeCount} new CHA edges`);
15701570
} catch (err) {
15711571
debug(`CHA post-pass role re-classification failed: ${toErrorMessage(err)}`);
15721572
}

0 commit comments

Comments
 (0)