GHC -O2 and unsafePerformIO

Neil Mitchell ndmitchell at gmail.com
Thu May 3 04:59:51 EDT 2007


Hi Simon,

> This is clearly a misuse of unsafePerformIO (as I'm sure you're aware).  Just
> out of interest - what's the context?

I am writing an optimiser for Yhc, doing whole-program optimisation,
with the intention of keeping it fast and high performance. Since
writing out Yhc bytecode would kill any performance benefits, I am
writing back to Haskell to be compiled with GHC. So the basic sequence
of steps is:

compile Haskell to Yhc Core
transform Yhc Core
convert Yhc Core to Haskell
compile Haskell to GHC

The problem I'm currently overcoming is that Yhc inserts its own IO
monad, which isn't the same as the GHC one. By the time I get to GHC
Haskell, all of the Yhc monad is invisible to GHC, so I have to
unsafePerformIO the getchar/putchar functions. With this as the
primitive getchar, it seems to work for my particular example, but is
clearly a bit fragile.

All the examples I'm doing for now are wc -c, wc -l, so shouldn't
stress the IO much more than getchar/putchar.

Thanks

Neil


More information about the Glasgow-haskell-users mailing list