-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
n_popped
, n_pushed
is the wrong abstraction for stack effect
#105034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I might be wrong here. I'm ending up doing the equivalent of low = -popped
net = pushed - popped
high = max(0, net) So two numbers ( |
Abstractly, each instruction, or op, pops some number of values, then either fails or pushes some other number of values. For example, instruction You need to model the stack, rather than just adding up values.
|
The tricky bits happen when the stack effect depends on |
Fortunately there are (as yet) no ops with variable-size stack effects. So in #104909 we can use Mark's algorithm. There is a hypothetical case where the tuple |
Does it? Doesn't the cases generator convert temporaries pushed to the stack by one op and popped by the next into temporary variables, meaning the |
Let's close this since we don't need it. |
Uh oh!
There was an error while loading. Please reload this page.
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()
.The text was updated successfully, but these errors were encountered: