Issue 27695: Long constant calculations stall compilation (original) (raw)
Issue27695
Created on 2016-08-05 17:39 by fcostantini, last changed 2022-04-11 14:58 by admin. This issue is now closed.
Messages (5) | ||
---|---|---|
msg272046 - (view) | Author: Franco Costantini (fcostantini) | Date: 2016-08-05 17:39 |
Hi, we currently are fuzzing Python programs to find valid code that fails to compile. We found this program never finishes its compilation. $ echo "raise ValueError ; 2 ** 12345678912345" > inf.py $ python -m py_compile inf.py 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 | ||
msg272047 - (view) | Author: SilentGhost (SilentGhost) * ![]() |
Date: 2016-08-05 17:47 |
On 3.6 it takes a very long time, but it does finish. time ./python -c "raise ValueError ; 2 ** 12345678912345" Traceback (most recent call last): File "", line 1, in ValueError real 1m35.673s user 1m18.952s sys 0m16.644s | ||
msg272050 - (view) | Author: Ammar Askar (ammar2) * ![]() |
Date: 2016-08-05 18:09 |
Just in case anyone is wondering why this happens. The compiler's peephole optimizer will fold constant expressions like x = 5 + 5 into x = 10 More specifically, this bit here: https://github.com/python/cpython/blob/0f21fe6155227d11dc02bd3ef3b061de4ecea445/Python/peephole.c#L240 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. | ||
msg272066 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2016-08-05 22:20 |
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/ | ||
msg272105 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2016-08-06 19:54 |
See also . |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:58:34 | admin | set | github: 71882 |
2017-12-14 13:16:06 | serhiy.storchaka | set | status: open -> closedsuperseder: Too aggressive constant foldingresolution: duplicatestage: resolved |
2016-08-06 19:54:30 | serhiy.storchaka | set | messages: + |
2016-08-06 17:49:14 | brett.cannon | set | title: Compilation doesnt' end -> Long constant calculations stall compilation |
2016-08-05 22:20:29 | vstinner | set | messages: + |
2016-08-05 18:09:59 | ammar2 | set | nosy: + ammar2messages: + |
2016-08-05 17:47:23 | SilentGhost | set | nosy: + SilentGhostmessages: + |
2016-08-05 17:45:01 | SilentGhost | set | type: compile error -> resource usageversions: + Python 2.7 |
2016-08-05 17:43:26 | SilentGhost | set | nosy: + vstinner, serhiy.storchakacomponents: + Interpreter Coreversions: + Python 3.6, - Python 2.7 |
2016-08-05 17:39:36 | fcostantini | create |