Skip to content

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

Merged
merged 8 commits into from
Mar 24, 2017

Conversation

ilevkivskyi
Copy link
Member

@serhiy-storchaka @brettcannon
These are two remaining changes to close http://bugs.python.org/issue28810
This needs a backport to 3.6

@mention-bot
Copy link

@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.

@@ -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.
Copy link
Member

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.

@@ -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
Copy link
Member

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 serhiy-storchaka added type-feature A feature request or enhancement needs backport to 3.6 docs Documentation in the Doc dir and removed type-feature A feature request or enhancement labels Mar 13, 2017
@ilevkivskyi
Copy link
Member Author

@serhiy-storchaka Thanks!

I think this should be moved to the top of the document, under impl-detail block

I was also thinking about this. I implemented both your comments in a new commit.

@@ -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
Copy link
Contributor

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`

Copy link
Member Author

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.

@ilevkivskyi
Copy link
Member Author

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?

@brettcannon
Copy link
Member

@ilevkivskyi separate PR would be great!

@ilevkivskyi
Copy link
Member Author

separate PR would be great!

OK, will do this.
So it looks like this PR could be merged now.

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.

The meaning of HAVE_ARGUMENT was changed too. Now all instructions have an argument, but opcodes < HAVE_ARGUMENT ignore it.

how to decode it.

.. versionchanged:: 3.6
Added support for negative line number delta.
Copy link
Member

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.

@@ -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.
Copy link
Member

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.

@ilevkivskyi
Copy link
Member Author

@serhiy-storchaka Thanks, I implemented your comments.

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.

I don't know whether the changes use good English, but in general LGTM.

how to decode it.

.. versionchanged:: 3.6
Line numbers can be not monotonically increasing.
Copy link
Member

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"

Copy link
Member Author

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)

Copy link
Member

@serhiy-storchaka serhiy-storchaka Mar 14, 2017

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.

Copy link
Member

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".

Copy link
Member Author

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.

@@ -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.
Copy link
Member

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."

those which do ``>= HAVE_ARGUMENT``.

.. versionchanged:: 3.6
Now every instruction have an argument, but opcodes ``< HAVE_ARGUMENT``
Copy link
Member

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"

@ilevkivskyi
Copy link
Member Author

@brettcannon Thanks! I fixed both points in a new commit.

@brettcannon brettcannon self-assigned this Mar 20, 2017
@brettcannon brettcannon merged commit 8f9e1bb into python:master Mar 24, 2017
brettcannon pushed a commit to brettcannon/cpython that referenced this pull request Mar 24, 2017
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