[Python-ideas] Python-ideas Digest, Vol 90, Issue 30
Nathaniel Smith
njs at pobox.com
Wed May 21 23:14:41 CEST 2014
On Wed, May 21, 2014 at 8:44 PM, Raymond Hettinger
<raymond.hettinger at gmail.com> wrote:
> * I sympathize with "there is an irritating dimple in coverage.py"
> but that hasn't actually impaired its usability beyond creating a
> curiosity. Using that a reason to add a new CPython-only
> command-line switch seems like having the tail wag the dog.
I've certainly been frustrated by this wart in coverage.py's output --
if one uses a dev cycle where you constantly review every uncovered
line to make sure that tests are doing what you want, then even a
small number of spurious uncovered lines that appear and disappear
based on the optimizer's whim can result in a lot of wasted time. (Not
to mention the hours wasted the first time I ran into this, trying to
figure out why my tests weren't working and writing new ones
specifically to target the optimized-out line...)
That said, I'm also sympathetic to your point.
Isn't the real problem here that the peephole optimizer violates the
first rule of optimization ("don't change semantics") by breaking
sys.settrace? Couldn't we fix this directly?
One approach might be to enhance co_lnotab (if anyone dares touch it)
so that it can record that a peepholed jump instruction logically
belongs to multiple *different* lines, and when we encounter such an
instruction we call the trace function multiple times. Then the
peephole optimizer just has to propagate line number information
whenever it short-circuits a jump.
Or perhaps it would be enough to add a dead-code optimization pass
after the peephole optimizer, so that coverage.py can at least see
that things like Ned's "continue" didn't actually generate any code.
(This is suboptimal as well, since it will still cause coverage.py to
produce somewhat confusing output, as if the "continue" line had a
comment instead of real code -- but it'd still be better than the
status quo.)
-n
--
Nathaniel J. Smith
Postdoctoral researcher - Informatics - University of Edinburgh
http://vorpus.org
More information about the Python-ideas
mailing list