implements PR022

This commit is contained in:
bQUARKz 2026-03-06 11:23:34 +00:00
parent 05258c5363
commit 213c6a2f76
Signed by: bquarkz
SSH Key Fingerprint: SHA256:Z7dgqoglWwoK6j6u4QC87OveEq74WOhFN+gitsxtkf8
6 changed files with 72 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import p.studio.compiler.messages.FrontendPhaseContext;
import p.studio.compiler.models.IRBackend; import p.studio.compiler.models.IRBackend;
import p.studio.compiler.models.ProjectDescriptor; import p.studio.compiler.models.ProjectDescriptor;
import p.studio.compiler.models.SourceHandle; import p.studio.compiler.models.SourceHandle;
import p.studio.compiler.models.SourceKind;
import p.studio.compiler.pbs.PbsFrontendCompiler; import p.studio.compiler.pbs.PbsFrontendCompiler;
import p.studio.compiler.pbs.ast.PbsAst; import p.studio.compiler.pbs.ast.PbsAst;
import p.studio.compiler.pbs.lexer.PbsLexer; import p.studio.compiler.pbs.lexer.PbsLexer;
@ -48,6 +49,7 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
for (final var pId : ctx.stack.reverseTopologicalOrder) { for (final var pId : ctx.stack.reverseTopologicalOrder) {
final var projectDescriptor = ctx.projectTable.get(pId); final var projectDescriptor = ctx.projectTable.get(pId);
final var projectSourceKind = ctx.sourceKind(pId);
final var fileIds = ctx.fileTable.getFiles(pId); final var fileIds = ctx.fileTable.getFiles(pId);
for (final var fId : fileIds) { for (final var fId : fileIds) {
@ -65,7 +67,7 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
final var parseErrorBaseline = diagnostics.errorCount(); final var parseErrorBaseline = diagnostics.errorCount();
final var ast = parseSourceFile(fId, utf8Content, diagnostics); final var ast = parseSourceFile(fId, utf8Content, diagnostics);
moduleUnit.sources.add(new PbsModuleVisibilityValidator.SourceFile(fId, ast)); 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) { if (diagnostics.errorCount() > parseErrorBaseline) {
failedModuleKeys.add(moduleKey); failedModuleKeys.add(moduleKey);
} }
@ -114,6 +116,9 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
continue; continue;
} }
final var irBackendFile = frontendCompiler.compileParsedFile(parsedSource.fileId(), parsedSource.ast(), diagnostics); final var irBackendFile = frontendCompiler.compileParsedFile(parsedSource.fileId(), parsedSource.ast(), diagnostics);
if (parsedSource.sourceKind() == SourceKind.SDK_INTERFACE) {
continue;
}
irBackendAggregator.merge(irBackendFile); irBackendAggregator.merge(irBackendFile);
} }
@ -197,6 +202,7 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
private record ParsedSourceFile( private record ParsedSourceFile(
FileId fileId, FileId fileId,
PbsAst.File ast, PbsAst.File ast,
String moduleKey) { String moduleKey,
SourceKind sourceKind) {
} }
} }

View File

@ -7,8 +7,10 @@ import p.studio.compiler.messages.FrontendPhaseContext;
import p.studio.compiler.models.BuildStack; import p.studio.compiler.models.BuildStack;
import p.studio.compiler.models.ProjectDescriptor; import p.studio.compiler.models.ProjectDescriptor;
import p.studio.compiler.models.SourceHandle; import p.studio.compiler.models.SourceHandle;
import p.studio.compiler.models.SourceKind;
import p.studio.compiler.pbs.linking.PbsLinkErrors; import p.studio.compiler.pbs.linking.PbsLinkErrors;
import p.studio.compiler.source.diagnostics.DiagnosticSink; 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.FileTable;
import p.studio.compiler.source.tables.ProjectTable; import p.studio.compiler.source.tables.ProjectTable;
import p.studio.compiler.utilities.SourceProviderFactory; import p.studio.compiler.utilities.SourceProviderFactory;
@ -173,8 +175,49 @@ class PBSFrontendPhaseServiceTest {
assertEquals(2, irBackend.getFunctions().size()); 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( private void registerFile(
final p.studio.compiler.source.identifiers.ProjectId projectId, final ProjectId projectId,
final Path projectRoot, final Path projectRoot,
final Path file, final Path file,
final FileTable fileTable) throws IOException { final FileTable fileTable) throws IOException {
@ -187,4 +230,5 @@ class PBSFrontendPhaseServiceTest {
attributes.lastModifiedTime().toMillis(), attributes.lastModifiedTime().toMillis(),
SourceProviderFactory.filesystem())); SourceProviderFactory.filesystem()));
} }
} }

View File

@ -13,4 +13,6 @@ public final class ProjectDescriptor {
private final String name; // project name private final String name; // project name
private final String version; // project version private final String version; // project version
private final ReadOnlyList<Path> sourceRoots; // source roots canon paths for the project private final ReadOnlyList<Path> sourceRoots; // source roots canon paths for the project
@Builder.Default
private final SourceKind sourceKind = SourceKind.PROJECT;
} }

View File

@ -0,0 +1,7 @@
package p.studio.compiler.models;
public enum SourceKind {
PROJECT,
SDK_INTERFACE
}

View File

@ -1,6 +1,7 @@
package p.studio.compiler.source.tables; package p.studio.compiler.source.tables;
import p.studio.compiler.models.ProjectDescriptor; import p.studio.compiler.models.ProjectDescriptor;
import p.studio.compiler.models.SourceKind;
import p.studio.compiler.source.identifiers.ProjectId; import p.studio.compiler.source.identifiers.ProjectId;
import java.nio.file.Path; import java.nio.file.Path;
@ -9,4 +10,7 @@ import java.util.Optional;
public interface ProjectTableReader extends DenseTableReader<ProjectId, ProjectDescriptor> { public interface ProjectTableReader extends DenseTableReader<ProjectId, ProjectDescriptor> {
Optional<ProjectDescriptor> optional(Path pathCanon); Optional<ProjectDescriptor> optional(Path pathCanon);
Optional<ProjectId> optionalId(Path pathCanon); Optional<ProjectId> optionalId(Path pathCanon);
default SourceKind sourceKind(final ProjectId projectId) {
return get(projectId).getSourceKind();
}
} }

View File

@ -1,6 +1,8 @@
package p.studio.compiler.messages; package p.studio.compiler.messages;
import p.studio.compiler.models.BuildStack; 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.FileTableReader;
import p.studio.compiler.source.tables.ProjectTableReader; import p.studio.compiler.source.tables.ProjectTableReader;
@ -17,4 +19,8 @@ public class FrontendPhaseContext {
this.fileTable = fileTable; this.fileTable = fileTable;
this.stack = stack; this.stack = stack;
} }
public SourceKind sourceKind(final ProjectId projectId) {
return projectTable.sourceKind(projectId);
}
} }