Eugene Toder 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 generation,
New submission from Eugene Toder :
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 pro
Changes by Eugene Toder :
--
nosy: +alexandre.vassalotti, pitrou
___
Python tracker
<http://bugs.python.org/issue12290>
___
___
Python-bugs-list mailing list
Unsub
Eugene Toder 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
<http://bugs.python.org/issue12
Eugene Toder added the comment:
Anyone has any thoughts on this?
--
___
Python tracker
<http://bugs.python.org/issue5996>
___
___
Python-bugs-list mailin
Eugene Toder 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 do
Eugene Toder 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/ab162f925761/Ob
Changes by Eugene Toder :
--
nosy: -eltoder
___
Python tracker
<http://bugs.python.org/issue11816>
___
___
Python-bugs-list mailing list
Unsubscribe:
Eugene Toder 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, along with a
New submission from Eugene Toder :
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 times.
2) It does
Changes by Eugene Toder :
--
keywords: +patch
Added file: http://bugs.python.org/file21074/dedup_const_plana.patch
___
Python tracker
<http://bugs.python.org/issue11
Eugene Toder added the comment:
(either plana or planb should be applied)
--
Added file: http://bugs.python.org/file21075/dedup_const_planb.patch
___
Python tracker
<http://bugs.python.org/issue11
Changes by Eugene Toder :
Added file: http://bugs.python.org/file21076/unused_consts.patch
___
Python tracker
<http://bugs.python.org/issue11462>
___
___
Python-bug
Eugene Toder added the comment:
(test case)
--
nosy: +pitrou
Added file: http://bugs.python.org/file21077/consts_test.patch
___
Python tracker
<http://bugs.python.org/issue11
Eugene Toder 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;
there are only about 25
Eugene Toder added the comment:
Antoine, sure, I'll fix it with any other suggested changes if patches will be
accepted.
--
___
Python tracker
<http://bugs.python.org/is
Eugene Toder added the comment:
Mark, looks better now?
--
Added file: http://bugs.python.org/file21082/fold-0.patch
___
Python tracker
<http://bugs.python.org/issue11
Changes by Eugene Toder :
Removed file: http://bugs.python.org/file21082/fold-0.patch
___
Python tracker
<http://bugs.python.org/issue11244>
___
___
Python-bugs-list m
Eugene Toder added the comment:
(forgot parens around 0)
--
Added file: http://bugs.python.org/file21083/fold-0.2.patch
___
Python tracker
<http://bugs.python.org/issue11
Eugene Toder 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 i
Eugene Toder 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 in
the first loop.
Eugene Toder 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 pa
Eugene Toder 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 -&g
New submission from Eugene Toder :
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
Eugene Toder 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
<http://bugs.python.org/issue11
Eugene Toder 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 entry in tuple and
Eugene Toder added the comment:
Yes, my patch doesn't fix the regression, only a special case of -0.
--
___
Python tracker
<http://bugs.python.org/is
Eugene Toder 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 pat
Eugene Toder 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
New submission from Eugene Toder :
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
New submission from Eugene Toder :
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 and a few
Changes by Eugene Toder :
--
keywords: +patch
Added file: http://bugs.python.org/file21198/0_ast.patch
___
Python tracker
<http://bugs.python.org/issue11
Changes by Eugene Toder :
Added file: http://bugs.python.org/file21199/0_fold.patch
___
Python tracker
<http://bugs.python.org/issue11549>
___
___
Python-bugs-list mailin
Changes by Eugene Toder :
Added file: http://bugs.python.org/file21200/0_compile.patch
___
Python tracker
<http://bugs.python.org/issue11549>
___
___
Python-bugs-list m
Changes by Eugene Toder :
Added file: http://bugs.python.org/file21201/0_generated.patch
___
Python tracker
<http://bugs.python.org/issue11549>
___
___
Python-bugs-list m
Changes by Eugene Toder :
Added file: http://bugs.python.org/file21202/0_tests.patch
___
Python tracker
<http://bugs.python.org/issue11549>
___
___
Python-bugs-list mailin
Changes by Eugene Toder :
--
nosy: +pitrou, rhettinger
___
Python tracker
<http://bugs.python.org/issue11549>
___
___
Python-bugs-list mailing list
Unsubscribe:
Eugene Toder 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 stil
Eugene Toder added the comment:
Because I don't know how to make them. Any pointers?
--
___
Python tracker
<http://bugs.python.org/issue11549>
___
___
Pytho
Eugene Toder added the comment:
Thanks. Review link: http://codereview.appspot.com/4281051
--
___
Python tracker
<http://bugs.python.org/issue11549>
___
___
Pytho
Eugene Toder added the comment:
I see. Should I attach diffs vs. some revision from hg.python.org?
--
___
Python tracker
<http://bugs.python.org/issue11
Eugene Toder added the comment:
Any comments on the code so far or suggestions on how we should move forward?
--
___
Python tracker
<http://bugs.python.org/issue11
Eugene Toder 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 to me
Eugene Toder 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
<http://bugs.python.org/is
Eugene Toder 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.
#1
Eugene Toder added the comment:
Is anyone looking or planing to look at the patch?
--
___
Python tracker
<http://bugs.python.org/issue11549>
___
___
Python-bug
Eugene Toder 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
Eugene Toder 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 remo
Eugene Toder 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
Eugene Toder 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
<http://bugs.python.
Eugene Toder 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 will corresp
New submission from Eugene Toder :
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 disassembly as a string
Changes by Eugene Toder :
Removed file: http://bugs.python.org/file21598/dis.diff
___
Python tracker
<http://bugs.python.org/issue11816>
___
___
Python-bugs-list mailin
Changes by Eugene Toder :
Added file: http://bugs.python.org/file21599/dis.patch
___
Python tracker
<http://bugs.python.org/issue11816>
___
___
Python-bugs-list mailin
Changes by Eugene Toder :
--
nosy: +ncoghlan
___
Python tracker
<http://bugs.python.org/issue11816>
___
___
Python-bugs-list mailing list
Unsubscribe:
Eugene Toder added the comment:
Agreed, but that would require rewriting of all tests in test_peepholer.
--
___
Python tracker
<http://bugs.python.org/issue11
Eugene Toder 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
Eugene Toder added the comment:
So in the near term, dis-based tests should continue to copy/paste sys.stdout
redirection code?
--
___
Python tracker
<http://bugs.python.org/issue11
New submission from Eugene Toder :
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 includes c
Eugene Toder 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
<http://bugs.python.
Eugene Toder 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 with the same code in
Eugene Toder 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
<http://bugs.py
Change by Eugene Toder :
--
nosy: +brett.cannon
___
Python tracker
<https://bugs.python.org/issue42125>
___
___
Python-bugs-list mailing list
Unsubscribe:
Change by Eugene Toder :
--
nosy: +ncoghlan, vstinner
___
Python tracker
<https://bugs.python.org/issue42125>
___
___
Python-bugs-list mailing list
Unsubscribe:
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
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.
Eugene Toder added the comment:
Ammar, thank you for the link.
--
___
Python tracker
<https://bugs.python.org/issue42903>
___
___
Python-bugs-list mailin
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
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
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]
wh
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) ass
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 hangi
Eugene Toder added the comment:
Agreed. That's what I've put in my code as a work around.
--
___
Python tracker
<http://bugs.python.org/issue16602>
___
___
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_OBJ
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
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
Changes by Eugene Toder :
--
versions: +Python 3.3, Python 3.4 -Python 3.1
___
Python tracker
<http://bugs.python.org/issue1062277>
___
___
Python-bugs-list mailin
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)
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_f
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
&g
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 i
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
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 m
Changes by Eugene Toder :
--
nosy: +eltoder
___
Python tracker
<http://bugs.python.org/issue24991>
___
___
Python-bugs-list mailing list
Unsubscribe:
Eugene Toder added the comment:
Davis, the possible cases (i.e. recursion via appropriate mutable objects) are
already supported, and the impossible cases are, well, impossible. The only
open issue is whether to implement better error handling for infinite recursion
problems, instead of
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
&g
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
Eugene Toder added the comment:
Fairly sure it's 5 years old.
--
___
Python tracker
<http://bugs.python.org/issue11549>
___
___
Python-bugs-list mailing list
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 that
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
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 not
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 do
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 class
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.
--
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
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
<h
Changes by Eugene Toder :
Added file: http://bugs.python.org/file38624/class_gc2.diff
___
Python tracker
<http://bugs.python.org/issue23726>
___
___
Python-bugs-list m
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
<h
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
<http://bugs.python.org/is
99 matches
Mail list logo