-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-28810: Document remaining bytecode changes in 3.6 #651
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
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
@@ -280,6 +287,7 @@ details of bytecode instructions as :class:`Instruction` instances: | |||
|
|||
|
|||
The Python compiler currently generates the following bytecode instructions. | |||
Every instruction takes 2 bytes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -210,6 +210,13 @@ operation is being performed, so the intermediate analysis object isn't useful: | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -210,6 +213,11 @@ operation is being performed, so the intermediate analysis object isn't useful: | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -20,6 +20,9 @@ interpreter. | |||
between versions of Python. Use of this module should not be considered to | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -20,6 +20,10 @@ interpreter. | |||
between versions of Python. Use of this module should not be considered to | |||
work across Python VMs or Python releases. | |||
|
|||
.. 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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