[WIP] core: Enable assembly_format on types and attrs#5907
Open
n-io wants to merge 9 commits into
Open
Conversation
Add the foundational classes for a declarative assembly format system for ParametrizedAttribute types, mirroring the existing op-side system: AttrFormatDirective ABC, structural directives (whitespace, punctuation, keyword), ParameterVariable, AttrFormatProgram, and AttrFormatParser.
…nition Integrate the attr declarative assembly format into the attribute definition system. ParametrizedAttribute subclasses can now set assembly_format = "..." to auto-generate parse_parameters and print_parameters methods.
Add AttrOptionalGroupDirective and parse_optional_group to support optional groups in attribute/type declarative assembly formats, enabling conditional parameter parsing with else branches.
Add QualifiedParameterVariable (no-op in xdsl since print_attribute always qualifies) and parse_qualified_directive for MLIR format compatibility.
Add ParamsDirective that captures all parameters of an attribute and prints them comma-separated. Includes _all_param_variables helper in AttrFormatParser, with tests for basic, three-param, and optional cases.
Add StructDirective that prints parameters as key=value pairs and parses them in any order. Supports struct(params) for all parameters and struct($a, $b) for a subset.
Add AttrCustomDirective ABC and irdl_attr_custom_directive decorator for user-defined assembly format directives in attribute/type formats, mirroring the existing CustomDirective system for operations.
Add parse_possible_ref_directive to support ref($var) inside custom directive arguments, allowing a parameter to be referenced without re-binding it.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## nicolai/attr-asm-fmt-pt7-custom-v2 #5907 +/- ##
======================================================================
- Coverage 86.22% 86.22% -0.01%
======================================================================
Files 418 418
Lines 60297 60302 +5
Branches 7010 7011 +1
======================================================================
+ Hits 51990 51994 +4
- Misses 6695 6696 +1
Partials 1612 1612 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
superlopuh
reviewed
Apr 21, 2026
| params.append(param) | ||
| return directive(*params) | ||
|
|
||
| def parse_possible_ref_directive(self) -> AttrFormatDirective: |
Member
There was a problem hiding this comment.
what does "possible" mean here?
Collaborator
Author
There was a problem hiding this comment.
This mirrors the op-side parser's parse_possible_ref_directive function.
Collaborator
|
Just wanted to add, for the sake of encouragement, that I'm excited to have this feature! |
The op-side WhitespaceDirective, PunctuationDirective and KeywordDirective now delegate their print logic to the shared _print_whitespace / _print_punctuation / _print_keyword helpers instead of duplicating it, matching how the attr-side directives already use them.
n-io
added a commit
that referenced
this pull request
Jul 9, 2026
Adding foundational classes for a declarative assembly format system, mirroring the implementations for op assembly format. The existing format directives are tightly wired to operations, so this PR proposes instead to have a separate hierarchy based on AttrFormatDirective to keep the systems separate which helped keep the implementation clean. This first PR contains only the plumbing — the `AttrFormatDirective` base class, `AttrFormatProgram`, and an `AttrFormatParser` skeleton — and currently supports only the empty format; concrete directives follow in later PRs. The `AttrFormatProgram` and `AttrFormatParser` resemble what is implemented for operations. This PR is the first in a stacked series to enable full support for attribute/type assembly_format. See also: * #5907
n-io
added a commit
that referenced
this pull request
Jul 13, 2026
Adds `AttrWhitespaceDirective` to declarative assembly format for attributes. WIP: * #5907
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Work-in-progress PR for enabling full support for
assembly_formaton attributes and types in xDSL.Declarative
assembly_formatexists for operations, but currently not for types and attributes. The implementation of existing format directives is tightly wired to operations, so the proposal is instead to have a separate hierararchy based on AttrFormatDirective to keep the systems separate which helped keep the implementation clean. TheAttrFormatProgramandAttrFormatParserresemble what is implemented for operations.Note:
An alternative implementation I have considered was using multiple-inheritance, for instance,
class WhitespaceDirective(FormatDirective, AttrFormatDirective). However, this runs into the problem that on the op-side,DirectiveusesIRDLOperationandFormatDirectiveusesParsingState. Conversely, there appears to be very little overhead in having two separateWhitespaceDirective(FormatDirective)andAttrWhitespaceDirective(AttrFormatDirective)classes with shared code between these two, which appears to lead to an overall more elegant and less invasive design.This is the [WIP] PR for enabling full support for attribute/type assembly_format: