-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[mypyc] Add LoadLiteral and use tables to construct and store literals #10040
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
Merged
Conversation
This file contains hidden or 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
I'm not waiting for code review since I have a bunch of other changes that depend on this. If somebody would like to give feedback, I will respond to it in a separate PR. |
JukkaL
added a commit
that referenced
this pull request
Feb 6, 2021
…0041) Add support for loading tuple literals using `LoadLiteral`. The literal tuple objects will be constructed during module import time, similar to other literals. Only tuples containing items of supported literal types can be represented (this includes other tuples). Add `None`, `True` and `False` to the literals array so that they can be used as tuple literal items. Currently tuple literals aren't used for anything. I added some unit tests to check parts of the implementation. The primary use case I have in mind is supporting vectorcall APIs which expect a tuple of keyword argument names. I will implemented this in a separate PR. This will also add some end-to-end testing for tuple literals. These could be used to avoid repeatedly constructing tuples with literal values in other contexts as well. Use array-based encoding for tuple literal values. We use the literal object array introduced in #10040 to allow a simple integer-based encoding of heterogeneous tuples. For example, tuple `('x', 5)` could be encoded like this as three integers: * 2 (length of tuple) * 123 (index of literal `'x'`) * 345 (index of literal `5`)
JukkaL
added a commit
that referenced
this pull request
Feb 27, 2021
#10040) Redesign the implementation of constant `PyObject *` values, such as string and integer literals. There are several related changes: * Add `LoadLiteral` op for loading literal values instead of using `LoadStatic`. * No longer store all literals in a table while we construct IR to make it easier to remove literals no longer needed after optimizations in the future. * Simplify the pretty-printed IR for loading literals. * Rename the helpers used to construct literal references (e.g. `load_static_unicode` -> `load_str`). * Collect all used literals values after we have final IR. * Store literal value initialization information in C arrays instead of generating code for each value. * Store constructed literal objects in a single `CPyStatics` array. The goal is to speed up compiles (slightly) and to make it easy to support tuple literals and efficient table-driven import statements. Both of these can use the `CPyStatics` array. Closes mypyc/mypyc#794. Closes mypyc/mypyc#797.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Redesign the implementation of constant
PyObject *
values, such as string and integerliterals.
There are several related changes:
LoadLiteral
op for loading literal values instead of usingLoadStatic
.literals no longer needed after optimizations in the future.
load_static_unicode
->load_str
).each value.
CPyStatics
array.The goal is to speed up compiles (slightly) and to make it easy to support tuple literals
and efficient table-driven import statements. Both of these can use the
CPyStatics
array.Closes mypyc/mypyc#794. Closes mypyc/mypyc#797.