-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[mypyc] feat: specialize any
and all
using for loop helpers if possible [1/2]
#19948
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
base: master
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
r12 = list_get_item_unsafe r2, r9 | ||
r13 = cast(str, r12) | ||
__mypyc_any_item__ = r13 | ||
r14 = CPyStr_IsTrue(__mypyc_any_item__) |
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 boolean check for the any
call is now specialized per the dtype of the iterable, and we no longer have to use python's iterator protocol for the input
r12 = list_get_item_unsafe r2, r9 | ||
r13 = cast(str, r12) | ||
__mypyc_all_item__ = r13 | ||
r14 = CPyStr_IsTrue(__mypyc_all_item__) |
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 boolean check for the all
call is now specialized per the dtype of the iterable, and we no longer have to use python's iterator protocol for the input
builder.goto(loop_exit) | ||
builder.activate_block(true_block) | ||
|
||
index_type = builder._analyze_iterable_item_type(arg) |
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.
should I deduplicate this block or is this fine?
|
||
def create_synthetic_nameexpr(index_name: str, index_type: Type) -> NameExpr: | ||
"""This helper spoofs a NameExpr to use as the lvalue in one of the for loop helpers.""" | ||
index = NameExpr(index_name) |
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 probably need something here to ensure no name collisions globally, but not sure what
any
and all
using for loop helpers if possible [1/2]
This PR modifies the
any
andall
call specializers to use our for loop helpers in cases where they can be used.This is only marginally helpful now but will become more impactful with the addition of
ForMap
andForFilter
helpers, as well as any future helpers.While the private helpers might seem unnecessary at this point, I intend to use them for future specialization use cases such as
list(iterable)
andtuple(iterable)
as discussed in #19649 , andsum(iterable)
which will come shortly after this PR.This PR is ready for review
Update: The
sum(iterable)
is now ready in #19950. It's a bit more involved than this one so I'm going to leave it separate.Update: The helpers are no longer private