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
Long constant calculations stall compilation #71882
We realize the computation is a large one and takes a very long time, in this case the compiler consumes more and more memory over time. Perhaps the compiler shouldn't try to calculate this indefinitely and just return an error.
I'd say the current behavior of the compilation taking a long time is fine since at runtime it would run the exact same "2 ** 12345678912345" expression and spend a long time/run out of memory.
However I'd say the fact that this happens so silently can be a "gotcha" in some very rare cases.
FYI my Python reimplementation of the bytecode peephole optimizer doesn't
have this issue. It estimates the size of a**b using exp() and ln()
functions. http://bytecode.readthedocs.io/en/latest/
Activity
fcostantini commentedon Aug 5, 2016
Hi, we currently are fuzzing Python programs to find valid code that fails to compile. We found this program never finishes its compilation.
We realize the computation is a large one and takes a very long time, in this case the compiler consumes more and more memory over time. Perhaps the compiler shouldn't try to calculate this indefinitely and just return an error.
Regards
SilentGhost commentedon Aug 5, 2016
On 3.6 it takes a very long time, but it does finish.
real 1m35.673s
user 1m18.952s
sys 0m16.644s
ammaraskar commentedon Aug 5, 2016
Just in case anyone is wondering why this happens. The compiler's peephole optimizer will fold constant expressions like
into
More specifically, this bit here:
cpython/Python/peephole.c
Line 240 in 0f21fe6
I'd say the current behavior of the compilation taking a long time is fine since at runtime it would run the exact same "2 ** 12345678912345" expression and spend a long time/run out of memory.
However I'd say the fact that this happens so silently can be a "gotcha" in some very rare cases.
vstinner commentedon Aug 5, 2016
FYI my Python reimplementation of the bytecode peephole optimizer doesn't
have this issue. It estimates the size of a**b using exp() and ln()
functions.
http://bytecode.readthedocs.io/en/latest/
[-]Compilation doesnt' end[/-][+]Long constant calculations stall compilation[/+]serhiy-storchaka commentedon Aug 6, 2016
See also bpo-21074.