Skip to content

bpo-26213: Document _UNPACK bytecodes and BUILD_MAP changes #238

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 8 commits into from
Mar 3, 2017

Conversation

ilevkivskyi
Copy link
Member

This needs to be backported to 3.5 and 3.6

This fixes http://bugs.python.org/issue26213

@serhiy-storchaka Please take a look

.. versionadded:: 3.5


.. opcode:: BUILD_MAP_UNPACK_WITH_CALL (count)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The semantic is different in 3.5. The lowest byte of oparg is the count of mappings, the relative position of the callable is encoded in the second byte of oparg. Thus needed ".. versionadded:: 3.6".

Or maybe first write a patch that describes 3.5 semantic and change it later in 3.6+ patch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add the 3.6 semantics in a separate PR. In the new commit I decided to describe the 3.5 semantics.

@@ -772,8 +813,11 @@ All of the following opcodes use their arguments.

.. opcode:: BUILD_MAP (count)

Pushes a new dictionary object onto the stack. The dictionary is pre-sized
to hold *count* entries.
Pushes a new dictionary object onto the stack. Pops ``2 * count`` items
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a nitpick, but different PEPs recommend to use a double space after sentence ending period.

so that the dictionary holds ``count`` entries:
``{..., TOS3: TOS2, TOS1: TOS}``.

.. versionchanged:: 3.5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention what is changed.

@@ -723,6 +723,47 @@ All of the following opcodes use their arguments.
are put onto the stack right-to-left.


.. opcode:: BUILD_TUPLE_UNPACK (count)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following opcodes create the collection by concatenating/merging several values from the stack. I think it would be better to place their descriptions after BUILD_STRING (which is similar to BUILD_*_UNPACK opcodes but for strings).

.. opcode:: BUILD_TUPLE_UNPACK (count)

Pops ``count`` iterables from the stack, joins them in a single tuple,
and pushes the result.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be worth to mention that it is used for implementing iterable unpacking in tuple displays (see https://docs.python.org/3/whatsnew/3.5.html#pep-465-a-dedicated-infix-operator-for-matrix-multiplication). Example: (*x, *y, *z).

@ilevkivskyi
Copy link
Member Author

Serhiy, thank you for review! I implemented your comments in a new commit.


Pops ``count`` iterables from the stack, joins them in a single tuple,
and pushes the result. This bytecode is used for implementing iterable
unpacking in tuple displays ``(*x, *y, *z)``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add examples for other opcodes?

[*x, *y, *z]
{*x, *y, *z}
{**x, **y, **z}

Pushes a new dictionary object onto the stack. The dictionary is pre-sized
to hold *count* entries.
Pushes a new dictionary object onto the stack. Pops ``2 * count`` items
so that the dictionary holds ``count`` entries:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BUILD_TUPLE and others format the parameter as *count* rather than ``count``.


.. opcode:: BUILD_MAP_UNPACK (count)

Pops ``count`` mappings from the stack, joins them in a single dictionary,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "merges" is more appropriate term than "joins".

@ilevkivskyi
Copy link
Member Author

Thanks! I have implemented new comments in another commit.

@ilevkivskyi
Copy link
Member Author

2 * count is an expression, all expressions are formatted with ``.

Fixed.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it LGTM. Thank you Ivan. But would be nice if some native speaker take a look.

@ilevkivskyi
Copy link
Member Author

Now it LGTM. Thank you Ivan. But would be nice if some native speaker take a look.

@briancurtin Could you please also take a look at this?

Note that I will update the BUILD_MAP_UNPACK_WITH_CALL docs in a separate PR (or maybe I will just update #239) after this is merged.

@ilevkivskyi
Copy link
Member Author

Now it LGTM. Thank you Ivan. But would be nice if some native speaker take a look.

@brettcannon Could you please also take a look at this?

Note that I will update the BUILD_MAP_UNPACK_WITH_CALL docs in a separate PR (or maybe I will just update #239) after this is merged.


@briancurtin Sorry for disturbing! This was intended for @brettcannon

.. opcode:: BUILD_TUPLE_UNPACK (count)

Pops *count* iterables from the stack, joins them in a single tuple,
and pushes the result. This bytecode is used for implementing iterable
Copy link
Contributor

@DimitrisJim DimitrisJim Feb 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though not technically incorrect, using the sentence "This bytecode is used .." for every case is somewhat repetitive IMO.It might be better to use the same format the other opcodes in the docs use and go for:

Implements iterable unpacking for displays <type_display>

Other than that change, which I believe would be beneficial, the rest look good to me.

@ilevkivskyi
Copy link
Member Author

Implements iterable unpacking for displays <type_display>
Other than that change, which I believe would be beneficial, the rest look good to me

Thanks! Fixed this in a new commit.

@brettcannon
Copy link
Member

I tweaked a single word in the PR. Once Travis is green again I'll merge and backport.

@brettcannon brettcannon changed the title bpo-26213: Document _UNPACK bytecodes added in 3.5 and BUILD_MAP changes bpo-26213: Document _UNPACK bytecodes and BUILD_MAP changes Mar 3, 2017
@brettcannon brettcannon merged commit 0705f66 into python:master Mar 3, 2017
brettcannon pushed a commit to brettcannon/cpython that referenced this pull request Mar 3, 2017
brettcannon pushed a commit to brettcannon/cpython that referenced this pull request Mar 3, 2017
@serhiy-storchaka
Copy link
Member

Thank you Ivan and Brett.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants