Idle bytecode query on apparently unreachable returns

Tom Anderson twic at
Thu Oct 13 01:02:53 CEST 2005

On Tue, 11 Oct 2005, Raymond Hettinger wrote:

> [Tom Anderson]:
>> What puzzles me, though, are bytecodes 17, 39 and 42 - surely these 
>> aren't reachable? Does the compiler just throw in a default 'return 
>> None' epilogue, with routes there from every code path, even when it's 
>> not needed? If so, why?
> Since unreachable code is never executed, there is no performance payoff 
> for optimizing it away.  It is not hard to write a dead-code elimination 
> routine, but why bother?

Fair enough - it wasn't a criticism, i was just wondering if those 
bytecodes were serving some crucial function i hadn't appreciated!

> It would save a few bytes, slow down compilation time, save nothing at 
> runtime, and make the compiler more complex/fragile.

I have this vague idea that a compiler could be written in such a way 
that, rather than dead code being weeded out by some 
extra-complexity-inducing component, it would simply never be generated in 
the first place; that could perhaps even be simpler than the situation at 
present. I have tree reduction and SSA graphs frolicking in soft focus in 
my imagination. But, that said, i have no experience of actually writing 
compilers, so maybe this SSA stuff is harder than it sounds!


That's no moon!

More information about the Python-list mailing list