Re: Should compilers elide errors when possible?
- From: Tim Bradshaw <tfb+google@xxxxxxxx>
- Date: Sat, 22 Dec 2007 09:03:15 -0800 (PST)
On Dec 22, 2:12 am, Ray Dillinger <b...@xxxxxxxxx> wrote:
Should it also be legal for a compiler to emit code that
simply returns 2 (from the if expression), or should the
programmer be able to _rely_ on a function like forever
to transfer flow of control to an exception handler?
This problem is obviously not soluble in general because it's the
halting problem.
However, in the specific case where a compiler can prove that there
are no side-effects of a function and its result is not used, then it
certainly generally ought to be OK to elide calls to it.
However "no side effects" is an interesting question which is often
over simplified. Consider this:
(progn (sleep 10) (do-something))
Well, with an obvious definition, SLEEP has "no side effects". Except
it does: it waits for 10 seconds, and that's a very important real-
world side-effect. If I put the comments back in to this code, we can
see why:
(progn
(sleep 10) ; give user time to panic and interrupt
(do-something)) ; bounce system
I'd be pretty unhappy if the compiler elided that call to SLEEP.
Thinking of it this way, failure to halt is a pretty serious side-
effect. So (for a modified definition)
(defun forever () (loop))
(if (forever) (set-off-the-bomb) (set-off-the-bomb))
I'd kind of like it to be the case that a responsible compiler did
*not* elide that call.
So I think that really this is a subtle question. In my view a
compiler should elide code only if it can prove no side effects, where
"side effects" include intentional real-world side-effects, such as
pausing the program (and many other things), and in particular where
it can prove that the code halts.
One real-world side effect is exhausting the system's resources. For
your definition of FOREVER I find it hard to see that it would not do
that, because of the (* 2 (forever)) - either that's going to burst
the stack, or it's going to get a bignum overflow at some point I
think. If it does not do that, then it fails to halt, and I think
that is a side-effect (by my definition) for sure.
So I think these questions are very subtle in general, and working
from some theoretical model of computation does not tell you the
useful answer to give.
--tim
No hyphens were harmed in the production of this message
.
- Follow-Ups:
- Re: Should compilers elide errors when possible?
- From: Kaz Kylheku
- Re: Should compilers elide errors when possible?
- References:
- Should compilers elide errors when possible?
- From: Ray Dillinger
- Should compilers elide errors when possible?
- Prev by Date: Re: NIL is not of type CONS
- Next by Date: Re: Assigning values from a list
- Previous by thread: Re: Should compilers elide errors when possible?
- Next by thread: Re: Should compilers elide errors when possible?
- Index(es):
Relevant Pages
|