Skip to content

Conversation

BobTheBuidler
Copy link
Contributor

@BobTheBuidler BobTheBuidler commented Sep 28, 2025

This PR modifies the any and all 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 and ForFilter 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) and tuple(iterable) as discussed in #19649 , and sum(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

r12 = list_get_item_unsafe r2, r9
r13 = cast(str, r12)
__mypyc_any_item__ = r13
r14 = CPyStr_IsTrue(__mypyc_any_item__)
Copy link
Contributor Author

@BobTheBuidler BobTheBuidler Sep 28, 2025

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__)
Copy link
Contributor Author

@BobTheBuidler BobTheBuidler Sep 28, 2025

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)
Copy link
Contributor Author

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)
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 probably need something here to ensure no name collisions globally, but not sure what

@BobTheBuidler BobTheBuidler changed the title [mypyc] feat: specialize any and all using for loop helpers if possible [mypyc] feat: specialize any and all using for loop helpers if possible [1/2] Oct 1, 2025
@BobTheBuidler BobTheBuidler changed the title [mypyc] feat: specialize any and all using for loop helpers if possible [1/2] [mypyc] feat: specialize any and all using for loop helpers if possible [1/2] Oct 1, 2025
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.

1 participant