Open MatthieuDartiailh opened 3 months ago
Right, now that we effectly store all of them in the "fast locals", we should clean up the docs about it. However, I'm not sure what's the best way to proceed. Should we create a new term for the local names? Or should we change the definition of varnames
?
I asked this question because I maintain https://github.com/MatthieuDartiailh/bytecode and I usually stumble about undocumented bytecode changes each time I start the work to support the latest Python.
I do not think the definition of varnames should be changed since cell values never appeared there but I may be missing something. Currently the len of varnames matches the value passed to types.CodeType
nlocals
parameters. Does this remain true or has it also changed ?
I agree that the definition of varnames
should stay.
I see that some opcodes in dis.rst
already refer to "fast locals".
Examples:
Could a similar thing be done for LOAD_FAST
, LOAD_FAST_FAST
, and related - write they access "fast locals" instead of co_varnames
? That would be consistent.
If the notion of fast locals is clearly defined I am fine with it.
While considering this, I had a second though: since load fast may access a cell, should it have the has_free flag set ? I do not think it should, but I am finding more and more difficult to understand what the dis.hasfree list covers if cell vars may be accessed by opcodes outside of it.
Documentation
LOAD_FAST is documented (https://docs.python.org/3.13/library/dis.html#opcode-LOAD_FAST) as:
Pushes a reference to the local co_varnames[var_num] onto the stack.
However running dis on the following snippet shows that it may load other names:
Output