-
Notifications
You must be signed in to change notification settings - Fork 49
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
Conversation
>>> is_call_to(node, "plus") | ||
False | ||
""" | ||
if isinstance(fun, (list, tuple, set)): |
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 isinstance()
check doesn't match the typying annotation for fun
.
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 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]: |
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.
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
).
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.
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.
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.
ILGTM.
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.