Possibly Pythonic Tail Call Optimization (TCO/TRE)

Steven D'Aprano steve at pearwood.info
Tue Jul 14 19:48:32 CEST 2015


On Wed, 15 Jul 2015 03:29 am, Marko Rauhamaa wrote:

> Chris Angelico <rosuav at gmail.com>:
> 
>> On Tue, Jul 14, 2015 at 11:38 PM, Marko Rauhamaa <marko at pacujo.net>
>> wrote:
>>> No, tail call optimization doesn't change the behavior of the
>>> program, for the worse anyway.
>>
>> It does, because you lose traceback records. That's pretty significant
>> when you come to try to debug something.
> 
> Doesn't count. 

Says you.

> Optimization can do weird things to code and make 
> debugging challenging. That's why you usually tell the compiler not to
> optimize the debug builds.

Here's a real scenario for you to chew on: testing. Test suites should be
considered an application where the developer is the end user, and the
point of the application is to verify that the code passes tests, and if
they don't, present the user (i.e. the developer) with sufficient
information to debug the problem (i.e. full stack traces).

So how do you test your optimized code?

If you turn optimizations on globally, you're testing something which may or
may not have the same behaviour as the code you wrote. Compiler bugs exist,
so it is more important than ever to ensure that the post-optimization code
passes the test suite. But if it fails, you no longer get the stack traces
you need to debug the problem.

But if you turn optimizations off globally, you're not testing the optimized
code any longer.


-- 
Steven



More information about the Python-list mailing list