implements PR-O4.5

This commit is contained in:
2026-03-24 13:42:28 +00:00
parent 0073469555
commit 5abadc62fa
7 changed files with 97 additions and 7 deletions
@@ -35,10 +35,18 @@ public final class IRVMProfileFeatureGate {
this.allowedByProfile = allowedByProfile == null ? Map.of() : Map.copyOf(allowedByProfile);
}
public String normalizeProfile(final String profile) {
return profile == null || profile.isBlank() ? "core-v1" : profile;
}
public boolean isSupportedProfile(final String profile) {
return allowedByProfile.containsKey(normalizeProfile(profile));
}
public boolean isAllowed(
final String profile,
final IRVMOp op) {
final var allowed = allowedByProfile.get(profile == null || profile.isBlank() ? "core-v1" : profile);
final var allowed = allowedByProfile.get(normalizeProfile(profile));
return allowed != null && allowed.contains(op);
}
}
@@ -29,6 +29,12 @@ public class LowerToIRVMService {
}
public IRVMProgram lower(final IRBackend backend) {
return lower(backend, "core-v1");
}
public IRVMProgram lower(
final IRBackend backend,
final String vmProfile) {
if (backend == null || backend.getExecutableFunctions().isEmpty()) {
throw new IRVMLoweringException(
IRVMLoweringErrorCode.LOWER_IRVM_EMPTY_EXECUTABLE_INPUT,
@@ -194,7 +200,7 @@ public class LowerToIRVMService {
ReadOnlyList.wrap(operations)));
}
final var module = new IRVMModule("core-v1", ReadOnlyList.wrap(loweredFunctions));
final var module = new IRVMModule(vmProfile, ReadOnlyList.wrap(loweredFunctions));
validator.validate(module, false);
return new IRVMProgram(
module,
@@ -5,26 +5,35 @@ import java.util.Objects;
public class OptimizeIRVMService {
private final IRVMValidator validator;
private final IRVMProfileFeatureGate profileFeatureGate;
private final List<IRVMPass> passes;
public OptimizeIRVMService() {
this(new IRVMValidator(), List.of(new NoOpPass()));
this(new IRVMValidator(), new IRVMProfileFeatureGate(), List.of(new NoOpPass()));
}
OptimizeIRVMService(final IRVMValidator validator) {
this(validator, List.of(new NoOpPass()));
this(validator, new IRVMProfileFeatureGate(), List.of(new NoOpPass()));
}
OptimizeIRVMService(
final IRVMValidator validator,
final List<IRVMPass> passes) {
this(validator, new IRVMProfileFeatureGate(), passes);
}
OptimizeIRVMService(
final IRVMValidator validator,
final IRVMProfileFeatureGate profileFeatureGate,
final List<IRVMPass> passes) {
this.validator = validator;
this.profileFeatureGate = profileFeatureGate;
this.passes = passes == null ? List.of(new NoOpPass()) : List.copyOf(passes);
}
public IRVMProgram optimize(final IRVMProgram input) {
final var program = input == null ? IRVMProgram.empty() : input;
if (!"core-v1".equals(program.module().vmProfile())) {
if (!profileFeatureGate.isSupportedProfile(program.module().vmProfile())) {
throw new IllegalArgumentException("unsupported vm profile: " + program.module().vmProfile());
}
var current = program;
@@ -2,4 +2,16 @@ package p.studio.compiler.messages;
public record BuilderPipelineConfig(
boolean explain,
String rootProjectPath) {}
String rootProjectPath,
String vmProfile) {
public BuilderPipelineConfig(
final boolean explain,
final String rootProjectPath) {
this(explain, rootProjectPath, "core-v1");
}
public BuilderPipelineConfig {
vmProfile = vmProfile == null || vmProfile.isBlank() ? "core-v1" : vmProfile;
}
}
@@ -32,7 +32,7 @@ public class LowerToIRVMPipelineStage implements PipelineStage {
.message("[BUILD]: IRBackend is missing before LowerToIRVM stage"));
}
try {
ctx.irvm = lowerToIRVMService.lower(ctx.irBackend);
ctx.irvm = lowerToIRVMService.lower(ctx.irBackend, ctx.config.vmProfile());
} catch (IRVMLoweringException e) {
return BuildingIssueSink.empty()
.report(builder -> builder