Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Add default valued attributes #3305

Merged
merged 6 commits into from
Oct 16, 2024
Merged

core: Add default valued attributes #3305

merged 6 commits into from
Oct 16, 2024

Conversation

alexarice
Copy link
Collaborator

Adds the equivalents for the tablegen DefaultValuedAttribute and DefaultValuedOptionalAttribute.

This is a blocker for updating mlir.


@zero9178, would you be able to check if the test cases agree with what you think mlir should be doing, as you seemed to have some idea about what was going on here when I last asked about this.

Lastly is there a nice python way to specify that an opt_prop_def should return an Attribute instead of Attribute | None when it is specified with a default value?

@alexarice alexarice self-assigned this Oct 15, 2024
@alexarice alexarice added the core xDSL core (ir, textual format, ...) label Oct 15, 2024
Copy link

codecov bot commented Oct 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.03%. Comparing base (84a215d) to head (91d67cd).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3305      +/-   ##
==========================================
+ Coverage   90.01%   90.03%   +0.01%     
==========================================
  Files         445      445              
  Lines       55965    56166     +201     
  Branches     5364     5390      +26     
==========================================
+ Hits        50379    50571     +192     
- Misses       4177     4179       +2     
- Partials     1409     1416       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@zero9178 zero9178 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me and the implementation seems to capture the nuances of the differences between optional and non-optional default values attributes/properties as far as I can tell. Just one test-case is missing for full branch coverage I believe.

Comment on lines 2111 to 2119
parsed = Parser(ctx, "test.default").parse_operation()

assert isinstance(parsed, DefaultOp)

assert parsed.def_prop.value.data == 0

assert parsed.def_opt_prop is not None

assert parsed.def_opt_prop.value.data == 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add a test here where we parse in the operation as a generic but don't specify in the dictionary an optioanl attribute/property?

In MLIR the auto-generated getter (say getDefOptProp) should then still return True, while getAttr("def_opt_propt") would return null/missing

assert parsed.opt_attr.value.data == 1


def test_generic_accessors():
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this test particularly but also the one above it should probably not live here, but am not sure exactly where they should go

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving it to test_operation_definition.py

@alexarice
Copy link
Collaborator Author

Also added some overloads to opt_attr_def and opt_prop_def so that pyright knows that the accessor always returns an attribute when a default value is specified

@alexarice
Copy link
Collaborator Author

I hit a bug with renamed properties when continuing to update mlir. Should hopefully be fixed in latest commit

Copy link
Collaborator

@math-fehr math-fehr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool!
I find ODS semantics quite weird, I didn't know you could have optional attributes with default values, I think it completely breaks the roundtripping.
Thanks for looking at it and implementing it!

@alexarice alexarice merged commit 543bc95 into main Oct 16, 2024
14 checks passed
@alexarice alexarice deleted the alexarice/default branch October 16, 2024 13:10
EdmundGoodman pushed a commit to EdmundGoodman/xdsl that referenced this pull request Dec 6, 2024
Adds the equivalents for the tablegen `DefaultValuedAttribute` and
`DefaultValuedOptionalAttribute`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core xDSL core (ir, textual format, ...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants