-
Notifications
You must be signed in to change notification settings - Fork 80
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: (arith) split generic binary op definition into specific ones #3274
Conversation
@@ -214,10 +213,15 @@ def __hash__(self) -> int: | |||
return id(self) | |||
|
|||
|
|||
SignlessIntegerBinaryOp = BinaryOperation[Annotated[Attribute, signlessIntegerLike]] | |||
class FloatingPointLikeBinaryOperation(IRDLOperation, abc.ABC): |
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.
turns out all the floating ops below are actually with fastmath
Annotated[Attribute, floatingPointLike] | ||
] | ||
|
||
IntegerBinaryOp = BinaryOperation[IntegerType] |
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 used
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3274 +/- ##
=======================================
Coverage 89.98% 89.98%
=======================================
Files 444 444
Lines 55628 55631 +3
Branches 5352 5353 +1
=======================================
+ Hits 50057 50060 +3
Misses 4174 4174
Partials 1397 1397 ☔ 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.
🚀
Sad to see it gone, but it doesn't matter that much I guess
@classmethod | ||
def constr( | ||
cls, | ||
*, | ||
n: GenericAttrConstraint[Attribute] | None = None, | ||
p: GenericAttrConstraint[_T] | None = None, | ||
q: GenericAttrConstraint[Attribute] | None = None, | ||
) -> BaseAttr[ParamOne[Attribute]] | ParamAttrConstraint[ParamOne[_T]]: | ||
if n is None and p is None and q is None: | ||
return BaseAttr(cls) | ||
return ParamAttrConstraint(cls, (n, p, q)) | ||
|
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.
Are those changes related?
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
@@ -271,7 +273,7 @@ def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]: | |||
|
|||
|
|||
@irdl_op_definition | |||
class Addi(SignlessIntegerBinaryOp): | |||
class Addi(SignlessIntegerBinaryOperation): |
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.
Any particular reason to change the name 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.
The undocumented recommendation is for ABCs to have the full Operation and concrete ops to have Op as a suffix
@@ -15,7 +15,8 @@ | |||
|
|||
# map the arith operation to the right varith op: | |||
ARITH_TO_VARITH_TYPE_MAP: dict[ | |||
type[arith.BinaryOperation[Attribute]], type[varith.VarithOp] | |||
type[arith.SignlessIntegerBinaryOperation | arith.FloatingPointLikeBinaryOperation], |
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 worth making a type alias for this?
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.
IDK, I wouldn't bother
I can't even see the changes Mathieu reviewed, was this just a merging/rebasing mishap? |
Co-authored-by: Alex Rice <alexrice999@hotmail.co.uk>
This makes the next step for Pyright updating easier, as we can't actually properly represent generics in the IRDL constraint system. Currently, the arith base class helpers work because the generics are all specified by the time the ops are "defined" with the annotation. But my proposed solution of replacing the Annotated with VarConstraints means that we need to define the constraint on a specific type already. My understanding is that this is not a functional change, only requiring some clients of the base classes to update the names that they refer to.
Part of #3264
Note stacked PR.