Skip to content

Commit

Permalink
Mark undefined instructions as deopting to themselves
Browse files Browse the repository at this point in the history
Summary:
When CPython hands out the bytecode it will first do a de-opt on it:

https://www.internalfb.com/code/fbsource/[241e0d0760d4c107a3c0ac2b4914524120b0c909]/third-party/python/3.12/Objects/codeobject.c?lines=1540&reveal=1540

This uses the de-opt table which only defines the known opcodes, meaning unknown opcodes get turned into 0's. We need CPython to at least define unknown opcodes to at least de-opt to themselves.

Upstream PR: python/cpython#128044

Reviewed By: jbower-fb

Differential Revision: D67350914

fbshipit-source-id: 0073efab52da1be775272e7dd9ae5a46468ccb10
  • Loading branch information
DinoV authored and facebook-github-bot committed Dec 18, 2024
1 parent 45f400c commit 3d1b81e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
62 changes: 62 additions & 0 deletions Include/internal/pycore_opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Tools/build/generate_opcode_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ def main(opcode_py, outfile='Include/opcode.h',
iobj.write("\nconst uint8_t _PyOpcode_Deopt[256] = {\n")
for opt, deopt in sorted(deoptcodes.items()):
iobj.write(f" [{opt}] = {deopt},\n")
for i, name in enumerate(opname):
if not used[i]:
iobj.write(f" [{i}] = {i},\n")
iobj.write("};\n")
iobj.write("#endif // NEED_OPCODE_TABLES\n")

Expand Down

0 comments on commit 3d1b81e

Please sign in to comment.