perf(javascript): share one lexical index between static and semantic analysis (#14148)

* perf(javascript): share one lexical index between static and semantic analysis

The static and semantic phases each built a private semantic state for
the same parsed program, so definitions, ambient writes and
member-mutation facts were derived twice per file.

Sharing the state requires separating what it holds. Index facts are
shared. Memoized query results are declared through one owner so a new
consumer or index step starts without them. Observations (resource
limits and returned-reference widenings) are recorded per derivation:
index steps record into the index's own log and each consumer starts
from that log, so the semantic phase reports exactly what a private
index would have.

The worker builds one index per parsed file and the semantic phase
continues from it when its resolution mode matches the static phase.

Refs #14147

* fix(javascript): let a shared lexical index continue only one semantic phase

The semantic phase appends its module links and callable facts to the
state it continues from, so a second phase from the same index reported
each import link twice. Admission is now consumed by the first phase and
a second is rejected like any other index that does not match.
This commit is contained in:
morluto
2026-11-23 23:20:26 +00:00
committed by GitHub
parent 03f68dbcba
commit 24d2c4f16b
29 changed files with 579 additions and 147 deletions
@@ -39,6 +39,7 @@ import {
semanticDirectEvalRecorded,
semanticGlobalCodeSites,
} from "./javascriptSemanticEffectRecord.js";
import { semanticConsumerMemo } from "./javascriptSemanticConsumer.js";
// Match the complete Rolldown runtime operations, including its live getters.
// Names and formatting are irrelevant; lexical roles, operators and keys are not.
@@ -999,13 +1000,10 @@ const controlBodyOperation = (node: t.Node): t.Node => {
return node;
};
const ambientWriteInterops = new WeakMap<
JavaScriptSemanticAnalysisState,
{
readonly generation: number;
readonly interop: ReturnType<typeof createSemanticModuleInterop>;
}
>();
const ambientWriteInterops = semanticConsumerMemo<{
readonly generation: number;
readonly interop: ReturnType<typeof createSemanticModuleInterop>;
}>();
/**
* Module interop that retains every recorded ambient global write, so an