@@ -47,9 +47,10 @@ import qualified GHC
4747import GhcMonad
4848import GhcPlugins as GHC hiding (fst3, (<>))
4949import qualified HeaderInfo as Hdr
50−import HscMain (hscInteractive)
50+import HscMain (hscInteractive, hscSimplify)
5151import MkIface
5252import StringBuffer as SB
53+import TcRnMonad (tcg_th_coreplugins)
5354import TidyPgm
5455
5556import Control.Monad.Extra
@@ -148,9 +149,14 @@ compileModule packageState deps tmr =
148149 let pm' = pm{pm_mod_summary = tweak $ pm_mod_summary pm}
149150 let tm' = tm{tm_parsed_module = pm'}
150151 GHC.dm_core_module <$> GHC.desugarModule tm'
151−
152+ let tc_result = fst (tm_internals_ (tmrModule tmr))
153+ -- Have to call the simplifier on the code even if we are at
154+ -- -O0 as otherwise the code generation fails which leads to
155+ -- errors like #256
156+ plugins <- liftIO $ readIORef (tcg_th_coreplugins tc_result)
157+ desugared_guts <- liftIO $ hscSimplify session plugins desugar
152158 -- give variables unique OccNames
153− (guts, details) <- liftIO $ tidyProgram session desugar
159+ (guts, details) <- liftIO $ tidyProgram session desugared_guts
154160 return (map snd warnings, (mg_safe_haskell desugar, guts, details))
155161
156162generateByteCode :: HscEnv -> [TcModuleResult] -> TcModuleResult -> CgGuts -> IO (IdeResult Linkable)