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

refactor[next]: Use is_call_to instead of equality comparison with itir.Ref. #1532

Merged
merged 6 commits into from
Apr 18, 2024

Conversation

tehrengruber
Copy link
Contributor

@tehrengruber tehrengruber commented Apr 18, 2024

In the new ITIR type inference #1531 IR nodes store their type in the node itself. While we initially exclude the attribute from equality comparison we should nonetheless avoid comparison of node that only differ in type. This PR removes many of this occurrences.

>>> is_call_to(node, "plus")
False
"""
if isinstance(fun, (list, tuple, set)):
Copy link
Contributor

Choose a reason for hiding this comment

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

This isinstance() check doesn't match the typying annotation for fun.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I switched to collections.abc.Iterable, but still included list, tuple, set for performance reasons.

def is_if_call(node: itir.Expr) -> TypeGuard[itir.FunCall]:
"""Match expression of the form `if_(cond, true_branch, false_branch)`."""
return isinstance(node, itir.FunCall) and node.fun == im.ref("if_")
def is_call_to(node: itir.Node, fun: str | list[str]) -> TypeGuard[itir.FunCall]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Just an optional suggestion, feel free to ignore: I'd like better to include the actual name of the node FunCall in its typeguard function (e.g. is_funcall_to).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We opted for maximum convenience in the ir_makers module, e.g. im.ref also creates a SymRef so I'll keep call for now.

Copy link
Contributor

@egparedes egparedes left a comment

Choose a reason for hiding this comment

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

ILGTM.

@tehrengruber tehrengruber merged commit 2c06bc6 into GridTools:main Apr 18, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants