hardens IRGlobal structural metadata for PBS lifecycle lowering
This commit is contained in:
+3
-7
@@ -5,6 +5,7 @@ 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.models.IRHiddenGlobalKind;
|
||||
import p.studio.compiler.source.Span;
|
||||
import p.studio.compiler.source.identifiers.CallableId;
|
||||
import p.studio.compiler.source.identifiers.ModuleId;
|
||||
@@ -501,9 +502,9 @@ public class LowerToIRVMService {
|
||||
"synthetic wrapper entrypoint missing: " + publishedWrapper.callableName());
|
||||
}
|
||||
|
||||
final var expectedBootGuardName = bootGuardName(publishedWrapper.moduleId());
|
||||
final var bootGuardPresent = backend.getGlobals().stream()
|
||||
.anyMatch(global -> expectedBootGuardName.equals(global.name())
|
||||
.anyMatch(global -> global.hiddenKind() == IRHiddenGlobalKind.BOOT_GUARD
|
||||
&& global.isHidden()
|
||||
&& sameModuleIdentity(publishedWrapper.moduleId(), global.moduleId()));
|
||||
if (!bootGuardPresent) {
|
||||
throw new IRVMLoweringException(
|
||||
@@ -531,11 +532,6 @@ public class LowerToIRVMService {
|
||||
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) {
|
||||
|
||||
+39
-24
@@ -4,6 +4,9 @@ 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.IRGlobalOrigin;
|
||||
import p.studio.compiler.models.IRGlobalVisibility;
|
||||
import p.studio.compiler.models.IRHiddenGlobalKind;
|
||||
import p.studio.compiler.models.IRSyntheticCallableKind;
|
||||
import p.studio.compiler.models.IRSyntheticFunction;
|
||||
import p.studio.compiler.models.IRSyntheticOrigin;
|
||||
@@ -66,12 +69,7 @@ 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())))
|
||||
.globals(ReadOnlyList.from(hiddenBootGuard(0)))
|
||||
.syntheticFunctions(ReadOnlyList.from(new IRSyntheticFunction(
|
||||
new ModuleId(0),
|
||||
"__pbs.frame_wrapper$m0",
|
||||
@@ -115,12 +113,7 @@ 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())))
|
||||
.globals(ReadOnlyList.from(hiddenBootGuard(0)))
|
||||
.syntheticFunctions(ReadOnlyList.from(new IRSyntheticFunction(
|
||||
new ModuleId(0),
|
||||
"__pbs.frame_wrapper$m0",
|
||||
@@ -139,12 +132,7 @@ class LowerToIRVMServiceTest {
|
||||
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())))
|
||||
.globals(ReadOnlyList.from(hiddenBootGuard(0)))
|
||||
.syntheticFunctions(ReadOnlyList.from(new IRSyntheticFunction(
|
||||
new ModuleId(0),
|
||||
"__pbs.frame_wrapper$m0",
|
||||
@@ -187,12 +175,7 @@ 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())))
|
||||
.globals(ReadOnlyList.from(userVisibleGlobal("__pbs.boot_guard$m0", 0)))
|
||||
.syntheticFunctions(ReadOnlyList.from(new IRSyntheticFunction(
|
||||
new ModuleId(0),
|
||||
"__pbs.frame_wrapper$m0",
|
||||
@@ -419,6 +402,38 @@ class LowerToIRVMServiceTest {
|
||||
assertTrue(thrown.getMessage().contains("qualified entrypoint"));
|
||||
}
|
||||
|
||||
private static IRGlobal hiddenBootGuard(final int moduleId) {
|
||||
final var fileId = new FileId(0);
|
||||
final var ownerModuleId = new ModuleId(moduleId);
|
||||
return new IRGlobal(
|
||||
fileId,
|
||||
ownerModuleId,
|
||||
"__pbs.boot_guard$m" + moduleId,
|
||||
"bool",
|
||||
0,
|
||||
IRGlobalVisibility.MODULE,
|
||||
true,
|
||||
IRHiddenGlobalKind.BOOT_GUARD,
|
||||
new IRGlobalOrigin(fileId, ownerModuleId, "frame", Span.none(), "BOOT_GUARD"),
|
||||
Span.none());
|
||||
}
|
||||
|
||||
private static IRGlobal userVisibleGlobal(final String name, final int moduleId) {
|
||||
final var fileId = new FileId(0);
|
||||
final var ownerModuleId = new ModuleId(moduleId);
|
||||
return new IRGlobal(
|
||||
fileId,
|
||||
ownerModuleId,
|
||||
name,
|
||||
"bool",
|
||||
0,
|
||||
IRGlobalVisibility.MODULE,
|
||||
false,
|
||||
IRHiddenGlobalKind.NONE,
|
||||
new IRGlobalOrigin(fileId, ownerModuleId, name, Span.none(), name),
|
||||
Span.none());
|
||||
}
|
||||
|
||||
private static IRBackendExecutableFunction fn(
|
||||
final String name,
|
||||
final String moduleKey,
|
||||
|
||||
Reference in New Issue
Block a user