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

[mypyc] (Re-)Support iterating over an Union of dicts #14713

Merged
merged 3 commits into from
Feb 16, 2023

Conversation

ichard26
Copy link
Collaborator

@ichard26 ichard26 commented Feb 16, 2023

An optimization to make iterating over dict.keys(), dict.values() and dict.items() faster caused mypyc to crash while compiling a Union of dictionaries. This commit fixes the optimization helpers to properly handle unions.

irbuild.Builder.get_dict_base_type() now returns list[Instance] with the union items. In the common case we don't have a union, a single-element list is returned. And get_dict_key_type() and get_dict_value_type() will now build a simplified RUnion as needed.

Fixes mypyc/mypyc#965 and probably #14694.

An optimization to make iterating over dict.keys(), dict.values() and
dict.items() faster caused mypyc to crash while compiling a Union of
dictionaries. This commit fixes the optimization helpers to properly
handle unions.

irbuild.Builder.get_dict_base_type() now returns list[Instance] with the
union items. In the common case we don't have a union, a single-element
list is returned. And get_dict_key_type() and get_dict_value_type()
will now build a simplified RUnion as needed.
Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Thanks for the fix! I'm not the most familiar with mypyc, but this looks straightforward enough

@JukkaL JukkaL merged commit 7237831 into python:master Feb 16, 2023
@ichard26 ichard26 deleted the resupport-union-of-dicts branch February 19, 2023 04:21
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.

AssertionError when building IR for a for loop over an Union of dictionaries
3 participants