Skip to content

[mypyc] Foundational support for tuple literals (+ None and bool) #10041

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
merged 4 commits into from
Feb 6, 2021

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Feb 6, 2021

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 JukkaL merged commit 047e427 into master Feb 6, 2021
@JukkaL JukkaL deleted the lazy-literals-2 branch February 6, 2021 14:43
JukkaL added a commit that referenced this pull request Feb 19, 2021
JukkaL added a commit that referenced this pull request Feb 19, 2021
…ool) (#10041)" (#10112)

This reverts commit 047e427.

Looks like that the new literals implementation broke Windows builds somehow.
JukkaL added a commit that referenced this pull request Feb 27, 2021
This adds back #10041 that was reverted because of failing Windows builds.

original PR.
JukkaL added a commit that referenced this pull request Feb 27, 2021
…y 2 (#10148)

This adds back #10041 that was reverted because of failing Windows builds.

The Windows issue was fixed in #10147, so this is just a rebased version of the
original PR.
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.

1 participant