Skip to content

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

Merged
JukkaL merged 3 commits intopython:masterfrom
ichard26:resupport-union-of-dicts
Feb 16, 2023
Merged

[mypyc] (Re-)Support iterating over an Union of dicts#14713
JukkaL merged 3 commits intopython:masterfrom
ichard26:resupport-union-of-dicts

Conversation

@ichard26
Copy link
Copy Markdown
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
Copy Markdown
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