implements PLN-0128
Intrepid/Prometeu/Studio/pipeline/pr-master Build started...
JaCoCo Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 62.10% (17811/28682) * Branch Coverage: 52.81% (6878/13025) * Lines of Code: 28682 * Cyclomatic Complexity: 11494 #### Quality Gates Summary Output truncated.
Test / Build skipped: 15, passed: 653
Intrepid/Prometeu/Studio/pipeline/head This commit looks good

Add a test-only synth FrontendProvider that traverses compile() to
verified bytecode without PBS. Expose register/unregister on the static
registry and lock the obligation in specs 23 and 22.

Housekeep DSC-0063 with LSN-0065.
This commit is contained in:
2026-09-19 03:03:37 +01:00
parent d0b91f8526
commit 79a682b8ec
11 changed files with 473 additions and 81 deletions
@@ -0,0 +1,99 @@
package p.studio.compiler.integration;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import p.studio.compiler.FrontendRegistryService;
import p.studio.compiler.messages.BuilderPipelineConfig;
import p.studio.compiler.models.BuilderPipelineContext;
import p.studio.compiler.models.IRBackendReader;
import p.studio.compiler.models.IRHiddenGlobalKind;
import p.studio.compiler.synth.SyntheticFrontendProvider;
import p.studio.compiler.workspaces.BuilderPipelineService;
import p.studio.utilities.logs.LogAggregator;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
class SyntheticFrontendPipelineTest {
@TempDir
Path projectRoot;
@Test
void compileMustEmitVerifiedBytecodeWithoutPbs() throws IOException {
writeSyntheticProject();
final var provider = new SyntheticFrontendProvider();
FrontendRegistryService.register(provider);
try {
final var context = BuilderPipelineContext.fromConfig(
new BuilderPipelineConfig(false, projectRoot.toString()));
final var result = BuilderPipelineService.INSTANCE.compile(context, LogAggregator.empty());
assertTrue(provider.syntheticCompiler().invoked(), "synthetic compiler must be the effective frontend");
assertEquals(
SyntheticFrontendProvider.LANGUAGE_ID,
result.analysisSnapshot().frontendSpec().getLanguageId());
assertFalse("pbs".equals(result.analysisSnapshot().frontendSpec().getLanguageId()));
assertTrue(provider.languageService().isEmpty());
assertTrue(
result.diagnostics().stream().noneMatch(issue -> issue.isError()),
result.diagnostics().toString());
assertNotNull(result.bytecodeModule());
assertNotNull(result.bytecodeBytes());
assertTrue(result.bytecodeBytes().length > 0);
final var backend = result.analysisSnapshot().irBackend();
assertEquals("__prometeu.lifecycle.frame_wrapper$m0", backend.getEntryPointCallableName());
assertTrue(backend.getGlobals().stream().anyMatch(global ->
global.hiddenKind() == IRHiddenGlobalKind.BOOT_GUARD
&& "__prometeu.lifecycle.boot_guard$m0".equals(global.name())));
assertNoPbsNames(backend);
assertTrue(noPbsSources(projectRoot));
} finally {
FrontendRegistryService.unregister(SyntheticFrontendProvider.LANGUAGE_ID);
assertEquals(1, FrontendRegistryService.listProviders().size());
assertEquals(
"pbs",
FrontendRegistryService.listProviders().getFirst().specification().getLanguageId());
}
}
private void writeSyntheticProject() throws IOException {
Files.writeString(projectRoot.resolve("prometeu.json"), """
{
"name": "synth-fixture",
"version": "1.0.0",
"language": "synth",
"stdlib": "1",
"target": "Game",
"dependencies": []
}
""");
Files.createDirectory(projectRoot.resolve("src"));
}
private void assertNoPbsNames(final IRBackendReader backend) {
assertFalse(backend.getEntryPointCallableName().contains("__pbs."));
assertTrue(backend.getExecutableFunctions().stream()
.noneMatch(function -> function.callableName().contains("__pbs.")));
assertTrue(backend.getSyntheticFunctions().stream()
.noneMatch(function -> function.callableName().contains("__pbs.")));
assertTrue(backend.getGlobals().stream()
.noneMatch(global -> global.name().contains("__pbs.")));
}
private boolean noPbsSources(final Path root) throws IOException {
try (final var files = Files.walk(root)) {
return files
.filter(Files::isRegularFile)
.map(path -> path.getFileName().toString())
.noneMatch(name -> name.endsWith(".pbs") || name.endsWith(".barrel"));
}
}
}
@@ -95,7 +95,8 @@ class BackendConformanceMatrixSpecTest {
"PBS13-12.7",
"PBS13-12.8",
"PBS13-12.9",
"G23-5.2");
"G23-5.2",
"G23-8.3");
@Test
void matrixMustExistAndContainRequiredRequirementRows() throws IOException {
@@ -0,0 +1,81 @@
package p.studio.compiler.synth;
import p.studio.compiler.messages.BuildingIssueSink;
import p.studio.compiler.messages.FrontendPhaseContext;
import p.studio.compiler.models.IRBackend;
import p.studio.compiler.models.IRBackendExecutableFunction;
import p.studio.compiler.models.IRLifecycleCallableReference;
import p.studio.compiler.models.IRLifecycleCallableRole;
import p.studio.compiler.models.IRLifecycleDeclaration;
import p.studio.compiler.models.IRLifecycleModuleDeclaration;
import p.studio.compiler.services.FrontendPhaseService;
import p.studio.compiler.source.Span;
import p.studio.compiler.source.diagnostics.DiagnosticSink;
import p.studio.compiler.source.identifiers.CallableId;
import p.studio.compiler.source.identifiers.FileId;
import p.studio.compiler.source.identifiers.ModuleId;
import p.studio.compiler.source.tables.CallableSignatureRef;
import p.studio.compiler.source.tables.ModuleReference;
import p.studio.utilities.logs.LogAggregator;
import p.studio.utilities.structures.ReadOnlyList;
import java.util.concurrent.atomic.AtomicBoolean;
public final class SyntheticFrontendPhaseService implements FrontendPhaseService {
private final AtomicBoolean invoked = new AtomicBoolean();
public boolean invoked() {
return invoked.get();
}
@Override
public IRBackend compile(
final FrontendPhaseContext request,
final DiagnosticSink diagnostics,
final LogAggregator logs,
final BuildingIssueSink issues) {
invoked.set(true);
final var moduleId = new ModuleId(0);
final var fileId = new FileId(0);
final var callableId = new CallableId(0);
final var span = new Span(fileId, 0, 1);
final var frame = new IRBackendExecutableFunction(
fileId,
moduleId,
"frame",
callableId,
0,
1,
0,
0,
0,
1,
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.RET,
"",
null,
null,
span)),
span);
final var frameRoot = new IRLifecycleCallableReference(
moduleId,
fileId,
callableId,
IRLifecycleCallableRole.FRAME_ROOT,
span);
return IRBackend.builder()
.entryPointCallableName("frame")
.entryPointModuleId(moduleId)
.modulePool(ReadOnlyList.from(new ModuleReference("synth", ReadOnlyList.from("main"))))
.callableSignatures(ReadOnlyList.from(
new CallableSignatureRef(moduleId, "frame", 0, "() -> unit")))
.executableFunctions(ReadOnlyList.from(frame))
.lifecycleDeclaration(new IRLifecycleDeclaration(
ReadOnlyList.from(new IRLifecycleModuleDeclaration(moduleId, ReadOnlyList.empty())),
null,
frameRoot))
.build();
}
}
@@ -0,0 +1,31 @@
package p.studio.compiler.synth;
import p.studio.compiler.models.FrontendSpec;
import p.studio.compiler.services.FrontendPhaseService;
import p.studio.compiler.services.FrontendProvider;
import p.studio.utilities.structures.ReadOnlySet;
public final class SyntheticFrontendProvider implements FrontendProvider {
public static final String LANGUAGE_ID = "synth";
private final FrontendSpec specification = FrontendSpec.builder()
.languageId(LANGUAGE_ID)
.allowedExtensions(ReadOnlySet.from("synth"))
.sourceRoots(ReadOnlySet.from("src"))
.build();
private final SyntheticFrontendPhaseService compiler = new SyntheticFrontendPhaseService();
@Override
public FrontendSpec specification() {
return specification;
}
@Override
public FrontendPhaseService compiler() {
return compiler;
}
public SyntheticFrontendPhaseService syntheticCompiler() {
return compiler;
}
}
@@ -62,7 +62,7 @@ public class FrontendRegistryService {
.toList();
}
static void register(final FrontendProvider provider) {
public static void register(final FrontendProvider provider) {
final var languageId = provider.specification().getLanguageId();
if (FRONTEND_PROVIDERS.containsKey(languageId)) {
throw new IllegalArgumentException("Duplicate frontend languageId: " + languageId);
@@ -71,6 +71,16 @@ public class FrontendRegistryService {
FRONTEND_PROVIDERS.put(languageId, provider);
}
public static void unregister(final String languageId) {
if (languageId == null || languageId.isBlank()) {
return;
}
if (PBSDefinitions.PBS.getLanguageId().equals(languageId)) {
throw new IllegalArgumentException("Cannot unregister the default PBS frontend: " + languageId);
}
FRONTEND_PROVIDERS.remove(languageId);
}
private static void registerIfAbsent(final FrontendProvider provider) {
FRONTEND_PROVIDERS.putIfAbsent(provider.specification().getLanguageId(), provider);
}
@@ -1,6 +1,15 @@
package p.studio.compiler;
import org.junit.jupiter.api.Test;
import p.studio.compiler.messages.BuildingIssueSink;
import p.studio.compiler.messages.FrontendPhaseContext;
import p.studio.compiler.models.FrontendSpec;
import p.studio.compiler.models.IRBackend;
import p.studio.compiler.services.FrontendPhaseService;
import p.studio.compiler.services.FrontendProvider;
import p.studio.compiler.source.diagnostics.DiagnosticSink;
import p.studio.utilities.logs.LogAggregator;
import p.studio.utilities.structures.ReadOnlySet;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
@@ -41,4 +50,89 @@ class FrontendRegistryServiceTest {
assertEquals(1, providers.size());
assertEquals(PBSDefinitions.PBS.getLanguageId(), providers.getFirst().specification().getLanguageId());
}
@Test
void registerShouldResolveAndUnregisterTemporaryProvider() {
final var provider = new TemporaryFrontendProvider("registry-temp");
FrontendRegistryService.register(provider);
try {
assertSame(provider, FrontendRegistryService.require("registry-temp"));
assertEquals(2, FrontendRegistryService.listProviders().size());
} finally {
FrontendRegistryService.unregister("registry-temp");
}
assertEquals(1, FrontendRegistryService.listProviders().size());
assertEquals(PBSDefinitions.PBS.getLanguageId(),
FrontendRegistryService.listProviders().getFirst().specification().getLanguageId());
}
@Test
void registerShouldRejectDuplicateLanguageId() {
final var provider = new TemporaryFrontendProvider("registry-dup");
FrontendRegistryService.register(provider);
try {
final var thrown = assertThrows(
IllegalArgumentException.class,
() -> FrontendRegistryService.register(new TemporaryFrontendProvider("registry-dup")));
assertTrue(thrown.getMessage().contains("registry-dup"));
} finally {
FrontendRegistryService.unregister("registry-dup");
}
}
@Test
void unregisterMustRefuseToRemoveDefaultPbs() {
final var thrown = assertThrows(
IllegalArgumentException.class,
() -> FrontendRegistryService.unregister(PBSDefinitions.PBS.getLanguageId()));
assertTrue(thrown.getMessage().contains(PBSDefinitions.PBS.getLanguageId()));
assertEquals(1, FrontendRegistryService.listProviders().size());
assertSame(
PBSDefinitions.PBS,
FrontendRegistryService.require(PBSDefinitions.PBS.getLanguageId()).specification());
}
@Test
void unregisterUnknownLanguageIdMustBeNoOp() {
FrontendRegistryService.unregister(null);
FrontendRegistryService.unregister(" ");
FrontendRegistryService.unregister("unknown-language");
assertEquals(1, FrontendRegistryService.listProviders().size());
assertEquals(PBSDefinitions.PBS.getLanguageId(),
FrontendRegistryService.listProviders().getFirst().specification().getLanguageId());
}
private static final class TemporaryFrontendProvider implements FrontendProvider {
private final FrontendSpec specification;
private TemporaryFrontendProvider(final String languageId) {
this.specification = FrontendSpec.builder()
.languageId(languageId)
.allowedExtensions(ReadOnlySet.from("tmp"))
.sourceRoots(ReadOnlySet.from("src"))
.build();
}
@Override
public FrontendSpec specification() {
return specification;
}
@Override
public FrontendPhaseService compiler() {
return new FrontendPhaseService() {
@Override
public IRBackend compile(
final FrontendPhaseContext request,
final DiagnosticSink diagnostics,
final LogAggregator logs,
final BuildingIssueSink issues) {
return IRBackend.builder().build();
}
};
}
}
}