implements PR-08.2

This commit is contained in:
2026-03-24 13:42:32 +00:00
parent 40188b67ab
commit 0490f64870
11 changed files with 520 additions and 23 deletions
@@ -5,8 +5,10 @@ import p.studio.compiler.source.Span;
import p.studio.compiler.source.identifiers.CallableId;
import p.studio.compiler.source.identifiers.FileId;
import p.studio.compiler.source.identifiers.IntrinsicId;
import p.studio.compiler.source.identifiers.ModuleId;
import p.studio.compiler.source.tables.CallableSignatureRef;
import p.studio.compiler.source.tables.IntrinsicReference;
import p.studio.compiler.source.tables.ModuleReference;
import p.studio.utilities.structures.ReadOnlyList;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -300,4 +302,76 @@ class IRBackendExecutableContractTest {
assertEquals(21, emittedInstructionSpan.getStart());
assertEquals(34, emittedInstructionSpan.getEnd());
}
@Test
void aggregatorMustReindexModulesIntoGlobalDensePool() {
final var fileA = new IRBackendFile(
new FileId(1),
ReadOnlyList.empty(),
ReadOnlyList.from(new IRBackendExecutableFunction(
new FileId(1),
new ModuleId(0),
"app:mod/a",
"entry",
new CallableId(0),
0,
5,
0,
0,
0,
1,
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.RET,
"",
"",
null,
null,
Span.none())),
Span.none())),
IRReservedMetadata.empty(),
ReadOnlyList.from(new ModuleReference("app", ReadOnlyList.from("mod", "a"))),
ReadOnlyList.from(new CallableSignatureRef(new ModuleId(0), "app:mod/a", "entry", 0, "() -> unit")),
ReadOnlyList.empty());
final var fileB = new IRBackendFile(
new FileId(2),
ReadOnlyList.empty(),
ReadOnlyList.from(new IRBackendExecutableFunction(
new FileId(2),
new ModuleId(0),
"app:mod/b",
"aux",
new CallableId(0),
6,
10,
0,
0,
0,
1,
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.RET,
"",
"",
null,
null,
Span.none())),
Span.none())),
IRReservedMetadata.empty(),
ReadOnlyList.from(new ModuleReference("app", ReadOnlyList.from("mod", "b"))),
ReadOnlyList.from(new CallableSignatureRef(new ModuleId(0), "app:mod/b", "aux", 0, "() -> unit")),
ReadOnlyList.empty());
final var aggregator = IRBackend.aggregator();
aggregator.merge(fileA);
aggregator.merge(fileB);
final var backend = aggregator.emit();
assertEquals(2, backend.getModulePool().size());
assertEquals("mod", backend.getModulePool().get(0).pathSegments().get(0));
assertEquals("a", backend.getModulePool().get(0).pathSegments().get(1));
assertEquals("b", backend.getModulePool().get(1).pathSegments().get(1));
assertEquals(0, backend.getExecutableFunctions().get(0).moduleId().getIndex());
assertEquals(1, backend.getExecutableFunctions().get(1).moduleId().getIndex());
assertEquals(0, backend.getCallableSignatures().get(0).moduleId().getIndex());
assertEquals(1, backend.getCallableSignatures().get(1).moduleId().getIndex());
}
}