implements PR-09.2: migrate PBS frontend lowering to ModuleId-only
This commit is contained in:
parent
32ab6d7a76
commit
5c69a02973
@ -79,7 +79,6 @@ public final class PbsFrontendCompiler {
|
|||||||
diagnostics,
|
diagnostics,
|
||||||
sourceKind,
|
sourceKind,
|
||||||
ModuleId.none(),
|
ModuleId.none(),
|
||||||
"",
|
|
||||||
ReadOnlyList.empty(),
|
ReadOnlyList.empty(),
|
||||||
hostAdmissionContext,
|
hostAdmissionContext,
|
||||||
nameTable);
|
nameTable);
|
||||||
@ -93,7 +92,7 @@ public final class PbsFrontendCompiler {
|
|||||||
final FileId fileId,
|
final FileId fileId,
|
||||||
final PbsAst.File ast,
|
final PbsAst.File ast,
|
||||||
final DiagnosticSink diagnostics) {
|
final DiagnosticSink diagnostics) {
|
||||||
return compileParsedFile(fileId, ast, diagnostics, SourceKind.PROJECT, "", HostAdmissionContext.permissiveDefault());
|
return compileParsedFile(fileId, ast, diagnostics, SourceKind.PROJECT, HostAdmissionContext.permissiveDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
public IRBackendFile compileParsedFile(
|
public IRBackendFile compileParsedFile(
|
||||||
@ -101,7 +100,7 @@ public final class PbsFrontendCompiler {
|
|||||||
final PbsAst.File ast,
|
final PbsAst.File ast,
|
||||||
final DiagnosticSink diagnostics,
|
final DiagnosticSink diagnostics,
|
||||||
final SourceKind sourceKind) {
|
final SourceKind sourceKind) {
|
||||||
return compileParsedFile(fileId, ast, diagnostics, sourceKind, "", HostAdmissionContext.permissiveDefault());
|
return compileParsedFile(fileId, ast, diagnostics, sourceKind, HostAdmissionContext.permissiveDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
public IRBackendFile compileParsedFile(
|
public IRBackendFile compileParsedFile(
|
||||||
@ -116,26 +115,6 @@ public final class PbsFrontendCompiler {
|
|||||||
diagnostics,
|
diagnostics,
|
||||||
sourceKind,
|
sourceKind,
|
||||||
ModuleId.none(),
|
ModuleId.none(),
|
||||||
"",
|
|
||||||
ReadOnlyList.empty(),
|
|
||||||
hostAdmissionContext,
|
|
||||||
new NameTable());
|
|
||||||
}
|
|
||||||
|
|
||||||
public IRBackendFile compileParsedFile(
|
|
||||||
final FileId fileId,
|
|
||||||
final PbsAst.File ast,
|
|
||||||
final DiagnosticSink diagnostics,
|
|
||||||
final SourceKind sourceKind,
|
|
||||||
final String moduleKey,
|
|
||||||
final HostAdmissionContext hostAdmissionContext) {
|
|
||||||
return compileParsedFile(
|
|
||||||
fileId,
|
|
||||||
ast,
|
|
||||||
diagnostics,
|
|
||||||
sourceKind,
|
|
||||||
ModuleId.none(),
|
|
||||||
moduleKey,
|
|
||||||
ReadOnlyList.empty(),
|
ReadOnlyList.empty(),
|
||||||
hostAdmissionContext,
|
hostAdmissionContext,
|
||||||
new NameTable());
|
new NameTable());
|
||||||
@ -147,7 +126,6 @@ public final class PbsFrontendCompiler {
|
|||||||
final DiagnosticSink diagnostics,
|
final DiagnosticSink diagnostics,
|
||||||
final SourceKind sourceKind,
|
final SourceKind sourceKind,
|
||||||
final ModuleId moduleId,
|
final ModuleId moduleId,
|
||||||
final String moduleKey,
|
|
||||||
final ReadOnlyList<ModuleReference> modulePool,
|
final ReadOnlyList<ModuleReference> modulePool,
|
||||||
final HostAdmissionContext hostAdmissionContext,
|
final HostAdmissionContext hostAdmissionContext,
|
||||||
final NameTable nameTable) {
|
final NameTable nameTable) {
|
||||||
@ -157,7 +135,6 @@ public final class PbsFrontendCompiler {
|
|||||||
diagnostics,
|
diagnostics,
|
||||||
sourceKind,
|
sourceKind,
|
||||||
moduleId,
|
moduleId,
|
||||||
moduleKey,
|
|
||||||
modulePool,
|
modulePool,
|
||||||
hostAdmissionContext,
|
hostAdmissionContext,
|
||||||
nameTable,
|
nameTable,
|
||||||
@ -172,7 +149,6 @@ public final class PbsFrontendCompiler {
|
|||||||
final DiagnosticSink diagnostics,
|
final DiagnosticSink diagnostics,
|
||||||
final SourceKind sourceKind,
|
final SourceKind sourceKind,
|
||||||
final ModuleId moduleId,
|
final ModuleId moduleId,
|
||||||
final String moduleKey,
|
|
||||||
final ReadOnlyList<ModuleReference> modulePool,
|
final ReadOnlyList<ModuleReference> modulePool,
|
||||||
final HostAdmissionContext hostAdmissionContext,
|
final HostAdmissionContext hostAdmissionContext,
|
||||||
final NameTable nameTable,
|
final NameTable nameTable,
|
||||||
@ -225,7 +201,6 @@ public final class PbsFrontendCompiler {
|
|||||||
ast,
|
ast,
|
||||||
effectiveSupplementalTopDecls,
|
effectiveSupplementalTopDecls,
|
||||||
effectiveModuleId,
|
effectiveModuleId,
|
||||||
moduleKey,
|
|
||||||
effectiveReservedMetadata,
|
effectiveReservedMetadata,
|
||||||
effectiveNameTable,
|
effectiveNameTable,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
@ -261,12 +236,10 @@ public final class PbsFrontendCompiler {
|
|||||||
final PbsAst.File ast,
|
final PbsAst.File ast,
|
||||||
final ReadOnlyList<PbsAst.TopDecl> supplementalTopDecls,
|
final ReadOnlyList<PbsAst.TopDecl> supplementalTopDecls,
|
||||||
final ModuleId moduleId,
|
final ModuleId moduleId,
|
||||||
final String moduleKey,
|
|
||||||
final IRReservedMetadata reservedMetadata,
|
final IRReservedMetadata reservedMetadata,
|
||||||
final NameTable nameTable,
|
final NameTable nameTable,
|
||||||
final DiagnosticSink diagnostics,
|
final DiagnosticSink diagnostics,
|
||||||
final ReadOnlyList<ImportedCallableSurface> importedCallables) {
|
final ReadOnlyList<ImportedCallableSurface> importedCallables) {
|
||||||
final var normalizedModuleKey = moduleKey == null ? "" : moduleKey;
|
|
||||||
final var normalizedModuleId = moduleId == null ? ModuleId.none() : moduleId;
|
final var normalizedModuleId = moduleId == null ? ModuleId.none() : moduleId;
|
||||||
final var hostByMethodName = new HashMap<NameId, List<IRReservedMetadata.HostMethodBinding>>();
|
final var hostByMethodName = new HashMap<NameId, List<IRReservedMetadata.HostMethodBinding>>();
|
||||||
for (final var hostBinding : reservedMetadata.hostMethodBindings()) {
|
for (final var hostBinding : reservedMetadata.hostMethodBindings()) {
|
||||||
@ -405,7 +378,6 @@ public final class PbsFrontendCompiler {
|
|||||||
}
|
}
|
||||||
final var loweringContext = new ExecutableLoweringContext(
|
final var loweringContext = new ExecutableLoweringContext(
|
||||||
normalizedModuleId,
|
normalizedModuleId,
|
||||||
normalizedModuleKey,
|
|
||||||
diagnostics,
|
diagnostics,
|
||||||
nameTable,
|
nameTable,
|
||||||
hostByMethodName,
|
hostByMethodName,
|
||||||
@ -1341,7 +1313,6 @@ public final class PbsFrontendCompiler {
|
|||||||
|
|
||||||
private static final class ExecutableLoweringContext {
|
private static final class ExecutableLoweringContext {
|
||||||
private final ModuleId moduleId;
|
private final ModuleId moduleId;
|
||||||
private final String moduleKey;
|
|
||||||
private final DiagnosticSink diagnostics;
|
private final DiagnosticSink diagnostics;
|
||||||
private final NameTable nameTable;
|
private final NameTable nameTable;
|
||||||
private final Map<NameId, List<IRReservedMetadata.HostMethodBinding>> hostByMethodName;
|
private final Map<NameId, List<IRReservedMetadata.HostMethodBinding>> hostByMethodName;
|
||||||
@ -1359,7 +1330,6 @@ public final class PbsFrontendCompiler {
|
|||||||
|
|
||||||
private ExecutableLoweringContext(
|
private ExecutableLoweringContext(
|
||||||
final ModuleId moduleId,
|
final ModuleId moduleId,
|
||||||
final String moduleKey,
|
|
||||||
final DiagnosticSink diagnostics,
|
final DiagnosticSink diagnostics,
|
||||||
final NameTable nameTable,
|
final NameTable nameTable,
|
||||||
final Map<NameId, List<IRReservedMetadata.HostMethodBinding>> hostByMethodName,
|
final Map<NameId, List<IRReservedMetadata.HostMethodBinding>> hostByMethodName,
|
||||||
@ -1372,7 +1342,6 @@ public final class PbsFrontendCompiler {
|
|||||||
final IntrinsicTable intrinsicIdTable,
|
final IntrinsicTable intrinsicIdTable,
|
||||||
final Map<NameId, Integer> localSlotByNameId) {
|
final Map<NameId, Integer> localSlotByNameId) {
|
||||||
this.moduleId = moduleId == null ? ModuleId.none() : moduleId;
|
this.moduleId = moduleId == null ? ModuleId.none() : moduleId;
|
||||||
this.moduleKey = moduleKey;
|
|
||||||
this.diagnostics = diagnostics;
|
this.diagnostics = diagnostics;
|
||||||
this.nameTable = nameTable;
|
this.nameTable = nameTable;
|
||||||
this.hostByMethodName = hostByMethodName;
|
this.hostByMethodName = hostByMethodName;
|
||||||
@ -1390,10 +1359,6 @@ public final class PbsFrontendCompiler {
|
|||||||
return moduleId;
|
return moduleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String moduleKey() {
|
|
||||||
return moduleKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
private DiagnosticSink diagnostics() {
|
private DiagnosticSink diagnostics() {
|
||||||
return diagnostics;
|
return diagnostics;
|
||||||
}
|
}
|
||||||
@ -1503,7 +1468,6 @@ public final class PbsFrontendCompiler {
|
|||||||
|
|
||||||
public record ImportedCallableSurface(
|
public record ImportedCallableSurface(
|
||||||
ModuleId moduleId,
|
ModuleId moduleId,
|
||||||
String moduleKey,
|
|
||||||
String callableName,
|
String callableName,
|
||||||
int arity,
|
int arity,
|
||||||
int returnSlots,
|
int returnSlots,
|
||||||
|
|||||||
@ -178,7 +178,6 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
|||||||
diagnostics,
|
diagnostics,
|
||||||
parsedSource.sourceKind(),
|
parsedSource.sourceKind(),
|
||||||
parsedSource.moduleId(),
|
parsedSource.moduleId(),
|
||||||
renderModuleKey(moduleTable, parsedSource.moduleId()),
|
|
||||||
canonicalModulePool,
|
canonicalModulePool,
|
||||||
ctx.hostAdmissionContext(),
|
ctx.hostAdmissionContext(),
|
||||||
nameTable,
|
nameTable,
|
||||||
@ -430,7 +429,6 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
|||||||
if (importedTopDeclsByName == null) {
|
if (importedTopDeclsByName == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final var importedModuleKey = renderModuleKey(moduleTable, importedModuleId);
|
|
||||||
importedReservedMetadata = mergeReservedMetadata(
|
importedReservedMetadata = mergeReservedMetadata(
|
||||||
importedReservedMetadata,
|
importedReservedMetadata,
|
||||||
reservedMetadataByModule.getOrDefault(importedModuleId, IRReservedMetadata.empty()));
|
reservedMetadataByModule.getOrDefault(importedModuleId, IRReservedMetadata.empty()));
|
||||||
@ -449,7 +447,6 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
|||||||
importedCallableKeys,
|
importedCallableKeys,
|
||||||
new PbsFrontendCompiler.ImportedCallableSurface(
|
new PbsFrontendCompiler.ImportedCallableSurface(
|
||||||
importedModuleId,
|
importedModuleId,
|
||||||
importedModuleKey,
|
|
||||||
localName + "." + method.name(),
|
localName + "." + method.name(),
|
||||||
method.parameters().size(),
|
method.parameters().size(),
|
||||||
returnSlotsFor(method),
|
returnSlotsFor(method),
|
||||||
@ -463,7 +460,6 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
|||||||
importedCallableKeys,
|
importedCallableKeys,
|
||||||
new PbsFrontendCompiler.ImportedCallableSurface(
|
new PbsFrontendCompiler.ImportedCallableSurface(
|
||||||
importedModuleId,
|
importedModuleId,
|
||||||
importedModuleKey,
|
|
||||||
localName,
|
localName,
|
||||||
functionDecl.parameters().size(),
|
functionDecl.parameters().size(),
|
||||||
returnSlotsFor(functionDecl),
|
returnSlotsFor(functionDecl),
|
||||||
@ -672,7 +668,7 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
|||||||
final ArrayList<PbsFrontendCompiler.ImportedCallableSurface> importedCallables,
|
final ArrayList<PbsFrontendCompiler.ImportedCallableSurface> importedCallables,
|
||||||
final Set<String> importedCallableKeys,
|
final Set<String> importedCallableKeys,
|
||||||
final PbsFrontendCompiler.ImportedCallableSurface importedCallableSurface) {
|
final PbsFrontendCompiler.ImportedCallableSurface importedCallableSurface) {
|
||||||
final var callableKey = importedCallableSurface.moduleKey()
|
final var callableKey = importedCallableSurface.moduleId().getIndex()
|
||||||
+ "#"
|
+ "#"
|
||||||
+ importedCallableSurface.callableName()
|
+ importedCallableSurface.callableName()
|
||||||
+ "#"
|
+ "#"
|
||||||
@ -805,13 +801,6 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
|||||||
return moduleTable.register(new ModuleReference(project, pathSegments));
|
return moduleTable.register(new ModuleReference(project, pathSegments));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String renderModuleKey(
|
|
||||||
final ModuleTable moduleTable,
|
|
||||||
final ModuleId moduleId) {
|
|
||||||
final var moduleReference = moduleTable.get(moduleId);
|
|
||||||
return moduleReference.project() + ":" + String.join("/", moduleReference.pathSegments().asList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private ReadOnlyList<ModuleReference> emitModulePool(final ModuleTable moduleTable) {
|
private ReadOnlyList<ModuleReference> emitModulePool(final ModuleTable moduleTable) {
|
||||||
final var pool = new ArrayList<ModuleReference>(moduleTable.size());
|
final var pool = new ArrayList<ModuleReference>(moduleTable.size());
|
||||||
for (final var moduleId : moduleTable.identifiers()) {
|
for (final var moduleId : moduleTable.identifiers()) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user