implements PLN-0125
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
JaCoCo Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 61.95% (17766/28676) * Branch Coverage: 52.69% (6860/13019) * Lines of Code: 28676 * Cyclomatic Complexity: 11490 #### Quality Gates Summary Output truncated.
Test / Build skipped: 15, passed: 643
Intrepid/Prometeu/Studio/pipeline/pr-master This commit looks good

Move lifecycle assembly out of the PBS frontend into a common
AssembleLifecyclePipelineStage. PBS emits a typed IRLifecycleDeclaration;
the assembler owns wrappers, boot guard, and single project-init execution.

Housekeep DSC-0059 with LSN-0062, and include the DSC-0062 PVM/PBX
neutrality spec and lesson already present on this branch.
This commit is contained in:
2026-09-19 00:19:45 +01:00
parent c6ef56114f
commit 46bd0c42d3
42 changed files with 2349 additions and 762 deletions
@@ -58,6 +58,11 @@ class IRBackendExecutableContractTest {
IRGlobalOrigin.class,
IRGlobalVisibility.class,
IRHiddenGlobalKind.class,
IRLifecycleDeclaration.class,
IRLifecycleModuleDeclaration.class,
IRLifecycleFileDeclaration.class,
IRLifecycleCallableReference.class,
IRLifecycleCallableRole.class,
IRReservedMetadata.class,
IRReservedMetadata.HostMethodBinding.class,
IRReservedMetadata.BuiltinTypeSurface.class,
@@ -80,7 +85,12 @@ class IRBackendExecutableContractTest {
IRReservedMetadata.class,
IRSyntheticCallableKind.class,
IRSyntheticFunction.class,
IRSyntheticOrigin.class);
IRSyntheticOrigin.class,
IRLifecycleDeclaration.class,
IRLifecycleModuleDeclaration.class,
IRLifecycleFileDeclaration.class,
IRLifecycleCallableReference.class,
IRLifecycleCallableRole.class);
assertTrue(
PUBLIC_CONTRACT_TYPES.containsAll(expectedTopLevelModelTypes),
@@ -137,6 +147,14 @@ class IRBackendExecutableContractTest {
assertEquals(FileId.class, recordComponentType(IRSyntheticOrigin.class, "fileId"));
assertEquals(ModuleId.class, recordComponentType(IRSyntheticFunction.class, "moduleId"));
assertEquals(ModuleId.class, recordComponentType(IRLifecycleModuleDeclaration.class, "moduleId"));
assertEquals(ModuleId.class, recordComponentType(IRLifecycleFileDeclaration.class, "moduleId"));
assertEquals(FileId.class, recordComponentType(IRLifecycleFileDeclaration.class, "fileId"));
assertEquals(ModuleId.class, recordComponentType(IRLifecycleCallableReference.class, "moduleId"));
assertEquals(FileId.class, recordComponentType(IRLifecycleCallableReference.class, "fileId"));
assertEquals(CallableId.class, recordComponentType(IRLifecycleCallableReference.class, "callableId"));
assertEquals(Span.class, recordComponentType(IRLifecycleCallableReference.class, "origin"));
assertEquals(String.class, recordComponentType(ModuleReference.class, "project"));
assertEquals(String.class, recordComponentType(CallableSignatureRef.class, "callableName"));
assertEquals(String.class, recordComponentType(IntrinsicReference.class, "canonicalName"));
@@ -640,6 +658,146 @@ class IRBackendExecutableContractTest {
second.getExecutableFunctions().get(1).callableId());
}
@Test
void aggregatorMustRemapTypedLifecycleReferencesAndPreserveDeclaredModuleOrder() {
final var fileASpan = new Span(new FileId(10), 1, 8);
final var fileBSpan = new Span(new FileId(20), 2, 9);
final var fileA = new IRBackendFile(
new FileId(10),
ReadOnlyList.empty(),
ReadOnlyList.from(new IRSyntheticFunction(
new ModuleId(0),
"file_init_zzz",
IRSyntheticCallableKind.FILE_INIT_FRAGMENT,
new IRSyntheticOrigin(new FileId(10), "warmup", fileASpan))),
ReadOnlyList.empty(),
ReadOnlyList.from(executable("file_init_zzz", 10, 0, 0, fileASpan)),
IRReservedMetadata.empty(),
ReadOnlyList.from(new ModuleReference("app", ReadOnlyList.from("zzz"))),
ReadOnlyList.from(new CallableSignatureRef(new ModuleId(0), "file_init_zzz", 0, "() -> unit")),
ReadOnlyList.empty(),
new IRLifecycleFileDeclaration(
new ModuleId(0),
new FileId(10),
new IRLifecycleCallableReference(
new ModuleId(0),
new FileId(10),
new CallableId(0),
IRLifecycleCallableRole.FILE_INIT_FRAGMENT,
fileASpan),
null,
null));
final var fileB = new IRBackendFile(
new FileId(20),
ReadOnlyList.empty(),
ReadOnlyList.empty(),
ReadOnlyList.empty(),
ReadOnlyList.from(
executable("boot", 20, 0, 0, fileBSpan),
executable("frame", 20, 0, 1, fileBSpan)),
IRReservedMetadata.empty(),
ReadOnlyList.from(new ModuleReference("app", ReadOnlyList.from("aaa"))),
ReadOnlyList.from(
new CallableSignatureRef(new ModuleId(0), "boot", 0, "() -> unit"),
new CallableSignatureRef(new ModuleId(0), "frame", 0, "() -> unit")),
ReadOnlyList.empty(),
new IRLifecycleFileDeclaration(
new ModuleId(0),
new FileId(20),
null,
new IRLifecycleCallableReference(
new ModuleId(0),
new FileId(20),
new CallableId(0),
IRLifecycleCallableRole.PROJECT_INIT,
fileBSpan),
new IRLifecycleCallableReference(
new ModuleId(0),
new FileId(20),
new CallableId(1),
IRLifecycleCallableRole.FRAME_ROOT,
fileBSpan)));
final var aggregator = IRBackend.aggregator();
aggregator.merge(fileA);
aggregator.merge(fileB);
aggregator.lifecycleModuleOrder(ReadOnlyList.from(new ModuleId(1), new ModuleId(0)));
final var backend = aggregator.emit();
final var declaration = backend.getLifecycleDeclaration();
assertNotNull(declaration);
assertEquals(2, declaration.modules().size());
assertEquals(1, declaration.modules().get(0).moduleId().getIndex());
assertEquals(0, declaration.modules().get(1).moduleId().getIndex());
assertEquals("aaa", backend.getModulePool().get(1).pathSegments().getFirst());
assertEquals("zzz", backend.getModulePool().get(0).pathSegments().getFirst());
assertEquals(IRLifecycleCallableRole.FILE_INIT_FRAGMENT, declaration.modules().get(1).fileInitFragments().getFirst().role());
assertEquals(0, declaration.modules().get(1).fileInitFragments().getFirst().callableId().getIndex());
assertEquals(1, declaration.projectInit().callableId().getIndex());
assertEquals(2, declaration.frameRoot().callableId().getIndex());
assertEquals(20, declaration.frameRoot().fileId().getId());
assertEquals(2, declaration.frameRoot().origin().getStart());
assertEquals("boot", backend.getExecutableFunctions().get(1).callableName());
assertEquals("frame", backend.getExecutableFunctions().get(2).callableName());
}
@Test
void aggregatorMustOmitLifecycleDeclarationWhenNoFileContributesOne() {
final var aggregator = IRBackend.aggregator();
aggregator.merge(new IRBackendFile(
new FileId(1),
ReadOnlyList.empty(),
ReadOnlyList.from(new IRBackendExecutableFunction(
new FileId(1),
"entry",
new CallableId(0),
0,
10,
0,
0,
0,
1,
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.RET,
"",
null,
null,
Span.none())),
Span.none())),
IRReservedMetadata.empty(),
ReadOnlyList.from(new CallableSignatureRef("entry", 0, "() -> unit")),
ReadOnlyList.empty()));
final var backend = aggregator.emit();
assertNull(backend.getLifecycleDeclaration());
}
private static IRBackendExecutableFunction executable(
final String name,
final int fileId,
final int moduleId,
final int callableId,
final Span span) {
return new IRBackendExecutableFunction(
new FileId(fileId),
new ModuleId(moduleId),
name,
new CallableId(callableId),
(int) span.getStart(),
(int) span.getEnd(),
0,
0,
0,
1,
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.RET,
"",
null,
null,
span)),
span);
}
private static IRBackend emitDeterministicAggregateFixture() {
final var aggregator = IRBackend.aggregator();
aggregator.merge(new IRBackendFile(