alanz / ghc-exactprint

GHC version of haskell-src-exts exactPrint
BSD 3-Clause "New" or "Revised" License
70 stars 32 forks source link

Pure interface for module parsing #38

Open lspitzner opened 8 years ago

lspitzner commented 8 years ago

Imo the unsafeGlobalDynFlags justify adding a pure wrapper, because "unsafe" and no real documentation that i can find if it is ok to use them.

This probably needs ghc-api additions, like a pure parseDynamicFilePragma.

mpickering commented 8 years ago

This ticket is tracking the GHC issue -- https://ghc.haskell.org/trac/ghc/ticket/10961?cversion=0&cnum_hist=1

I just unsafePerfromIO on the wrapper and have never encountered meaningful problems. The part which is used by the parser is not initialised in IO and so there shouldn't be any problems.

lspitzner commented 8 years ago

The differences i observed between parseWith [..] GHC.parseModule .. and parseModule are:

  1. parseWith does not respect LANGUAGE pragmas.
  2. parseWith does not return annotations, i guess because i did not set GHC.Opt_KeepRawTokenStream, which happens as part of the unexposed initDynFlags when using parseModule.

I'll make a PR in a sec.

mpickering commented 8 years ago

If you are parsing a whole module, have you tried using parseModule?

lspitzner commented 8 years ago

Yes. However, parseModule is fundamentally impure, reading the source from some file. This difference threads through the internal functions, too.

lspitzner commented 8 years ago

39 seems to be "mostly pure", although i have not looked into exactly what side-effects are done by e.g. parseDynamicFilePragma.