[clean-list] My very first program crashes!

Fergus Henderson fjh@cs.mu.oz.au
Tue, 29 May 2001 02:59:45 +1000


On 28-May-2001, Maarten de Mol <maartenm@cs.kun.nl> wrote:
> > It's without doubt that the program had errors, but is it normal that it
> > produces no compile errors and simply CRASHES? I thought that the main
> > benefit of CLEAN is that it has no run-time crashes...
> 
> One of the benefits of Clean it its strong type system, which is able to
> catch many programming errors at compile time. There are, however,
> also errors (like this one) that are not caught by the type system and will
> still produce run-time errors.
> 
> So, a benefit of Clean could be that it produces LESS run-time crashes,
> but, unfortunately, not all run-time crashes can be avoided. (or else the
> halting problem would have been solved)

That's true, but it's possible to do a better job than the current
Clean implementation.

Firstly, it's quite easy for the compiler to detect cases like this one
where a function calls itself with the same arguments, and to issue a
warning.  For example, the Mercury compiler does that.  As it happens,
Mercury uses a syntax where function calls are written with commas to
separate the arguments, so the problem would be unlikely to arise in
the first place ;-).  But if you ignore that, and go ahead and write an
equivalent program in Mercury, the compiler will report the following
warning:

 | test1.m:012: Warning: recursive call will lead to infinite recursion.

Secondly, it's possible for the implementation to catch stack overflow
at runtime, and to issue a nicer error message than just "Stack Fault".
For example, if you compile with no special options and run the program
on Linux, then the Mercury runtime system will report the following
message:

 | Mercury runtime: memory zone detstack#0 overflowed
 | PC at signal: 134513980 (804853c)
 | This may have been caused by a stack overflow, due to unbounded recursion.

The first two lines here are probably not especially helpful.
But the last line may help a lot, particularly for newcomers.

Of course, the Mercury compiler does have its own flaws, so there may
well be examples where the Clean compiler does things better.
But by plugging the features of a rival implementation, maybe I can
spur the Clean team into handling this particular issue better ;-)

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.