[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-hackers] [PATCH] "deep-stack" option, declaration and build

From: Peter Bex
Subject: Re: [Chicken-hackers] [PATCH] "deep-stack" option, declaration and build-mode
Date: Wed, 1 Aug 2012 21:14:11 +0200
User-agent: Mutt/

On Wed, Aug 01, 2012 at 02:07:34PM +0200, Felix wrote:
> This patch adds a compiler option to emit extra nursery checks.
> Enabling this mode by default should IMHO be avoided, since runaway
> recursions (which is the usual reason for stack-exhaustion) will
> consume all available memory and thus may bring the machine to a halt.

I think this is preferable to segfaulting and maps better to what the
program is really doing; it *is* eating up all memory.  There are many
reasons a program might segfault and they're always a bug.  Deep
recursions are not by definition a bug and don't eat up all memory
unless they're unbounded.

I think that seasoned Schemers tend to avoid non-tailrecursion as a
matter of instinct, whereas beginners will use the recursive style more
often so they will hit this bug more often (the original bug in Trac was
also filed by someone who was doing SICP exercises).  Those are exactly
the wrong people you'd want to have to explain to that they will need to
rebuild their entire Scheme system to use their code as-is (yes, their
entire system, since they're probably using the interpreter, as beginners).

Furthermore, a program that does use a recursive process (whether written
by a newbie or because it was simpler to express the algorithm that way)
might seem to work fine for typical inputs, yet when larger inputs are
fed to the program it would *suddenly* segfault.  If this option were
enabled by default, it would degrade more gracefully, eating up more
memory.  Hopefully this will be noticed before it eats all memory
(if monitoring is in place, you will), but at least it won't result in
an immediate denial of service.  At 4 in the morning.  So you get called
out of bed to fix the damn server.

I understand that there are differing viewpoints on this, but I think
cutting it off at some arbitrary point when the stack is overflown is
just as awkward as cutting off memory allocation at some arbitrary point.
We let a user use up all available memory too by repeatedly consing onto
a list.  I don't see why the C stack (an implementation detail which is
irrelevant when coding in just Scheme) has to be treated differently.

"The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music."
                                                        -- Donald Knuth

reply via email to

[Prev in Thread] Current Thread [Next in Thread]