implements PLN-0125
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
JaCoCo Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 61.95% (17766/28676)
* Branch Coverage: 52.69% (6860/13019)
* Lines of Code: 28676
* Cyclomatic Complexity: 11490
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 15, passed: 643
Intrepid/Prometeu/Studio/pipeline/pr-master This commit looks good
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
JaCoCo Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 61.95% (17766/28676)
* Branch Coverage: 52.69% (6860/13019)
* Lines of Code: 28676
* Cyclomatic Complexity: 11490
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 15, passed: 643
Intrepid/Prometeu/Studio/pipeline/pr-master This commit looks good
Move lifecycle assembly out of the PBS frontend into a common AssembleLifecyclePipelineStage. PBS emits a typed IRLifecycleDeclaration; the assembler owns wrappers, boot guard, and single project-init execution. Housekeep DSC-0059 with LSN-0062, and include the DSC-0062 PVM/PBX neutrality spec and lesson already present on this branch.
This commit is contained in:
+93
@@ -34,6 +34,7 @@ public class IRBackend implements IRBackendReader {
|
||||
private final ReadOnlyList<IntrinsicReference> intrinsicPool = ReadOnlyList.empty();
|
||||
@Builder.Default
|
||||
private final IRReservedMetadata reservedMetadata = IRReservedMetadata.empty();
|
||||
private final IRLifecycleDeclaration lifecycleDeclaration;
|
||||
|
||||
public static IRBackendAggregator aggregator() {
|
||||
return new IRBackendAggregator();
|
||||
@@ -53,6 +54,8 @@ public class IRBackend implements IRBackendReader {
|
||||
private final ArrayList<IRReservedMetadata.BuiltinTypeSurface> builtinTypeSurfaces = new ArrayList<>();
|
||||
private final ArrayList<IRReservedMetadata.BuiltinConstSurface> builtinConstSurfaces = new ArrayList<>();
|
||||
private final LinkedHashSet<String> requiredCapabilities = new LinkedHashSet<>();
|
||||
private final ArrayList<IRLifecycleFileDeclaration> lifecycleFiles = new ArrayList<>();
|
||||
private ReadOnlyList<ModuleId> lifecycleModuleOrder = ReadOnlyList.empty();
|
||||
|
||||
public void merge(final IRBackendFile backendFile) {
|
||||
if (backendFile == null) {
|
||||
@@ -90,6 +93,12 @@ public class IRBackend implements IRBackendReader {
|
||||
for (final var function : backendFile.executableFunctions()) {
|
||||
executableFunctions.add(remapExecutableFunction(function, moduleRemap, callableRemap, intrinsicRemap));
|
||||
}
|
||||
if (backendFile.lifecycleDeclaration() != null && !backendFile.lifecycleDeclaration().isEmpty()) {
|
||||
lifecycleFiles.add(remapLifecycleFileDeclaration(
|
||||
backendFile.lifecycleDeclaration(),
|
||||
moduleRemap,
|
||||
callableRemap));
|
||||
}
|
||||
final var metadata = backendFile.reservedMetadata();
|
||||
hostMethodBindings.addAll(metadata.hostMethodBindings().asList());
|
||||
builtinTypeSurfaces.addAll(metadata.builtinTypeSurfaces().asList());
|
||||
@@ -111,6 +120,11 @@ public class IRBackend implements IRBackendReader {
|
||||
return this;
|
||||
}
|
||||
|
||||
public IRBackendAggregator lifecycleModuleOrder(final ReadOnlyList<ModuleId> moduleOrder) {
|
||||
lifecycleModuleOrder = moduleOrder == null ? ReadOnlyList.empty() : moduleOrder;
|
||||
return this;
|
||||
}
|
||||
|
||||
private ModuleId[] reindexModules(final ReadOnlyList<ModuleReference> localModulePool) {
|
||||
if (localModulePool == null || localModulePool.isEmpty()) {
|
||||
return new ModuleId[0];
|
||||
@@ -203,6 +217,37 @@ public class IRBackend implements IRBackendReader {
|
||||
function.span());
|
||||
}
|
||||
|
||||
private IRLifecycleFileDeclaration remapLifecycleFileDeclaration(
|
||||
final IRLifecycleFileDeclaration declaration,
|
||||
final ModuleId[] moduleRemap,
|
||||
final CallableId[] callableRemap) {
|
||||
final var remappedModuleId = remapModuleId(
|
||||
declaration.moduleId(),
|
||||
moduleRemap,
|
||||
"lifecycle file");
|
||||
return new IRLifecycleFileDeclaration(
|
||||
remappedModuleId,
|
||||
declaration.fileId(),
|
||||
remapLifecycleCallable(declaration.fileInitFragment(), moduleRemap, callableRemap),
|
||||
remapLifecycleCallable(declaration.projectInit(), moduleRemap, callableRemap),
|
||||
remapLifecycleCallable(declaration.frameRoot(), moduleRemap, callableRemap));
|
||||
}
|
||||
|
||||
private IRLifecycleCallableReference remapLifecycleCallable(
|
||||
final IRLifecycleCallableReference reference,
|
||||
final ModuleId[] moduleRemap,
|
||||
final CallableId[] callableRemap) {
|
||||
if (reference == null) {
|
||||
return null;
|
||||
}
|
||||
return new IRLifecycleCallableReference(
|
||||
remapModuleId(reference.moduleId(), moduleRemap, "lifecycle callable"),
|
||||
reference.fileId(),
|
||||
remapCallableId(reference.callableId(), callableRemap, "lifecycle callable"),
|
||||
reference.role(),
|
||||
reference.origin());
|
||||
}
|
||||
|
||||
private ModuleId remapModuleId(
|
||||
final ModuleId localModuleId,
|
||||
final ModuleId[] moduleRemap,
|
||||
@@ -273,6 +318,52 @@ public class IRBackend implements IRBackendReader {
|
||||
return ReadOnlyList.wrap(pool);
|
||||
}
|
||||
|
||||
private IRLifecycleDeclaration emitLifecycleDeclaration() {
|
||||
if (lifecycleFiles.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
if (lifecycleModuleOrder.isEmpty()) {
|
||||
throw new IllegalStateException("lifecycle module order is required for executable handoff");
|
||||
}
|
||||
|
||||
final var modules = new ArrayList<IRLifecycleModuleDeclaration>();
|
||||
IRLifecycleCallableReference projectInit = null;
|
||||
IRLifecycleCallableReference frameRoot = null;
|
||||
for (final var moduleId : lifecycleModuleOrder) {
|
||||
final var fragments = new ArrayList<IRLifecycleCallableReference>();
|
||||
var hasLifecycleContribution = false;
|
||||
for (final var lifecycleFile : lifecycleFiles) {
|
||||
if (!sameModuleId(moduleId, lifecycleFile.moduleId())) {
|
||||
continue;
|
||||
}
|
||||
hasLifecycleContribution = true;
|
||||
if (lifecycleFile.fileInitFragment() != null) {
|
||||
fragments.add(lifecycleFile.fileInitFragment());
|
||||
}
|
||||
if (projectInit == null && lifecycleFile.projectInit() != null) {
|
||||
projectInit = lifecycleFile.projectInit();
|
||||
}
|
||||
if (frameRoot == null && lifecycleFile.frameRoot() != null) {
|
||||
frameRoot = lifecycleFile.frameRoot();
|
||||
}
|
||||
}
|
||||
if (hasLifecycleContribution) {
|
||||
modules.add(new IRLifecycleModuleDeclaration(moduleId, ReadOnlyList.wrap(fragments)));
|
||||
}
|
||||
}
|
||||
return new IRLifecycleDeclaration(ReadOnlyList.wrap(modules), projectInit, frameRoot);
|
||||
}
|
||||
|
||||
private boolean sameModuleId(final ModuleId left, final ModuleId right) {
|
||||
if (left == null || right == null) {
|
||||
return left == right;
|
||||
}
|
||||
if (left.isNone() || right.isNone()) {
|
||||
return left.isNone() && right.isNone();
|
||||
}
|
||||
return left.getIndex() == right.getIndex();
|
||||
}
|
||||
|
||||
public IRBackend emit() {
|
||||
return IRBackend
|
||||
.builder()
|
||||
@@ -290,6 +381,7 @@ public class IRBackend implements IRBackendReader {
|
||||
ReadOnlyList.wrap(builtinTypeSurfaces),
|
||||
ReadOnlyList.wrap(builtinConstSurfaces),
|
||||
ReadOnlyList.wrap(requiredCapabilities.stream().toList())))
|
||||
.lifecycleDeclaration(emitLifecycleDeclaration())
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -321,6 +413,7 @@ public class IRBackend implements IRBackendReader {
|
||||
.append(", builtinTypes=").append(reservedMetadata.builtinTypeSurfaces().size())
|
||||
.append(", builtinConsts=").append(reservedMetadata.builtinConstSurfaces().size())
|
||||
.append(", requiredCapabilities=").append(reservedMetadata.requiredCapabilities().size())
|
||||
.append(", lifecycle=").append(lifecycleDeclaration == null ? "none" : "declared")
|
||||
.append('}');
|
||||
|
||||
if (functions.isEmpty()) {
|
||||
|
||||
+35
-6
@@ -17,7 +17,8 @@ public record IRBackendFile(
|
||||
IRReservedMetadata reservedMetadata,
|
||||
ReadOnlyList<ModuleReference> modulePool,
|
||||
ReadOnlyList<CallableSignatureRef> callableSignatures,
|
||||
ReadOnlyList<IntrinsicReference> intrinsicPool) {
|
||||
ReadOnlyList<IntrinsicReference> intrinsicPool,
|
||||
IRLifecycleFileDeclaration lifecycleDeclaration) {
|
||||
public IRBackendFile {
|
||||
fileId = Objects.requireNonNull(fileId, "fileId");
|
||||
functions = functions == null ? ReadOnlyList.empty() : functions;
|
||||
@@ -30,6 +31,29 @@ public record IRBackendFile(
|
||||
intrinsicPool = intrinsicPool == null ? ReadOnlyList.empty() : intrinsicPool;
|
||||
}
|
||||
|
||||
public IRBackendFile(
|
||||
final FileId fileId,
|
||||
final ReadOnlyList<IRFunction> functions,
|
||||
final ReadOnlyList<IRSyntheticFunction> syntheticFunctions,
|
||||
final ReadOnlyList<IRGlobal> globals,
|
||||
final ReadOnlyList<IRBackendExecutableFunction> executableFunctions,
|
||||
final IRReservedMetadata reservedMetadata,
|
||||
final ReadOnlyList<ModuleReference> modulePool,
|
||||
final ReadOnlyList<CallableSignatureRef> callableSignatures,
|
||||
final ReadOnlyList<IntrinsicReference> intrinsicPool) {
|
||||
this(
|
||||
fileId,
|
||||
functions,
|
||||
syntheticFunctions,
|
||||
globals,
|
||||
executableFunctions,
|
||||
reservedMetadata,
|
||||
modulePool,
|
||||
callableSignatures,
|
||||
intrinsicPool,
|
||||
null);
|
||||
}
|
||||
|
||||
public IRBackendFile(
|
||||
final FileId fileId,
|
||||
final ReadOnlyList<IRFunction> functions) {
|
||||
@@ -42,7 +66,8 @@ public record IRBackendFile(
|
||||
IRReservedMetadata.empty(),
|
||||
ReadOnlyList.empty(),
|
||||
ReadOnlyList.empty(),
|
||||
ReadOnlyList.empty());
|
||||
ReadOnlyList.empty(),
|
||||
null);
|
||||
}
|
||||
|
||||
public static IRBackendFile empty(final FileId fileId) {
|
||||
@@ -55,7 +80,8 @@ public record IRBackendFile(
|
||||
IRReservedMetadata.empty(),
|
||||
ReadOnlyList.empty(),
|
||||
ReadOnlyList.empty(),
|
||||
ReadOnlyList.empty());
|
||||
ReadOnlyList.empty(),
|
||||
null);
|
||||
}
|
||||
|
||||
public IRBackendFile(
|
||||
@@ -71,7 +97,8 @@ public record IRBackendFile(
|
||||
reservedMetadata,
|
||||
ReadOnlyList.empty(),
|
||||
ReadOnlyList.empty(),
|
||||
ReadOnlyList.empty());
|
||||
ReadOnlyList.empty(),
|
||||
null);
|
||||
}
|
||||
|
||||
public IRBackendFile(
|
||||
@@ -90,7 +117,8 @@ public record IRBackendFile(
|
||||
reservedMetadata,
|
||||
ReadOnlyList.empty(),
|
||||
callableSignatures,
|
||||
intrinsicPool);
|
||||
intrinsicPool,
|
||||
null);
|
||||
}
|
||||
|
||||
public IRBackendFile(
|
||||
@@ -110,6 +138,7 @@ public record IRBackendFile(
|
||||
reservedMetadata,
|
||||
modulePool,
|
||||
callableSignatures,
|
||||
intrinsicPool);
|
||||
intrinsicPool,
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -17,4 +17,5 @@ public interface IRBackendReader {
|
||||
ReadOnlyList<CallableSignatureRef> getCallableSignatures();
|
||||
ReadOnlyList<IntrinsicReference> getIntrinsicPool();
|
||||
IRReservedMetadata getReservedMetadata();
|
||||
IRLifecycleDeclaration getLifecycleDeclaration();
|
||||
}
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
import p.studio.compiler.source.Span;
|
||||
import p.studio.compiler.source.identifiers.CallableId;
|
||||
import p.studio.compiler.source.identifiers.FileId;
|
||||
import p.studio.compiler.source.identifiers.ModuleId;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record IRLifecycleCallableReference(
|
||||
ModuleId moduleId,
|
||||
FileId fileId,
|
||||
CallableId callableId,
|
||||
IRLifecycleCallableRole role,
|
||||
Span origin) {
|
||||
public IRLifecycleCallableReference {
|
||||
moduleId = Objects.requireNonNull(moduleId, "moduleId");
|
||||
fileId = Objects.requireNonNull(fileId, "fileId");
|
||||
callableId = Objects.requireNonNull(callableId, "callableId");
|
||||
role = Objects.requireNonNull(role, "role");
|
||||
origin = origin == null ? Span.none() : origin;
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
public enum IRLifecycleCallableRole {
|
||||
FILE_INIT_FRAGMENT,
|
||||
PROJECT_INIT,
|
||||
FRAME_ROOT
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
public record IRLifecycleDeclaration(
|
||||
ReadOnlyList<IRLifecycleModuleDeclaration> modules,
|
||||
IRLifecycleCallableReference projectInit,
|
||||
IRLifecycleCallableReference frameRoot) {
|
||||
public IRLifecycleDeclaration {
|
||||
modules = modules == null ? ReadOnlyList.empty() : modules;
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
import p.studio.compiler.source.identifiers.FileId;
|
||||
import p.studio.compiler.source.identifiers.ModuleId;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record IRLifecycleFileDeclaration(
|
||||
ModuleId moduleId,
|
||||
FileId fileId,
|
||||
IRLifecycleCallableReference fileInitFragment,
|
||||
IRLifecycleCallableReference projectInit,
|
||||
IRLifecycleCallableReference frameRoot) {
|
||||
public IRLifecycleFileDeclaration {
|
||||
moduleId = Objects.requireNonNull(moduleId, "moduleId");
|
||||
fileId = Objects.requireNonNull(fileId, "fileId");
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return fileInitFragment == null && projectInit == null && frameRoot == null;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
import p.studio.compiler.source.identifiers.ModuleId;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record IRLifecycleModuleDeclaration(
|
||||
ModuleId moduleId,
|
||||
ReadOnlyList<IRLifecycleCallableReference> fileInitFragments) {
|
||||
public IRLifecycleModuleDeclaration {
|
||||
moduleId = Objects.requireNonNull(moduleId, "moduleId");
|
||||
fileInitFragments = fileInitFragments == null ? ReadOnlyList.empty() : fileInitFragments;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user