@brandtbucher pointed out that we could automatically evaluate pure ops in the JIT.
Back when I originally envisioned this in the JIT optimizer, it was way simpler. Right now we have stackrefs which complicate things a little.
The main idea is that fully pure bytecodes can just run their body in the JIT optimizer, allowing for automatic constant prop/evaluation. This also cuts down code duplication and also the amount of human error from manually writing constant propagation code.
We'd have to replace all the stackref functions with the appropriate sym accessing functions, either through macros or the cases generator.
Just talked with @savannahostrowski, she's going to modify the cases generator to replace the entire instruction when constant evaluation produces an immortal value.
@savannahostrowski we still have this left #136048 . The problem is with these constant propagation, the optimizer can now error, and we need to handle that properly.
Activity
brandtbucher commented on Apr 24, 2025
Two follow-ups to this:
gh-132732: Automatically constant evaluate pure operations (GH-132733)
pythongh-132732: Treat `bytes` as constants in `_Py_uop_sym_is_safe_c…
gh-132732: JIT: Only allow compact ints in pure evaluation (GH-136040)
brandtbucher commented on Jun 27, 2025
Just talked with @savannahostrowski, she's going to modify the cases generator to replace the entire instruction when constant evaluation produces an immortal value.
gh-132732: Fix up pure types in JIT (GH-136050)
pythongh-132732: Automatically constant evaluate pure operations (pyt…
pythongh-132732: JIT: Only allow compact ints in pure evaluation (pyt…
pythongh-132732: Fix up pure types in JIT (pythonGH-136050)
pythongh-132732: Automatically constant evaluate pure operations (pyt…
pythongh-132732: JIT: Only allow compact ints in pure evaluation (pyt…
4 remaining items
pythongh-132732: Fix up pure types in JIT (pythonGH-136050)
pythongh-132732: Automatically constant evaluate pure operations (pyt…
pythongh-132732: JIT: Only allow compact ints in pure evaluation (pyt…
pythongh-132732: Fix up pure types in JIT (pythonGH-136050)
pythonGH-132732: Use pure op machinery to optimize `COMPARE_OP_INT/FL…
GH-132732: Use pure op machinery to optimize various instructions wit…
savannahostrowski commented on Sep 15, 2025
@Fidget-Spinner @brandtbucher Are we good to close this out after #137577 or is there more I should work on here? 😈
Fidget-Spinner commented on Sep 15, 2025
@savannahostrowski we still have this left #136048 . The problem is with these constant propagation, the optimizer can now error, and we need to handle that properly.
GH-132732: Remove textwrap import (#138933)
savannahostrowski commented on Sep 15, 2025
Ah! I missed that. I'll reassign this issue to you, and you can close it out when that lands.
gh-132732: Clear errors in JIT optimizer on error (GH-136048)
Fidget-Spinner commented on Sep 15, 2025
This is done! Thanks Savannah!