implements PR-19.9 conformance fixtures diagnostics and gate closure
This commit is contained in:
+4
@@ -5,6 +5,10 @@ public enum IRVMLoweringErrorCode {
|
||||
LOWER_IRVM_ENTRYPOINT_DECLARATION_MISSING,
|
||||
LOWER_IRVM_ENTRYPOINT_MISSING,
|
||||
LOWER_IRVM_ENTRYPOINT_AMBIGUOUS,
|
||||
LOWER_IRVM_SYNTHETIC_WRAPPER_ENTRYPOINT_MISSING,
|
||||
LOWER_IRVM_PUBLISHED_ENTRYPOINT_NOT_ZERO,
|
||||
LOWER_IRVM_HIDDEN_BOOT_GUARD_MISSING,
|
||||
LOWER_IRVM_SYNTHETIC_ORIGIN_MISSING,
|
||||
LOWER_IRVM_MISSING_CALLEE,
|
||||
LOWER_IRVM_INVALID_INTRINSIC_ID,
|
||||
LOWER_IRVM_CALL_ARG_SLOTS_MISMATCH,
|
||||
|
||||
+87
@@ -4,6 +4,7 @@ import p.studio.compiler.backend.bytecode.BytecodeEmitter;
|
||||
import p.studio.compiler.backend.bytecode.BytecodeModule;
|
||||
import p.studio.compiler.models.IRBackend;
|
||||
import p.studio.compiler.models.IRBackendExecutableFunction;
|
||||
import p.studio.compiler.models.IRSyntheticCallableKind;
|
||||
import p.studio.compiler.source.Span;
|
||||
import p.studio.compiler.source.identifiers.CallableId;
|
||||
import p.studio.compiler.source.identifiers.ModuleId;
|
||||
@@ -38,6 +39,7 @@ public class LowerToIRVMService {
|
||||
"IRBackend has no executable functions");
|
||||
}
|
||||
|
||||
validatePbsLifecycleStructure(backend);
|
||||
final var ordered = orderFunctions(backend);
|
||||
final var funcIdByCallableId = new HashMap<CallableId, Integer>();
|
||||
for (var i = 0; i < ordered.size(); i++) {
|
||||
@@ -452,6 +454,14 @@ public class LowerToIRVMService {
|
||||
entryPointModuleId.getIndex()));
|
||||
}
|
||||
final var entrypoint = entrypoints.getFirst();
|
||||
final var publishedWrapper = resolvePublishedWrapper(backend);
|
||||
if (publishedWrapper != null
|
||||
&& (!entryPointCallableName.equals(publishedWrapper.callableName())
|
||||
|| !sameModuleIdentity(entryPointModuleId, publishedWrapper.moduleId()))) {
|
||||
throw new IRVMLoweringException(
|
||||
IRVMLoweringErrorCode.LOWER_IRVM_PUBLISHED_ENTRYPOINT_NOT_ZERO,
|
||||
"published entrypoint is not function index 0 because entrypoint identity does not select the published wrapper");
|
||||
}
|
||||
final var ordered = new ArrayList<IRBackendExecutableFunction>(sorted.size());
|
||||
ordered.add(entrypoint);
|
||||
for (final var fn : sorted) {
|
||||
@@ -462,6 +472,83 @@ public class LowerToIRVMService {
|
||||
return ReadOnlyList.wrap(ordered);
|
||||
}
|
||||
|
||||
private void validatePbsLifecycleStructure(final IRBackend backend) {
|
||||
if (backend.getSyntheticFunctions().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (final var syntheticFunction : backend.getSyntheticFunctions()) {
|
||||
if (syntheticFunction.origin() == null
|
||||
|| syntheticFunction.origin().fileId() == null
|
||||
|| syntheticFunction.origin().anchorCallableName().isBlank()
|
||||
|| syntheticFunction.origin().span() == null
|
||||
|| syntheticFunction.origin().span().isNone()) {
|
||||
throw new IRVMLoweringException(
|
||||
IRVMLoweringErrorCode.LOWER_IRVM_SYNTHETIC_ORIGIN_MISSING,
|
||||
"synthetic callable origin missing for " + syntheticFunction.callableName());
|
||||
}
|
||||
}
|
||||
|
||||
final var publishedWrapper = resolvePublishedWrapper(backend);
|
||||
if (publishedWrapper == null) {
|
||||
return;
|
||||
}
|
||||
final var wrapperExecutablePresent = backend.getExecutableFunctions().stream()
|
||||
.anyMatch(function -> publishedWrapper.callableName().equals(function.callableName())
|
||||
&& sameModuleIdentity(publishedWrapper.moduleId(), function.moduleId()));
|
||||
if (!wrapperExecutablePresent) {
|
||||
throw new IRVMLoweringException(
|
||||
IRVMLoweringErrorCode.LOWER_IRVM_SYNTHETIC_WRAPPER_ENTRYPOINT_MISSING,
|
||||
"synthetic wrapper entrypoint missing: " + publishedWrapper.callableName());
|
||||
}
|
||||
|
||||
final var expectedBootGuardName = bootGuardName(publishedWrapper.moduleId());
|
||||
final var bootGuardPresent = backend.getGlobals().stream()
|
||||
.anyMatch(global -> expectedBootGuardName.equals(global.name())
|
||||
&& sameModuleIdentity(publishedWrapper.moduleId(), global.moduleId()));
|
||||
if (!bootGuardPresent) {
|
||||
throw new IRVMLoweringException(
|
||||
IRVMLoweringErrorCode.LOWER_IRVM_HIDDEN_BOOT_GUARD_MISSING,
|
||||
"hidden boot guard is missing for moduleId=%d".formatted(
|
||||
publishedWrapper.moduleId() == null || publishedWrapper.moduleId().isNone()
|
||||
? -1
|
||||
: publishedWrapper.moduleId().getIndex()));
|
||||
}
|
||||
}
|
||||
|
||||
private p.studio.compiler.models.IRSyntheticFunction resolvePublishedWrapper(final IRBackend backend) {
|
||||
p.studio.compiler.models.IRSyntheticFunction publishedWrapper = null;
|
||||
for (final var syntheticFunction : backend.getSyntheticFunctions()) {
|
||||
if (syntheticFunction.kind() != IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER) {
|
||||
continue;
|
||||
}
|
||||
if (publishedWrapper != null) {
|
||||
throw new IRVMLoweringException(
|
||||
IRVMLoweringErrorCode.LOWER_IRVM_ENTRYPOINT_AMBIGUOUS,
|
||||
"multiple published frame wrappers found in executable backend");
|
||||
}
|
||||
publishedWrapper = syntheticFunction;
|
||||
}
|
||||
return publishedWrapper;
|
||||
}
|
||||
|
||||
private String bootGuardName(final ModuleId moduleId) {
|
||||
final var normalizedModuleId = moduleId == null ? ModuleId.none() : moduleId;
|
||||
return "__pbs.boot_guard$m" + (normalizedModuleId.isNone() ? -1 : normalizedModuleId.getIndex());
|
||||
}
|
||||
|
||||
private boolean sameModuleIdentity(
|
||||
final ModuleId left,
|
||||
final ModuleId right) {
|
||||
final var normalizedLeft = left == null ? ModuleId.none() : left;
|
||||
final var normalizedRight = right == null ? ModuleId.none() : right;
|
||||
if (normalizedLeft.isNone() && normalizedRight.isNone()) {
|
||||
return true;
|
||||
}
|
||||
return !normalizedLeft.isNone()
|
||||
&& !normalizedRight.isNone()
|
||||
&& normalizedLeft.getIndex() == normalizedRight.getIndex();
|
||||
}
|
||||
|
||||
private String moduleSortKey(
|
||||
final IRBackend backend,
|
||||
final ModuleId moduleId) {
|
||||
|
||||
+114
@@ -3,6 +3,10 @@ package p.studio.compiler.backend.irvm;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import p.studio.compiler.models.IRBackend;
|
||||
import p.studio.compiler.models.IRBackendExecutableFunction;
|
||||
import p.studio.compiler.models.IRGlobal;
|
||||
import p.studio.compiler.models.IRSyntheticCallableKind;
|
||||
import p.studio.compiler.models.IRSyntheticFunction;
|
||||
import p.studio.compiler.models.IRSyntheticOrigin;
|
||||
import p.studio.compiler.source.Span;
|
||||
import p.studio.compiler.source.identifiers.CallableId;
|
||||
import p.studio.compiler.source.identifiers.FileId;
|
||||
@@ -62,6 +66,17 @@ class LowerToIRVMServiceTest {
|
||||
final var backend = IRBackend.builder()
|
||||
.entryPointCallableName("__pbs.frame_wrapper$m0")
|
||||
.entryPointModuleId(new ModuleId(0))
|
||||
.globals(ReadOnlyList.from(new IRGlobal(
|
||||
new FileId(0),
|
||||
new ModuleId(0),
|
||||
"__pbs.boot_guard$m0",
|
||||
"bool",
|
||||
Span.none())))
|
||||
.syntheticFunctions(ReadOnlyList.from(new IRSyntheticFunction(
|
||||
new ModuleId(0),
|
||||
"__pbs.frame_wrapper$m0",
|
||||
IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER,
|
||||
new IRSyntheticOrigin(new FileId(0), "frame", new Span(new FileId(0), 1, 10)))))
|
||||
.executableFunctions(ReadOnlyList.from(
|
||||
fn("__pbs.file_init$f1", "app", 30, ReadOnlyList.from(ret())),
|
||||
fn("__pbs.module_init$m0", "app", 31, ReadOnlyList.from(
|
||||
@@ -95,6 +110,105 @@ class LowerToIRVMServiceTest {
|
||||
.op());
|
||||
}
|
||||
|
||||
@Test
|
||||
void lowerMustRejectWhenSyntheticWrapperEntrypointIsMissing() {
|
||||
final var backend = IRBackend.builder()
|
||||
.entryPointCallableName("__pbs.frame_wrapper$m0")
|
||||
.entryPointModuleId(new ModuleId(0))
|
||||
.globals(ReadOnlyList.from(new IRGlobal(
|
||||
new FileId(0),
|
||||
new ModuleId(0),
|
||||
"__pbs.boot_guard$m0",
|
||||
"bool",
|
||||
Span.none())))
|
||||
.syntheticFunctions(ReadOnlyList.from(new IRSyntheticFunction(
|
||||
new ModuleId(0),
|
||||
"__pbs.frame_wrapper$m0",
|
||||
IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER,
|
||||
new IRSyntheticOrigin(new FileId(0), "frame", new Span(new FileId(0), 1, 10)))))
|
||||
.executableFunctions(ReadOnlyList.from(
|
||||
fn("frame", "app", 20, ReadOnlyList.from(ret()))))
|
||||
.build();
|
||||
|
||||
final var thrown = assertThrows(IRVMLoweringException.class, () -> new LowerToIRVMService().lower(backend));
|
||||
assertEquals(IRVMLoweringErrorCode.LOWER_IRVM_SYNTHETIC_WRAPPER_ENTRYPOINT_MISSING, thrown.code());
|
||||
}
|
||||
|
||||
@Test
|
||||
void lowerMustRejectWhenPublishedWrapperWouldNotOccupyFunctionZero() {
|
||||
final var backend = IRBackend.builder()
|
||||
.entryPointCallableName("frame")
|
||||
.entryPointModuleId(new ModuleId(0))
|
||||
.globals(ReadOnlyList.from(new IRGlobal(
|
||||
new FileId(0),
|
||||
new ModuleId(0),
|
||||
"__pbs.boot_guard$m0",
|
||||
"bool",
|
||||
Span.none())))
|
||||
.syntheticFunctions(ReadOnlyList.from(new IRSyntheticFunction(
|
||||
new ModuleId(0),
|
||||
"__pbs.frame_wrapper$m0",
|
||||
IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER,
|
||||
new IRSyntheticOrigin(new FileId(0), "frame", new Span(new FileId(0), 1, 10)))))
|
||||
.executableFunctions(ReadOnlyList.from(
|
||||
fn("__pbs.frame_wrapper$m0", "app", 40, ReadOnlyList.from(
|
||||
callFunc("app", "frame", 20),
|
||||
ret())),
|
||||
fn("frame", "app", 20, ReadOnlyList.from(ret()))))
|
||||
.build();
|
||||
|
||||
final var thrown = assertThrows(IRVMLoweringException.class, () -> new LowerToIRVMService().lower(backend));
|
||||
assertEquals(IRVMLoweringErrorCode.LOWER_IRVM_PUBLISHED_ENTRYPOINT_NOT_ZERO, thrown.code());
|
||||
}
|
||||
|
||||
@Test
|
||||
void lowerMustRejectWhenHiddenBootGuardIsMissing() {
|
||||
final var backend = IRBackend.builder()
|
||||
.entryPointCallableName("__pbs.frame_wrapper$m0")
|
||||
.entryPointModuleId(new ModuleId(0))
|
||||
.syntheticFunctions(ReadOnlyList.from(new IRSyntheticFunction(
|
||||
new ModuleId(0),
|
||||
"__pbs.frame_wrapper$m0",
|
||||
IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER,
|
||||
new IRSyntheticOrigin(new FileId(0), "frame", new Span(new FileId(0), 1, 10)))))
|
||||
.executableFunctions(ReadOnlyList.from(
|
||||
fn("__pbs.frame_wrapper$m0", "app", 40, ReadOnlyList.from(
|
||||
callFunc("app", "frame", 20),
|
||||
ret())),
|
||||
fn("frame", "app", 20, ReadOnlyList.from(ret()))))
|
||||
.build();
|
||||
|
||||
final var thrown = assertThrows(IRVMLoweringException.class, () -> new LowerToIRVMService().lower(backend));
|
||||
assertEquals(IRVMLoweringErrorCode.LOWER_IRVM_HIDDEN_BOOT_GUARD_MISSING, thrown.code());
|
||||
}
|
||||
|
||||
@Test
|
||||
void lowerMustRejectWhenSyntheticCallableOriginIsMissing() {
|
||||
final var backend = IRBackend.builder()
|
||||
.entryPointCallableName("__pbs.frame_wrapper$m0")
|
||||
.entryPointModuleId(new ModuleId(0))
|
||||
.globals(ReadOnlyList.from(new IRGlobal(
|
||||
new FileId(0),
|
||||
new ModuleId(0),
|
||||
"__pbs.boot_guard$m0",
|
||||
"bool",
|
||||
Span.none())))
|
||||
.syntheticFunctions(ReadOnlyList.from(new IRSyntheticFunction(
|
||||
new ModuleId(0),
|
||||
"__pbs.frame_wrapper$m0",
|
||||
IRSyntheticCallableKind.PUBLISHED_FRAME_WRAPPER,
|
||||
new IRSyntheticOrigin(new FileId(0), "", Span.none()))))
|
||||
.executableFunctions(ReadOnlyList.from(
|
||||
fn("__pbs.frame_wrapper$m0", "app", 40, ReadOnlyList.from(
|
||||
callFunc("app", "frame", 20),
|
||||
ret())),
|
||||
fn("frame", "app", 20, ReadOnlyList.from(ret()))))
|
||||
.build();
|
||||
|
||||
final var thrown = assertThrows(IRVMLoweringException.class, () -> new LowerToIRVMService().lower(backend));
|
||||
assertEquals(IRVMLoweringErrorCode.LOWER_IRVM_SYNTHETIC_ORIGIN_MISSING, thrown.code());
|
||||
}
|
||||
|
||||
@Test
|
||||
void lowerMustMapHostAndIntrinsicCallsites() {
|
||||
final var backend = IRBackend.builder()
|
||||
|
||||
+3
-3
@@ -13,9 +13,9 @@ import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
class BackendClaimScopeSpecTest {
|
||||
private static final String LOWERING_SPEC_RELATIVE_PATH =
|
||||
"docs/compiler/general/specs/20. IRBackend to IRVM Lowering Specification.md";
|
||||
"docs/specs/compiler/20. IRBackend to IRVM Lowering Specification.md";
|
||||
private static final String MATRIX_RELATIVE_PATH =
|
||||
"docs/compiler/general/specs/22. Backend Spec-to-Test Conformance Matrix.md";
|
||||
"docs/specs/compiler/22. Backend Spec-to-Test Conformance Matrix.md";
|
||||
private static final String DECISION_RELATIVE_PATH =
|
||||
"docs/compiler/pbs/decisions/SPAWN-YIELD v1 Claim Rescope Decision.md";
|
||||
|
||||
@@ -63,7 +63,7 @@ class BackendClaimScopeSpecTest {
|
||||
private Path locateRepoRoot() {
|
||||
var cursor = Path.of(System.getProperty("user.dir")).toAbsolutePath().normalize();
|
||||
while (cursor != null) {
|
||||
final var hasDocs = Files.isDirectory(cursor.resolve("docs/compiler/general/specs"));
|
||||
final var hasDocs = Files.isDirectory(cursor.resolve("docs/specs/compiler"));
|
||||
final var hasCompiler = Files.isDirectory(cursor.resolve("prometeu-compiler"));
|
||||
if (hasDocs && hasCompiler) {
|
||||
return cursor;
|
||||
|
||||
+3
-2
@@ -14,7 +14,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class BackendConformanceMatrixSpecTest {
|
||||
private static final String MATRIX_RELATIVE_PATH =
|
||||
"docs/compiler/general/specs/22. Backend Spec-to-Test Conformance Matrix.md";
|
||||
"docs/specs/compiler/22. Backend Spec-to-Test Conformance Matrix.md";
|
||||
private static final String MATRIX_HARD_GATE_ENV = "PROMETEU_MATRIX_HARD_GATE";
|
||||
private static final String CHANGED_FILES_ENV = "PROMETEU_CHANGED_FILES";
|
||||
private static final List<String> HARD_GATE_PATH_PREFIXES = List.of(
|
||||
@@ -158,8 +158,9 @@ class BackendConformanceMatrixSpecTest {
|
||||
var cursor = Path.of(System.getProperty("user.dir")).toAbsolutePath().normalize();
|
||||
while (cursor != null) {
|
||||
final var hasDocs = Files.isDirectory(cursor.resolve("docs/compiler/general/specs"));
|
||||
final var hasCurrentDocs = Files.isDirectory(cursor.resolve("docs/specs/compiler"));
|
||||
final var hasCompiler = Files.isDirectory(cursor.resolve("prometeu-compiler"));
|
||||
if (hasDocs && hasCompiler) {
|
||||
if ((hasDocs || hasCurrentDocs) && hasCompiler) {
|
||||
return cursor;
|
||||
}
|
||||
cursor = cursor.getParent();
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ class NoModuleKeyRegressionSpecTest {
|
||||
private Path locateRepoRoot() {
|
||||
var cursor = Path.of(System.getProperty("user.dir")).toAbsolutePath().normalize();
|
||||
while (cursor != null) {
|
||||
final var hasDocs = Files.isDirectory(cursor.resolve("docs/compiler/general/specs"));
|
||||
final var hasDocs = Files.isDirectory(cursor.resolve("docs/specs/compiler"));
|
||||
final var hasCompiler = Files.isDirectory(cursor.resolve("prometeu-compiler"));
|
||||
if (hasDocs && hasCompiler) {
|
||||
return cursor;
|
||||
|
||||
Reference in New Issue
Block a user