feat(pbs): add parametric arrays and concrete generic contracts
Support explicit contract type parameters, canonical nominal applications, recursive substitution, concrete implementations and instantiated editor views. Complete parametric Array syntax and contextual construction integration. Preserve type origins across imports and reexports, fix trait argument stack order, and relocate global slots before lifecycle assembly. Publish specs, installed examples and consolidated discussion lessons. Validate frontend, common pipeline, architecture, LSP and installed knowledge gates, plus the full production VM conformance corpus with 14 generic fixtures.
This commit is contained in:
+12
-4
@@ -68,6 +68,7 @@ public class IRBackend implements IRBackendReader {
|
||||
}
|
||||
functions.addAll(backendFile.functions().asList());
|
||||
final var moduleRemap = reindexModules(backendFile.modulePool());
|
||||
final var globalRemap = new java.util.HashMap<Integer, Integer>();
|
||||
for (final var syntheticFunction : backendFile.syntheticFunctions()) {
|
||||
syntheticFunctions.add(new IRSyntheticFunction(
|
||||
remapModuleId(syntheticFunction.moduleId(), moduleRemap, "synthetic function"),
|
||||
@@ -76,12 +77,15 @@ public class IRBackend implements IRBackendReader {
|
||||
syntheticFunction.origin()));
|
||||
}
|
||||
for (final var global : backendFile.globals()) {
|
||||
final var linkedSlot = globals.size();
|
||||
if (globalRemap.putIfAbsent(global.slot(), linkedSlot) != null)
|
||||
throw new IllegalArgumentException("duplicate file-local global slot: " + global.slot());
|
||||
globals.add(new IRGlobal(
|
||||
global.fileId(),
|
||||
remapModuleId(global.moduleId(), moduleRemap, "global"),
|
||||
global.name(),
|
||||
global.declaredTypeSurface(),
|
||||
global.slot(),
|
||||
linkedSlot,
|
||||
global.visibility(),
|
||||
global.isHidden(),
|
||||
global.hiddenKind(),
|
||||
@@ -101,7 +105,7 @@ public class IRBackend implements IRBackendReader {
|
||||
ReadOnlyList.wrap(impl.methods().stream().map(id -> remapCallableId(id, callableRemap, "implementation")).toList())));
|
||||
}
|
||||
for (final var function : backendFile.executableFunctions()) {
|
||||
executableFunctions.add(remapExecutableFunction(function, moduleRemap, callableRemap, intrinsicRemap));
|
||||
executableFunctions.add(remapExecutableFunction(function, moduleRemap, callableRemap, intrinsicRemap, globalRemap));
|
||||
}
|
||||
if (backendFile.lifecycleDeclaration() != null && !backendFile.lifecycleDeclaration().isEmpty()) {
|
||||
lifecycleFiles.add(remapLifecycleFileDeclaration(
|
||||
@@ -172,7 +176,8 @@ public class IRBackend implements IRBackendReader {
|
||||
final IRBackendExecutableFunction function,
|
||||
final ModuleId[] moduleRemap,
|
||||
final CallableId[] callableRemap,
|
||||
final IntrinsicId[] intrinsicRemap) {
|
||||
final IntrinsicId[] intrinsicRemap,
|
||||
final java.util.Map<Integer, Integer> globalRemap) {
|
||||
final var remappedInstructions = new ArrayList<IRBackendExecutableFunction.Instruction>(function.instructions().size());
|
||||
final var remappedFunctionModuleId = remapModuleId(
|
||||
function.moduleId(),
|
||||
@@ -208,7 +213,10 @@ public class IRBackend implements IRBackendReader {
|
||||
remappedIntrinsic,
|
||||
instruction.label(),
|
||||
instruction.targetLabel(),
|
||||
instruction.expectedArgSlots(),
|
||||
instruction.kind() == IRBackendExecutableFunction.InstructionKind.GET_GLOBAL
|
||||
|| instruction.kind() == IRBackendExecutableFunction.InstructionKind.SET_GLOBAL
|
||||
? globalRemap.getOrDefault(instruction.expectedArgSlots(), instruction.expectedArgSlots())
|
||||
: instruction.expectedArgSlots(),
|
||||
instruction.expectedRetSlots(),
|
||||
instruction.span(), instruction.registryInstruction() == null ? null :
|
||||
new p.studio.compiler.models.registry.IRRegistryInstruction(instruction.registryInstruction().kind(), instruction.registryInstruction().type(), instruction.registryInstruction().targetType(),
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import p.studio.compiler.source.Span;
|
||||
import p.studio.compiler.source.identifiers.*;
|
||||
import p.studio.compiler.source.tables.CallableSignatureRef;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class IRGlobalRelocationTest {
|
||||
@Test void independentFileGlobalsCannotAliasAfterAggregation() {
|
||||
var aggregator = IRBackend.aggregator();
|
||||
for (int i = 0; i < 2; i++) {
|
||||
var file = new FileId(i);
|
||||
var span = new Span(file, 0, 1);
|
||||
var function = new IRBackendExecutableFunction(file, ModuleId.none(), "read"+i, new CallableId(0),
|
||||
0, 1, 0, 0, 1, 1, ReadOnlyList.from(
|
||||
new IRBackendExecutableFunction.Instruction(IRBackendExecutableFunction.InstructionKind.GET_GLOBAL,
|
||||
null,"",null,null,null,"","",0,null,span),
|
||||
new IRBackendExecutableFunction.Instruction(IRBackendExecutableFunction.InstructionKind.RET,"",null,null,span)), span);
|
||||
aggregator.merge(new IRBackendFile(file, null, null,
|
||||
ReadOnlyList.from(new IRGlobal(file, ModuleId.none(), "state", "int", span)),
|
||||
ReadOnlyList.from(function), null, null,
|
||||
ReadOnlyList.from(new CallableSignatureRef("read"+i, 0, "()->simple:int")), null));
|
||||
}
|
||||
var backend = aggregator.emit();
|
||||
assertEquals(0, backend.getGlobals().get(0).slot());
|
||||
assertEquals(1, backend.getGlobals().get(1).slot());
|
||||
assertEquals(0, backend.getExecutableFunctions().get(0).instructions().getFirst().expectedArgSlots());
|
||||
assertEquals(1, backend.getExecutableFunctions().get(1).instructions().getFirst().expectedArgSlots());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user