Re: constant folding - why not more

2020-11-11 Thread Serhiy Storchaka
11.11.20 02:46, Skip Montanaro пише: > I can think of two reasons. One, this kind of comparison will almost never > appear in production code (maybe in unit tests?). Unlike the C family of > languages, Python doesn't have a macro processor which would give symbolic > names to numeric constants or s

Re: constant folding - why not more

2020-11-10 Thread Skip Montanaro
> > On the contrary, comparison remains for runtime: > >>> dis.dis(compile('1 < 2', filename='', mode='eval', > >>> optimize=2)) > 1 0 LOAD_CONST 0 (1) > 2 LOAD_CONST 1 (2) > 4 COMPARE_OP 0 (<) > 6 RETUR

Re: constant folding - why not more

2020-11-10 Thread Chris Angelico
On Wed, Nov 11, 2020 at 4:01 AM David Kolovratník wrote: > On the contrary, comparison remains for runtime: > >>> dis.dis(compile('1 < 2', filename='', mode='eval', > >>> optimize=2)) > 1 0 LOAD_CONST 0 (1) > 2 LOAD_CONST 1 (2) >

Re: constant folding - why not more

2020-11-10 Thread Terry Reedy
On 11/10/2020 1:03 PM, Barry Scott wrote: On 10 Nov 2020, at 14:45, David Kolovratník wrote: Dear all, I would like to learn about constant folding optimisation in Python. It seems to be implemented in Python/ast_opt.c. In order to get impression I used python3 and dis module: $ python3 -V

Re: constant folding - why not more

2020-11-10 Thread Barry Scott
> On 10 Nov 2020, at 14:45, David Kolovratník wrote: > > Dear all, > > I would like to learn about constant folding optimisation in Python. It seems > to be implemented in Python/ast_opt.c. In order to get impression I used > python3 and dis module: > > $ python3 -V > Python 3.7.3 I do not h

constant folding - why not more

2020-11-10 Thread David Kolovratník
Dear all, I would like to learn about constant folding optimisation in Python. It seems to be implemented in Python/ast_opt.c. In order to get impression I used python3 and dis module: $ python3 -V Python 3.7.3 Arithmetics expression is folded as expected: >>> dis.dis(compile('1 * 2', filename=