-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
9e8e3a5
commit 03040db
Showing
22 changed files
with
3,732 additions
and
2,765 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.