MatthieuDartiailh/bytecode

`LOAD_METHOD` is still a valid opname but doesn't seem to be fully supported

Closed this issue · 1 comments

Porting some code to 3.12 and I get

ddtrace/internal/wrapping/__init__.py:520: in wrap
    f.__code__ = code.to_code()
.riot/venv_py3120/lib/python3.12/site-packages/bytecode/bytecode.py:312: in to_code
    bc = self.to_concrete_bytecode(
.riot/venv_py3120/lib/python3.12/site-packages/bytecode/bytecode.py:327: in to_concrete_bytecode
    return converter.to_concrete_bytecode(
.riot/venv_py3120/lib/python3.12/site-packages/bytecode/concrete.py:1401: in to_concrete_bytecode
    self.concrete_instructions()
.riot/venv_py3120/lib/python3.12/site-packages/bytecode/concrete.py:1275: in concrete_instructions
    self.required_caches = c_instr.use_cache_opcodes()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <LOAD_METHOD arg=1 location=InstrLocation(lineno=105, end_lineno=None, col_offset=None, end_col_offset=None)>

    def use_cache_opcodes(self) -> int:
        print(self._opcode)
        return (
            # Not supposed to be used but we need it
>           dis._inline_cache_entries[self._opcode]  # type: ignore
            if sys.version_info >= (3, 11)
            else 0
        )
E       IndexError: list index out of range

.riot/venv_py3120/lib/python3.12/site-packages/bytecode/concrete.py:183: IndexError

so it looks like the LOAD_METHOD opcode is not supported by 0.15.0. However, LOAD_ATTR should provide a workaround by setting the first argument of the tuple to True.

The issue is that LOAD_METHOD is now a pseudo-instruction and as a consequence it still appears in the opcodes found in the opcode module. We would need to prune them from pseudo-instruction and instrumented-instruction. Feel free to make a PR otherwise I should be able to address within a month.