implements PR-O3.1

This commit is contained in:
2026-03-24 13:42:27 +00:00
parent ea27561e65
commit a38fedc591
7 changed files with 251 additions and 1 deletions
@@ -48,6 +48,8 @@ public record IRBackendExecutableFunction(
String calleeCallableName,
HostCallMetadata hostCall,
IntrinsicCallMetadata intrinsicCall,
String label,
String targetLabel,
Integer expectedArgSlots,
Integer expectedRetSlots,
Span span) {
@@ -58,7 +60,19 @@ public record IRBackendExecutableFunction(
final HostCallMetadata hostCall,
final IntrinsicCallMetadata intrinsicCall,
final Span span) {
this(kind, calleeModuleKey, calleeCallableName, hostCall, intrinsicCall, null, null, span);
this(kind, calleeModuleKey, calleeCallableName, hostCall, intrinsicCall, null, null, null, null, span);
}
public Instruction(
final InstructionKind kind,
final String calleeModuleKey,
final String calleeCallableName,
final HostCallMetadata hostCall,
final IntrinsicCallMetadata intrinsicCall,
final Integer expectedArgSlots,
final Integer expectedRetSlots,
final Span span) {
this(kind, calleeModuleKey, calleeCallableName, hostCall, intrinsicCall, null, null, expectedArgSlots, expectedRetSlots, span);
}
public Instruction {
@@ -66,6 +80,8 @@ public record IRBackendExecutableFunction(
span = span == null ? Span.none() : span;
calleeModuleKey = calleeModuleKey == null ? "" : calleeModuleKey;
calleeCallableName = calleeCallableName == null ? "" : calleeCallableName;
label = label == null ? "" : label;
targetLabel = targetLabel == null ? "" : targetLabel;
if (expectedArgSlots != null && expectedArgSlots < 0) {
throw new IllegalArgumentException("expectedArgSlots must be non-negative");
}
@@ -105,6 +121,32 @@ public record IRBackendExecutableFunction(
throw new IllegalArgumentException(kind + " must not carry expected slot metadata");
}
}
case LABEL -> {
if (label.isBlank()) {
throw new IllegalArgumentException("LABEL requires label");
}
if (!targetLabel.isBlank()
|| !calleeCallableName.isBlank()
|| hostCall != null
|| intrinsicCall != null
|| expectedArgSlots != null
|| expectedRetSlots != null) {
throw new IllegalArgumentException("LABEL must not carry call metadata");
}
}
case JMP, JMP_IF_TRUE, JMP_IF_FALSE -> {
if (targetLabel.isBlank()) {
throw new IllegalArgumentException(kind + " requires targetLabel");
}
if (!label.isBlank()
|| !calleeCallableName.isBlank()
|| hostCall != null
|| intrinsicCall != null
|| expectedArgSlots != null
|| expectedRetSlots != null) {
throw new IllegalArgumentException(kind + " must not carry call metadata");
}
}
}
}
}
@@ -115,6 +157,10 @@ public record IRBackendExecutableFunction(
CALL_FUNC,
CALL_HOST,
CALL_INTRINSIC,
LABEL,
JMP,
JMP_IF_TRUE,
JMP_IF_FALSE,
}
public record HostCallMetadata(
@@ -79,6 +79,33 @@ class IRBackendExecutableContractTest {
0));
}
@Test
void jumpAndLabelContractMustRequireNames() {
assertThrows(IllegalArgumentException.class, () -> new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.LABEL,
"",
"",
null,
null,
"",
"",
null,
null,
Span.none()));
assertThrows(IllegalArgumentException.class, () -> new IRBackendExecutableFunction.Instruction(
IRBackendExecutableFunction.InstructionKind.JMP,
"",
"",
null,
null,
"",
"",
null,
null,
Span.none()));
}
@Test
void aggregatorMustPreserveExecutableFunctionOrderDeterministically() {
final var fileA = new IRBackendFile(