Issue 16956: Allow signed line number deltas in the code object's line number table
Created on 2013-01-13 18:42 by Mark.Shannon, last changed 2022-04-11 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| dd04caae6647.diff | Mark.Shannon, 2013-01-13 18:44 | review | ||
| Repositories containing patches | |||
|---|---|---|---|
| https://bitbucket.org/markshannon/cpython-lnotab-signed | |||
| Messages (6) | |||
|---|---|---|---|
| msg179887 - (view) | Author: Mark Shannon (Mark.Shannon) * ![]() |
Date: 2013-01-13 18:42 | |
The restriction that line numbers must be monotonically increasing w.r.t bytecode offset in the co_lnotab array prevents a number of beneficial transformations in the bytecode compiler. This patch allows negative line number deltas and uses this capability to generate code for 'while' loops in standard text book fashion, putting the test *after* the body. |
|||
| msg179948 - (view) | Author: Antoine Pitrou (pitrou) * ![]() |
Date: 2013-01-14 16:03 | |
How does this interact with pdb? |
|||
| msg180006 - (view) | Author: Mark Shannon (Mark.Shannon) * ![]() |
Date: 2013-01-15 09:26 | |
The interaction between bdb/pdb and the line number table is via the frame.f_lineno attribute. Allowing signed offsets changes the one-to-one line muber => bytecode offset relation into a one-to-many relation. Reading frame.f_lineno is not an issue as each bytecode offset will always refer to exactly one line number. Setting frame.f_lineno requires some thought as each line number could potentially refer to several bytecode offsets. However, the proposed patch retains the one-to-one relation, as the test in the while statement is merely moved, not duplicated. I am reluctant to change frame_setlineno() until there really is a one-to-many relation as it will be untestable. Once a one-to-many relation exists (e.g. duplicating finally blocks to avoid 'pseudo excpetions') then frame_setlineno should be modified (and tests added) |
|||
| msg181767 - (view) | Author: Xavier de Gaye (xdegaye) * ![]() |
Date: 2013-02-09 22:57 | |
> How does this interact with pdb? Also, the findlinestarts() function from the dis module computes line numbers from lnotab. This function is used by pdb when displaying the lines of a traceback. |
|||
| msg181768 - (view) | Author: Antoine Pitrou (pitrou) * ![]() |
Date: 2013-02-09 23:01 | |
Your patch doesn't seem to work properly: a "while" loop doesn't generate negative line offsets. The reason seems to be that compiler_set_lineno() prevents it. (also, if I re-add the `assert(d_lineno >= 0);` in assemble_lnotab(), I don't get any crash) |
|||
| msg258671 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2016-01-20 11:36 | |
Good news: this issue has been fixed in issue #26107. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:57:40 | admin | set | github: 61160 |
| 2016-01-20 11:36:19 | vstinner | set | status: open -> closed superseder: PEP 511: code.co_lnotab: use signed line number delta to support moving instructions in an optimizer resolution: fixed messages: + msg258671 |
| 2013-02-09 23:01:07 | pitrou | set | messages: + msg181768 |
| 2013-02-09 22:57:19 | xdegaye | set | messages: + msg181767 |
| 2013-02-09 20:07:14 | xdegaye | set | nosy:
+ xdegaye |
| 2013-01-15 09:26:26 | Mark.Shannon | set | messages: + msg180006 |
| 2013-01-14 16:03:32 | pitrou | set | versions:
+ Python 3.4 nosy: + georg.brandl, vstinner, pitrou messages: + msg179948 type: enhancement |
| 2013-01-13 18:44:06 | Mark.Shannon | set | files:
+ dd04caae6647.diff keywords: + patch |
| 2013-01-13 18:42:34 | Mark.Shannon | create | |

