This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Patch for bug 1441486: bad unary minus folding in compiler
Type: Stage:
Components: None Versions:
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: nascheme Nosy List: logistix, nascheme, nnorwitz
Priority: normal Keywords: patch

Created on 2006-03-10 02:33 by logistix, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
bad_long.diff logistix, 2006-03-10 02:33 Fix for unary minus constant folding
unary-minus.patch nnorwitz, 2006-03-20 07:39 nn revised version 1
Messages (3)
msg49710 - (view) Author: Grant Olson (logistix) Date: 2006-03-10 02:33
In the old compiler, there was a optimization in
com_factor that folded a unary minus against a constant.

In the new AST, it looks like numbers are converted
from strings into PyObjects earlier in the pipeline. 
The compiler does fold a unary minus against a
constant, but since the PyObject has already been
created, it may return a PyLong when a PyInt is
sufficient.  This patch adds a check that will convert
a PyLong object back into a PyInt if possible.
msg49711 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-03-20 07:39
Logged In: YES 


Unfortunately, this patch leaves the long in co_consts:

>>> def foo():
...   x = -9223372036854775808
>>> foo.func_code.co_consts
(None, 9223372036854775808L, -9223372036854775808)

This is a 64-bit system.  On 2.4, there is only sys.minint:

Python 2.4.2 (#1, Oct 30 2005, 21:35:48)
>>> def foo():
...   x = -9223372036854775808
>>> foo.func_code.co_consts
(None, -9223372036854775808)

Can you revise the patch to fix this?  I cleaned up some
things.  Attached is an updated version I was using.
msg49712 - (view) Author: Neil Schemenauer (nascheme) * (Python committer) Date: 2006-07-09 21:20
Logged In: YES 

Fixed in SVN rev 50495.  I did the folding in the CST->AST
phase, similar to how it was done in the old compiler.
Date User Action Args
2022-04-11 14:56:15adminsetgithub: 43007
2006-03-10 02:33:08logistixcreate