Incompatibility between Yi and GHC 6.8 (rc)

Simon Peyton-Jones simonpj at microsoft.com
Fri Oct 26 03:17:08 EDT 2007


(Narrowing to cvs-ghc)

| The GHC experts will see here that this cannot work :) Indeed, GHC has
| a number of "global variables", which, if accessed through code loaded
| in a GHC session, will be instanciated again. This means that
| accessing a "level 1" session with "level 2" code is normally not
| possible.

I'm not sure how this works.  Can you give a tiny example? I think it amounts to passing the global variables (or perhaps their contents) as parameters to the level-2 function?

| However, I found a workaround: encapsulate all calls to the GHC API in
| a data structure in "level 1" code, which is then passed to "level 2".
| (A haskell version of C-style callbacks). While this worked
| beautifully with GHC 6.6, it fails with 6.8rc. with
|
|   exception :: GhcException
|   yi: panic! (the 'impossible' happened)
|     (GHC version 6.8.0.20071019 for i386-unknown-linux):
|           a static opt was looked at too early!

I don't know the details here.  But I can tell you what this is about.   Not only does GHC use naughty global variables (too much), but it also uses them in a naughty way.  It's very convenient for a "static" option to be accessed simply as a top-level value:
        opt_DoSomething :: Bool
But how can we control that Bool from the command line?  By a dirty trick:
        opt_DoSomehing = unsafePerformIO (do {
                                opts <- read v_staticOpts;
                                lookup opts "do-something" })

        v_opts :: IORef [(String,Bool)]
        v_opts = unsafePerformIO (newIORef "Read too early")

Now, GHC's initialisation code reads the command line flags and stores them in v_opts.  Then, *later*, anyone who pokes on the opt_DoSomthing top-level thunk will find the flag.  But if you poke too early you get the message you saw.

I can't tell you why you are poking "too early".  Presumably you are not executing the code that writes v_opts?  Either in level 1 (unlikely) or level 2 (more plausible).

I hope this gives you some clues.

Simon



More information about the Cvs-ghc mailing list