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

dialects: (arith) split generic binary op definition into specific ones #3274

Merged
merged 7 commits into from
Oct 10, 2024

Conversation

superlopuh
Copy link
Member

@superlopuh superlopuh commented Oct 9, 2024

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.

@superlopuh superlopuh added the dialects Changes on the dialects label Oct 9, 2024
@superlopuh superlopuh requested a review from math-fehr October 9, 2024 23:27
@superlopuh superlopuh self-assigned this Oct 9, 2024
@@ -214,10 +213,15 @@ def __hash__(self) -> int:
return id(self)


SignlessIntegerBinaryOp = BinaryOperation[Annotated[Attribute, signlessIntegerLike]]
class FloatingPointLikeBinaryOperation(IRDLOperation, abc.ABC):
Copy link
Member Author

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]
Copy link
Member Author

Choose a reason for hiding this comment

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

this is not used

Copy link

codecov bot commented Oct 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.98%. Comparing base (ff389e4) to head (e1dcd12).
Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

Base automatically changed from sasha/misc/all-constr to main October 9, 2024 23:34
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.

🚀
Sad to see it gone, but it doesn't matter that much I guess

Comment on lines 1667 to 1678
@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))

Copy link
Collaborator

Choose a reason for hiding this comment

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

Are those changes related?

tests/tblgen_to_py/test.py Outdated Show resolved Hide resolved
xdsl/dialects/builtin.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@alexarice alexarice left a comment

Choose a reason for hiding this comment

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

Looks good

xdsl/dialects/arith.py Outdated Show resolved Hide resolved
@@ -271,7 +273,7 @@ def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:


@irdl_op_definition
class Addi(SignlessIntegerBinaryOp):
class Addi(SignlessIntegerBinaryOperation):
Copy link
Collaborator

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?

Copy link
Member Author

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],
Copy link
Collaborator

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?

Copy link
Member Author

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

@alexarice
Copy link
Collaborator

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>
xdsl/dialects/arith.py Outdated Show resolved Hide resolved
@superlopuh superlopuh merged commit 964834a into main Oct 10, 2024
14 checks passed
@superlopuh superlopuh deleted the sasha/misc/arith-split-ops branch October 10, 2024 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dialects Changes on the dialects
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants