hardens IRGlobal structural metadata for PBS lifecycle lowering
This commit is contained in:
+13
@@ -5,6 +5,8 @@ import p.studio.compiler.models.IRBackendExecutableFunction;
|
||||
import p.studio.compiler.models.IRBackendFile;
|
||||
import p.studio.compiler.models.IRFunction;
|
||||
import p.studio.compiler.models.IRGlobal;
|
||||
import p.studio.compiler.models.IRGlobalOrigin;
|
||||
import p.studio.compiler.models.IRGlobalVisibility;
|
||||
import p.studio.compiler.models.IRReservedMetadata;
|
||||
import p.studio.compiler.models.IRSyntheticCallableKind;
|
||||
import p.studio.compiler.models.IRSyntheticFunction;
|
||||
@@ -243,6 +245,7 @@ public final class PbsFrontendCompiler {
|
||||
final ModuleId moduleId,
|
||||
final PbsAst.File ast) {
|
||||
final var globals = new ArrayList<IRGlobal>();
|
||||
var nextSlot = 0;
|
||||
for (final var topDecl : ast.topDecls()) {
|
||||
if (!(topDecl instanceof PbsAst.GlobalDecl globalDecl)) {
|
||||
continue;
|
||||
@@ -252,6 +255,16 @@ public final class PbsFrontendCompiler {
|
||||
moduleId,
|
||||
globalDecl.name(),
|
||||
PbsReservedMetadataExtractor.typeSurfaceKey(globalDecl.explicitType()),
|
||||
nextSlot++,
|
||||
IRGlobalVisibility.MODULE,
|
||||
false,
|
||||
p.studio.compiler.models.IRHiddenGlobalKind.NONE,
|
||||
new IRGlobalOrigin(
|
||||
fileId,
|
||||
moduleId,
|
||||
globalDecl.name(),
|
||||
globalDecl.span(),
|
||||
globalDecl.name()),
|
||||
globalDecl.span()));
|
||||
}
|
||||
return ReadOnlyList.wrap(globals);
|
||||
|
||||
+41
-3
@@ -5,6 +5,10 @@ import p.studio.compiler.messages.BuildingIssueSink;
|
||||
import p.studio.compiler.messages.FrontendPhaseContext;
|
||||
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.pbs.PbsFrontendCompiler;
|
||||
import p.studio.compiler.pbs.PbsReservedMetadataExtractor;
|
||||
@@ -285,22 +289,34 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
||||
|
||||
if (globals.stream().noneMatch(global ->
|
||||
moduleIdsMatch(entryPointModuleId, global.moduleId())
|
||||
&& PbsFrontendCompiler.bootGuardGlobalName(entryPointModuleId).equals(global.name()))) {
|
||||
globals.add(new p.studio.compiler.models.IRGlobal(
|
||||
&& global.hiddenKind() == IRHiddenGlobalKind.BOOT_GUARD)) {
|
||||
globals.add(new IRGlobal(
|
||||
frameExecutable.fileId(),
|
||||
entryPointModuleId,
|
||||
PbsFrontendCompiler.bootGuardGlobalName(entryPointModuleId),
|
||||
"bool",
|
||||
0,
|
||||
IRGlobalVisibility.MODULE,
|
||||
true,
|
||||
IRHiddenGlobalKind.BOOT_GUARD,
|
||||
new IRGlobalOrigin(
|
||||
frameExecutable.fileId(),
|
||||
entryPointModuleId,
|
||||
frameAnchorsByModule.getOrDefault(entryPointModuleId, frameExecutable.callableName()),
|
||||
frameExecutable.span(),
|
||||
"BOOT_GUARD"),
|
||||
frameExecutable.span()));
|
||||
}
|
||||
}
|
||||
|
||||
final var normalizedGlobals = normalizeGlobalSlots(globals);
|
||||
|
||||
return IRBackend.builder()
|
||||
.entryPointCallableName(entryPointCallableName)
|
||||
.entryPointModuleId(entryPointModuleId)
|
||||
.functions(baseBackend.getFunctions())
|
||||
.syntheticFunctions(baseBackend.getSyntheticFunctions())
|
||||
.globals(ReadOnlyList.wrap(globals))
|
||||
.globals(ReadOnlyList.wrap(normalizedGlobals))
|
||||
.executableFunctions(ReadOnlyList.wrap(executableFunctions))
|
||||
.modulePool(baseBackend.getModulePool())
|
||||
.callableSignatures(ReadOnlyList.wrap(callableSignatures))
|
||||
@@ -309,6 +325,28 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
||||
.build();
|
||||
}
|
||||
|
||||
private ArrayList<IRGlobal> normalizeGlobalSlots(final ArrayList<IRGlobal> globals) {
|
||||
final var nextSlotByModule = new LinkedHashMap<ModuleId, Integer>();
|
||||
final var normalized = new ArrayList<IRGlobal>(globals.size());
|
||||
for (final var global : globals) {
|
||||
final var moduleId = normalizeModuleId(global.moduleId());
|
||||
final var slot = nextSlotByModule.getOrDefault(moduleId, 0);
|
||||
nextSlotByModule.put(moduleId, slot + 1);
|
||||
normalized.add(new IRGlobal(
|
||||
global.fileId(),
|
||||
moduleId,
|
||||
global.name(),
|
||||
global.declaredTypeSurface(),
|
||||
slot,
|
||||
global.visibility(),
|
||||
global.isHidden(),
|
||||
global.hiddenKind(),
|
||||
global.origin(),
|
||||
global.span()));
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
private IRBackendExecutableFunction resolveExecutable(
|
||||
final ArrayList<IRBackendExecutableFunction> executableFunctions,
|
||||
final ModuleId moduleId,
|
||||
|
||||
Reference in New Issue
Block a user