Reuse lowered units across builds behind SCRIPTC_INCR_LOWERING=1

This commit is contained in:
Chris Tate
2026-10-28 23:57:15 -05:00
parent c0ef82865d
commit 16ea77108b
19 changed files with 8361 additions and 134 deletions
+9 -1
View File
@@ -20,6 +20,7 @@ import {
} from "../backend/target-diagnostics.js";
import type { LowerResult, LowerStats } from "../frontend/lowering/lowerer.js";
import type { FrontendFactory } from "../frontend/pipeline.js";
import type { UnitStore } from "../frontend/lowering/unit-reuse.js";
import type { CompilationTiming } from "../timing.js";
import { readProjectConfig } from "../project-config.js";
import { nodeIslandPolicy } from "../node-islands/policy.js";
@@ -42,7 +43,9 @@ export interface PreparedExecutableModule {
warnings: ScrDiagnostic[];
}
/** Release the parser/checker before native object generation begins. */
/** Release the parser/checker before native object generation begins.
* `unitStore` keeps the lowered units of this build for the next one
* (unit-reuse.ts). */
export function prepareExecutableModule(
entryPath: string,
opts: CompileRequestOptions,
@@ -52,6 +55,7 @@ export function prepareExecutableModule(
timing: CompilationTiming = () => {},
lowerIslands: ReadonlyMap<string, IslandPackage> = new Map(),
retryFences = true,
unitStore: UnitStore | null = null,
): PreparedExecutableModule | CompileFailure {
// The island decision reads the detector's scan unless islands are off.
const islandScan =
@@ -115,6 +119,7 @@ export function prepareExecutableModule(
timing,
grown,
retryFences,
unitStore,
);
}
return fail(fe.preflight);
@@ -127,6 +132,7 @@ export function prepareExecutableModule(
targetPlatform: buildPlatform,
...(ffi !== null ? { ffiImports: ffi.functions } : {}),
...(opts.tier !== undefined ? { tierMode: opts.tier } : {}),
...(unitStore !== null ? { unitStore } : {}),
},
(module) => validateModule(module).length === 0,
);
@@ -165,6 +171,7 @@ export function prepareExecutableModule(
timing,
grown,
retryFences,
unitStore,
);
}
// A failed program whose compiled packages need the runtime or a
@@ -267,6 +274,7 @@ export function prepareExecutableModule(
timing,
islands,
false,
unitStore,
);
if (islanded.ok) return islanded;
firstError ??= islanded.diagnostics[0] ?? null;