[Yhc] Compiling Prelude.hs

Thomas Shackell shackell at cs.york.ac.uk
Thu Jan 19 06:33:44 EST 2006


Krasimir Angelov wrote:
> I have to deal with another hack this time. See the comment from IExtract.hs:
> 
> -- addPreludeTupleInstances is an efficiency hack.
> -- It takes a long time to parse the Prelude.hi file, and adding large
> -- numbers of tuple instances to the .hi file increases compile-times
> -- by 30% or more.
> -- Omitting them from the .hi file and adding them by hand here, therefore
> -- gives a big time saving.
> 
> The problem is that all instances for tuples >3 aren't defined in the
> prelude but the required type declarations are injected explicitly in
> the IExtract.hs module. In this way no bytecode for them will be
> generated. In Data.Ix are defined Ix instances for all tuples with
> size up to 15. Since the Ix instance depends on Ord, when I am
> compiling these Ix instances the byte code will have references to the
> corresponding Ord instances but unfortunately they don't exist. This
> is reported as missing reference from the assembler. I have fixed that
> with some dummy instance declarations in Prelude.hs.

I don't think I had to do anything special to do this, I believe it 
worked as normal, though I haven't actually checked ...

> Another problem is that sometimes the compiler is generating
> references to tuples with size 1. Of course this type of tuple doesn't
> exist and I again end up with unresolved references in the assembling
> phase. It seems like these tuples are generated from CaseLib.caseTuple
> but I still don't know how to avoid this.

Yes this is a problem, I had to add size 1 tuple directly into the 
runtime. Thus no Haskell programmer can write something with a size one 
tuple but the compiler can still generate code that uses it.

This is done in src/runtime/BCKernel/builtin/Prelude.c

   prim_addCon("1", 1, 0, CI_NONE);

which adds a data type called "1" directly into the prelude dictionary 
(which makes sense since (,) is called "2" and (,,) is called "3").

I'm not sure how'd you do this in your setup, since you're compiling 
directly to .NET IL. One option is to get the compiler to 'know' that 
the type "One_" should be renamed "1". Then you could write

data One_ a = One_ a


Hope that helps.



Tom


More information about the Yhc mailing list