GHC API initialisation
Simon Marlow
marlowsd at gmail.com
Thu Jun 7 11:51:40 CEST 2012
On 05/06/2012 11:36, "Philip K. F. Hölzenspies" wrote:
> Dear GHC-ers,
>
> Is there a reason why GHC panics with
>
>
> ghc: panic! (the 'impossible' happened)
> (GHC version 7.4.1 for x86_64-apple-darwin):
> no package state yet: call GHC.setSessionDynFlags
>
>
> when I call functions that are not in a GhcMonad (viz. newHscEnv,
> parser, etc.)? I feel a bit silly that most of my code starts with:
>
> defaultErrorHandler defaultLogAction (runGhc (Just libdir) $
> getSessionDynFlags>>= setSessionDynFlags)
>
> Was this a design choice? Would it be wise/nice to have a function
> "initialise" in the API that does precisely this?
I could make the panic go away by initialising with an empty package
state. But I'm not sure I understand how you ran into this problem: the
panic is embedded inside defaultDynFlags, so if you're just using GHC
API functions outside the monad you would encounter the panic regardless
of whether you had this
defaultErrorHandler defaultLogAction (runGhc (Just libdir) $
getSessionDynFlags>>= setSessionDynFlags)
at the beginning of the program. The above line should have no effect;
it doesn't update any global state or anything.
Cheers,
Simon
More information about the Cvs-ghc
mailing list