Skip to content

Centralize Symbol trait behavior as trait binding metadata #164

@jonathanvdc

Description

@jonathanvdc

Problem

Symbol trait behavior is real MLIR semantics, but the generator currently handles it with scattered checks for the Symbol trait and the sym_name attribute. This creates special cases in member planning, property emission, and custom assembly rebuilding.

Trait-driven behavior should be represented in a centralized trait binding model.

Current Hotspots

  • src/MLIR.Generators/Emitters/Operations/OperationMemberPlanner.cs: maps sym_name to SymbolName
  • src/MLIR.Generators/Emitters/Operations/OperationMemberPlanner.cs: suppresses generic sym_name typing in some paths
  • src/MLIR.Generators/Emitters/Operations/OperationPropertyEmitter.cs: emits SymbolName
  • src/MLIR.Generators/Emitters/AssemblyFormat/BuildCustomAssemblySyntaxEmitter.cs: maps assembly variable sym_name back to SymbolName

Proposed Direction

Introduce trait binding metadata, for example:

public sealed class TraitBindingModel
{
    public string TraitRecordName { get; }
    public IReadOnlyList<GeneratedPropertyBinding> Properties { get; }
    public IReadOnlyList<string> SuppressedAttributeProperties { get; }
    public string? OperationBaseType { get; }
}

The Symbol trait binding would contribute:

  • SymbolName property
  • backing attribute: sym_name
  • storage/public type: string via builtin StringAttr
  • suppression of generic SymName
  • assembly-format variable alias from sym_name to SymbolName

Acceptance Criteria

  • Symbol trait behavior is described in one centralized trait binding location.
  • Operation member planning consumes trait bindings instead of checking Symbol directly.
  • Operation property emission consumes generated property bindings instead of hardcoding SymbolName.
  • Custom assembly syntax rebuild resolves trait-provided aliases without ad hoc sym_name logic.
  • Existing symbol operations keep the SymbolName API and avoid duplicate SymName properties.

Suggested Tests

  • Generated symbol op exposes SymbolName.
  • Generated symbol op does not also expose generic SymName.
  • SymbolName getter/setter round-trips through sym_name and builtin StringAttr.
  • Custom assembly involving $sym_name rebuilds from SymbolName.
  • Non-symbol op with an attribute named sym_name follows normal attribute behavior.

Notes

This issue intentionally keeps the Symbol special case semantically, but moves it out of emitter control flow and into trait metadata.

Metadata

Metadata

Assignees

No one assigned

    Labels

    code qualitygeneratorRelated to the ODS to C# generator logicods 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