inside the GHC code generator

Ben Rudiak-Gould Benjamin.Rudiak-Gould at cl.cam.ac.uk
Thu Feb 23 18:04:26 EST 2006


bulat.ziganshin at gmail.com wrote:
> * multiple results can be returned via C++ pair<a,b> template, if this is
> efficiently implemented in gcc

There's a -freg-struct-return option in 2.x, 3.x and 4.x. I think it's off 
by default on many architectures.

> * recursive definitions translated into the for/while loops if possible

I think recent versions of GCC do a good job of this. See

     http://home.in.tum.de/~baueran/thesis/

All of this efficiency stuff aside, there's a big problem you're neglecting: 
GARBAGE COLLECTION. For a language that allocates as much as Haskell I think 
a conservative collector is absolutely out of the question, because they 
can't compact the heap and so allocation becomes very expensive. A copying 
collector has to be able to walk the stack and find all the roots, and that 
interacts very badly with optimization. All the languages I've seen that 
compile via C either aren't garbage collected or use a conservative or 
reference-count collector.

The closest thing I've seen to a solution is the technique used in Urban 
Boquist's thesis, which is to put a static table in the executable with 
information about register and stack usage indexed by procedure return 
point, and use that to unwind the stack and find roots. Some C compilers 
(including gcc) support debugging of optimized code, so it might be possible 
to parse the debugging tables and extract this information. As far as I 
know, no one has ever looked into the feasibility of doing this, which is 
kind of surprising since root-finding is probably the single biggest 
obstacle to compiling functional languages via C.

-- Ben



More information about the Glasgow-haskell-users mailing list