refactor(javascript): own coverage facts and reuse block prefixes

Separate syntax, semantic uncertainty, examination limits and observed Electron applicability at the static producer, then preserve them through worker, graph and retained/inline summary views. Derive the established parse_status from the same facts and leave historical measurements unknown. Give semantic resource-limit classifications one schema owner.

Replace repeated block-prefix searches and copies with collector-scoped syntax indexes. Keep invocation environments separate, charge indexing/replay to the existing work budget and yield during prefix work. Remove the superseded synchronous collector entrypoint.

Validated producer, worker, CLI/MCP, historical and partial-coverage regressions, plus actual cancellation during indexing. Bounded authored 128/256-call controls preserved all prior facts while replacing repeated search/copy work with one index pass; this is not a throughput or agent-token benchmark.
This commit is contained in:
morluto committed 2026-10-25 09:49:26 +08:00
1 parent c8269ca497
commit f62a2baad8
21 files changed
+898 -125

No files matched your search

@@ -0,0 +1,85 @@
import * as t from "@babel/types";
import { symbolicDefiniteExit } from "./javascriptSymbolicControlFlow.js";
/** Syntax alone can establish an exit, but never a branch's contextual truth. */
export type ElectronStatementFallthrough =
| { readonly kind: "exit" }
| {
readonly kind: "branch";
readonly test: t.Expression;
readonly consequentExits: boolean;
readonly alternateExits: boolean;
};
interface PrefixEntry {
readonly position: number;
readonly fact: ElectronStatementFallthrough;
}
interface BlockIndex {
readonly positions: WeakMap<t.Node, number>;
readonly entries: readonly PrefixEntry[];
}
/**
* One collector's immutable syntax facts. Positions replace repeated body
* searches; ordinary fallthrough statements need no replay. Conditional tests
* remain present even when neither branch exits, since evaluating them belongs
* to the invocation's symbolic environment and can establish unknown coverage.
*/
export class ElectronCallPathBlockPrefixes {
readonly #blocks = new WeakMap<t.BlockStatement, BlockIndex>();
readonly #facts = new WeakMap<
t.Statement,
ElectronStatementFallthrough | null
>();
constructor(private readonly admitVisit: () => boolean) {}
statement(statement: t.Statement): ElectronStatementFallthrough | null {
const cached = this.#facts.get(statement);
if (cached !== undefined) return cached;
const fact: ElectronStatementFallthrough | null = symbolicDefiniteExit(
statement,
)
? { kind: "exit" }
: t.isIfStatement(statement)
? {
kind: "branch",
test: statement.test,
consequentExits: symbolicDefiniteExit(statement.consequent),
alternateExits: symbolicDefiniteExit(statement.alternate),
}
: null;
this.#facts.set(statement, fact);
return fact;
}
*before(
block: t.BlockStatement,
child: t.Node,
): Generator<
void,
| { readonly entries: readonly PrefixEntry[]; readonly before: number }
| undefined
> {
let index = this.#blocks.get(block);
if (index === undefined) {
const positions = new WeakMap<t.Node, number>();
const entries: PrefixEntry[] = [];
for (const [position, statement] of block.body.entries()) {
if (!this.admitVisit()) return undefined;
positions.set(statement, position);
const fact = this.statement(statement);
if (fact !== null) entries.push({ position, fact });
if ((position + 1) % 1024 === 0) yield;
}
index = { positions, entries };
this.#blocks.set(block, index);
}
const before = index.positions.get(child);
return before === undefined
? undefined
: { entries: index.entries, before };
}
}