Hi all,
I’m new to hacking on cpython and the Python source code in general. I’ve been working on Remove LOAD_CLOSURE #105775
From the ticket and poking around in compiler.c
I know that LOAD_CLOSURE
was added to keep the local/cell variable logic more readable. Particularly when we get to fix_cell_offsets
, we don’t have information about how the variable being loaded was introduced to the scope, so labeling with LOAD_CLOSURE
provided a kind of clean way to preserve that information throughout the instruction’s lifecycle.
My questions are the following (and apologies if this is not the right place for them, I wasn’t sure if they were better asked here, on the ticket itself, or one of the mailing lists):
- Does it seem like
fix_cell_offset
mainly where we’ll need some change in logic to accommodate convertingLOAD_CLOSURE
toLOAD_FAST
, or are there other considerations aside from coming up with some way to maintain information about the instructions provenance - When I first set up my cpython development environment, I followed the guidance on the developer’s guide and have been studying the compiler design page closely. From my reading of it, when I remove an opcode, I need to
- Remove references to the opcode from the code and update any logic impacted
- Remove the opcode from
Lib/opcode.py
and thedis
module documentation - Run
make regen-opcode regen-opcode-targets
to regenerateInclude/opcode.h
andPython/opcode_targets.h
- Update the magic number in
Lib/importlib/_bootstrap_external.py
andPC/launcher.c
- (See below)
- Run
make regen-importlib
On the Compiler Design page under the Introducing New Bytecode section, it says
Changes to
Lib/importlib/_bootstrap_external.py
will take effect only after runningmake regen-importlib
. Running this command before adding the new bytecode target toPython/ceval.c
will result in an error. You should only runmake regen-importlib
after the new bytecode target has been added.
I didn’t understand the last two sentences here --it makes sense to me that if we’re introducing a new opcode, we should ideally have logic to handle the new instructions in ceval.c
, but it’s not clear to me what error would be triggered if we’re not referencing the new instruction, so I feel I’m not understanding something
I’d really appreciate any guidance on these points, and again, I apologize if these questions aren’t appropriate for this forum!