You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Summary:
This diff adds support for inlining list/dict/set comprehensions where it is considered safe - names introduced by inlined comprehension will not conflict with local names used in comprehensions or free/implicitly global names used in sibling scopes. It also only inlines comprehensions in functions - inlining for top level statements comes with additional set of challenges and I'm not sure whether adding extra complexity to handle something that is executed once would be worth it.
After inlining comprehension we generate the code to delete locals added by comprehension to avoid adding extra references that are not controlled by user. This works fine for non-exceptional case however in case of exception being raised by the comprehension lifetime of object referenced by comprehension iteration variable will be extended until execution leaves current frame. Another related issue is - if original iterable being used in comprehension yields no values, comprehension iteration variable will stay unbound and `DELETE_FAST` would fail. To handle this we can either:
- relax requirements to `DELETE_FAST` so deleting unbound name would be no-op
- have a dedicated opcode that would behave as relaxed `DELETE_FAST`
- keep `DELETE_FAST` relaxed (similar to (1)) but change generated code for `del x` to be `LOAD_FAST; POP_TOP; DELETE_FAST` so name binding would still be checked by `LOAD_FAST` (suggested by DinoV)
This diff currently uses option 1 as the simplest one but this could be changed.
Reviewed By: vladima
Differential Revision: D28940584
fbshipit-source-id: b5b7512
0 commit comments