Skip to content

Commit f41f88f

Browse files
committed
suggested circleci fix
1 parent 43b97cd commit f41f88f

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

plugins/tactics/hls-tactics-plugin.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ library
7575
, syb
7676
, text
7777
, transformers
78+
, deepseq
7879

7980
default-language: Haskell2010
8081

plugins/tactics/src/Ide/Plugin/Tactic/Debug.hs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
{-# LANGUAGE BangPatterns #-}
2+
{-# LANGUAGE CPP #-}
3+
{-# LANGUAGE TypeApplications #-}
4+
15
module Ide.Plugin.Tactic.Debug
26
( unsafeRender
37
, unsafeRender'
@@ -9,17 +13,36 @@ module Ide.Plugin.Tactic.Debug
913
, traceMX
1014
) where
1115

16+
import Control.DeepSeq
17+
import Control.Exception
1218
import Debug.Trace
1319
import DynFlags (unsafeGlobalDynFlags)
1420
import Outputable hiding ((<>))
21+
import System.IO.Unsafe (unsafePerformIO)
22+
23+
#if __GLASGOW_HASKELL__ >= 808
24+
import PlainPanic (PlainGhcException)
25+
type GHC_EXCEPTION = PlainGhcException
26+
#else
27+
import Panic (GhcException)
28+
type GHC_EXCEPTION = GhcException
29+
#endif
30+
1531

1632
------------------------------------------------------------------------------
1733
-- | Print something
1834
unsafeRender :: Outputable a => a -> String
1935
unsafeRender = unsafeRender' . ppr
2036

37+
2138
unsafeRender' :: SDoc -> String
22-
unsafeRender' = showSDoc unsafeGlobalDynFlags
39+
unsafeRender' sdoc = unsafePerformIO $ do
40+
let z = showSDoc unsafeGlobalDynFlags sdoc
41+
-- We might not have unsafeGlobalDynFlags (like during testing), in which
42+
-- case GHC panics. Instead of crashing, let's just fail to print.
43+
!res <- try @GHC_EXCEPTION $ evaluate $ deepseq z z
44+
pure $ either (const "<unsafeRender'>") id res
45+
{-# NOINLINE unsafeRender' #-}
2346

2447
traceMX :: (Monad m, Show a) => String -> a -> m ()
2548
traceMX str a = traceM $ mappend ("!!!" <> str <> ": ") $ show a

0 commit comments

Comments
 (0)