Issue 7682: Optimisation of if with constant expression (original) (raw)

Issue7682

Created on 2010-01-12 12:22 by sdefresne, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
compile.diff sdefresne,2010-01-12 12:23 Patch
Messages (4)
msg97631 - (view) Author: Sylvain Defresne (sdefresne) Date: 2010-01-12 12:22
Python compiler detect some constant expression used in if / while statement and evaluate them at compilation. However, it does not perform some simple optimisation (evaluating not unary expression or checking if and or or expression are constant because of the first expression). The attached patch allow Python to detect some more constant expression, and to optimise test like the following: if __debug__ and x: pass if not __debug__: pass
msg97632 - (view) Author: Sylvain Defresne (sdefresne) Date: 2010-01-12 12:23
Correct version of the patch.
msg169939 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-09-06 20:42
I'm working on a different approach: an AST optimizer. It is already able to replace "if __debug__ and x: ...." with "if x: ..." ("pythonenv" option must be enabled). https://bitbucket.org/haypo/astoptimizer/
msg350915 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-08-31 10:56
This was optimized in 3.7. See and .
History
Date User Action Args
2022-04-11 14:56:56 admin set github: 51931
2019-08-31 10:56:32 serhiy.storchaka set status: open -> closednosy: + serhiy.storchakamessages: + resolution: out of datestage: patch review -> resolved
2012-09-06 20:42:43 vstinner set nosy: + vstinnermessages: +
2010-03-17 17:28:42 pitrou set nosy: + rhettinger
2010-01-12 12:45:16 pitrou set priority: normalstage: patch review
2010-01-12 12:23:03 sdefresne set files: + compile.diffmessages: +
2010-01-12 12:22:28 sdefresne set files: - compile.diff
2010-01-12 12:22:02 sdefresne create