on master help sign in
Fix GHC panic on showOutputable

Closes #544. It looks like when we call 'showSDocUnsafe' it uses `unsafeGlobalDynFlags` wwhich the `settings` field is not initialised unless someone calls `setUnsafeGlobalDynFlags`, `initGhcMonad` or `runGhc` and throws a panic. I couldn't pinpoint the exact cause, but I suspect probably there was a change either on Ormolu or ghc-lib-parser which removed a call to one of the functions above before we print manualExts. Anyway, we actually don't need to call `showSDocUnsafe` since we already have a populated `DynFlags`. This commit removes the unsafe call and passes the `DynFlags` we have to `showSDoc`.

commite7c080e2aa4fc460488cfd4b381045381456a36e authorUtku Demir <me@utdemir.com> dateTue 14 Apr 2020, 09:27 (7 years ago) parentd09429f
1 file changed+2−1
src/Ormolu/Utils.hs+2−1
src/Ormolu/Utils.hs+2−1
@@ -22,6 +22,7 @@ import Data.Maybe (fromMaybe)
2222import Data.Text (Text)
2323import qualified Data.Text as T
2424import GHC
25+import GHC.DynFlags (baseDynFlags)
2526import qualified Outputable as GHC
2627
2728-- | Combine all source spans from the given list.
@@ -38,7 +39,7 @@ notImplemented msg = error $ "not implemented yet: " ++ msg
3839
3940-- | Pretty-print an 'GHC.Outputable' thing.
4041showOutputable :: GHC.Outputable o => o -> String
41−showOutputable = GHC.showSDocUnsafe . GHC.ppr
42+showOutputable = GHC.showSDoc baseDynFlags . GHC.ppr
4243
4344-- | Split and normalize a doc string. The result is a list of lines that
4445-- make up the comment.