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
Allow signed line number deltas in the code object's line number table #61160
Comments
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. |
How does this interact with pdb? |
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. |
Also, the findlinestarts() function from the dis module computes line |
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. |
Good news: this issue has been fixed in issue bpo-26107. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: