-
Notifications
You must be signed in to change notification settings - Fork 72
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 BitEnumAttribute
#2617
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2617 +/- ##
==========================================
- Coverage 89.85% 89.84% -0.01%
==========================================
Files 413 413
Lines 51852 51888 +36
Branches 8006 8011 +5
==========================================
+ Hits 46592 46620 +28
- Misses 3970 3975 +5
- Partials 1290 1293 +3 ☔ View full report in Codecov by Sentry. |
Ah, @zero9178, now it's just the formatting failing, should be easy enough to get working locally for you, then should be good to open up for review when you're ready |
BitEnumAttribute
BitEnumAttribute
8b06f3f
to
1391b8b
Compare
Currently taking over, I'm splitting this PR in multiple ones as well |
@math-fehr what's the latest on this? |
Sorry about this. I merged part of it (the parsing for enums) but now I don't have time anymore to continue it in the next month. |
c66c49b
to
6c0a1a9
Compare
d94f49d
to
147d745
Compare
BitEnumAttribute
BitEnumAttribute
I rebased this, fixed some things and added tests and documentation. I think it's ready for review! |
xdsl/ir/core.py
Outdated
|
||
cls.enum_type = enum_type | ||
super().__init__(tuple(cast(set[EnumType], flags_))) |
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.
Is the cast here necessary? it seems that all the branches above set it to the expected 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.
Hmm, the branches do set it to StrEnum, set[StrEnum] does not equal set[EnumType]
Expression of type "set[StrEnum] is imcompatible with return type "set[EnumType]"
Even though EnumType = TypeVar('EnumType', bound=StrEnum)
This is because cls.enumtype is StrEnum
. I cannot hovewer make this EnumType
, as it is illegal to have a typevar as a classvariable
if value is None: | ||
return None | ||
|
||
return {cast(type[EnumType], cls.enum_type)(value)} |
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.
ditto
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.
And below
The
BitEnumAttribute
is meant to be the equivalent ofBitEnumAttr
in MLIR: https://github.com/llvm/llvm-project/blob/e67f2cc3fc38cec2041cfb197ac4688ed3d16e7e/mlir/include/mlir/IR/EnumAttr.td#L266It allows defining an attribute which in abstract is a set of flag values where each flag value is defined within an enum.
The base class is meant to be easy to use like
EnumAttribute
and automatically define suitable parsers and printers.For an in-tree user that is converted by this PR see
FastMathAttr
in the LLVM and arith dialects.