GH-104584: Restore `frame->stacktop` on optimizer error by brandtbucher · Pull Request #108953 · python/cpython
brandtbucher
changed the title
GH-104584: Restore
GH-104584: Restore stack_pointer on optimizer errorframe->stacktop on optimizer error
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just ran into this by coincidence. Fine to merge, but I do have a quibble (more aimed at @markshannon perhaps :-).
| if (err <= 0) { | ||
| assert(executor == NULL); | ||
| if (err < 0) { | ||
| _PyFrame_SetStackPointer(frame, stack_pointer); |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, interesting. It seems this is needed because when JUMP_BACKWARD calls _PyOptimizer_BackEdge it doesn't update the stack pointer in the frame, it just passes the stack pointer to the optimizer, which upon success passes it to the executor, which will eventually call STORE_SP() to update the stack pointer in the frame. And sure, this PR seems to fix the hole, but I wonder if it wouldn't be more robust to just save it before even calling _PyOptimizer_BackEdge.