You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect output due to Tier 2 _LOAD_CONST_INLINE #117051
I've constructed a sneaky way to break the remove_globals() optimization, by executing a code object in two different globals dicts. (Credit goes to @brandtbucher who started the conversation about this topic, though this particular example is mine.)
Take this code:
src="""def f(): global x def inner(i): a = 1 for _ in range(100): a = x + i return a return innerfunc = f()"""co=compile(src, __file__, "exec")
ns1= {"x": 1000}
eval(co, ns1)
func1=ns1["func"]
foriinrange(1000):
x=func1(i)
print(x)
ns2= {"x": 2000}
eval(co, ns2)
func2=ns2["func"]
foriinrange(1000):
x=func2(i)
print(x)
This should print
1999
2999
(try it with Python 3.12, or Python 3.13 without JIT or -Xuops).
However with current main (EDIT: when using JIT or -Xuops) it prints
I was thinking that another workaround would be to leave in the first _GUARD_GLOBALS_VERSION. In fact, I'm not sure why that isn't kept by remove_globals()? (The algorithm there is hard for me to follow.) Of course it ought to be moved to the top, before the start of the loop, which would require #117062 first.
Activity
gvanrossum commentedon Mar 20, 2024
git bisect points its sneaky little finger at GH-116460.
A workaround would be to comment out the
remove_globals()call in_Py_uop_analyze_and_optimize().gvanrossum commentedon Mar 20, 2024
I was thinking that another workaround would be to leave in the first
_GUARD_GLOBALS_VERSION. In fact, I'm not sure why that isn't kept byremove_globals()? (The algorithm there is hard for me to follow.) Of course it ought to be moved to the top, before the start of the loop, which would require #117062 first.markshannon commentedon Jun 30, 2026
This seems to have been fixed. We add a
_GUARD_GLOBALS_VERSIONto check for this