Reported here: #122762 (comment)
The locations for branches in while statements are not consistent. The first iteration shows different locations from the second and later iterations.
I've not check earlier versions, but this could be an issue for 3.12 as well.
3.13, CPython main branch
No response
Here's my hypothesis:
This is an artifact of compiling while cond: body as:
start: if not cond: goto end body if cond goto start end:
and the assembler converting condition backwards jumps from if cond goto target to
if not cond goto end goto target end:
So we end up with:
start: if not cond: goto end body if not cond goto end goto start end:
When cond is True, the first branch jumps from cond to body, but the second branch jumps from cond to cond.
Compiling while cond: body as:
start: if not cond: goto end body goto start end:
should fix this.
GH-122821: Simplify compilation of while statements to ensure consist…
pythonGH-122821: Simplify compilation of while statements to ensure c…
Activity
markshannon commented on Aug 8, 2024
Here's my hypothesis:
This is an artifact of compiling while cond: body as:
start: if not cond: goto end body if cond goto start end:and the assembler converting condition backwards jumps from if cond goto target to
if not cond goto end goto target end:So we end up with:
start: if not cond: goto end body if not cond goto end goto start end:When cond is True, the first branch jumps from cond to body, but the second branch jumps from cond to cond.
Compiling while cond: body as:
start: if not cond: goto end body goto start end:should fix this.
GH-122821: Simplify compilation of while statements to ensure consist…
pythonGH-122821: Simplify compilation of while statements to ensure c…