Skip to content

Support typed arrays of generated enum constraints #133

@jonathanvdc

Description

@jonathanvdc

Goal

Support typed arrays whose element constraint is a pure enum attribute constraint after pure enum wrappers have been removed.

Pure enum constraints inside typed arrays should decode from and encode to global::MLIR.IntegerAttr, not generated enum wrapper classes.

Depends On

  • Pure enum constraints must already store/bind as global::MLIR.IntegerAttr.
  • Pure enum wrapper emission must already be removed.

Files To Inspect First

  • src/MLIR.Generators/AttributeConstraintCodeStrategy.cs
  • src/MLIR.Generators/Emitters/AssemblyFormat/AttributeAssemblyFormatEmitter.cs
  • src/MLIR.Generators/Emitters/AttributeConstraintEmitter.cs
  • src/MLIR.Generators/Emitters/Operations/OperationAttributeValueHelpers.cs
  • tests/MLIR.Generators.Tests/DialectGeneratorTypedAttributeTests.cs
  • tests/MLIR.Generators.Tests/DialectImporterTests.cs

Implementation Steps

  1. Add a generated-source test for a typed array whose element is a pure enum.

    Use an upstream-style shape if the importer already supports it. A representative example:

    include "mlir/IR/EnumAttr.td"
    
    def MINI_MODE_A : I32EnumAttrCase<"a", 0>;
    def MINI_MODE_B : I32EnumAttrCase<"b", 1>;
    
    def MiniEnum_Mode : I32EnumAttr<"Mode", "mode summary", [MINI_MODE_A, MINI_MODE_B]> {
      let cppNamespace = "::mlir::minienum";
    }
    
    def MiniEnum_ModeArray : TypedArrayAttrBase<MiniEnum_Mode, "mode array">;
    

    Then use MiniEnum_ModeArray in an operation argument.

    If this exact TableGen shape is not supported yet, follow the existing typed-array test conventions in the repo and keep the test focused on enum element storage.

  2. Update enum typed-array decode hooks.

    In EnumAttributeConstraintCodeStrategy, implement or adjust typed-array element decoding so it:

    • decodes each element syntax through the structured attribute decoder
    • casts the decoded value to global::MLIR.IntegerAttr
    • converts the integer payload to the generated enum type using the enum info helper
    • falls back consistently when the integer value is unknown
  3. Update enum typed-array encode hooks.

    Ensure generated code converts each enum element back to global::MLIR.IntegerAttr syntax using the enum bitwidth and integer type.

  4. Remove any typed-array dependency on deleted wrapper classes.

    Search generated source and generator source for assumptions like:

    .TypedValue
    AttrConstraintAttributeValue

    Keep .TypedValue only for dedicated EnumAttr generated attribute classes where it still applies.

Acceptance Criteria

  • Typed arrays of pure enum constraints generate code that compiles.
  • Generated typed-array enum paths decode elements from global::MLIR.IntegerAttr.
  • Generated typed-array enum paths encode elements to global::MLIR.IntegerAttr.
  • Generated source does not reference deleted pure enum wrapper classes.
  • Existing EnumAttr AttrDef behavior remains unchanged.

Validation

dotnet test tests/MLIR.Generators.Tests/MLIR.Generators.Tests.csproj

If the change affects normal dialect generation:

dotnet build src/MLIR/MLIR.csproj -m:1 -p:EmitCompilerGeneratedFiles=true -p:CompilerGeneratedFilesOutputPath=obj/Generated
rg -n "AttrConstraintAttributeValue|TypedArray|IntegerAttr|public enum" src/MLIR/obj/Generated/MLIR.Generators/MLIR.Generators.DialectGenerator

Metadata

Metadata

Assignees

No one assigned

    Labels

    new featureIntroduces a new feature or support for a currently-unsupported upstream MLIR construct

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions