implements PR029
This commit is contained in:
+1
-5
@@ -64,11 +64,7 @@ public final class PbsFrontendCompiler {
|
||||
return IRBackendFile.empty(fileId);
|
||||
}
|
||||
|
||||
final var admissionErrorBaseline = diagnostics.errorCount();
|
||||
final var reservedMetadata = reservedMetadataExtractor.extract(ast, sourceKind, diagnostics);
|
||||
if (diagnostics.errorCount() > admissionErrorBaseline) {
|
||||
return IRBackendFile.empty(fileId);
|
||||
}
|
||||
final var reservedMetadata = reservedMetadataExtractor.extract(ast, sourceKind);
|
||||
|
||||
final ReadOnlyList<IRFunction> functions = sourceKind == SourceKind.SDK_INTERFACE
|
||||
? ReadOnlyList.empty()
|
||||
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
package p.studio.compiler.pbs;
|
||||
|
||||
public enum PbsLoadErrors {
|
||||
E_LOAD_UNSUPPORTED_RESERVED_METADATA_SURFACE,
|
||||
E_LOAD_DUPLICATE_BUILTIN_SLOT_INDEX,
|
||||
}
|
||||
+18
-57
@@ -2,31 +2,26 @@ package p.studio.compiler.pbs.metadata;
|
||||
|
||||
import p.studio.compiler.models.IRReservedMetadata;
|
||||
import p.studio.compiler.models.SourceKind;
|
||||
import p.studio.compiler.pbs.PbsLoadErrors;
|
||||
import p.studio.compiler.pbs.ast.PbsAst;
|
||||
import p.studio.compiler.source.Span;
|
||||
import p.studio.compiler.source.diagnostics.DiagnosticSink;
|
||||
import p.studio.compiler.source.diagnostics.Diagnostics;
|
||||
import p.studio.compiler.source.diagnostics.RelatedSpan;
|
||||
import p.studio.compiler.pbs.semantics.PbsBuiltinLayoutResolver;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalLong;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class PbsReservedMetadataExtractor {
|
||||
private static final String ATTR_HOST = "Host";
|
||||
private static final String ATTR_BUILTIN_TYPE = "BuiltinType";
|
||||
private static final String ATTR_INTRINSIC_CALL = "IntrinsicCall";
|
||||
private static final String ATTR_BUILTIN_CONST = "BuiltinConst";
|
||||
private static final String ATTR_SLOT = "Slot";
|
||||
|
||||
public IRReservedMetadata extract(
|
||||
final PbsAst.File ast,
|
||||
final SourceKind sourceKind,
|
||||
final DiagnosticSink diagnostics) {
|
||||
final SourceKind sourceKind) {
|
||||
if (sourceKind != SourceKind.SDK_INTERFACE) {
|
||||
return IRReservedMetadata.empty();
|
||||
}
|
||||
@@ -34,6 +29,10 @@ public final class PbsReservedMetadataExtractor {
|
||||
final var hostMethodBindings = new ArrayList<IRReservedMetadata.HostMethodBinding>();
|
||||
final var builtinTypeSurfaces = new ArrayList<IRReservedMetadata.BuiltinTypeSurface>();
|
||||
final var builtinConstSurfaces = new ArrayList<IRReservedMetadata.BuiltinConstSurface>();
|
||||
final var inferredLayoutsByName = PbsBuiltinLayoutResolver.resolve(ast).layouts().stream()
|
||||
.collect(Collectors.toMap(
|
||||
PbsBuiltinLayoutResolver.ResolvedBuiltinLayout::sourceTypeName,
|
||||
layout -> layout));
|
||||
|
||||
for (final var topDecl : ast.topDecls()) {
|
||||
if (topDecl instanceof PbsAst.HostDecl hostDecl) {
|
||||
@@ -41,7 +40,7 @@ public final class PbsReservedMetadataExtractor {
|
||||
continue;
|
||||
}
|
||||
if (topDecl instanceof PbsAst.BuiltinTypeDecl builtinTypeDecl) {
|
||||
extractBuiltinTypeSurface(builtinTypeDecl, builtinTypeSurfaces, diagnostics);
|
||||
extractBuiltinTypeSurface(builtinTypeDecl, inferredLayoutsByName, builtinTypeSurfaces);
|
||||
continue;
|
||||
}
|
||||
if (topDecl instanceof PbsAst.ConstDecl constDecl) {
|
||||
@@ -79,8 +78,8 @@ public final class PbsReservedMetadataExtractor {
|
||||
|
||||
private void extractBuiltinTypeSurface(
|
||||
final PbsAst.BuiltinTypeDecl builtinTypeDecl,
|
||||
final List<IRReservedMetadata.BuiltinTypeSurface> builtinTypeSurfaces,
|
||||
final DiagnosticSink diagnostics) {
|
||||
final Map<String, PbsBuiltinLayoutResolver.ResolvedBuiltinLayout> inferredLayoutsByName,
|
||||
final List<IRReservedMetadata.BuiltinTypeSurface> builtinTypeSurfaces) {
|
||||
final var builtinTypeAttribute = firstAttributeNamed(builtinTypeDecl.attributes(), ATTR_BUILTIN_TYPE);
|
||||
if (builtinTypeAttribute.isEmpty()) {
|
||||
return;
|
||||
@@ -89,45 +88,18 @@ public final class PbsReservedMetadataExtractor {
|
||||
final var builtinTypeMetadata = builtinTypeAttribute.get();
|
||||
final var canonicalTypeName = stringArgument(builtinTypeMetadata, "name").orElse(builtinTypeDecl.name());
|
||||
final var canonicalVersion = longArgument(builtinTypeMetadata, "version").orElse(0L);
|
||||
final var inferredLayout = inferredLayoutsByName.get(builtinTypeDecl.name());
|
||||
|
||||
final var fields = new ArrayList<IRReservedMetadata.BuiltinFieldSurface>(builtinTypeDecl.fields().size());
|
||||
final var firstFieldBySlot = new HashMap<Long, Span>();
|
||||
for (final var field : builtinTypeDecl.fields()) {
|
||||
final var slotAttribute = firstAttributeNamed(field.attributes(), ATTR_SLOT);
|
||||
if (slotAttribute.isEmpty()) {
|
||||
reportUnsupportedSurface(
|
||||
diagnostics,
|
||||
field.span(),
|
||||
"Builtin field '%s' in '%s' requires Slot(index=...) for lowering admission"
|
||||
.formatted(field.name(), builtinTypeDecl.name()));
|
||||
continue;
|
||||
}
|
||||
|
||||
final var slotStart = longArgument(slotAttribute.get(), "index");
|
||||
if (slotStart.isEmpty()) {
|
||||
reportUnsupportedSurface(
|
||||
diagnostics,
|
||||
slotAttribute.get().span(),
|
||||
"Builtin field '%s' in '%s' requires numeric Slot(index=...) for lowering admission"
|
||||
.formatted(field.name(), builtinTypeDecl.name()));
|
||||
continue;
|
||||
}
|
||||
|
||||
final var firstField = firstFieldBySlot.putIfAbsent(slotStart.getAsLong(), field.span());
|
||||
if (firstField != null) {
|
||||
Diagnostics.error(
|
||||
diagnostics,
|
||||
PbsLoadErrors.E_LOAD_DUPLICATE_BUILTIN_SLOT_INDEX.name(),
|
||||
"Duplicate builtin slot index %d in '%s'".formatted(slotStart.getAsLong(), builtinTypeDecl.name()),
|
||||
field.span(),
|
||||
List.of(new RelatedSpan("First builtin field using this slot is here", firstField)));
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int i = 0; i < builtinTypeDecl.fields().size(); i++) {
|
||||
final var field = builtinTypeDecl.fields().get(i);
|
||||
final var slotStart = inferredLayout != null && i < inferredLayout.fields().size()
|
||||
? inferredLayout.fields().get(i).slotStart()
|
||||
: i;
|
||||
fields.add(new IRReservedMetadata.BuiltinFieldSurface(
|
||||
field.name(),
|
||||
typeSurfaceKey(field.typeRef()),
|
||||
slotStart.getAsLong(),
|
||||
slotStart,
|
||||
field.span()));
|
||||
}
|
||||
|
||||
@@ -171,17 +143,6 @@ public final class PbsReservedMetadataExtractor {
|
||||
constDecl.span()));
|
||||
}
|
||||
|
||||
private void reportUnsupportedSurface(
|
||||
final DiagnosticSink diagnostics,
|
||||
final Span span,
|
||||
final String message) {
|
||||
Diagnostics.error(
|
||||
diagnostics,
|
||||
PbsLoadErrors.E_LOAD_UNSUPPORTED_RESERVED_METADATA_SURFACE.name(),
|
||||
message,
|
||||
span);
|
||||
}
|
||||
|
||||
private Optional<PbsAst.Attribute> firstAttributeNamed(
|
||||
final ReadOnlyList<PbsAst.Attribute> attributes,
|
||||
final String attributeName) {
|
||||
|
||||
+4
@@ -472,6 +472,10 @@ public final class PbsParser {
|
||||
if (cursor.match(PbsTokenKind.LEFT_PAREN)) {
|
||||
parseAttributeArguments(arguments);
|
||||
}
|
||||
if ("Slot".equals(name.lexeme())) {
|
||||
report(name, ParseErrors.E_PARSE_INVALID_DECL_SHAPE,
|
||||
"Attribute 'Slot' is not part of PBS syntax; builtin slots are inferred by the compiler");
|
||||
}
|
||||
|
||||
long end = Math.max(leftBracket.end(), name.end());
|
||||
if (cursor.match(PbsTokenKind.RIGHT_BRACKET)) {
|
||||
|
||||
+277
@@ -0,0 +1,277 @@
|
||||
package p.studio.compiler.pbs.semantics;
|
||||
|
||||
import p.studio.compiler.pbs.ast.PbsAst;
|
||||
import p.studio.compiler.source.Span;
|
||||
import p.studio.compiler.source.diagnostics.DiagnosticSink;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public final class PbsBuiltinLayoutResolver {
|
||||
private static final Set<String> BUILTIN_SCALAR_TYPES = Set.of("int", "float", "bool", "str");
|
||||
|
||||
private enum ResolveState {
|
||||
UNVISITED,
|
||||
RESOLVING,
|
||||
RESOLVED,
|
||||
FAILED
|
||||
}
|
||||
|
||||
private enum WidthStatus {
|
||||
OK,
|
||||
CYCLE,
|
||||
FAILED
|
||||
}
|
||||
|
||||
private final Map<String, PbsAst.BuiltinTypeDecl> builtinDeclByName = new LinkedHashMap<>();
|
||||
private final Map<String, ResolveState> stateByBuiltinName = new HashMap<>();
|
||||
private final Map<String, ResolvedBuiltinLayout> resolvedLayouts = new HashMap<>();
|
||||
private final Set<String> reportedCycles = new HashSet<>();
|
||||
private final DiagnosticSink diagnostics;
|
||||
|
||||
private PbsBuiltinLayoutResolver(
|
||||
final PbsAst.File ast,
|
||||
final DiagnosticSink diagnostics) {
|
||||
this.diagnostics = diagnostics;
|
||||
for (final var topDecl : ast.topDecls()) {
|
||||
if (!(topDecl instanceof PbsAst.BuiltinTypeDecl builtinTypeDecl)) {
|
||||
continue;
|
||||
}
|
||||
builtinDeclByName.putIfAbsent(builtinTypeDecl.name(), builtinTypeDecl);
|
||||
}
|
||||
for (final var builtinTypeName : builtinDeclByName.keySet()) {
|
||||
stateByBuiltinName.put(builtinTypeName, ResolveState.UNVISITED);
|
||||
}
|
||||
}
|
||||
|
||||
public static ResolvedBuiltinLayoutTable resolve(final PbsAst.File ast) {
|
||||
return new PbsBuiltinLayoutResolver(ast, null).resolveAll();
|
||||
}
|
||||
|
||||
public static ResolvedBuiltinLayoutTable resolve(
|
||||
final PbsAst.File ast,
|
||||
final DiagnosticSink diagnostics) {
|
||||
return new PbsBuiltinLayoutResolver(ast, diagnostics).resolveAll();
|
||||
}
|
||||
|
||||
private ResolvedBuiltinLayoutTable resolveAll() {
|
||||
for (final var builtinTypeName : builtinDeclByName.keySet()) {
|
||||
resolveBuiltinLayout(builtinTypeName);
|
||||
}
|
||||
return new ResolvedBuiltinLayoutTable(ReadOnlyList.wrap(new ArrayList<>(resolvedLayouts.values())));
|
||||
}
|
||||
|
||||
private WidthResult resolveBuiltinLayout(final String builtinTypeName) {
|
||||
final var state = stateByBuiltinName.getOrDefault(builtinTypeName, ResolveState.UNVISITED);
|
||||
if (state == ResolveState.RESOLVED) {
|
||||
return WidthResult.ok(resolvedLayouts.get(builtinTypeName).totalWidth());
|
||||
}
|
||||
if (state == ResolveState.FAILED) {
|
||||
return WidthResult.failed();
|
||||
}
|
||||
if (state == ResolveState.RESOLVING) {
|
||||
return WidthResult.cycle();
|
||||
}
|
||||
|
||||
final var declaration = builtinDeclByName.get(builtinTypeName);
|
||||
if (declaration == null) {
|
||||
return WidthResult.failed();
|
||||
}
|
||||
|
||||
stateByBuiltinName.put(builtinTypeName, ResolveState.RESOLVING);
|
||||
|
||||
long slotCursor = 0L;
|
||||
var failed = false;
|
||||
final var fieldLayouts = new ArrayList<ResolvedBuiltinFieldLayout>(declaration.fields().size());
|
||||
for (final var field : declaration.fields()) {
|
||||
final var width = resolveFieldWidth(builtinTypeName, field);
|
||||
if (width.status() != WidthStatus.OK) {
|
||||
failed = true;
|
||||
continue;
|
||||
}
|
||||
fieldLayouts.add(new ResolvedBuiltinFieldLayout(
|
||||
field.name(),
|
||||
slotCursor,
|
||||
width.width(),
|
||||
field.span()));
|
||||
slotCursor += width.width();
|
||||
}
|
||||
|
||||
if (failed) {
|
||||
stateByBuiltinName.put(builtinTypeName, ResolveState.FAILED);
|
||||
return WidthResult.failed();
|
||||
}
|
||||
|
||||
final var layout = new ResolvedBuiltinLayout(
|
||||
declaration.name(),
|
||||
slotCursor,
|
||||
ReadOnlyList.wrap(fieldLayouts));
|
||||
resolvedLayouts.put(builtinTypeName, layout);
|
||||
stateByBuiltinName.put(builtinTypeName, ResolveState.RESOLVED);
|
||||
return WidthResult.ok(slotCursor);
|
||||
}
|
||||
|
||||
private WidthResult resolveFieldWidth(
|
||||
final String ownerBuiltinName,
|
||||
final PbsAst.BuiltinFieldDecl field) {
|
||||
final var typeRef = normalizeFieldType(field.typeRef());
|
||||
if (typeRef == null || typeRef.kind() != PbsAst.TypeRefKind.SIMPLE) {
|
||||
reportTypeNotAdmissible(ownerBuiltinName, field, field.typeRef());
|
||||
return WidthResult.failed();
|
||||
}
|
||||
|
||||
if (BUILTIN_SCALAR_TYPES.contains(typeRef.name())) {
|
||||
return WidthResult.ok(1L);
|
||||
}
|
||||
|
||||
final var nestedBuiltin = builtinDeclByName.get(typeRef.name());
|
||||
if (nestedBuiltin == null) {
|
||||
reportTypeNotAdmissible(ownerBuiltinName, field, field.typeRef());
|
||||
return WidthResult.failed();
|
||||
}
|
||||
|
||||
final var nestedWidth = resolveBuiltinLayout(typeRef.name());
|
||||
if (nestedWidth.status() == WidthStatus.OK) {
|
||||
return nestedWidth;
|
||||
}
|
||||
if (nestedWidth.status() == WidthStatus.CYCLE) {
|
||||
reportCycleIfNeeded(typeRef.name(), ownerBuiltinName, field.name(), field.span());
|
||||
return WidthResult.cycle();
|
||||
}
|
||||
|
||||
reportUnresolvableWidth(ownerBuiltinName, field, typeRef.name());
|
||||
return WidthResult.failed();
|
||||
}
|
||||
|
||||
private PbsAst.TypeRef normalizeFieldType(final PbsAst.TypeRef typeRef) {
|
||||
var current = typeRef;
|
||||
while (current != null && current.kind() == PbsAst.TypeRefKind.GROUP) {
|
||||
current = current.inner();
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
private void reportTypeNotAdmissible(
|
||||
final String ownerBuiltinName,
|
||||
final PbsAst.BuiltinFieldDecl field,
|
||||
final PbsAst.TypeRef typeRef) {
|
||||
if (diagnostics == null) {
|
||||
return;
|
||||
}
|
||||
p.studio.compiler.source.diagnostics.Diagnostics.error(
|
||||
diagnostics,
|
||||
PbsSemanticsErrors.E_SEM_BUILTIN_LAYOUT_FIELD_TYPE_NOT_ADMISSIBLE.name(),
|
||||
"Builtin field '%s.%s' uses non-admissible layout type '%s'"
|
||||
.formatted(ownerBuiltinName, field.name(), renderTypeSurface(typeRef)),
|
||||
field.span());
|
||||
}
|
||||
|
||||
private void reportCycleIfNeeded(
|
||||
final String targetBuiltinName,
|
||||
final String ownerBuiltinName,
|
||||
final String ownerFieldName,
|
||||
final Span span) {
|
||||
if (diagnostics == null) {
|
||||
return;
|
||||
}
|
||||
final String cycleKey = ownerBuiltinName == null
|
||||
? "cycle:" + targetBuiltinName
|
||||
: "cycle:" + ownerBuiltinName + "." + ownerFieldName + "->" + targetBuiltinName;
|
||||
if (!reportedCycles.add(cycleKey)) {
|
||||
return;
|
||||
}
|
||||
final var primarySpan = span != null
|
||||
? span
|
||||
: Optional.ofNullable(builtinDeclByName.get(targetBuiltinName))
|
||||
.map(PbsAst.BuiltinTypeDecl::span)
|
||||
.orElse(Span.none());
|
||||
p.studio.compiler.source.diagnostics.Diagnostics.error(
|
||||
diagnostics,
|
||||
PbsSemanticsErrors.E_SEM_BUILTIN_LAYOUT_CYCLIC_COMPOSITION.name(),
|
||||
ownerBuiltinName == null
|
||||
? "Builtin layout cycle detected for '%s'".formatted(targetBuiltinName)
|
||||
: "Builtin field '%s.%s' introduces cyclic builtin layout dependency on '%s'"
|
||||
.formatted(ownerBuiltinName, ownerFieldName, targetBuiltinName),
|
||||
primarySpan);
|
||||
}
|
||||
|
||||
private void reportUnresolvableWidth(
|
||||
final String ownerBuiltinName,
|
||||
final PbsAst.BuiltinFieldDecl field,
|
||||
final String nestedBuiltinName) {
|
||||
if (diagnostics == null) {
|
||||
return;
|
||||
}
|
||||
p.studio.compiler.source.diagnostics.Diagnostics.error(
|
||||
diagnostics,
|
||||
PbsSemanticsErrors.E_SEM_BUILTIN_LAYOUT_UNRESOLVABLE_WIDTH.name(),
|
||||
"Builtin field '%s.%s' cannot resolve flattened layout width for '%s'"
|
||||
.formatted(ownerBuiltinName, field.name(), nestedBuiltinName),
|
||||
field.span());
|
||||
}
|
||||
|
||||
private String renderTypeSurface(final PbsAst.TypeRef typeRef) {
|
||||
if (typeRef == null) {
|
||||
return "void";
|
||||
}
|
||||
return switch (typeRef.kind()) {
|
||||
case SIMPLE -> typeRef.name();
|
||||
case SELF -> "Self";
|
||||
case OPTIONAL -> "optional %s".formatted(renderTypeSurface(typeRef.inner()));
|
||||
case UNIT -> "void";
|
||||
case GROUP -> "(%s)".formatted(renderTypeSurface(typeRef.inner()));
|
||||
case NAMED_TUPLE -> "(%s)".formatted(typeRef.fields().stream()
|
||||
.map(field -> "%s: %s".formatted(field.label(), renderTypeSurface(field.typeRef())))
|
||||
.reduce((left, right) -> left + ", " + right)
|
||||
.orElse(""));
|
||||
case ERROR -> "<error>";
|
||||
};
|
||||
}
|
||||
|
||||
private record WidthResult(
|
||||
WidthStatus status,
|
||||
long width) {
|
||||
static WidthResult ok(final long width) {
|
||||
return new WidthResult(WidthStatus.OK, width);
|
||||
}
|
||||
|
||||
static WidthResult cycle() {
|
||||
return new WidthResult(WidthStatus.CYCLE, 0L);
|
||||
}
|
||||
|
||||
static WidthResult failed() {
|
||||
return new WidthResult(WidthStatus.FAILED, 0L);
|
||||
}
|
||||
}
|
||||
|
||||
public record ResolvedBuiltinLayoutTable(
|
||||
ReadOnlyList<ResolvedBuiltinLayout> layouts) {
|
||||
public Optional<ResolvedBuiltinLayout> findByName(final String builtinTypeName) {
|
||||
for (final var layout : layouts) {
|
||||
if (layout.sourceTypeName().equals(builtinTypeName)) {
|
||||
return Optional.of(layout);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
public record ResolvedBuiltinLayout(
|
||||
String sourceTypeName,
|
||||
long totalWidth,
|
||||
ReadOnlyList<ResolvedBuiltinFieldLayout> fields) {
|
||||
}
|
||||
|
||||
public record ResolvedBuiltinFieldLayout(
|
||||
String fieldName,
|
||||
long slotStart,
|
||||
long slotWidth,
|
||||
Span span) {
|
||||
}
|
||||
}
|
||||
+4
-28
@@ -19,14 +19,12 @@ public final class PbsDeclarationSemanticsValidator {
|
||||
private static final String ATTR_BUILTIN_TYPE = "BuiltinType";
|
||||
private static final String ATTR_BUILTIN_CONST = "BuiltinConst";
|
||||
private static final String ATTR_INTRINSIC_CALL = "IntrinsicCall";
|
||||
private static final String ATTR_SLOT = "Slot";
|
||||
|
||||
private static final Set<String> RESERVED_ATTRIBUTES = Set.of(
|
||||
ATTR_HOST,
|
||||
ATTR_BUILTIN_TYPE,
|
||||
ATTR_BUILTIN_CONST,
|
||||
ATTR_INTRINSIC_CALL,
|
||||
ATTR_SLOT);
|
||||
ATTR_INTRINSIC_CALL);
|
||||
|
||||
private final NameTable nameTable = new NameTable();
|
||||
private final PbsConstSemanticsValidator constSemanticsValidator = new PbsConstSemanticsValidator();
|
||||
@@ -150,6 +148,9 @@ public final class PbsDeclarationSemanticsValidator {
|
||||
}
|
||||
|
||||
constSemanticsValidator.validate(ast, diagnostics);
|
||||
if (interfaceModule) {
|
||||
PbsBuiltinLayoutResolver.resolve(ast, diagnostics);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateStructDeclaration(
|
||||
@@ -448,29 +449,15 @@ public final class PbsDeclarationSemanticsValidator {
|
||||
private void validateBuiltinFieldAttributes(
|
||||
final PbsAst.BuiltinFieldDecl field,
|
||||
final DiagnosticSink diagnostics) {
|
||||
final var slotAttributes = attributesNamed(field.attributes(), ATTR_SLOT);
|
||||
for (final var attribute : field.attributes()) {
|
||||
if (!isReservedAttribute(attribute.name())) {
|
||||
continue;
|
||||
}
|
||||
if (ATTR_SLOT.equals(attribute.name())) {
|
||||
continue;
|
||||
}
|
||||
reportInvalidReservedAttributeTarget(
|
||||
attribute,
|
||||
"Attribute '%s' is not valid on builtin fields".formatted(attribute.name()),
|
||||
diagnostics);
|
||||
}
|
||||
|
||||
if (slotAttributes.size() > 1) {
|
||||
for (int i = 1; i < slotAttributes.size(); i++) {
|
||||
reportDuplicateReservedAttribute(slotAttributes.get(i), ATTR_SLOT, diagnostics);
|
||||
}
|
||||
}
|
||||
|
||||
if (!slotAttributes.isEmpty()) {
|
||||
validateSlotAttributeShape(slotAttributes.getFirst(), diagnostics);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateIntrinsicCallAttributes(
|
||||
@@ -553,17 +540,6 @@ public final class PbsDeclarationSemanticsValidator {
|
||||
}
|
||||
}
|
||||
|
||||
private void validateSlotAttributeShape(
|
||||
final PbsAst.Attribute attribute,
|
||||
final DiagnosticSink diagnostics) {
|
||||
final var args = validateNamedArguments(attribute, Set.of("index"), Set.of(), diagnostics);
|
||||
if (args == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
validateRequiredIntArgument(attribute, args, "index", false, diagnostics);
|
||||
}
|
||||
|
||||
private Map<String, PbsAst.AttributeValue> validateNamedArguments(
|
||||
final PbsAst.Attribute attribute,
|
||||
final Set<String> requiredNames,
|
||||
|
||||
+3
@@ -21,6 +21,9 @@ public enum PbsSemanticsErrors {
|
||||
E_SEM_CONST_INITIALIZER_TYPE_MISMATCH,
|
||||
E_SEM_CONST_CYCLIC_DEPENDENCY,
|
||||
E_SEM_CONST_UNRESOLVED_REFERENCE,
|
||||
E_SEM_BUILTIN_LAYOUT_FIELD_TYPE_NOT_ADMISSIBLE,
|
||||
E_SEM_BUILTIN_LAYOUT_CYCLIC_COMPOSITION,
|
||||
E_SEM_BUILTIN_LAYOUT_UNRESOLVABLE_WIDTH,
|
||||
E_SEM_INVALID_RETURN_INSIDE_CTOR,
|
||||
E_SEM_APPLY_NON_CALLABLE_TARGET,
|
||||
E_SEM_APPLY_UNRESOLVED_OVERLOAD,
|
||||
|
||||
Reference in New Issue
Block a user