hardens IRGlobal structural metadata for PBS lifecycle lowering

This commit is contained in:
2026-03-26 20:00:16 +00:00
parent 14eaa0e0c0
commit 64762ca227
11 changed files with 185 additions and 38 deletions
@@ -2,6 +2,7 @@ package p.studio.compiler.pbs;
import org.junit.jupiter.api.Test;
import p.studio.compiler.messages.HostAdmissionContext;
import p.studio.compiler.models.IRHiddenGlobalKind;
import p.studio.compiler.models.IRSyntheticCallableKind;
import p.studio.compiler.models.SourceKind;
import p.studio.compiler.pbs.lexer.LexErrors;
@@ -12,6 +13,7 @@ import p.studio.compiler.source.identifiers.FileId;
import p.studio.utilities.structures.ReadOnlyList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class PbsFrontendCompilerTest {
@@ -60,6 +62,10 @@ class PbsFrontendCompilerTest {
assertTrue(diagnostics.isEmpty(), diagnostics.stream().map(d -> d.getCode() + ":" + d.getMessage()).toList().toString());
assertEquals(1, fileBackend.globals().size());
assertEquals("SCORE", fileBackend.globals().getFirst().name());
assertEquals(0, fileBackend.globals().getFirst().slot());
assertFalse(fileBackend.globals().getFirst().isHidden());
assertEquals(IRHiddenGlobalKind.NONE, fileBackend.globals().getFirst().hiddenKind());
assertEquals("SCORE", fileBackend.globals().getFirst().origin().derivedFromUserSymbol());
assertEquals(4, fileBackend.syntheticFunctions().size());
assertTrue(fileBackend.syntheticFunctions().stream().anyMatch(fn -> fn.kind() == IRSyntheticCallableKind.FILE_INIT_FRAGMENT));
assertTrue(fileBackend.syntheticFunctions().stream().anyMatch(fn -> fn.kind() == IRSyntheticCallableKind.MODULE_INIT));
@@ -5,6 +5,7 @@ import org.junit.jupiter.api.io.TempDir;
import p.studio.compiler.messages.BuildingIssueSink;
import p.studio.compiler.messages.FrontendPhaseContext;
import p.studio.compiler.models.BuildStack;
import p.studio.compiler.models.IRHiddenGlobalKind;
import p.studio.compiler.models.ProjectDescriptor;
import p.studio.compiler.models.SourceHandle;
import p.studio.compiler.models.SourceKind;
@@ -362,8 +363,12 @@ class PBSFrontendPhaseServiceTest {
assertTrue(diagnostics.isEmpty(), diagnostics.stream().map(d -> d.getCode() + ":" + d.getMessage()).toList().toString());
assertTrue(irBackend.getEntryPointCallableName().startsWith("__pbs.frame_wrapper$m"));
assertTrue(irBackend.getGlobals().stream().anyMatch(global ->
global.name().startsWith("__pbs.boot_guard$m")));
final var bootGuard = irBackend.getGlobals().stream()
.filter(global -> global.hiddenKind() == IRHiddenGlobalKind.BOOT_GUARD)
.findFirst()
.orElseThrow();
assertTrue(bootGuard.isHidden());
assertTrue(bootGuard.name().startsWith("__pbs.boot_guard$m"));
final var wrapper = irBackend.getExecutableFunctions().stream()
.filter(function -> irBackend.getEntryPointCallableName().equals(function.callableName()))
.findFirst()
@@ -439,7 +444,7 @@ class PBSFrontendPhaseServiceTest {
assertTrue(irBackend.getExecutableFunctions().stream().anyMatch(function ->
function.callableName().startsWith("__pbs.project_init$m")));
assertTrue(irBackend.getGlobals().stream().anyMatch(global -> "SCORE".equals(global.name())));
assertTrue(irBackend.getGlobals().stream().anyMatch(global -> global.name().startsWith("__pbs.boot_guard$m")));
assertTrue(irBackend.getGlobals().stream().anyMatch(global -> global.hiddenKind() == IRHiddenGlobalKind.BOOT_GUARD));
}
@Test