-
Notifications
You must be signed in to change notification settings - Fork 77
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
dialects: (builtin) Fix printing and parsing of UnitAttr
#2744
Conversation
xdsl/parser/attribute_parser.py
Outdated
@@ -1250,6 +1250,7 @@ def _parse_optional_integer_or_float_type(self) -> Attribute | None: | |||
Parse as integer or float type, if present. | |||
integer-or-float-type ::= index-type | integer-type | float-type | |||
index-type ::= `index` | |||
unit-attribute ::= `unit` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I first tried to add this as a normal attribute not type, but then the test failed, saying "type expected". I have a supsicion it's actually a type in MLIR also, but my quick search for the definition didn't yield much so I thought I'd open a PR anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not a type, it's an attribute though: https://mlir.llvm.org/docs/Dialects/Builtin/#unitattr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I change the test instead? When I put the code for parsing into parse_attribute
it fails, as the block argument expects a type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which test? And yes, we should change it I think
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2744 +/- ##
==========================================
- Coverage 89.78% 89.77% -0.01%
==========================================
Files 370 370
Lines 47617 47626 +9
Branches 7299 7301 +2
==========================================
+ Hits 42751 42758 +7
- Misses 3730 3731 +1
- Partials 1136 1137 +1 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking at this!
unit
is an attribute, not a type in MLIR, and we should stay the same.
So here I would not add it in the parse_optional_integer_or_float_type
xdsl/parser/attribute_parser.py
Outdated
# Unit type | ||
if name == "unit": | ||
self._consume_token() | ||
return UnitAttr() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the right place to add this though, this is neither an integer nor attribute type?
This reverts commit 5e83ef9.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just some small misc. comments
@@ -8,6 +8,9 @@ | |||
|
|||
// CHECK: (index) | |||
|
|||
"func.func"() ({}) {function_type = () -> (), sym_name = "unit_attr_func", unitarray = [unit]} : () -> () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I suggest using the test
dialect here? I don't think we want to depend on func
here...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree in general, although here it seemed like a good fit for consistency, happy to change it if you or anyone else insist
""" | ||
if self._current_token.kind != Token.Kind.BARE_IDENT: | ||
return None | ||
name = self._current_token.span.text |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
supernit: Not sure this extra variable assignment is needed here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
definitely not, although it doesn't really hurt either
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing the low footprint, I'm guessing this preserves the behaviour of unit attribute being printed as "just a name" in attribute dictionaries?
I had no clue they were handled otherwise in other places 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me now (I would just fix the comment that Emilien pointed)
It's actually
unit
not the empty string.