Skip to content

Support C# member mappings for MLIR AttrInterface records via TableGen extends overlays #179

@jonathanvdc

Description

@jonathanvdc

Problem

Issue #155 established a metadata-driven mechanism for projecting selected upstream TypeInterface records into member-bearing C# interfaces via MLIR.NET extends overlays, and for letting generated TypeDef classes satisfy those members through matching generated properties or explicit implementation expressions.

That mechanism is currently limited to TypeInterface and generated TypeDef classes. Upstream AttrInterface records are still treated as marker-only metadata in generated C#.

This leaves a gap for attribute-oriented interfaces whose getter-like API should surface as real C# members on generated AttrDef classes.

Proposed Change

Extend the interface overlay/import/generation pipeline to support AttrInterface records and generated AttrDef classes.

Specifically:

  • import MLIRNet_InterfaceExtension metadata on AttrInterface records into the ODS model;
  • emit member-bearing partial C# interfaces for mapped AttrInterface records, while preserving marker-only emission when no csharpMembers are present;
  • teach generated AttrDef classes to satisfy mapped interface members by:
    • reusing compatible generated public members when they already exist;
    • otherwise emitting members from explicit csharpInterfaceImplementations overlay expressions;
    • otherwise producing a clear generator diagnostic.

The implementation should reuse the generic overlay-based mechanism introduced for type interfaces, not introduce per-interface generator branches.

Design Principles

  • Keep the mechanism generic and metadata-driven.
  • Do not special-case specific upstream attribute interfaces in the generator.
  • Preserve marker-only behavior for unmapped interfaces.
  • Prefer property mappings for getter-like upstream methods.
  • Keep generated interfaces partial so handwritten extensions remain possible.
  • Preserve existing generated attribute behavior when no interface mapping is present.

Out Of Scope

  • Operation interface support.
  • Automatic translation of arbitrary C++ interface signatures to C#.
  • Runtime verification of interface constraints.
  • Handwritten runtime attribute types outside generated AttrDef output.
  • Mapped interface methods with parameters; this issue is primarily about carrying the current property-focused mechanism over to attributes.

Acceptance Criteria

  • AttrInterface records can carry MLIRNet_InterfaceExtension metadata through import.
  • Generated C# emits member-bearing partial interfaces for mapped AttrInterface records.
  • Generated AttrDef classes reuse compatible generated members when they already satisfy the mapped contract.
  • Generated AttrDef classes emit explicit implementation members from csharpInterfaceImplementations when needed.
  • Missing implementations for mapped attribute interfaces produce a clear diagnostic.
  • Add importer and generator tests using a small local attribute interface and attr def.
  • Preserve existing marker-only behavior for unmapped AttrInterface records.

Metadata

Metadata

Assignees

No one assigned

    Labels

    generatorRelated to the ODS to C# generator logicnew featureIntroduces a new feature or support for a currently-unsupported upstream MLIR constructods modelRelated to the ODS model and importer (MLIR.ODS)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions