[issue42903] optimize lru_cache for functions with no arguments

2021-01-12 Thread Eugene Toder
Eugene Toder added the comment: @cache does not address the problem or any of the concerns brought up in the thread. Thread-safe @once is a nice idea, but more work of course. -- ___ Python tracker <https://bugs.python.org/issue42

[issue42903] optimize lru_cache for functions with no arguments

2021-01-11 Thread Eugene Toder
Eugene Toder added the comment: Ammar, thank you for the link. -- ___ Python tracker <https://bugs.python.org/issue42903> ___ ___ Python-bugs-list mailin

[issue42903] optimize lru_cache for functions with no arguments

2021-01-11 Thread Eugene Toder
Eugene Toder added the comment: As you can see in my original post, the difference between @cache (aka @lru_cache(None)) and just @lru_cache() is negligible in this case. The optimization in this PR makes a much bigger difference. At the expense of some lines of code, that's true. Also

[issue42903] optimize lru_cache for functions with no arguments

2021-01-11 Thread Eugene Toder
New submission from Eugene Toder : It's convenient to use @lru_cache on functions with no arguments to delay doing some work until the first time it is needed. Since @lru_cache is implemented in C, it is already faster than manually caching in a closure variable. However, it can be made even

[issue42125] linecache cannot get source for the __main__ module with a custom loader

2020-12-18 Thread Eugene Toder
Change by Eugene Toder : -- nosy: +ncoghlan, vstinner ___ Python tracker <https://bugs.python.org/issue42125> ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue42125] linecache cannot get source for the __main__ module with a custom loader

2020-12-15 Thread Eugene Toder
Change by Eugene Toder : -- nosy: +brett.cannon ___ Python tracker <https://bugs.python.org/issue42125> ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue42125] linecache cannot get source for the __main__ module with a custom loader

2020-10-22 Thread Eugene Toder
New submission from Eugene Toder : If a module has a loader, linecache calls its get_source() passing __name__ as the argument. This works most of the time, except that the __main__ module has it set to "__main__", which is commonly not the real name of the module. Luckily, w

[issue11549] Build-out an AST optimizer, moving some functionality out of the peephole optimizer

2017-02-01 Thread Eugene Toder
Eugene Toder added the comment: Yes, doing optimizations on AST in CPython is unlikely to give any sizable speed improvements in real world programs. Python as a language is not suited for static optimization, and even if you manage to inline a function, there's still CPython's interpreted

[issue11549] Build-out an AST optimizer, moving some functionality out of the peephole optimizer

2017-01-31 Thread Eugene Toder
Eugene Toder added the comment: > We have already Constant and NameConstant. So it seems there are no need for > None, Bool, TupleConst, SetConst nodes. Yes, Constant is Victor's version of Lit. > I think converting Num, Str, Bytes, Ellipsis into Constant in folding stage > is

[issue20371] datetime.datetime.replace bypasses a subclass's __new__

2016-05-15 Thread Eugene Toder
Eugene Toder added the comment: namedtuple._replace() actually doesn't call subclass' __new__. It calls tuple.__new__ directly, so it has the same problem as datetime classes. Parameter and Signature are new in 3.3. I'm not sure if they're expected to be used as base classes. @r.david.murray

[issue20371] datetime.datetime.replace bypasses a subclass's __new__

