Purely using the parser entry points

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Purely using the parser entry points

Matthew Pickering
I've been working with the new parser entry points - they have been
very useful.

Ostensibly the new parser entry points are pure functions but they
require a copy of DynFlags. As far as I can work out there's no pure
way to reliably construct DynFlags but it also seems that the Parser
doesn't use any of the impure mutable parts of it. This makes it
tricky to write pure functions such as "parseExprFromString :: String
-> LHsExpr RdrName" which would use some sort of dummy configuration.

So far I've tried using "unsafeGlobalDynFlags" which (expectedly)
fails occasionally. I've found a more reliable method to be the
following which relies on unsafePerformIO.

getDynFlags = unsafePerformIO $
  GHC.defaultErrorHandler GHC.defaultFatalMessager GHC.defaultFlushOut $
    GHC.runGhc (Just libdir) GHC.getSessionDynFlags

The question is - is this use of unsafePerformIO safe? Is there a
better way to purely initialise a copy of DynFlags?

Thanks, Matt
ghc-devs mailing list
[hidden email]