implements PR-09.3: enforce qualified entrypoint and moduleId-only ordering in LowerToIRVM

This commit is contained in:
2026-03-24 13:42:33 +00:00
parent 5c69a02973
commit 8876a8fa35
7 changed files with 48 additions and 30 deletions
@@ -297,6 +297,11 @@ public class LowerToIRVMService {
"frontend IRBackend entrypoint declaration is missing");
}
final var entryPointModuleId = backend.getEntryPointModuleId();
if (entryPointModuleId == null || entryPointModuleId.isNone()) {
throw new IRVMLoweringException(
IRVMLoweringErrorCode.LOWER_IRVM_ENTRYPOINT_DECLARATION_MISSING,
"frontend IRBackend qualified entrypoint declaration is missing entryPointModuleId");
}
final var sorted = new ArrayList<>(backend.getExecutableFunctions().asList());
sorted.sort((left, right) -> {
final var leftModuleKey = moduleSortKey(backend, left.moduleId());
@@ -315,44 +320,25 @@ public class LowerToIRVMService {
}
return Integer.compare(left.sourceStart(), right.sourceStart());
});
final java.util.List<IRBackendExecutableFunction> entrypoints;
if (entryPointModuleId != null && !entryPointModuleId.isNone()) {
final var expectedModuleIndex = entryPointModuleId.getIndex();
entrypoints = sorted.stream()
.filter(candidate -> entryPointCallableName.equals(candidate.callableName()))
.filter(candidate -> !candidate.moduleId().isNone() && candidate.moduleId().getIndex() == expectedModuleIndex)
.toList();
} else {
entrypoints = sorted.stream()
.filter(candidate -> entryPointCallableName.equals(candidate.callableName()))
.toList();
}
final var expectedModuleIndex = entryPointModuleId.getIndex();
final var entrypoints = sorted.stream()
.filter(candidate -> entryPointCallableName.equals(candidate.callableName()))
.filter(candidate -> !candidate.moduleId().isNone() && candidate.moduleId().getIndex() == expectedModuleIndex)
.toList();
if (entrypoints.isEmpty()) {
if (entryPointModuleId != null && !entryPointModuleId.isNone()) {
throw new IRVMLoweringException(
IRVMLoweringErrorCode.LOWER_IRVM_ENTRYPOINT_MISSING,
"missing qualified entrypoint callable '%s' for moduleId=%d".formatted(
entryPointCallableName,
entryPointModuleId.getIndex()));
}
throw new IRVMLoweringException(
IRVMLoweringErrorCode.LOWER_IRVM_ENTRYPOINT_MISSING,
"missing entrypoint callable '%s'".formatted(entryPointCallableName));
"missing qualified entrypoint callable '%s' for moduleId=%d".formatted(
entryPointCallableName,
entryPointModuleId.getIndex()));
}
if (entrypoints.size() > 1) {
if (entryPointModuleId != null && !entryPointModuleId.isNone()) {
throw new IRVMLoweringException(
IRVMLoweringErrorCode.LOWER_IRVM_ENTRYPOINT_AMBIGUOUS,
"ambiguous qualified entrypoint: found %d callables named '%s' in moduleId=%d".formatted(
entrypoints.size(),
entryPointCallableName,
entryPointModuleId.getIndex()));
}
throw new IRVMLoweringException(
IRVMLoweringErrorCode.LOWER_IRVM_ENTRYPOINT_AMBIGUOUS,
"ambiguous entrypoint: found %d callables named '%s'".formatted(
"ambiguous qualified entrypoint: found %d callables named '%s' in moduleId=%d".formatted(
entrypoints.size(),
entryPointCallableName));
entryPointCallableName,
entryPointModuleId.getIndex()));
}
final var entrypoint = entrypoints.getFirst();
final var ordered = new ArrayList<IRBackendExecutableFunction>(sorted.size());