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) {
|
||||
|
||||
Reference in New Issue
Block a user