Compile time function execution...

Kevin Bealer kevinbealer at gmail.com
Thu Feb 15 23:37:19 PST 2007


Walter Bright wrote:
> janderson wrote:
>> Walter Bright wrote:
>>> Right now, the compiler will fail if the compile time execution 
>>> results in infinite recursion or an infinite loop. I'll have to 
>>> figure out some way to eventually deal with this.
>>
>> Maybe you could allow the user to specify stack size and maximum 
>> iteration per loop/recursion function to the compiler as flags (with 
>> some defaults).   This way the user can up the size if they really 
>> need it.  This would make it a platform thing.  That way a D compiler 
>> could still be made for less powerful systems.
> 
> Whether you tell it to fail at a smaller limit, or it fails by itself at 
> a smaller limit, doesn't make any difference as to whether it runs on a 
> less powerful system or not <g>.
> 
> The C standard has these "minimum translation limits" for all kinds of 
> things - number of lines, chars in a string, expression nesting level, 
> etc. It's all kind of bogus, hearkening back to primitive compilers that 
> actually used fixed array sizes internally (Brand X, 
> who-shall-not-be-named, was notorious for exceeding internal table 
> limits, much to the delight of Zortech's sales staff). The right way to 
> build a compiler is it either runs out of stack or memory, and that's 
> the only limit.
> 
> If your system is too primitive to run the compiler, you use a cross 
> compiler running on a more powerful machine.
> 
> I have thought of just putting a timer in the interpreter - if it runs 
> for more than a minute, assume things have gone terribly awry and quit 
> with a message.

I remember one of the first "facts of life" of computer science in 
college being that some problems can't be solved, and the example given 
was the 'halting problem'.

If it runs until done or bust, that's okay with me.  But for the purpose 
of distributing software, it would be a lot easier if either it was 
unbounded, or the bound was something that depended mostly or completely 
on the source code.  That way I can compile on my super-duper 
development machine and if it doesn't "time out", I know whether it will 
fail on some user's second rate hardware or not.

If the number used doesn't mean anything concrete, that's okay.  I guess 
the simplest thing would be to bump a counter in some inner loop and cut 
out when it gets to a jillion.

Kevin



More information about the Digitalmars-d mailing list