implements PR022
This commit is contained in:
parent
05258c5363
commit
213c6a2f76
@ -6,6 +6,7 @@ import p.studio.compiler.messages.FrontendPhaseContext;
|
||||
import p.studio.compiler.models.IRBackend;
|
||||
import p.studio.compiler.models.ProjectDescriptor;
|
||||
import p.studio.compiler.models.SourceHandle;
|
||||
import p.studio.compiler.models.SourceKind;
|
||||
import p.studio.compiler.pbs.PbsFrontendCompiler;
|
||||
import p.studio.compiler.pbs.ast.PbsAst;
|
||||
import p.studio.compiler.pbs.lexer.PbsLexer;
|
||||
@ -48,6 +49,7 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
||||
|
||||
for (final var pId : ctx.stack.reverseTopologicalOrder) {
|
||||
final var projectDescriptor = ctx.projectTable.get(pId);
|
||||
final var projectSourceKind = ctx.sourceKind(pId);
|
||||
final var fileIds = ctx.fileTable.getFiles(pId);
|
||||
|
||||
for (final var fId : fileIds) {
|
||||
@ -65,7 +67,7 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
||||
final var parseErrorBaseline = diagnostics.errorCount();
|
||||
final var ast = parseSourceFile(fId, utf8Content, diagnostics);
|
||||
moduleUnit.sources.add(new PbsModuleVisibilityValidator.SourceFile(fId, ast));
|
||||
parsedSourceFiles.add(new ParsedSourceFile(fId, ast, moduleKey));
|
||||
parsedSourceFiles.add(new ParsedSourceFile(fId, ast, moduleKey, projectSourceKind));
|
||||
if (diagnostics.errorCount() > parseErrorBaseline) {
|
||||
failedModuleKeys.add(moduleKey);
|
||||
}
|
||||
@ -114,6 +116,9 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
||||
continue;
|
||||
}
|
||||
final var irBackendFile = frontendCompiler.compileParsedFile(parsedSource.fileId(), parsedSource.ast(), diagnostics);
|
||||
if (parsedSource.sourceKind() == SourceKind.SDK_INTERFACE) {
|
||||
continue;
|
||||
}
|
||||
irBackendAggregator.merge(irBackendFile);
|
||||
}
|
||||
|
||||
@ -197,6 +202,7 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
||||
private record ParsedSourceFile(
|
||||
FileId fileId,
|
||||
PbsAst.File ast,
|
||||
String moduleKey) {
|
||||
String moduleKey,
|
||||
SourceKind sourceKind) {
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,8 +7,10 @@ import p.studio.compiler.messages.FrontendPhaseContext;
|
||||
import p.studio.compiler.models.BuildStack;
|
||||
import p.studio.compiler.models.ProjectDescriptor;
|
||||
import p.studio.compiler.models.SourceHandle;
|
||||
import p.studio.compiler.models.SourceKind;
|
||||
import p.studio.compiler.pbs.linking.PbsLinkErrors;
|
||||
import p.studio.compiler.source.diagnostics.DiagnosticSink;
|
||||
import p.studio.compiler.source.identifiers.ProjectId;
|
||||
import p.studio.compiler.source.tables.FileTable;
|
||||
import p.studio.compiler.source.tables.ProjectTable;
|
||||
import p.studio.compiler.utilities.SourceProviderFactory;
|
||||
@ -173,8 +175,49 @@ class PBSFrontendPhaseServiceTest {
|
||||
assertEquals(2, irBackend.getFunctions().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSkipIrLoweringForSourcesMarkedAsSdkInterface() throws IOException {
|
||||
final var projectRoot = tempDir.resolve("project-sdk-interface");
|
||||
final var sourceRoot = projectRoot.resolve("src");
|
||||
final var modulePath = sourceRoot.resolve("gfx");
|
||||
Files.createDirectories(modulePath);
|
||||
|
||||
final var sourceFile = modulePath.resolve("source.pbs");
|
||||
final var modBarrel = modulePath.resolve("mod.barrel");
|
||||
Files.writeString(sourceFile, "fn draw() -> int { return 1; }");
|
||||
Files.writeString(modBarrel, "pub fn draw() -> int;");
|
||||
|
||||
final var projectTable = new ProjectTable();
|
||||
final var fileTable = new FileTable(1);
|
||||
final var projectId = projectTable.register(ProjectDescriptor.builder()
|
||||
.rootPath(projectRoot)
|
||||
.name("gfx-sdk")
|
||||
.version("1.0.0")
|
||||
.sourceRoots(ReadOnlyList.wrap(List.of(sourceRoot)))
|
||||
.sourceKind(SourceKind.SDK_INTERFACE)
|
||||
.build());
|
||||
|
||||
registerFile(projectId, projectRoot, sourceFile, fileTable);
|
||||
registerFile(projectId, projectRoot, modBarrel, 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());
|
||||
assertEquals(0, irBackend.getFunctions().size());
|
||||
}
|
||||
|
||||
private void registerFile(
|
||||
final p.studio.compiler.source.identifiers.ProjectId projectId,
|
||||
final ProjectId projectId,
|
||||
final Path projectRoot,
|
||||
final Path file,
|
||||
final FileTable fileTable) throws IOException {
|
||||
@ -187,4 +230,5 @@ class PBSFrontendPhaseServiceTest {
|
||||
attributes.lastModifiedTime().toMillis(),
|
||||
SourceProviderFactory.filesystem()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -13,4 +13,6 @@ public final class ProjectDescriptor {
|
||||
private final String name; // project name
|
||||
private final String version; // project version
|
||||
private final ReadOnlyList<Path> sourceRoots; // source roots canon paths for the project
|
||||
@Builder.Default
|
||||
private final SourceKind sourceKind = SourceKind.PROJECT;
|
||||
}
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
public enum SourceKind {
|
||||
PROJECT,
|
||||
SDK_INTERFACE
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package p.studio.compiler.source.tables;
|
||||
|
||||
import p.studio.compiler.models.ProjectDescriptor;
|
||||
import p.studio.compiler.models.SourceKind;
|
||||
import p.studio.compiler.source.identifiers.ProjectId;
|
||||
|
||||
import java.nio.file.Path;
|
||||
@ -9,4 +10,7 @@ import java.util.Optional;
|
||||
public interface ProjectTableReader extends DenseTableReader<ProjectId, ProjectDescriptor> {
|
||||
Optional<ProjectDescriptor> optional(Path pathCanon);
|
||||
Optional<ProjectId> optionalId(Path pathCanon);
|
||||
default SourceKind sourceKind(final ProjectId projectId) {
|
||||
return get(projectId).getSourceKind();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package p.studio.compiler.messages;
|
||||
|
||||
import p.studio.compiler.models.BuildStack;
|
||||
import p.studio.compiler.models.SourceKind;
|
||||
import p.studio.compiler.source.identifiers.ProjectId;
|
||||
import p.studio.compiler.source.tables.FileTableReader;
|
||||
import p.studio.compiler.source.tables.ProjectTableReader;
|
||||
|
||||
@ -17,4 +19,8 @@ public class FrontendPhaseContext {
|
||||
this.fileTable = fileTable;
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
public SourceKind sourceKind(final ProjectId projectId) {
|
||||
return projectTable.sourceKind(projectId);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user