Software Assurance Reference Dataset

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Sun Jul 20 13:50:23 PDT 2014


On 7/20/2014 3:27 AM, Dmitry Olshansky wrote:
> Functional programming is full of simple recursion and it would be nice not to
> stack overflow in debug builds.

Traditional FP languages don't have loops, and so must do recursion. D has 
loops, even in pure functions, there's no reason not to use them.


> Another use case is so-called threaded code interpreter, that can be done with
> either computed gotos (and bunch of labels) or forced tail calls (and bunch of
> functions). In both cases computed jump or tail call is indirect.

http://eli.thegreenplace.net/2012/07/12/computed-goto-for-efficient-dispatch-tables/

The computed goto is faster for two reasons, according to the article:

1.The switch does a bit more per iteration because of bounds checking.

2.The effects of hardware branch prediction.


(1) is eliminated with final switch. I know this optimization is not done with 
dmd, but D doesn't need a new language feature because of that.

(2) with a bit more work, this could also be implemented as a compiler optimization.


Both of these are worthy of bugzilla enhancement requests. I'd much rather 
implement improvements as better code generation rather than more language features.


More information about the Digitalmars-d mailing list