Skip to content

core: (assembly format) fix optional typed attribute parsing - #6311

Open
lowbyteguy wants to merge 1 commit into
xdslproject:mainfrom
lowbyteguy:fix/optional-typed-attr-parse
Open

core: (assembly format) fix optional typed attribute parsing#6311
lowbyteguy wants to merge 1 commit into
xdslproject:mainfrom
lowbyteguy:fix/optional-typed-attr-parse

Conversation

@lowbyteguy

@lowbyteguy lowbyteguy commented Jul 27, 2026

Copy link
Copy Markdown

Closes #5562.

An optional attribute variable whose constraint pins a unique typed base is parsed through TypedAttribute.parse_with_type, which has no optional counterpart and raises rather than returning None. So in an optional group like ($index^)? `of`, the absent case failed with Expected integer literal instead of skipping the group — this is what broke pdl_interp.get_operands' assembly format.

TypedAttributeVariable.parse_attr now backtracks to the attribute's start position and returns None when the parse fails in the optional case, matching the optional contract the sibling AttributeVariable implementations already honour.

Regression test added in tests/irdl/test_declarative_assembly_format.py alongside the existing optional-property tests, covering both the present and absent forms; it fails on main and passes with the fix.

An optional attribute variable with a unique typed base parsed via
`TypedAttribute.parse_with_type`, which has no optional counterpart and
raises instead of returning None. In an optional group such as
`($index^)? `of` ...` the absent case therefore failed with
"Expected integer literal" rather than skipping the group.

Backtrack to the attribute's start position and return None when
`parse_with_type` raises, matching the optional contract of the sibling
`AttributeVariable.parse_attr` implementations.

Adds a regression test for an optional `IntegerAttr` property in an
optional group, present and absent.
@superlopuh

Copy link
Copy Markdown
Member

Hi, sorry for the delay in reviewing. I don't think this is the right approach. We would want to make more fundamental changes to the assembly format infrastructure, more closely mirroring the existing Parser convention of parse and parse_optional. I'm happy to give pointers on the kind of class structure I have in mind, but just wanted to warn you that there are likely to be quite a lot of changes first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assembly format with optional IntegerAttr property doesn't parse

2 participants