@@ -9,6 +9,7 @@
9-- Given a list of paths to find libraries, and a file to compile, produce a list of 'CoreModule' values.
9-- Given a list of paths to find libraries, and a file to compile, produce a list of 'CoreModule' values.
10module Development.IDE.Core.Compile
10module Development.IDE.Core.Compile
11 ( TcModuleResult(..)
11 ( TcModuleResult(..)
12 , compileModule
13 , compileModule
13 , parseModule
14 , parseModule
14 , typecheckModule
15 , typecheckModule
@@ -131,14 +132,21 @@ initPlugins modSummary = do
131 return modSummary
132 return modSummary
135+-- | Whether we should run the -O0 simplifier when generating core.
137+-- This is required for template Haskell to work but we disable this in DAML.
139+newtype RunSimplifier = RunSimplifier Bool
134-- | Compile a single type-checked module to a 'CoreModule' value, or
141-- | Compile a single type-checked module to a 'CoreModule' value, or
135-- provide errors.
142-- provide errors.
136compileModule
143compileModule
137− :: HscEnv
145+ -> HscEnv
138 -> [TcModuleResult]
146 -> [TcModuleResult]
139 -> TcModuleResult
147 -> TcModuleResult
140 -> IO (IdeResult (SafeHaskellMode, CgGuts, ModDetails))
148 -> IO (IdeResult (SafeHaskellMode, CgGuts, ModDetails))
141−compileModule packageState deps tmr =
149+compileModule (RunSimplifier simplify) packageState deps tmr =
142 fmap (either (, Nothing) (second Just)) $
150 fmap (either (, Nothing) (second Just)) $
143 runGhcEnv packageState $
151 runGhcEnv packageState $
144 catchSrcErrors "compile" $ do
152 catchSrcErrors "compile" $ do
@@ -152,11 +160,12 @@ compileModule packageState deps tmr =
152 let tm' = tm{tm_parsed_module = pm'}
160 let tm' = tm{tm_parsed_module = pm'}
153 GHC.dm_core_module <$> GHC.desugarModule tm'
161 GHC.dm_core_module <$> GHC.desugarModule tm'
154 let tc_result = fst (tm_internals_ (tmrModule tmr))
162 let tc_result = fst (tm_internals_ (tmrModule tmr))
155− -- Have to call the simplifier on the code even if we are at
163+ desugared_guts <-
156− -- -O0 as otherwise the code generation fails which leads to
164+ if simplify
157− -- errors like #256
165+ then do
158− plugins <- liftIO $ readIORef (tcg_th_coreplugins tc_result)
166+ plugins <- liftIO $ readIORef (tcg_th_coreplugins tc_result)
159− desugared_guts <- liftIO $ hscSimplify session plugins desugar
167+ liftIO $ hscSimplify session plugins desugar
160 -- give variables unique OccNames
169 -- give variables unique OccNames
161 (guts, details) <- liftIO $ tidyProgram session desugared_guts
170 (guts, details) <- liftIO $ tidyProgram session desugared_guts
162 return (map snd warnings, (mg_safe_haskell desugar, guts, details))
171 return (map snd warnings, (mg_safe_haskell desugar, guts, details))