Hi Skip, I modified co_lnotab format when I worked on the FAT Python optimization project which modified the AST to emit more efficient bytecode. My optimizer moved instructions, the line number could become non-monotonic (..., line 2, line 3, line 2, line 4, ...), and so lnotab (..., +1, -1, +2, ...) could be negative. Example with loop unrolling: def func1(): for i in ("a", "b"): print(i) is optimized: def func2(): i = "a" # line 1 print(i) # line 2 (+1) i = "b" # line 1 (-1) print(i) # line 2 (+1) I'm happy to see that Python 3.10 now also implements faster bytecode which rely on this change ;-) It seems like loop unrolling is not implemented in Python 3.10 yet. I guess that Python/ast_opt.c has no strategy yet to decide if an optimization should be applied or not depending on the code size. Loop unrolling can make code way bigger. Victor On Thu, Mar 18, 2021 at 12:12 AM Ned Batchelder <ned@nedbatchelder.com> wrote:
On 3/17/21 6:41 PM, MRAB wrote:
On 2021-03-17 22:10, Skip Montanaro wrote:
I stumbled on this while trying to generate a line number table in my side project register VM. As I understand it, the line number delta in the output table is supposed to always be >= 0. In my code I'm using dis.findlinestarts() to determine the line numbers for each block. Perhaps I should be modifying its results. OTOH, maybe it's a bug. (If that's the consensus, I will create an issue.)
co_lnotab has had negative deltas since 3.6.
--Ned. _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/EK2O6SE6... Code of Conduct: http://python.org/psf/codeofconduct/
-- Night gathers, and now my watch begins. It shall not end until my death.