Description
The code generator produces metadata for use by the compiler that tells it how many stack entries were pushed and popped by an opcode. These two quantities are subtracted to compute the net stack effect. (The metadata is in the form of functions _PyOpcode_num_popped
and _PyOpcode_num_pushed
in opcode_metadata.h.)
But what we really need to know, if we want accurate information about what an opcode (or micro-op) does to the stack, is three numbers: how low it goes, how high it goes, and where it ends. For example, if we have a micro-op that pops two entries and then pushes one, and another that pushes two and then pops one, and we combine them into a macro, the macro's net effect is zero, but the lowest point is two below the initial stack level, and the highest point is one above it.
There are various ways to express this, but there is no way to express all this information with just two numbers.
Note that the relevant calculation is already present in the generator, as part of analyze_macro()
.