diff --git a/prometeu-compiler/frontends/prometeu-frontend-pbs/src/main/java/p/studio/compiler/pbs/PbsFrontendCompiler.java b/prometeu-compiler/frontends/prometeu-frontend-pbs/src/main/java/p/studio/compiler/pbs/PbsFrontendCompiler.java index 25e52f41..3286f13d 100644 --- a/prometeu-compiler/frontends/prometeu-frontend-pbs/src/main/java/p/studio/compiler/pbs/PbsFrontendCompiler.java +++ b/prometeu-compiler/frontends/prometeu-frontend-pbs/src/main/java/p/studio/compiler/pbs/PbsFrontendCompiler.java @@ -360,7 +360,6 @@ public final class PbsFrontendCompiler { final var callableShapeId = callableShapeId(declaredFn, typeSurfaceTable, callableShapeTable); final var callableId = callableIdTable.register( normalizedModuleId, - normalizedModuleKey, declaredCallable.callableName(), declaredFn.parameters().size(), callableShapeSurface(callableShapeId, typeSurfaceTable, callableShapeTable)); @@ -376,7 +375,6 @@ public final class PbsFrontendCompiler { for (final var importedCallable : importedCallables) { final var callableId = callableIdTable.register( importedCallable.moduleId(), - importedCallable.moduleKey(), importedCallable.callableName(), importedCallable.arity(), importedCallable.shapeSurface()); @@ -425,7 +423,6 @@ public final class PbsFrontendCompiler { instructions.add(new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.RET, "", - "", null, null, null, @@ -451,7 +448,6 @@ public final class PbsFrontendCompiler { executableFunctions.add(new IRBackendExecutableFunction( fileId, normalizedModuleId, - normalizedModuleKey, callable.callableName(), functionCallableId, start, @@ -670,7 +666,6 @@ public final class PbsFrontendCompiler { context.instructions().add(new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.RET, "", - "", null, null, null, @@ -926,7 +921,6 @@ public final class PbsFrontendCompiler { context.instructions().add(new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.CALL_HOST, "", - "", new IRBackendExecutableFunction.HostCallMetadata( host.abiModule(), host.abiMethod(), @@ -948,7 +942,6 @@ public final class PbsFrontendCompiler { context.instructions().add(new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC, "", - "", null, new IRBackendExecutableFunction.IntrinsicCallMetadata( intrinsic.canonicalName(), @@ -977,7 +970,6 @@ public final class PbsFrontendCompiler { context.instructions().add(new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.CALL_FUNC, calleeSignature.moduleId(), - calleeSignature.moduleKey(), calleeSignature.callableName(), calleeCallableId, null, @@ -1127,7 +1119,7 @@ public final class PbsFrontendCompiler { final ExecutableLoweringContext context) { context.instructions().add(new IRBackendExecutableFunction.Instruction( jumpKind, - "", + ModuleId.none(), "", null, null, @@ -1145,7 +1137,7 @@ public final class PbsFrontendCompiler { final ExecutableLoweringContext context) { context.instructions().add(new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.LABEL, - "", + ModuleId.none(), "", null, null, @@ -1163,7 +1155,7 @@ public final class PbsFrontendCompiler { final ExecutableLoweringContext context) { context.instructions().add(new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.PUSH_I32, - "", + ModuleId.none(), "", null, null, @@ -1181,7 +1173,7 @@ public final class PbsFrontendCompiler { final ExecutableLoweringContext context) { context.instructions().add(new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.PUSH_CONST, - "", + ModuleId.none(), "", null, null, @@ -1199,7 +1191,7 @@ public final class PbsFrontendCompiler { final ExecutableLoweringContext context) { context.instructions().add(new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.GET_LOCAL, - "", + ModuleId.none(), "", null, null, diff --git a/prometeu-compiler/frontends/prometeu-frontend-pbs/src/test/java/p/studio/compiler/pbs/PbsGoldenArtifactsTest.java b/prometeu-compiler/frontends/prometeu-frontend-pbs/src/test/java/p/studio/compiler/pbs/PbsGoldenArtifactsTest.java index 5a03007d..2e087cc3 100644 --- a/prometeu-compiler/frontends/prometeu-frontend-pbs/src/test/java/p/studio/compiler/pbs/PbsGoldenArtifactsTest.java +++ b/prometeu-compiler/frontends/prometeu-frontend-pbs/src/test/java/p/studio/compiler/pbs/PbsGoldenArtifactsTest.java @@ -46,7 +46,7 @@ class PbsGoldenArtifactsTest { final var callable = file.callableSignatures().get(i); out.append(i) .append(':') - .append(callable.moduleKey()) + .append(callable.moduleId().isNone() ? "-" : callable.moduleId().getIndex()) .append("::") .append(callable.callableName()) .append('/') @@ -61,7 +61,7 @@ class PbsGoldenArtifactsTest { out.append("fn#") .append(i) .append(':') - .append(fn.moduleKey()) + .append(fn.moduleId().isNone() ? "-" : fn.moduleId().getIndex()) .append("::") .append(fn.callableName()) .append(" id=") diff --git a/prometeu-compiler/frontends/prometeu-frontend-pbs/src/test/java/p/studio/compiler/services/PBSFrontendPhaseServiceTest.java b/prometeu-compiler/frontends/prometeu-frontend-pbs/src/test/java/p/studio/compiler/services/PBSFrontendPhaseServiceTest.java index a771f26f..c0ccf6a9 100644 --- a/prometeu-compiler/frontends/prometeu-frontend-pbs/src/test/java/p/studio/compiler/services/PBSFrontendPhaseServiceTest.java +++ b/prometeu-compiler/frontends/prometeu-frontend-pbs/src/test/java/p/studio/compiler/services/PBSFrontendPhaseServiceTest.java @@ -211,7 +211,6 @@ class PBSFrontendPhaseServiceTest { assertNotNull(callInstruction.calleeModuleId()); assertEquals(targetFn.moduleId().getIndex(), callInstruction.calleeModuleId().getIndex()); - assertEquals(targetFn.moduleKey(), callInstruction.calleeModuleKey()); assertTrue(callerFn.moduleId().getIndex() != callInstruction.calleeModuleId().getIndex()); } @@ -916,7 +915,8 @@ class PBSFrontendPhaseServiceTest { .filter(function -> "frame".equals(function.callableName())) .findFirst(); final var executableNames = irBackend.getExecutableFunctions().stream() - .map(function -> function.callableName() + "@" + function.moduleKey()) + .map(function -> function.callableName() + "@" + + (function.moduleId().isNone() ? "-" : function.moduleId().getIndex())) .toList(); assertTrue( frameExecutableOptional.isPresent(), diff --git a/prometeu-compiler/frontends/prometeu-frontend-pbs/src/test/resources/golden/frontend-irbackend.txt b/prometeu-compiler/frontends/prometeu-frontend-pbs/src/test/resources/golden/frontend-irbackend.txt index a43f9cb2..4ff905e1 100644 --- a/prometeu-compiler/frontends/prometeu-frontend-pbs/src/test/resources/golden/frontend-irbackend.txt +++ b/prometeu-compiler/frontends/prometeu-frontend-pbs/src/test/resources/golden/frontend-irbackend.txt @@ -1,11 +1,11 @@ callables=2 -0:::b/1|(simple:int)->simple:int -1:::a/0|()->simple:int +0:-::b/1|(simple:int)->simple:int +1:-::a/0|()->simple:int intrinsics=0 -fn#0:::b id=0 +fn#0:-::b id=0 GET_LOCAL calleeId=- intrinsicId=- RET calleeId=- intrinsicId=- -fn#1:::a id=1 +fn#1:-::a id=1 PUSH_I32 calleeId=- intrinsicId=- CALL_FUNC calleeId=0 intrinsicId=- RET calleeId=- intrinsicId=- diff --git a/prometeu-compiler/prometeu-build-pipeline/src/main/java/p/studio/compiler/backend/irvm/LowerToIRVMService.java b/prometeu-compiler/prometeu-build-pipeline/src/main/java/p/studio/compiler/backend/irvm/LowerToIRVMService.java index 05710baf..075f0c87 100644 --- a/prometeu-compiler/prometeu-build-pipeline/src/main/java/p/studio/compiler/backend/irvm/LowerToIRVMService.java +++ b/prometeu-compiler/prometeu-build-pipeline/src/main/java/p/studio/compiler/backend/irvm/LowerToIRVMService.java @@ -299,8 +299,8 @@ public class LowerToIRVMService { final var entryPointModuleId = backend.getEntryPointModuleId(); final var sorted = new ArrayList<>(backend.getExecutableFunctions().asList()); sorted.sort((left, right) -> { - final var leftModuleKey = moduleSortKey(backend, left.moduleId(), left.moduleKey()); - final var rightModuleKey = moduleSortKey(backend, right.moduleId(), right.moduleKey()); + final var leftModuleKey = moduleSortKey(backend, left.moduleId()); + final var rightModuleKey = moduleSortKey(backend, right.moduleId()); final var moduleCmp = leftModuleKey.compareTo(rightModuleKey); if (moduleCmp != 0) { return moduleCmp; @@ -367,15 +367,14 @@ public class LowerToIRVMService { private String moduleSortKey( final IRBackend backend, - final ModuleId moduleId, - final String fallbackModuleKey) { + final ModuleId moduleId) { if (moduleId != null && !moduleId.isNone()) { final var index = moduleId.getIndex(); if (index >= 0 && index < backend.getModulePool().size()) { return canonicalModuleSortKey(backend.getModulePool().get(index)); } } - return fallbackModuleKey == null ? "" : fallbackModuleKey; + return ""; } private String canonicalModuleSortKey(final ModuleReference reference) { diff --git a/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/backend/GoldenArtifactsTest.java b/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/backend/GoldenArtifactsTest.java index 45292ae6..0b39f615 100644 --- a/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/backend/GoldenArtifactsTest.java +++ b/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/backend/GoldenArtifactsTest.java @@ -45,7 +45,6 @@ class GoldenArtifactsTest { return IRBackend.builder() .executableFunctions(ReadOnlyList.from(new IRBackendExecutableFunction( new FileId(1), - "app/main", "main", new CallableId(0), 0, @@ -58,15 +57,12 @@ class GoldenArtifactsTest { new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.CALL_HOST, "", - "", - null, new IRBackendExecutableFunction.HostCallMetadata("gfx", "draw_pixel", 1, 0, 0), null, Span.none()), new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC, "", - "", null, new IRBackendExecutableFunction.IntrinsicCallMetadata("input.pad", 1, new IntrinsicId(0)), 0, @@ -75,7 +71,6 @@ class GoldenArtifactsTest { new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.RET, "", - "", null, null, Span.none())), diff --git a/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/backend/irvm/LowerToIRVMServiceTest.java b/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/backend/irvm/LowerToIRVMServiceTest.java index 95084e37..6f1271c6 100644 --- a/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/backend/irvm/LowerToIRVMServiceTest.java +++ b/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/backend/irvm/LowerToIRVMServiceTest.java @@ -264,7 +264,6 @@ class LowerToIRVMServiceTest { final ReadOnlyList instructions) { return new IRBackendExecutableFunction( new FileId(0), - moduleKey, name, new CallableId(callableId), 0, @@ -296,7 +295,6 @@ class LowerToIRVMServiceTest { return new IRBackendExecutableFunction( new FileId(0), new ModuleId(moduleId), - moduleKey, name, new CallableId(callableId), 0, @@ -313,7 +311,6 @@ class LowerToIRVMServiceTest { return new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.RET, "", - "", null, null, Span.none()); @@ -325,7 +322,7 @@ class LowerToIRVMServiceTest { final int calleeCallableId) { return new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.CALL_FUNC, - moduleKey, + ModuleId.none(), name, new CallableId(calleeCallableId), null, @@ -341,7 +338,7 @@ class LowerToIRVMServiceTest { final int expectedRetSlots) { return new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.CALL_FUNC, - moduleKey, + ModuleId.none(), name, new CallableId(calleeCallableId), null, @@ -360,7 +357,6 @@ class LowerToIRVMServiceTest { return new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.CALL_HOST, "", - "", new IRBackendExecutableFunction.HostCallMetadata(module, name, version, argSlots, retSlots), null, Span.none()); @@ -373,7 +369,6 @@ class LowerToIRVMServiceTest { return new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC, "", - "", null, new IRBackendExecutableFunction.IntrinsicCallMetadata(canonicalName, canonicalVersion, new IntrinsicId(intrinsicId)), 0, @@ -384,7 +379,7 @@ class LowerToIRVMServiceTest { private static IRBackendExecutableFunction.Instruction label(final String label) { return new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.LABEL, - "", + ModuleId.none(), "", null, null, @@ -399,7 +394,7 @@ class LowerToIRVMServiceTest { private static IRBackendExecutableFunction.Instruction jmp(final String target) { return new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.JMP, - "", + ModuleId.none(), "", null, null, diff --git a/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/backend/irvm/OptimizeIRVMEquivalenceHarnessTest.java b/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/backend/irvm/OptimizeIRVMEquivalenceHarnessTest.java index 57e44223..4c5ceec5 100644 --- a/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/backend/irvm/OptimizeIRVMEquivalenceHarnessTest.java +++ b/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/backend/irvm/OptimizeIRVMEquivalenceHarnessTest.java @@ -322,7 +322,6 @@ class OptimizeIRVMEquivalenceHarnessTest { final ReadOnlyList instructions) { return new IRBackendExecutableFunction( new FileId(1), - "app", name, new CallableId(callableId), 0, @@ -339,8 +338,6 @@ class OptimizeIRVMEquivalenceHarnessTest { return new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.RET, "", - "", - null, null, null, Span.none()); @@ -355,8 +352,6 @@ class OptimizeIRVMEquivalenceHarnessTest { return new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.CALL_HOST, "", - "", - null, new IRBackendExecutableFunction.HostCallMetadata(module, name, version, argSlots, retSlots), null, Span.none()); @@ -371,7 +366,6 @@ class OptimizeIRVMEquivalenceHarnessTest { return new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC, "", - "", null, null, new IRBackendExecutableFunction.IntrinsicCallMetadata(canonicalName, canonicalVersion, new IntrinsicId(intrinsicId)), diff --git a/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/integration/BackendGateIIntegrationTest.java b/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/integration/BackendGateIIntegrationTest.java index 6e1c2a23..236bd152 100644 --- a/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/integration/BackendGateIIntegrationTest.java +++ b/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/integration/BackendGateIIntegrationTest.java @@ -188,7 +188,6 @@ class BackendGateIIntegrationTest { final ReadOnlyList instructions) { return new IRBackendExecutableFunction( new FileId(1), - "app/main", name, new CallableId(1), 0, @@ -205,7 +204,6 @@ class BackendGateIIntegrationTest { return new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.RET, "", - "", null, null, Span.none()); @@ -220,7 +218,6 @@ class BackendGateIIntegrationTest { return new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.CALL_HOST, "", - "", new IRBackendExecutableFunction.HostCallMetadata(module, name, version, argSlots, retSlots), null, Span.none()); @@ -233,7 +230,6 @@ class BackendGateIIntegrationTest { return new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC, "", - "", null, new IRBackendExecutableFunction.IntrinsicCallMetadata(canonicalName, canonicalVersion, new IntrinsicId(intrinsicId)), 0, diff --git a/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/workspaces/stages/BackendSafetyGateSUTest.java b/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/workspaces/stages/BackendSafetyGateSUTest.java index 2b8f4f94..09f776f3 100644 --- a/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/workspaces/stages/BackendSafetyGateSUTest.java +++ b/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/workspaces/stages/BackendSafetyGateSUTest.java @@ -28,7 +28,6 @@ class BackendSafetyGateSUTest { final var backend = IRBackend.builder() .executableFunctions(ReadOnlyList.from(new IRBackendExecutableFunction( new FileId(1), - "app", "main", new CallableId(1), 0, @@ -40,7 +39,7 @@ class BackendSafetyGateSUTest { ReadOnlyList.from( new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.CALL_FUNC, - "app", + p.studio.compiler.source.identifiers.ModuleId.none(), "missing", new CallableId(99), null, @@ -51,7 +50,6 @@ class BackendSafetyGateSUTest { new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.RET, "", - "", null, null, Span.none())), @@ -113,7 +111,6 @@ class BackendSafetyGateSUTest { final var backend = IRBackend.builder() .executableFunctions(ReadOnlyList.from(new IRBackendExecutableFunction( new FileId(1), - "app", "main", new CallableId(1), 0, @@ -125,7 +122,6 @@ class BackendSafetyGateSUTest { ReadOnlyList.from(new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.RET, "", - "", null, null, Span.none())), diff --git a/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/workspaces/stages/LowerToIRVMPipelineStageTest.java b/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/workspaces/stages/LowerToIRVMPipelineStageTest.java index 13562bd3..db1f4390 100644 --- a/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/workspaces/stages/LowerToIRVMPipelineStageTest.java +++ b/prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/workspaces/stages/LowerToIRVMPipelineStageTest.java @@ -38,7 +38,6 @@ class LowerToIRVMPipelineStageTest { ctx.irBackend = IRBackend.builder() .executableFunctions(ReadOnlyList.from(new IRBackendExecutableFunction( new FileId(0), - "app", "main", new CallableId(1), 0, @@ -50,7 +49,6 @@ class LowerToIRVMPipelineStageTest { ReadOnlyList.from(new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.RET, "", - "", null, null, Span.none())), @@ -71,7 +69,6 @@ class LowerToIRVMPipelineStageTest { ctx.irBackend = IRBackend.builder() .executableFunctions(ReadOnlyList.from(new IRBackendExecutableFunction( new FileId(0), - "app", "main", new CallableId(1), 0, @@ -83,7 +80,6 @@ class LowerToIRVMPipelineStageTest { ReadOnlyList.from(new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.RET, "", - "", null, null, Span.none())), @@ -104,7 +100,6 @@ class LowerToIRVMPipelineStageTest { ctx.irBackend = IRBackend.builder() .executableFunctions(ReadOnlyList.from(new IRBackendExecutableFunction( new FileId(9), - "app", "main", new CallableId(1), 10, @@ -116,7 +111,7 @@ class LowerToIRVMPipelineStageTest { ReadOnlyList.from( new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.CALL_FUNC, - "app", + p.studio.compiler.source.identifiers.ModuleId.none(), "missing", new CallableId(99), null, @@ -125,7 +120,6 @@ class LowerToIRVMPipelineStageTest { new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.RET, "", - "", null, null, Span.none())), @@ -149,7 +143,6 @@ class LowerToIRVMPipelineStageTest { .executableFunctions(ReadOnlyList.from( new IRBackendExecutableFunction( new FileId(0), - "app", "callee", new CallableId(2), 0, @@ -161,14 +154,12 @@ class LowerToIRVMPipelineStageTest { ReadOnlyList.from(new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.RET, "", - "", null, null, Span.none())), Span.none()), new IRBackendExecutableFunction( new FileId(0), - "app", "main", new CallableId(1), 0, @@ -180,7 +171,7 @@ class LowerToIRVMPipelineStageTest { ReadOnlyList.from( new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.CALL_FUNC, - "app", + p.studio.compiler.source.identifiers.ModuleId.none(), "callee", new CallableId(2), null, @@ -191,7 +182,6 @@ class LowerToIRVMPipelineStageTest { new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.RET, "", - "", null, null, Span.none())), diff --git a/prometeu-compiler/prometeu-compiler-core/src/main/java/p/studio/compiler/source/tables/CallableSignatureRef.java b/prometeu-compiler/prometeu-compiler-core/src/main/java/p/studio/compiler/source/tables/CallableSignatureRef.java index 5afcd8f4..dfc571ae 100644 --- a/prometeu-compiler/prometeu-compiler-core/src/main/java/p/studio/compiler/source/tables/CallableSignatureRef.java +++ b/prometeu-compiler/prometeu-compiler-core/src/main/java/p/studio/compiler/source/tables/CallableSignatureRef.java @@ -6,17 +6,15 @@ import java.util.Objects; public record CallableSignatureRef( ModuleId moduleId, - String moduleKey, String callableName, int arity, String typeShape) { public CallableSignatureRef( - final String moduleKey, final String callableName, final int arity, final String typeShape) { - this(ModuleId.none(), moduleKey, callableName, arity, typeShape); + this(ModuleId.none(), callableName, arity, typeShape); } public CallableSignatureRef { @@ -24,7 +22,6 @@ public record CallableSignatureRef( if (!moduleId.isNone()) { moduleId.getIndex(); } - moduleKey = moduleKey == null ? "" : moduleKey; callableName = Objects.requireNonNull(callableName, "callableName"); typeShape = typeShape == null ? "" : typeShape; if (callableName.isBlank()) { diff --git a/prometeu-compiler/prometeu-compiler-core/src/main/java/p/studio/compiler/source/tables/CallableTable.java b/prometeu-compiler/prometeu-compiler-core/src/main/java/p/studio/compiler/source/tables/CallableTable.java index ce8d8a52..2ad5c275 100644 --- a/prometeu-compiler/prometeu-compiler-core/src/main/java/p/studio/compiler/source/tables/CallableTable.java +++ b/prometeu-compiler/prometeu-compiler-core/src/main/java/p/studio/compiler/source/tables/CallableTable.java @@ -10,19 +10,17 @@ public class CallableTable extends InternTable } public CallableId register( - final String moduleKey, final String callableName, final int arity, final String typeShape) { - return register(new CallableSignatureRef(ModuleId.none(), moduleKey, callableName, arity, typeShape)); + return register(new CallableSignatureRef(ModuleId.none(), callableName, arity, typeShape)); } public CallableId register( final ModuleId moduleId, - final String moduleKey, final String callableName, final int arity, final String typeShape) { - return register(new CallableSignatureRef(moduleId, moduleKey, callableName, arity, typeShape)); + return register(new CallableSignatureRef(moduleId, callableName, arity, typeShape)); } } diff --git a/prometeu-compiler/prometeu-compiler-core/src/test/java/p/studio/compiler/source/tables/CallableTableTest.java b/prometeu-compiler/prometeu-compiler-core/src/test/java/p/studio/compiler/source/tables/CallableTableTest.java index 6d2e56f7..c9a6db1e 100644 --- a/prometeu-compiler/prometeu-compiler-core/src/test/java/p/studio/compiler/source/tables/CallableTableTest.java +++ b/prometeu-compiler/prometeu-compiler-core/src/test/java/p/studio/compiler/source/tables/CallableTableTest.java @@ -11,9 +11,9 @@ class CallableTableTest { void shouldInternEqualCallableSignaturesToSameIdentifier() { final var table = new CallableTable(); - final var first = table.register("app/main", "draw", 2, "(simple:int,simple:int)->unit"); - final var second = table.register("app/main", "draw", 2, "(simple:int,simple:int)->unit"); - final var third = table.register("app/main", "draw", 1, "(simple:int)->unit"); + final var first = table.register("draw", 2, "(simple:int,simple:int)->unit"); + final var second = table.register("draw", 2, "(simple:int,simple:int)->unit"); + final var third = table.register("draw", 1, "(simple:int)->unit"); assertEquals(first, second); assertEquals(2, table.size()); @@ -22,7 +22,7 @@ class CallableTableTest { @Test void shouldRejectInvalidCallableSignatureReferenceContract() { - assertThrows(IllegalArgumentException.class, () -> new CallableSignatureRef("app/main", "", 1, "(unit)->unit")); - assertThrows(IllegalArgumentException.class, () -> new CallableSignatureRef("app/main", "draw", -1, "(unit)->unit")); + assertThrows(IllegalArgumentException.class, () -> new CallableSignatureRef("", 1, "(unit)->unit")); + assertThrows(IllegalArgumentException.class, () -> new CallableSignatureRef("draw", -1, "(unit)->unit")); } } diff --git a/prometeu-compiler/prometeu-frontend-api/src/main/java/p/studio/compiler/models/IRBackend.java b/prometeu-compiler/prometeu-frontend-api/src/main/java/p/studio/compiler/models/IRBackend.java index e06f531c..33438418 100644 --- a/prometeu-compiler/prometeu-frontend-api/src/main/java/p/studio/compiler/models/IRBackend.java +++ b/prometeu-compiler/prometeu-frontend-api/src/main/java/p/studio/compiler/models/IRBackend.java @@ -15,7 +15,6 @@ import p.studio.utilities.structures.ReadOnlyList; import java.util.ArrayList; import java.util.LinkedHashSet; -import java.util.List; @Builder @Getter @@ -108,12 +107,10 @@ public class IRBackend { final var signature = localCallableSignatures.get(i); final var remappedModuleId = remapModuleId( signature.moduleId(), - signature.moduleKey(), moduleRemap, "callable signature"); remap[i] = callableTable.register( remappedModuleId, - signature.moduleKey(), signature.callableName(), signature.arity(), signature.typeShape()); @@ -129,7 +126,6 @@ public class IRBackend { final var remappedInstructions = new ArrayList(function.instructions().size()); final var remappedFunctionModuleId = remapModuleId( function.moduleId(), - function.moduleKey(), moduleRemap, "function"); for (final var instruction : function.instructions()) { @@ -151,13 +147,11 @@ public class IRBackend { } final var remappedCalleeModuleId = remapModuleId( instruction.calleeModuleId(), - instruction.calleeModuleKey(), moduleRemap, "callee"); remappedInstructions.add(new IRBackendExecutableFunction.Instruction( instruction.kind(), remappedCalleeModuleId, - instruction.calleeModuleKey(), instruction.calleeCallableName(), remappedCallee, instruction.hostCall(), @@ -171,7 +165,6 @@ public class IRBackend { return new IRBackendExecutableFunction( function.fileId(), remappedFunctionModuleId, - function.moduleKey(), function.callableName(), remapCallableId(function.callableId(), callableRemap, "function"), function.sourceStart(), @@ -186,7 +179,6 @@ public class IRBackend { private ModuleId remapModuleId( final ModuleId localModuleId, - final String moduleKey, final ModuleId[] moduleRemap, final String label) { if (localModuleId != null && !localModuleId.isNone()) { @@ -196,33 +188,9 @@ public class IRBackend { } return moduleRemap[localIndex]; } - final var fallbackReference = moduleReferenceFromKey(moduleKey); - if (fallbackReference != null) { - return moduleTable.register(fallbackReference); - } return ModuleId.none(); } - private ModuleReference moduleReferenceFromKey(final String moduleKey) { - if (moduleKey == null || moduleKey.isBlank()) { - return null; - } - final var separator = moduleKey.indexOf(':'); - if (separator <= 0) { - return null; - } - final var project = moduleKey.substring(0, separator).trim(); - final var rawPath = moduleKey.substring(separator + 1).trim(); - if (project.isBlank()) { - return null; - } - if (rawPath.isBlank()) { - return new ModuleReference(project, ReadOnlyList.empty()); - } - final var segments = List.of(rawPath.split("/")); - return new ModuleReference(project, ReadOnlyList.wrap(segments)); - } - private CallableId remapCallableId( final CallableId localCallableId, final CallableId[] callableRemap, diff --git a/prometeu-compiler/prometeu-frontend-api/src/main/java/p/studio/compiler/models/IRBackendExecutableFunction.java b/prometeu-compiler/prometeu-frontend-api/src/main/java/p/studio/compiler/models/IRBackendExecutableFunction.java index 30a9cc96..c05867f6 100644 --- a/prometeu-compiler/prometeu-frontend-api/src/main/java/p/studio/compiler/models/IRBackendExecutableFunction.java +++ b/prometeu-compiler/prometeu-frontend-api/src/main/java/p/studio/compiler/models/IRBackendExecutableFunction.java @@ -12,7 +12,6 @@ import java.util.Objects; public record IRBackendExecutableFunction( FileId fileId, ModuleId moduleId, - String moduleKey, String callableName, CallableId callableId, int sourceStart, @@ -26,7 +25,6 @@ public record IRBackendExecutableFunction( public IRBackendExecutableFunction( final FileId fileId, - final String moduleKey, final String callableName, final CallableId callableId, final int sourceStart, @@ -40,7 +38,6 @@ public record IRBackendExecutableFunction( this( fileId, ModuleId.none(), - moduleKey, callableName, callableId, sourceStart, @@ -59,7 +56,6 @@ public record IRBackendExecutableFunction( if (!moduleId.isNone()) { moduleId.getIndex(); } - moduleKey = moduleKey == null ? "" : moduleKey; callableName = Objects.requireNonNull(callableName, "callableName"); if (callableName.isBlank()) { throw new IllegalArgumentException("callableName must not be blank"); @@ -88,7 +84,6 @@ public record IRBackendExecutableFunction( public record Instruction( InstructionKind kind, ModuleId calleeModuleId, - String calleeModuleKey, String calleeCallableName, CallableId calleeCallableId, HostCallMetadata hostCall, @@ -101,19 +96,17 @@ public record IRBackendExecutableFunction( public Instruction( final InstructionKind kind, final ModuleId calleeModuleId, - final String calleeModuleKey, final String calleeCallableName, final CallableId calleeCallableId, final HostCallMetadata hostCall, final IntrinsicCallMetadata intrinsicCall, final Span span) { - this(kind, calleeModuleId, calleeModuleKey, calleeCallableName, calleeCallableId, hostCall, intrinsicCall, null, null, null, null, span); + this(kind, calleeModuleId, calleeCallableName, calleeCallableId, hostCall, intrinsicCall, null, null, null, null, span); } public Instruction( final InstructionKind kind, final ModuleId calleeModuleId, - final String calleeModuleKey, final String calleeCallableName, final CallableId calleeCallableId, final HostCallMetadata hostCall, @@ -121,36 +114,33 @@ public record IRBackendExecutableFunction( final Integer expectedArgSlots, final Integer expectedRetSlots, final Span span) { - this(kind, calleeModuleId, calleeModuleKey, calleeCallableName, calleeCallableId, hostCall, intrinsicCall, null, null, expectedArgSlots, expectedRetSlots, span); + this(kind, calleeModuleId, calleeCallableName, calleeCallableId, hostCall, intrinsicCall, null, null, expectedArgSlots, expectedRetSlots, span); } public Instruction( final InstructionKind kind, final ModuleId calleeModuleId, - final String calleeModuleKey, final String calleeCallableName, final HostCallMetadata hostCall, final IntrinsicCallMetadata intrinsicCall, final Span span) { - this(kind, calleeModuleId, calleeModuleKey, calleeCallableName, null, hostCall, intrinsicCall, null, null, null, null, span); + this(kind, calleeModuleId, calleeCallableName, null, hostCall, intrinsicCall, null, null, null, null, span); } public Instruction( final InstructionKind kind, final ModuleId calleeModuleId, - final String calleeModuleKey, final String calleeCallableName, final HostCallMetadata hostCall, final IntrinsicCallMetadata intrinsicCall, final Integer expectedArgSlots, final Integer expectedRetSlots, final Span span) { - this(kind, calleeModuleId, calleeModuleKey, calleeCallableName, null, hostCall, intrinsicCall, null, null, expectedArgSlots, expectedRetSlots, span); + this(kind, calleeModuleId, calleeCallableName, null, hostCall, intrinsicCall, null, null, expectedArgSlots, expectedRetSlots, span); } public Instruction( final InstructionKind kind, - final String calleeModuleKey, final String calleeCallableName, final CallableId calleeCallableId, final HostCallMetadata hostCall, @@ -160,23 +150,21 @@ public record IRBackendExecutableFunction( final Integer expectedArgSlots, final Integer expectedRetSlots, final Span span) { - this(kind, ModuleId.none(), calleeModuleKey, calleeCallableName, calleeCallableId, hostCall, intrinsicCall, label, targetLabel, expectedArgSlots, expectedRetSlots, span); + this(kind, ModuleId.none(), calleeCallableName, calleeCallableId, hostCall, intrinsicCall, label, targetLabel, expectedArgSlots, expectedRetSlots, span); } public Instruction( final InstructionKind kind, - final String calleeModuleKey, final String calleeCallableName, final CallableId calleeCallableId, final HostCallMetadata hostCall, final IntrinsicCallMetadata intrinsicCall, final Span span) { - this(kind, ModuleId.none(), calleeModuleKey, calleeCallableName, calleeCallableId, hostCall, intrinsicCall, null, null, null, null, span); + this(kind, ModuleId.none(), calleeCallableName, calleeCallableId, hostCall, intrinsicCall, null, null, null, null, span); } public Instruction( final InstructionKind kind, - final String calleeModuleKey, final String calleeCallableName, final CallableId calleeCallableId, final HostCallMetadata hostCall, @@ -184,29 +172,27 @@ public record IRBackendExecutableFunction( final Integer expectedArgSlots, final Integer expectedRetSlots, final Span span) { - this(kind, ModuleId.none(), calleeModuleKey, calleeCallableName, calleeCallableId, hostCall, intrinsicCall, null, null, expectedArgSlots, expectedRetSlots, span); + this(kind, ModuleId.none(), calleeCallableName, calleeCallableId, hostCall, intrinsicCall, null, null, expectedArgSlots, expectedRetSlots, span); } public Instruction( final InstructionKind kind, - final String calleeModuleKey, final String calleeCallableName, final HostCallMetadata hostCall, final IntrinsicCallMetadata intrinsicCall, final Span span) { - this(kind, ModuleId.none(), calleeModuleKey, calleeCallableName, null, hostCall, intrinsicCall, null, null, null, null, span); + this(kind, ModuleId.none(), calleeCallableName, null, hostCall, intrinsicCall, null, null, null, null, span); } public Instruction( final InstructionKind kind, - final String calleeModuleKey, final String calleeCallableName, final HostCallMetadata hostCall, final IntrinsicCallMetadata intrinsicCall, final Integer expectedArgSlots, final Integer expectedRetSlots, final Span span) { - this(kind, ModuleId.none(), calleeModuleKey, calleeCallableName, null, hostCall, intrinsicCall, null, null, expectedArgSlots, expectedRetSlots, span); + this(kind, ModuleId.none(), calleeCallableName, null, hostCall, intrinsicCall, null, null, expectedArgSlots, expectedRetSlots, span); } public Instruction { @@ -216,7 +202,6 @@ public record IRBackendExecutableFunction( if (!calleeModuleId.isNone()) { calleeModuleId.getIndex(); } - calleeModuleKey = calleeModuleKey == null ? "" : calleeModuleKey; calleeCallableName = calleeCallableName == null ? "" : calleeCallableName; label = label == null ? "" : label; targetLabel = targetLabel == null ? "" : targetLabel; diff --git a/prometeu-compiler/prometeu-frontend-api/src/test/java/p/studio/compiler/models/IRBackendExecutableContractTest.java b/prometeu-compiler/prometeu-frontend-api/src/test/java/p/studio/compiler/models/IRBackendExecutableContractTest.java index 3dc29355..baa64a0c 100644 --- a/prometeu-compiler/prometeu-frontend-api/src/test/java/p/studio/compiler/models/IRBackendExecutableContractTest.java +++ b/prometeu-compiler/prometeu-frontend-api/src/test/java/p/studio/compiler/models/IRBackendExecutableContractTest.java @@ -21,7 +21,7 @@ class IRBackendExecutableContractTest { void callInstructionMustRequireCategorySpecificMetadata() { assertThrows(IllegalArgumentException.class, () -> new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.CALL_HOST, - "", + ModuleId.none(), "", null, null, @@ -29,7 +29,7 @@ class IRBackendExecutableContractTest { final var callFunc = new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.CALL_FUNC, - "app/main", + ModuleId.none(), "foo", new CallableId(7), null, @@ -42,7 +42,6 @@ class IRBackendExecutableContractTest { void functionContractMustRejectInvalidSlotAndSpanBounds() { assertThrows(IllegalArgumentException.class, () -> new IRBackendExecutableFunction( new FileId(1), - "app", "main", new CallableId(1), 10, @@ -56,7 +55,6 @@ class IRBackendExecutableContractTest { final var thrown = assertThrows(IllegalArgumentException.class, () -> new IRBackendExecutableFunction( new FileId(1), - "app", "main", new CallableId(1), 0, @@ -74,7 +72,7 @@ class IRBackendExecutableContractTest { void instructionContractMustRejectMixedMetadataKinds() { assertThrows(IllegalArgumentException.class, () -> new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.CALL_FUNC, - "app/main", + ModuleId.none(), "foo", new CallableId(1), new IRBackendExecutableFunction.HostCallMetadata("gfx", "draw", 1, 0, 0), @@ -93,7 +91,7 @@ class IRBackendExecutableContractTest { void jumpAndLabelContractMustRequireNames() { assertThrows(IllegalArgumentException.class, () -> new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.LABEL, - "", + ModuleId.none(), "", null, null, @@ -106,7 +104,7 @@ class IRBackendExecutableContractTest { assertThrows(IllegalArgumentException.class, () -> new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.JMP, - "", + ModuleId.none(), "", null, null, @@ -125,7 +123,6 @@ class IRBackendExecutableContractTest { ReadOnlyList.empty(), ReadOnlyList.from(new IRBackendExecutableFunction( new FileId(1), - "app/main", "entry", new CallableId(0), 0, @@ -137,21 +134,18 @@ class IRBackendExecutableContractTest { ReadOnlyList.from(new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.HALT, "", - "", - null, null, null, Span.none())), Span.none())), IRReservedMetadata.empty(), - ReadOnlyList.from(new CallableSignatureRef("app/main", "entry", 0, "() -> unit")), + ReadOnlyList.from(new CallableSignatureRef("entry", 0, "() -> unit")), ReadOnlyList.empty()); final var fileB = new IRBackendFile( new FileId(2), ReadOnlyList.empty(), ReadOnlyList.from(new IRBackendExecutableFunction( new FileId(2), - "app/main", "aux", new CallableId(0), 11, @@ -163,14 +157,12 @@ class IRBackendExecutableContractTest { ReadOnlyList.from(new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.RET, "", - "", - null, null, null, Span.none())), Span.none())), IRReservedMetadata.empty(), - ReadOnlyList.from(new CallableSignatureRef("app/main", "aux", 0, "() -> unit")), + ReadOnlyList.from(new CallableSignatureRef("aux", 0, "() -> unit")), ReadOnlyList.empty()); final var aggregator = IRBackend.aggregator(); @@ -213,7 +205,6 @@ class IRBackendExecutableContractTest { ReadOnlyList.empty(), ReadOnlyList.from(new IRBackendExecutableFunction( new FileId(1), - "app/main", "entry", new CallableId(0), 0, @@ -225,20 +216,18 @@ class IRBackendExecutableContractTest { ReadOnlyList.from(new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC, "", - "", null, new IRBackendExecutableFunction.IntrinsicCallMetadata("core.color.pack", 1, new IntrinsicId(0)), Span.none())), Span.none())), IRReservedMetadata.empty(), - ReadOnlyList.from(new CallableSignatureRef("app/main", "entry", 0, "() -> unit")), + ReadOnlyList.from(new CallableSignatureRef("entry", 0, "() -> unit")), ReadOnlyList.from(new IntrinsicReference("core.color.pack", 1))); final var fileB = new IRBackendFile( new FileId(2), ReadOnlyList.empty(), ReadOnlyList.from(new IRBackendExecutableFunction( new FileId(2), - "app/main", "aux", new CallableId(0), 11, @@ -250,13 +239,12 @@ class IRBackendExecutableContractTest { ReadOnlyList.from(new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC, "", - "", null, new IRBackendExecutableFunction.IntrinsicCallMetadata("core.color.pack", 1, new IntrinsicId(0)), Span.none())), Span.none())), IRReservedMetadata.empty(), - ReadOnlyList.from(new CallableSignatureRef("app/main", "aux", 0, "() -> unit")), + ReadOnlyList.from(new CallableSignatureRef("aux", 0, "() -> unit")), ReadOnlyList.from(new IntrinsicReference("core.color.pack", 1))); final var aggregator = IRBackend.aggregator(); @@ -280,7 +268,6 @@ class IRBackendExecutableContractTest { ReadOnlyList.empty(), ReadOnlyList.from(new IRBackendExecutableFunction( new FileId(7), - "app/main", "main", new CallableId(0), 10, @@ -292,13 +279,12 @@ class IRBackendExecutableContractTest { ReadOnlyList.from(new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.RET, "", - "", null, null, instructionSpan)), functionSpan)), IRReservedMetadata.empty(), - ReadOnlyList.from(new CallableSignatureRef("app/main", "main", 0, "() -> unit")), + ReadOnlyList.from(new CallableSignatureRef("main", 0, "() -> unit")), ReadOnlyList.empty()); final var aggregator = IRBackend.aggregator(); @@ -323,7 +309,6 @@ class IRBackendExecutableContractTest { ReadOnlyList.from(new IRBackendExecutableFunction( new FileId(1), new ModuleId(0), - "app:mod/a", "entry", new CallableId(0), 0, @@ -335,14 +320,13 @@ class IRBackendExecutableContractTest { ReadOnlyList.from(new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.RET, "", - "", null, null, Span.none())), Span.none())), IRReservedMetadata.empty(), ReadOnlyList.from(new ModuleReference("app", ReadOnlyList.from("mod", "a"))), - ReadOnlyList.from(new CallableSignatureRef(new ModuleId(0), "app:mod/a", "entry", 0, "() -> unit")), + ReadOnlyList.from(new CallableSignatureRef(new ModuleId(0), "entry", 0, "() -> unit")), ReadOnlyList.empty()); final var fileB = new IRBackendFile( new FileId(2), @@ -350,7 +334,6 @@ class IRBackendExecutableContractTest { ReadOnlyList.from(new IRBackendExecutableFunction( new FileId(2), new ModuleId(0), - "app:mod/b", "aux", new CallableId(0), 6, @@ -362,14 +345,13 @@ class IRBackendExecutableContractTest { ReadOnlyList.from(new IRBackendExecutableFunction.Instruction( IRBackendExecutableFunction.InstructionKind.RET, "", - "", null, null, Span.none())), Span.none())), IRReservedMetadata.empty(), ReadOnlyList.from(new ModuleReference("app", ReadOnlyList.from("mod", "b"))), - ReadOnlyList.from(new CallableSignatureRef(new ModuleId(0), "app:mod/b", "aux", 0, "() -> unit")), + ReadOnlyList.from(new CallableSignatureRef(new ModuleId(0), "aux", 0, "() -> unit")), ReadOnlyList.empty()); final var aggregator = IRBackend.aggregator();