implements PR-08.4
This commit is contained in:
+77
@@ -33,6 +33,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class PBSFrontendPhaseServiceTest {
|
||||
@@ -138,6 +139,82 @@ class PBSFrontendPhaseServiceTest {
|
||||
assertEquals("good", irBackend.getFunctions().getFirst().name());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldEmitCallFuncWithCalleeModuleIdentityFromResolvedTarget() throws IOException {
|
||||
final var projectRoot = tempDir.resolve("project-callsite-module-identity");
|
||||
final var sourceRoot = projectRoot.resolve("src");
|
||||
final var moduleAPath = sourceRoot.resolve("a");
|
||||
final var moduleBPath = sourceRoot.resolve("b");
|
||||
Files.createDirectories(moduleAPath);
|
||||
Files.createDirectories(moduleBPath);
|
||||
|
||||
final var sourceA = moduleAPath.resolve("source.pbs");
|
||||
final var barrelA = moduleAPath.resolve("mod.barrel");
|
||||
Files.writeString(sourceA, """
|
||||
fn target() -> int {
|
||||
return 1;
|
||||
}
|
||||
""");
|
||||
Files.writeString(barrelA, "pub fn target() -> int;");
|
||||
|
||||
final var sourceB = moduleBPath.resolve("source.pbs");
|
||||
final var barrelB = moduleBPath.resolve("mod.barrel");
|
||||
Files.writeString(sourceB, """
|
||||
import { target } from @app:a;
|
||||
|
||||
fn caller() -> int {
|
||||
return target();
|
||||
}
|
||||
""");
|
||||
Files.writeString(barrelB, "pub fn caller() -> int;");
|
||||
|
||||
final var projectTable = new ProjectTable();
|
||||
final var fileTable = new FileTable(1);
|
||||
final var projectId = projectTable.register(ProjectDescriptor.builder()
|
||||
.rootPath(projectRoot)
|
||||
.name("app")
|
||||
.version("1.0.0")
|
||||
.sourceRoots(ReadOnlyList.wrap(List.of(sourceRoot)))
|
||||
.build());
|
||||
|
||||
registerFile(projectId, projectRoot, sourceA, fileTable);
|
||||
registerFile(projectId, projectRoot, barrelA, fileTable);
|
||||
registerFile(projectId, projectRoot, sourceB, fileTable);
|
||||
registerFile(projectId, projectRoot, barrelB, fileTable);
|
||||
|
||||
final var ctx = new FrontendPhaseContext(
|
||||
projectTable,
|
||||
fileTable,
|
||||
new BuildStack(ReadOnlyList.wrap(List.of(projectId))));
|
||||
final var diagnostics = DiagnosticSink.empty();
|
||||
|
||||
final var irBackend = new PBSFrontendPhaseService().compile(
|
||||
ctx,
|
||||
diagnostics,
|
||||
LogAggregator.empty(),
|
||||
BuildingIssueSink.empty());
|
||||
|
||||
assertTrue(diagnostics.isEmpty(), diagnostics.stream().map(d -> d.getCode() + ":" + d.getMessage()).toList().toString());
|
||||
|
||||
final var targetFn = irBackend.getExecutableFunctions().stream()
|
||||
.filter(function -> "target".equals(function.callableName()))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
final var callerFn = irBackend.getExecutableFunctions().stream()
|
||||
.filter(function -> "caller".equals(function.callableName()))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
final var callInstruction = callerFn.instructions().stream()
|
||||
.filter(instruction -> instruction.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.CALL_FUNC)
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
|
||||
assertNotNull(callInstruction.calleeModuleId());
|
||||
assertEquals(targetFn.moduleId().getIndex(), callInstruction.calleeModuleId().getIndex());
|
||||
assertEquals(targetFn.moduleKey(), callInstruction.calleeModuleKey());
|
||||
assertTrue(callerFn.moduleId().getIndex() != callInstruction.calleeModuleId().getIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldLowerAllSourcesWhenNoAdmissionErrorsExist() throws IOException {
|
||||
final var projectRoot = tempDir.resolve("project-valid");
|
||||
|
||||
Reference in New Issue
Block a user