-
-
Couldn't load subscription status.
- Fork 33.3k
gh-140104: Set next_instr properly in the JIT during exceptions #140233
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
gh-140104: Set next_instr properly in the JIT during exceptions #140233
Conversation
Co-Authored-By: devdanzin <74280297+devdanzin@users.noreply.github.com>
|
This PR fixes all correctness bugs found by the fuzzer so far, thank you! |
|
Tailcall CI is broken for x86_64-pc-windows-msvc and aarch64-pc-windows-msvc. Updating Unfortunately, I cannot test aarch64. Hopefully, this fixes it as well. Would have liked to fail it during compiling like x86_64, not at runtime, though? |
Co-Authored-By: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
|
|
Python/ceval_macros.h
Outdated
| next_instr = frame->instr_ptr; \ | ||
| /* gh-140104: The exception handler expects frame->instr_ptr | ||
| to be pointing to next_instr, not this_instr! */ \ | ||
| next_instr = frame->instr_ptr + 1 + _PyOpcode_Caches[_PyOpcode_Deopt[frame->instr_ptr->op.code]]; \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| next_instr = frame->instr_ptr + 1 + _PyOpcode_Caches[_PyOpcode_Deopt[frame->instr_ptr->op.code]]; \ | |
| next_instr = frame->instr_ptr + 1; |
Just +1 to compensate for the the -1 in label(exception_unwind)
Pointing to the next instruction does work, but it is unnecessary. As long as next_inst -1 points into the current instruction, unwinding works correctly.
|
When you're done making the requested changes, leave the comment: |
Lib/test/test_capi/test_opt.py
Outdated
| def f(): | ||
| for i in range(TIER2_THRESHOLD + 3): | ||
| try: | ||
| g(i) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| g(i) | |
| undefined_variable(i) |
I'm assuming that the exception here is that g is undefined?
Can we have two tests?
- where the exception is raised on the first instruction of the block (like this one), and
- where it is raised on the last instruction.
Something like:
a_list[""] = 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand how to raise something on the last instruction. What does a_list contain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a_list contains a list.
a_list[""] = 0
compiles to
LOAD_SMALL_INT 0
LOAD_FAST_BORROW 0 (a_list)
LOAD_CONST 1 ('')
STORE_SUBSCR
The STORE_SUBSCR will raise an exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to admit I straight up forgot how to code Python and thought that was valid Python code that wouldn't raise an exception.
|
The code looks good now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
|
Thanks @Fidget-Spinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14. |
|
Sorry, @Fidget-Spinner, I could not cleanly backport this to |
|
GH-140687 is a backport of this pull request to the 3.14 branch. |
…pythonGH-140233) Co-authored-by: devdanzin <74280297+devdanzin@users.noreply.github.com> Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
|
Fixes #140104
UnboundLocalErrorfor same code with JIT on or off #140104