@@ -9,6 +9,7 @@
99-- Given a list of paths to find libraries, and a file to compile, produce a list of 'CoreModule' values.
1010module Development.IDE.Core.Compile
1111 ( TcModuleResult(..)
12+ , RunSimplifier(..)
1213 , compileModule
1314 , parseModule
1415 , typecheckModule
@@ -131,14 +132,21 @@ initPlugins modSummary = do
131132 return modSummary
132133#endif
133134
135+-- | Whether we should run the -O0 simplifier when generating core.
136+--
137+-- This is required for template Haskell to work but we disable this in DAML.
138+-- See #256
139+newtype RunSimplifier = RunSimplifier Bool
140+
134141-- | Compile a single type-checked module to a 'CoreModule' value, or
135142-- provide errors.
136143compileModule
137− :: HscEnv
144+ :: RunSimplifier
145+ -> HscEnv
138146 -> [TcModuleResult]
139147 -> TcModuleResult
140148 -> IO (IdeResult (SafeHaskellMode, CgGuts, ModDetails))
141−compileModule packageState deps tmr =
149+compileModule (RunSimplifier simplify) packageState deps tmr =
142150 fmap (either (, Nothing) (second Just)) $
143151 runGhcEnv packageState $
144152 catchSrcErrors "compile" $ do
@@ -152,11 +160,12 @@ compileModule packageState deps tmr =
152160 let tm' = tm{tm_parsed_module = pm'}
153161 GHC.dm_core_module <$> GHC.desugarModule tm'
154162 let tc_result = fst (tm_internals_ (tmrModule tmr))
155− -- Have to call the simplifier on the code even if we are at
156− -- -O0 as otherwise the code generation fails which leads to
157− -- errors like #256
158− plugins <- liftIO $ readIORef (tcg_th_coreplugins tc_result)
159− desugared_guts <- liftIO $ hscSimplify session plugins desugar
163+ desugared_guts <-
164+ if simplify
165+ then do
166+ plugins <- liftIO $ readIORef (tcg_th_coreplugins tc_result)
167+ liftIO $ hscSimplify session plugins desugar
168+ else pure desugar
160169 -- give variables unique OccNames
161170 (guts, details) <- liftIO $ tidyProgram session desugared_guts
162171 return (map snd warnings, (mg_safe_haskell desugar, guts, details))