implements PR-19.9 conformance fixtures diagnostics and gate closure

This commit is contained in:
2026-03-26 19:47:00 +00:00
parent 58c5ab26d7
commit 459f5e3b87
10 changed files with 322 additions and 12 deletions
@@ -416,6 +416,10 @@ public final class PbsFrontendCompiler {
return "__pbs.frame_wrapper$m" + normalizedModuleIndex(moduleId);
}
public static String bootGuardGlobalName(final ModuleId moduleId) {
return "__pbs.boot_guard$m" + normalizedModuleIndex(moduleId);
}
private static int normalizedModuleIndex(final ModuleId moduleId) {
final var normalized = moduleId == null ? ModuleId.none() : moduleId;
return normalized.isNone() ? -1 : normalized.getIndex();
@@ -119,6 +119,7 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
private IRBackend synthesizePublishedLifecycle(final IRBackend baseBackend) {
final var callableSignatures = new ArrayList<>(baseBackend.getCallableSignatures().asList());
final var executableFunctions = new ArrayList<>(baseBackend.getExecutableFunctions().asList());
final var globals = new ArrayList<>(baseBackend.getGlobals().asList());
final var fileInitFunctionsByModule = new LinkedHashMap<ModuleId, List<IRBackendExecutableFunction>>();
final var projectInitAnchorsByModule = new LinkedHashMap<ModuleId, String>();
final var wrapperNamesByModule = new LinkedHashMap<ModuleId, String>();
@@ -151,8 +152,9 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
entryPointModuleId = wrapperNamesByModule.keySet().iterator().next();
entryPointCallableName = wrapperNamesByModule.get(entryPointModuleId);
} else {
entryPointModuleId = baseBackend.getEntryPointModuleId();
entryPointCallableName = baseBackend.getEntryPointCallableName();
final var legacyEntrypoint = resolveLegacyEntrypoint(baseBackend);
entryPointModuleId = legacyEntrypoint.moduleId();
entryPointCallableName = legacyEntrypoint.callableName();
}
final var sortedModuleIds = new ArrayList<ModuleId>();
@@ -281,6 +283,17 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
1,
ReadOnlyList.wrap(instructions),
frameExecutable.span()));
if (globals.stream().noneMatch(global ->
moduleIdsMatch(entryPointModuleId, global.moduleId())
&& PbsFrontendCompiler.bootGuardGlobalName(entryPointModuleId).equals(global.name()))) {
globals.add(new p.studio.compiler.models.IRGlobal(
frameExecutable.fileId(),
entryPointModuleId,
PbsFrontendCompiler.bootGuardGlobalName(entryPointModuleId),
"bool",
frameExecutable.span()));
}
}
return IRBackend.builder()
@@ -288,7 +301,7 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
.entryPointModuleId(entryPointModuleId)
.functions(baseBackend.getFunctions())
.syntheticFunctions(baseBackend.getSyntheticFunctions())
.globals(baseBackend.getGlobals())
.globals(ReadOnlyList.wrap(globals))
.executableFunctions(ReadOnlyList.wrap(executableFunctions))
.modulePool(baseBackend.getModulePool())
.callableSignatures(ReadOnlyList.wrap(callableSignatures))
@@ -384,6 +397,19 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
return (int) value;
}
private LegacyEntrypoint resolveLegacyEntrypoint(final IRBackend backend) {
for (final var candidateName : List.of("frame", "main")) {
final var candidates = backend.getExecutableFunctions().stream()
.filter(function -> candidateName.equals(function.callableName()))
.filter(function -> function.moduleId() != null && !function.moduleId().isNone())
.toList();
if (candidates.size() == 1) {
return new LegacyEntrypoint(candidates.getFirst().moduleId(), candidateName);
}
}
return new LegacyEntrypoint(backend.getEntryPointModuleId(), backend.getEntryPointCallableName());
}
private Set<ModuleId> blockedModulesByDependency(
final Set<ModuleId> failedModuleIds,
final Map<ModuleId, Set<ModuleId>> dependenciesByModule) {
@@ -414,4 +440,9 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
ModuleId moduleId,
p.studio.compiler.models.IRBackendFile irBackendFile) {
}
private record LegacyEntrypoint(
ModuleId moduleId,
String callableName) {
}
}
@@ -308,6 +308,8 @@ 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 wrapper = irBackend.getExecutableFunctions().stream()
.filter(function -> irBackend.getEntryPointCallableName().equals(function.callableName()))
.findFirst()
@@ -319,6 +321,73 @@ class PBSFrontendPhaseServiceTest {
assertEquals(p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.RET, wrapper.instructions().get(3).kind());
}
@Test
void shouldSynthesizePositiveTopic19FixtureAcrossFileInitProjectInitAndFrame() throws IOException {
final var projectRoot = tempDir.resolve("project-topic-19-positive");
final var sourceRoot = projectRoot.resolve("src");
final var modulePath = sourceRoot.resolve("game");
Files.createDirectories(modulePath);
final var globalsSource = modulePath.resolve("globals.pbs");
final var mainSource = modulePath.resolve("main.pbs");
final var modBarrel = modulePath.resolve("mod.barrel");
Files.writeString(globalsSource, """
declare global SCORE: int = 0;
[Init]
fn warmup() -> void { return; }
""");
Files.writeString(mainSource, """
[Init]
fn boot() -> void { return; }
[Frame]
fn frame() -> void { return; }
""");
Files.writeString(modBarrel, """
pub fn warmup() -> void;
pub fn boot() -> void;
pub fn frame() -> void;
pub global SCORE;
""");
final var projectTable = new ProjectTable();
final var fileTable = new FileTable(1);
final var projectId = projectTable.register(ProjectDescriptor.builder()
.rootPath(projectRoot)
.name("core")
.version("1.0.0")
.sourceRoots(ReadOnlyList.wrap(List.of(sourceRoot)))
.build());
registerFile(projectId, projectRoot, globalsSource, fileTable);
registerFile(projectId, projectRoot, mainSource, fileTable);
registerFile(projectId, projectRoot, modBarrel, fileTable);
final var ctx = new FrontendPhaseContext(
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))));
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
ctx,
diagnostics,
LogAggregator.empty(),
BuildingIssueSink.empty());
assertTrue(diagnostics.isEmpty(), diagnostics.stream().map(d -> d.getCode() + ":" + d.getMessage()).toList().toString());
assertTrue(irBackend.getEntryPointCallableName().startsWith("__pbs.frame_wrapper$m"));
assertTrue(irBackend.getExecutableFunctions().stream().anyMatch(function ->
function.callableName().startsWith("__pbs.file_init$f")));
assertTrue(irBackend.getExecutableFunctions().stream().anyMatch(function ->
function.callableName().startsWith("__pbs.module_init$m")));
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")));
}
@Test
void shouldSkipIrLoweringForSourcesMarkedAsSdkInterface() throws IOException {
final var projectRoot = tempDir.resolve("project-sdk-interface");