-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
Description
Feature or enhancement
Proposal:
We occasionally want to pass values between the uops that are composed to form a specialized instruction. The natural (only?) way to do this is to pass them on the stack. This is possible if the stack effect of the generic instruction is greater than or equal to the number of values being passed, but may not be possible otherwise, because the stack size is calculated by using the stack effect of only the generic instructions.
I'm running into this as I try to make LOAD_ATTR_MODULE thread-safe in free-threaded builds. I would like to pass the module dict's keys object from _CHECK_ATTR_MODULE to _LOAD_ATTR_MODULE. Unfortunately, LOAD_ATTR has a stack effect of 0 or 1 and the module needs to remain on the stack, so we are not guaranteed to have sufficient stack space to pass the keys object.
Here are a few possible solutions:
- Modify the metadata generator and bytecode compiler to compute the maximum stack effect of each specialized instruction in a family, and use the maximum the when considering the effect that an instruction has on the maximum stack depth. This is the most comprehensive solution, but is quite complicated.
- Allow pushing and popping a handful of values beyond the maximum stack depth, similar to how the red zone works.
- Add space for a small number of extra values (1 or 2) after we've calculated the stack depth. This limits the number of values that can be passed safely, but is quite simple.
I think (3) is probably the best option; it's simple and should work for most cases.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response