2016-05-15 Thread Eugene Toder
Eugene Toder added the comment: This seems like it can lead to even more subtle bugs when replace() is not overriden. Currently, any extra state in the subclass is left uninitialized, which usually leads to obvious breakage and is relatively easy to trace back to replace(). (I've done

[issue20371] datetime.datetime.replace bypasses a subclass's __new__

2016-05-15 Thread Eugene Toder
Eugene Toder added the comment: Yes, this is similar to my second approach. (You need to copy via __reduce__, because __copy__ my have been overriden to return self.) The general problem with it, is that if a subclass is designed to be immutable (probably a common case here), it may

[issue20371] datetime.datetime.replace bypasses a subclass's __new__

2016-05-15 Thread Eugene Toder
Eugene Toder added the comment: Properly supporting subclasses in replace() is hard, at least without some cooperation from subclasses. For a proper replace() x.replace(a=newval).b == x.b should hold for every b not dependent on a, including ones added by subclasses. That is, it should

[issue11549] Build-out an AST optimizer, moving some functionality out of the peephole optimizer

2016-05-15 Thread Eugene Toder
Eugene Toder added the comment: Serhiy: Nice! Yes, _PyCode_ConstantKey solved the problem. But #16619 went in the opposite direction of this patch, and introduced a new type of literal node instead of unifying the existing ones. Kind of a shame, since *this* patch, I believe, both fixes

[issue11549] Build-out an AST optimizer, moving some functionality out of the peephole optimizer

2016-05-14 Thread Eugene Toder
Eugene Toder added the comment: Fairly sure it's 5 years old. -- ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue11549> ___ ___ Pyth

[issue23640] int.from_bytes() is broken for subclasses

2016-05-11 Thread Eugene Toder
Eugene Toder added the comment: They sure do. Check the example in my comment, or if you prefer the source code, it's pretty clear as well: https://hg.python.org/cpython/file/fff0c783d3db/Modules/_datetimemodule.c#l2770 -- ___ Python tracker <

[issue23640] int.from_bytes() is broken for subclasses

2016-05-11 Thread Eugene Toder
Eugene Toder added the comment: There's a similar issue with replace() methods on date/time/datetime classes. They create instances of derived types without calling derived __new__/__init__, thus potentially leaving those uninitialized. >>> from datetime import date >>

[issue24991] Define instance mutability explicitly on type objects

2015-09-03 Thread Eugene Toder
Changes by Eugene Toder <elto...@gmail.com>: -- nosy: +eltoder ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue24991> ___ __

[issue24912] The type of cached objects is mutable

2015-09-01 Thread Eugene Toder
Eugene Toder added the comment: Guido: IIUC the general intention is to support @property and __getattr__ style hooks on the module level. Assigning to sys.modules[name] from the module itself is a bit too late -- there's already a global dict for this module, and no way to create a module

[issue24912] The type of cached objects is mutable

2015-09-01 Thread Eugene Toder
Eugene Toder added the comment: Nathaniel, what if we allow creating module objects from an existing dict instead of always creating a new one. Does this solve your namespace diversion problem? FWIW, when I discovered this change I was quite surprised this came through without a PEP. I agree

[issue23726] Don't enable GC for classes that don't add new fields

2015-04-13 Thread Eugene Toder
Eugene Toder added the comment: Thank you! Benjamin, Nathaniel, any opinion if we should restrict reassigning __class__ for types like tuple, int and str, where some/many instances are cached? -- nosy: +njs ___ Python tracker rep...@bugs.python.org

[issue23726] Don't enable GC for classes that don't add new fields

2015-04-13 Thread Eugene Toder
Eugene Toder added the comment: Agreed. There's a small problem with that, as far as I know. Nothing on type declares that it is immutable. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23726

[issue23726] Don't enable GC for classes that don't add new fields

2015-03-21 Thread Eugene Toder
Changes by Eugene Toder elto...@gmail.com: Added file: http://bugs.python.org/file38624/class_gc2.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23726

[issue23726] Don't enable GC for classes that don't add new fields

2015-03-20 Thread Eugene Toder
New submission from Eugene Toder: As far as I can tell, if a new class does not add any new fields, and its base class doesn't use GC, there's no reason to enable GC for the new class. This is useful for creating lightweight wrappers around classes implemented in C. -- files

[issue23726] Don't enable GC for classes that don't add new fields

2015-03-20 Thread Eugene Toder
Eugene Toder added the comment: Agreed, but this is not new. This works without my change: class Tuple(tuple): ... __slots__ = () ... def __repr__(self): return 'Imma tuple!' ... ().__class__ = Tuple () Imma tuple

[issue23726] Don't enable GC for classes that don't add new fields

2015-03-20 Thread Eugene Toder
Eugene Toder added the comment: Actually, this is rather new -- new in 3.5. The check was relaxed in #22986: https://hg.python.org/cpython/rev/c0d25de5919e Previously only heap types allowed re-assigning __class__. -- ___ Python tracker rep

[issue11983] Inconsistent hash and comparison for code objects

2013-01-19 Thread Eugene Toder
Eugene Toder added the comment: If you add co_firstlineno into code_hash you can say something like /* The rest isn't used in hash and comparisons, except co_name and co_firstlineno, which are preserved for tracebacks and debuggers. */ (Otherwise you'd need to explain why co_firstlineno

[issue11983] Inconsistent hash and comparison for code objects

2013-01-16 Thread Eugene Toder
Eugene Toder added the comment: My comment will make more sense if you follow the links that I provided. Brett's check-in (http://hg.python.org/cpython-fullhistory/rev/8127a55a57cb) says that it fixes bug #1190011 (http://www.mail-archive.com/python-bugs-list@python.org/msg02440.html

[issue1062277] Pickle breakage with reduction of recursive structures

2012-12-28 Thread Eugene Toder
Eugene Toder added the comment: To recap, the issue is that pickle doesn't handle recursion via reduce arguments (i.e. arguments to the constructor function as returned in 2nd element of the tuple from __reduce__). This leads to 2 kind of effects: class C: def __init__(self, x=None

[issue1062277] Pickle breakage with reduction of recursive structures

2012-12-28 Thread Eugene Toder
Changes by Eugene Toder elto...@gmail.com: -- versions: +Python 3.3, Python 3.4 -Python 3.1 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1062277

[issue16602] weakref can return an object with 0 refcount

2012-12-08 Thread Eugene Toder
Eugene Toder added the comment: Thank you, Antoine. This change has one effect that's worth highlighting in NEWS at least -- the PyWeakref_GET_OBJECT() macro now evaluates its argument twice. This can break existing code where the argument has side-effects, e.g. o = PyWeakref_GET_OBJECT(p

[issue16602] weakref can return an object with 0 refcount

2012-12-08 Thread Eugene Toder
Eugene Toder added the comment: People should simply avoid doing this kind of thing, as it's knowingly fragile, and trivial to avoid anyway. Is this documented in the C API guide, or somewhere else? In any case, notifying people so they can quickly check their code seems much nicer than

[issue16602] weakref can return an object with 0 refcount

2012-12-04 Thread Eugene Toder
Eugene Toder added the comment: Agreed. That's what I've put in my code as a work around. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16602

[issue16602] weakref can return an object with 0 refcount

2012-12-03 Thread Eugene Toder
New submission from Eugene Toder: An interaction between weakrefs and trashcan can cause weakref to return the object it's pointing to after object's refcount is already 0. Given that the object is usually increfed and decrefed, this leads to double dealloc and crashing or hanging. Tested

[issue11549] Build-out an AST optimizer, moving some functionality out of the peephole optimizer

2012-09-05 Thread Eugene Toder
Eugene Toder added the comment: Method calls on literals are always fair game, though (e.g. you could optimise a b c.split()) What about optimizations that do not change behavior, except for different error messages? E.g. we can change y = [1,2][x] to y = (1,2)[x] where the tuple is constant

[issue11549] Build-out an AST optimizer, moving some functionality out of the peephole optimizer

2012-09-05 Thread Eugene Toder
Eugene Toder added the comment: If I'm not missing something, changing x in [1,2] to x in (1,2) and x in {1,2} to x in frozenset([1,2]) does not change any error messages. Agreed that without dynamic compilation we can pretty much only track literals (including functions and lambdas) assigned

[issue11816] Refactor the dis module to provide better building blocks for bytecode analysis

2011-08-23 Thread Eugene Toder
Changes by Eugene Toder elto...@gmail.com: -- nosy: -eltoder ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11816 ___ ___ Python-bugs-list mailing

[issue5996] abstract class instantiable when subclassing dict

2011-07-11 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: They are, when there's a most specific metaclass -- the one which is a subclass of all others (described here http://www.python.org/download/releases/2.2.3/descrintro/#metaclasses, implemented here http://hg.python.org/cpython/file

[issue12290] __setstate__ is called for false values

2011-06-15 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: So how about this correction? -- keywords: +patch nosy: +belopolsky, georg.brandl Added file: http://bugs.python.org/file22375/setstate.diff ___ Python tracker rep...@bugs.python.org http

[issue5996] abstract class instantiable when subclassing dict

2011-06-15 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: Anyone has any thoughts on this? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5996

[issue11549] Build-out an AST optimizer, moving some functionality out of the peephole optimizer

2011-06-15 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: I found a problem in constant de-duplication, already performed by compiler, that needs to be fixed before this change can be merged. Compiler tries to eliminate duplicate constants by putting them into a dict. However, duplicate in this case

[issue12290] __setstate__ is called for false values

2011-06-08 Thread Eugene Toder
New submission from Eugene Toder elto...@gmail.com: Pickle documentation [1] says: Note: If __getstate__() returns a false value, the __setstate__() method will not be called upon unpickling. However, this isn't quite true. This depends on the version of pickle protocol. A small example

[issue12290] __setstate__ is called for false values

2011-06-08 Thread Eugene Toder
Changes by Eugene Toder elto...@gmail.com: -- nosy: +alexandre.vassalotti, pitrou ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12290

[issue11549] Build-out an AST optimizer, moving some functionality out of the peephole optimizer

2011-06-07 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: Nick, if there's an interest in reviewing the patch I can update the it. I doubt it needs a lot of changes, given that visitor is auto-generated. Raymond, the patch contains a rewrite of low-level optimizations to work before byte code

[issue11983] Inconsistent hash and comparison for code objects

2011-05-08 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: It appears that * co_name was added to hash and cmp in this check-in by Guido: http://hg.python.org/cpython-fullhistory/diff/525b2358721e/Python/compile.c I think the reason was to preserve function name when defining multiple functions

[issue11983] Inconsistent hash and comparison for code objects

2011-05-08 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: Btw, disabling dedup for codes won't be the first exception -- we already avoid coalescing -0.0 with 0.0 for float and complex, even though they compare equal. -- ___ Python tracker rep

[issue11983] Inconsistent hash and comparison for code objects

2011-05-06 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: I would propose changing implementation to match the comment. At a minimum, remove co_firstlineno comparison. As the last resort, at least change the comment. -- ___ Python tracker rep

[issue11983] Inconsistent hash and comparison for code objects

2011-05-02 Thread Eugene Toder
New submission from Eugene Toder elto...@gmail.com: A comment in the definition of PyCodeObject in Include/code.h says: /* The rest doesn't count for hash or comparisons */ which, I think, makes a lot of sense. The implementation doesn't follow this comment, though. code_hash actually

[issue11816] Refactor the dis module to provide better building blocks for bytecode analysis

2011-04-10 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: So in the near term, dis-based tests should continue to copy/paste sys.stdout redirection code? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11816

[issue11816] Add functions to return disassembly as string

2011-04-09 Thread Eugene Toder
New submission from Eugene Toder elto...@gmail.com: As discussed in Issue11549 a couple of tests need to inspect disassembly of some code. Currently they have to override sys.stdout, run dis and restore stdout back. It would be much nicer if dis module provided functions that return

[issue11816] Add functions to return disassembly as string

2011-04-09 Thread Eugene Toder
Changes by Eugene Toder elto...@gmail.com: Removed file: http://bugs.python.org/file21598/dis.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11816

[issue11816] Add functions to return disassembly as string

2011-04-09 Thread Eugene Toder
Changes by Eugene Toder elto...@gmail.com: Added file: http://bugs.python.org/file21599/dis.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11816

[issue11816] Add functions to return disassembly as string

2011-04-09 Thread Eugene Toder
Changes by Eugene Toder elto...@gmail.com: -- nosy: +ncoghlan ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11816 ___ ___ Python-bugs-list mailing

[issue11816] Add functions to return disassembly as string

2011-04-09 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: Agreed, but that would require rewriting of all tests in test_peepholer. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11816

[issue5996] abstract class instantiable when subclassing dict

2011-04-09 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: This patch fixes the problem by moving the check from object_new to PyType_GenericAlloc. The check is very cheap, so this should not be an issue. -- keywords: +patch nosy: +eltoder Added file: http://bugs.python.org/file21600/abc.patch

[issue11549] Rewrite peephole to work on AST

2011-03-28 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: If we have to preserve backward compatibility of Python AST API, we can do this relatively easily (at the expense of some code complexity): * Add 'version' argument to compile() and ast.parse() with default value of 1 (old AST). Value 2

[issue11549] Rewrite peephole to work on AST

2011-03-27 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: Thanks. string concatenation will now work, and errors like 'hello' - 'world' should give a more informative TypeError Yes, 'x'*5 works too. Bikeshed: We use Attribute rather than Attr for that node type, perhaps the full Literal name would

[issue11549] Rewrite peephole to work on AST

2011-03-27 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: and with __future__ it should work on 2.5 as well. Actually, seems that at least str.format is not in 2.5 as well. Still the question is should I make it run on 2.5 or 2.4 or is 2.6 OK (then __future__ can be removed

[issue11549] Rewrite peephole to work on AST

2011-03-27 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: I don't think it can: That already doesn't work in dict and set (eq not consistent with hash), I don't think it's a big problem if that stops working in some other cases. Anyway, I said theoretically -- maybe after some conservative type

[issue11549] Rewrite peephole to work on AST

2011-03-27 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: Also, to avoid any confusion -- currently my patch only runs AST optimizations before code generation, so compile() with ast.PyCF_ONLY_AST returns non-optimized AST. -- ___ Python tracker rep

[issue11549] Rewrite peephole to work on AST

2011-03-23 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: Is anyone looking or planing to look at the patch? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11549

[issue11549] Rewrite peephole to work on AST

2011-03-19 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: AFAICT my patch has everything that #1346238 has, except BoolOps, which can be easily added (there's a TODO). I don't want to add any new code, though, until the current patch will get reviewed -- adding code will only make reviewing harder

[issue11549] Rewrite peephole to work on AST

2011-03-16 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: Any comments on the code so far or suggestions on how we should move forward? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11549

[issue11549] Rewrite peephole to work on AST

2011-03-16 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: I've updated patches on Rietveld with some small changes. This includes better code generation for boolops used outside of conditions and cleaned up optimize_jumps(). This is probably the last change before I get some feedback. Also, I forgot

[issue11549] Rewrite peephole to work on AST

2011-03-16 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: Just for fun I've run pystones. W/o my changes it averages to about 70k, with my changes to about 72.5k. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11549

[issue11244] Negative tuple elements produce inefficient code.

2011-03-15 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: Is anyone reviewing my patch? It's just 1 line long. Should it be moved to another issue? Though, technically, it's needed to address the regression in question: Python 3.1 folds -0, the current code still does

[issue11549] Rewrite peephole to work on AST

2011-03-15 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: Because I don't know how to make them. Any pointers? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11549

[issue11549] Rewrite peephole to work on AST

2011-03-15 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: Thanks. Review link: http://codereview.appspot.com/4281051 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11549

[issue11549] Rewrite peephole to work on AST

2011-03-15 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: I see. Should I attach diffs vs. some revision from hg.python.org? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11549

[issue11510] Peephole breaks set unpacking

2011-03-14 Thread Eugene Toder
New submission from Eugene Toder elto...@gmail.com: Since the time 'x in set' optimization was added to peephole it has the following bug with set unpacking: def foo(x,y): a,b = {x,y} return a,b dis(foo) 2 0 LOAD_FAST0 (x) 3

[issue11549] Rewrite peephole to work on AST

2011-03-14 Thread Eugene Toder
New submission from Eugene Toder elto...@gmail.com: As pointed out by Raymond, constant folding should be done on AST rather than on generated bytecode. Here's a patch to do that. It's rather long, so overview first. The patch replaces existing peephole pass with a folding pass on AST

[issue11549] Rewrite peephole to work on AST

2011-03-14 Thread Eugene Toder
Changes by Eugene Toder elto...@gmail.com: -- keywords: +patch Added file: http://bugs.python.org/file21198/0_ast.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11549

[issue11549] Rewrite peephole to work on AST

2011-03-14 Thread Eugene Toder
Changes by Eugene Toder elto...@gmail.com: Added file: http://bugs.python.org/file21199/0_fold.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11549

[issue11549] Rewrite peephole to work on AST

2011-03-14 Thread Eugene Toder
Changes by Eugene Toder elto...@gmail.com: Added file: http://bugs.python.org/file21200/0_compile.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11549

[issue11549] Rewrite peephole to work on AST

2011-03-14 Thread Eugene Toder
Changes by Eugene Toder elto...@gmail.com: Added file: http://bugs.python.org/file21201/0_generated.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11549

[issue11549] Rewrite peephole to work on AST

2011-03-14 Thread Eugene Toder
Changes by Eugene Toder elto...@gmail.com: Added file: http://bugs.python.org/file21202/0_tests.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11549

[issue11549] Rewrite peephole to work on AST

2011-03-14 Thread Eugene Toder
Changes by Eugene Toder elto...@gmail.com: -- nosy: +pitrou, rhettinger ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11549 ___ ___ Python-bugs

[issue11462] Peephole creates duplicate and unused constants

2011-03-11 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: Antoine, sure, I'll fix it with any other suggested changes if patches will be accepted. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11462

[issue11244] Negative tuple elements produce inefficient code.

2011-03-11 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: Mark, looks better now? -- Added file: http://bugs.python.org/file21082/fold-0.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244

[issue11244] Negative tuple elements produce inefficient code.

2011-03-11 Thread Eugene Toder
Changes by Eugene Toder elto...@gmail.com: Removed file: http://bugs.python.org/file21082/fold-0.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244

[issue11244] Negative tuple elements produce inefficient code.

2011-03-11 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: (forgot parens around 0) -- Added file: http://bugs.python.org/file21083/fold-0.2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244

[issue11462] Peephole creates duplicate and unused constants

2011-03-11 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: - why the #ifndef NDEBUG path? These entries in the table should not be used, but if something slips through and uses one of them, it's much easier to tell if we remap to invalid value. As this is an internal check, I didn't want it in release

[issue11462] Peephole creates duplicate and unused constants

2011-03-11 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: assert() doesn't quite work here. I need to check that this entry in the table is not used in the next loop. I'd need to put assert in that loop, but by that time I have no easy way to tell which entries are bad, unless I mark them

[issue11462] Peephole creates duplicate and unused constants

2011-03-11 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: _PyCode_AddObj() should be added to Include/code.h Should it be declared as PyAPI_FUNC too? This will make it unnecessarily exported (when patch in Issue11410 is merged), so I wanted to avoid that. btw, that you for reviewing the patch

[issue11462] Peephole creates duplicate and unused constants

2011-03-11 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: Right now, the pattern is tokenize - parse - AST - genbytecode - peephole optimization (which disassembles the bytecode, analyzed it and rewrites it) - final bytecode. The correct pattern is tokenize - parse - AST - optimize - genbytecode

[issue11471] If without else generates redundant jump

2011-03-11 Thread Eugene Toder
New submission from Eugene Toder elto...@gmail.com: If statement without else part generates unnecessary JUMP_FORWARD insn with jumps right to the next insn: def foo(x): if x: x = 1 dis(foo) 2 0 LOAD_FAST0 (x) 3 POP_JUMP_IF_FALSE 15

[issue11471] If without else generates redundant jump

2011-03-11 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: Test case (needed some refactoring to avoid duplication). -- Added file: http://bugs.python.org/file21092/if_no_else_test.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org

[issue11462] Peephole creates duplicate and unused constants

2011-03-11 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: Thomas, can you clarify, does loading interns all constants in co_consts, or do you mean that they are mostly small numbers and the like? Without interning I think that in-memory size difference is even bigger than on-disk, as you get one

[issue11244] Negative tuple elements produce inefficient code.

2011-03-11 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: Yes, my patch doesn't fix the regression, only a special case of -0. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244

[issue11462] Peephole creates duplicate and unused constants

2011-03-11 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: Alexander, my patch does 2 optimizations: doesn't insert a new constant if one already exist and removes unused constants after peephole is done. You patch seems to do only the latter. It's very similar, from a quick look at your patch: - My

[issue11462] Peephole creates duplicate and unused constants

2011-03-11 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: Raymond, you can be assured that I'm not developing this patch, unless I'm told it has chances to be accepted. I don't like to waste my time. On a related note, your review of my other patches is appreciated

[issue11244] Negative tuple elements produce inefficient code.

2011-03-10 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: As discussed on the list, peephole refuses to fold -0. The reasons for this are unclear. Folding was disabled with this commit: http://hg.python.org/cpython/diff/660419bdb4ae/Python/compile.c Here's a trivial patch to enable the folding again

[issue11462] Peephole creates duplicate and unused constants

2011-03-10 Thread Eugene Toder
New submission from Eugene Toder elto...@gmail.com: Peephole optimizer performs constant folding, however 1) When it replaces operation with LOAD_CONST it always adds a new constant to co_consts, even if constant with the same value is already there. It also can add the same constant multiple

[issue11462] Peephole creates duplicate and unused constants

2011-03-10 Thread Eugene Toder
Changes by Eugene Toder elto...@gmail.com: -- keywords: +patch Added file: http://bugs.python.org/file21074/dedup_const_plana.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11462

[issue11462] Peephole creates duplicate and unused constants

2011-03-10 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: (either plana or planb should be applied) -- Added file: http://bugs.python.org/file21075/dedup_const_planb.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11462

[issue11462] Peephole creates duplicate and unused constants

2011-03-10 Thread Eugene Toder
Changes by Eugene Toder elto...@gmail.com: Added file: http://bugs.python.org/file21076/unused_consts.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11462

[issue11462] Peephole creates duplicate and unused constants

2011-03-10 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: (test case) -- nosy: +pitrou Added file: http://bugs.python.org/file21077/consts_test.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11462

[issue11462] Peephole creates duplicate and unused constants

2011-03-10 Thread Eugene Toder
Eugene Toder elto...@gmail.com added the comment: I think the changes are fairly trivial. dedup_const_planb.patch is about 10 lines of new code with all the rest being trivial plubming. unused_consts.patch may look big, but only because I factored out fix ups into a separate function