bpo-28810: Document remaining bytecode changes in 3.6#651
bpo-28810: Document remaining bytecode changes in 3.6#651brettcannon merged 8 commits intopython:masterpython/cpython:masterfrom ilevkivskyi:more-bytecode-docsilevkivskyi/cpython:more-bytecode-docsCopy head branch name to clipboard
Conversation
|
@ilevkivskyi, thanks for your PR! By analyzing the history of the files in this pull request, we identified @birkenfeld, @ncoghlan, @benjaminp, @serhiy-storchaka and @1st1 to be potential reviewers. |
Doc/library/dis.rst
Outdated
|
|
||
|
|
||
| The Python compiler currently generates the following bytecode instructions. | ||
| Every instruction takes 2 bytes. |
There was a problem hiding this comment.
I think this should be moved to the top of the document, under impl-detail block, and decorated with versionchanged.
Doc/library/dis.rst
Outdated
| This generator function uses the ``co_firstlineno`` and ``co_lnotab`` | ||
| attributes of the code object *code* to find the offsets which are starts of | ||
| lines in the source code. They are generated as ``(offset, lineno)`` pairs. | ||
| Functions decoding directly ``co_lnotab`` should use a signed |
There was a problem hiding this comment.
Too much details for common user of the dis module, but too few details for reproducing decoding algorithm. I think just adding the reference to Objects/lnotab_notes.txt is enough.
|
@serhiy-storchaka Thanks!
I was also thinking about this. I implemented both your comments in a new commit. |
Doc/library/dis.rst
Outdated
| This generator function uses the ``co_firstlineno`` and ``co_lnotab`` | ||
| attributes of the code object *code* to find the offsets which are starts of | ||
| lines in the source code. They are generated as ``(offset, lineno)`` pairs. | ||
| See ``Objects/lnotab_notes.txt`` for the ``co_lnotab`` format and how to |
There was a problem hiding this comment.
Using a source ref here turn this into a suitable hyperlink to GitHub:
:source:`Objects/lnotab_notes.txt`
There was a problem hiding this comment.
Thank you, Nick!
Implemented this is a new commit.
|
By the way, I have noticed that the example in Objects/lnotab_notes.txt is outdated. It still uses Python 2 and old bytecode (not 2 bytes per instruction). Should I update it in this PR or open a separate issue and make a separate PR? |
|
@ilevkivskyi separate PR would be great! |
OK, will do this. |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
The meaning of HAVE_ARGUMENT was changed too. Now all instructions have an argument, but opcodes < HAVE_ARGUMENT ignore it.
Doc/library/dis.rst
Outdated
| how to decode it. | ||
|
|
||
| .. versionchanged:: 3.6 | ||
| Added support for negative line number delta. |
There was a problem hiding this comment.
This looks as implementation detail that should be described in lnotab_notes.txt. The change visible for the user of findlinestarts() is that line numbers now can not be monotonically increasing.
Doc/library/dis.rst
Outdated
| work across Python VMs or Python releases. | ||
|
|
||
| .. versionchanged:: 3.6 | ||
| Use fixed 2 bytes per instruction for all instructions. |
There was a problem hiding this comment.
May be worth to mention that instructions of variable length was used before.
…python into more-bytecode-docs
|
@serhiy-storchaka Thanks, I implemented your comments. |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
I don't know whether the changes use good English, but in general LGTM.
Doc/library/dis.rst
Outdated
| how to decode it. | ||
|
|
||
| .. versionchanged:: 3.6 | ||
| Line numbers can be not monotonically increasing. |
There was a problem hiding this comment.
"not monotonically" is not easy to understand. In What's New in Python 3.6, I wrote:
"The format of the co_lnotab attribute of code objects changed to support a negative line number delta"
There was a problem hiding this comment.
This is how I initially wrote it, but @serhiy-storchaka wanted me to change this to this wording.
His motivation is that negative delta is not a visible effect for user, see #651 (comment)
There was a problem hiding this comment.
This is the wording for describing the implementation details of co_lnotab. What is important for the user of findlinestarts() which shouldn't know anything about co_lnotab is that now this function can produce non-monotonic line numbers. That can affect user code.
There was a problem hiding this comment.
Just say "Line numbers can now go backwards." if you prefer. I would like to avoid "monotonically", especially "not monotonically".
There was a problem hiding this comment.
Line numbers can now go backwards.
This sounds not very clear to me. I changed this to an alternative formulation "Line numbers can be decreasing. Before, they were always increasing." I hope this works.
Doc/library/dis.rst
Outdated
|
|
||
| .. versionchanged:: 3.6 | ||
| Use fixed 2 bytes per instruction for all instructions. Instructions | ||
| of variable length were used before. |
There was a problem hiding this comment.
I would phrase this as "Use 2 bytes for each instruction. Previously the number of bytes varied by instruction."
Doc/library/dis.rst
Outdated
| those which do ``>= HAVE_ARGUMENT``. | ||
|
|
||
| .. versionchanged:: 3.6 | ||
| Now every instruction have an argument, but opcodes ``< HAVE_ARGUMENT`` |
There was a problem hiding this comment.
"Now every instruction has an argument"
|
@brettcannon Thanks! I fixed both points in a new commit. |
(cherry picked from commit 8f9e1bb)
@serhiy-storchaka @brettcannon
These are two remaining changes to close http://bugs.python.org/issue28810
This needs a backport to 3.6