Goal
Typed-array attribute constraints should no longer have their own attribute-constraint emission kind or per-constraint generated assembly-format shim. Treat them like the other storage-backed attribute constraints: emit a static AttributeConstraintDefinition that points at a reusable runtime assembly format, and rely on the existing global::MLIR.ArrayAttr storage overlays for typed operation properties.
Background
src/MLIR.Generators/Prelude/Extensions/mlir/IR/CommonAttrConstraintsExtensions.td already describes TypedArrayAttrBase-style constraints as global::MLIR.ArrayAttr storage. The specific array constraints refine the public property type and storage conversion through ArrayAttrConstraintHelpers, for example:
csharpStorageType = "global::MLIR.ArrayAttr"
csharpReturnType = "global::System.Collections.Generic.IReadOnlyList<...>"
csharpConvertFromStorage = "global::MLIR.Semantics.Attributes.Collections.ArrayAttrConstraintHelpers.GetItems(...)"
csharpConstBuilderCall = "global::MLIR.Semantics.Attributes.Collections.ArrayAttrConstraintHelpers.Create(...)"
So the generated typed-array constraint classes are not needed as semantic storage. Today the remaining special case is only a generated assembly-format class like:
internal sealed class I32ArrayAttrConstraintAttributeValueAssemblyFormat
: TypedArrayAttributeAssemblyFormat<int>
{
}
The TElement parameter is not used by TypedArrayAttributeAssemblyFormat<TElement> for parsing, binding, or printing: it parses an array literal, binds to ArrayAttr, and rebuilds from ArrayAttr.Value.
Proposed Change
-
Replace TypedArrayAttributeAssemblyFormat<TElement> with a non-generic reusable runtime format.
Suggested shape:
public sealed class TypedArrayAttributeAssemblyFormat : IAttributeAssemblyFormat
{
// same parse/bind/print behavior as the current generic base
}
Keep the existing behavior:
- parse
[ ... ] into ArrayAttributeValueSyntax
- bind with
ArrayAttrConstraintHelpers.BindFromSyntax(...)
- print from reusable
ArrayAttributeValueSyntax when available
- otherwise print from
ArrayAttr.Value
-
Make TypedArrayConstraintCodeStrategy use the normal static-definition path.
It should provide an assembly format expression equivalent to:
new global::MLIR.Dialects.Attributes.Collections.TypedArrayAttributeAssemblyFormat()
This should make typed-array constraints look like dictionary/type/unit/elements constraints from the emitter's point of view.
-
Delete the typed-array-specific emission kind and emitter path.
Remove:
AttributeConstraintEmissionKind.TypedArray
AttributeConstraintEmitter.EmitTypedArrayConstraint(...)
AttributeConstraintEmitter.GetTypedArrayElementTypeName(...)
- generated per-constraint
...AssemblyFormat : TypedArrayAttributeAssemblyFormat<TElement> classes
-
Keep operation property typing and setter/getter behavior driven by AttrModel overlays.
Do not regress the typed public surface for constraints such as:
I32ArrayAttr -> IReadOnlyList<int>
StrArrayAttr -> IReadOnlyList<string>
TypeArrayAttr -> IReadOnlyList<TypeReference>
DictArrayAttr -> IReadOnlyList<NamedAttributeCollection>
These should continue to use ArrayAttrConstraintHelpers.GetItems(...) and ArrayAttrConstraintHelpers.Create(...) from the TableGen extensions.
Acceptance Criteria
- Typed-array constraints are emitted as ordinary static constraint-definition holders.
- No per-typed-array generated assembly format classes are emitted.
- No generated typed-array
AttributeValue subclasses or helper Create/GetItems methods are emitted.
- The runtime has a single reusable typed-array/array attribute assembly format.
- Existing typed-array operation properties remain strongly typed through the
csharpStorageType, csharpReturnType, csharpConvertFromStorage, and csharpConstBuilderCall overlays.
- Remove dead typed-array emission code from
AttributeConstraintEmitter.
Suggested Validation
Run:
dotnet test tests/MLIR.Generators.Tests/MLIR.Generators.Tests.csproj -m:1
dotnet test tests/DialectTests/DialectTests.csproj -m:1
dotnet test tests/MLIR.Tests/MLIR.Tests.csproj -m:1
dotnet build samples/GeneratedDialectConsumer/GeneratedDialectConsumer.csproj -m:1
Strengthen TypedArrayAttrConstraintsAreGeneratedAsConstraintOnlyStaticClasses so it also asserts that typed-array constraints use the reusable runtime assembly format and do not emit per-constraint typed-array assembly-format classes.
Goal
Typed-array attribute constraints should no longer have their own attribute-constraint emission kind or per-constraint generated assembly-format shim. Treat them like the other storage-backed attribute constraints: emit a static
AttributeConstraintDefinitionthat points at a reusable runtime assembly format, and rely on the existingglobal::MLIR.ArrayAttrstorage overlays for typed operation properties.Background
src/MLIR.Generators/Prelude/Extensions/mlir/IR/CommonAttrConstraintsExtensions.tdalready describesTypedArrayAttrBase-style constraints asglobal::MLIR.ArrayAttrstorage. The specific array constraints refine the public property type and storage conversion throughArrayAttrConstraintHelpers, for example:csharpStorageType = "global::MLIR.ArrayAttr"csharpReturnType = "global::System.Collections.Generic.IReadOnlyList<...>"csharpConvertFromStorage = "global::MLIR.Semantics.Attributes.Collections.ArrayAttrConstraintHelpers.GetItems(...)"csharpConstBuilderCall = "global::MLIR.Semantics.Attributes.Collections.ArrayAttrConstraintHelpers.Create(...)"So the generated typed-array constraint classes are not needed as semantic storage. Today the remaining special case is only a generated assembly-format class like:
The
TElementparameter is not used byTypedArrayAttributeAssemblyFormat<TElement>for parsing, binding, or printing: it parses an array literal, binds toArrayAttr, and rebuilds fromArrayAttr.Value.Proposed Change
Replace
TypedArrayAttributeAssemblyFormat<TElement>with a non-generic reusable runtime format.Suggested shape:
Keep the existing behavior:
[ ... ]intoArrayAttributeValueSyntaxArrayAttrConstraintHelpers.BindFromSyntax(...)ArrayAttributeValueSyntaxwhen availableArrayAttr.ValueMake
TypedArrayConstraintCodeStrategyuse the normal static-definition path.It should provide an assembly format expression equivalent to:
This should make typed-array constraints look like dictionary/type/unit/elements constraints from the emitter's point of view.
Delete the typed-array-specific emission kind and emitter path.
Remove:
AttributeConstraintEmissionKind.TypedArrayAttributeConstraintEmitter.EmitTypedArrayConstraint(...)AttributeConstraintEmitter.GetTypedArrayElementTypeName(...)...AssemblyFormat : TypedArrayAttributeAssemblyFormat<TElement>classesKeep operation property typing and setter/getter behavior driven by
AttrModeloverlays.Do not regress the typed public surface for constraints such as:
I32ArrayAttr->IReadOnlyList<int>StrArrayAttr->IReadOnlyList<string>TypeArrayAttr->IReadOnlyList<TypeReference>DictArrayAttr->IReadOnlyList<NamedAttributeCollection>These should continue to use
ArrayAttrConstraintHelpers.GetItems(...)andArrayAttrConstraintHelpers.Create(...)from the TableGen extensions.Acceptance Criteria
AttributeValuesubclasses or helperCreate/GetItemsmethods are emitted.csharpStorageType,csharpReturnType,csharpConvertFromStorage, andcsharpConstBuilderCalloverlays.AttributeConstraintEmitter.Suggested Validation
Run:
Strengthen
TypedArrayAttrConstraintsAreGeneratedAsConstraintOnlyStaticClassesso it also asserts that typed-array constraints use the reusable runtime assembly format and do not emit per-constraint typed-array assembly-format classes.