on master help sign in
Allow disabling the simplifier in compileModule (#496)

It causes problems for our conversion to DAML-LF atm and isn’t necessary (since we don’t have template Haskell) so let’s make it configurable. I originally thought we could just copy paste all of compileModule to DAML but it turns out that this pull in too much stuff that I don’t want to see diverge from `ghcide` so I abandoned that idea.

commit07a5d325d57f5279bbc97c83e3b5a34cb03cbdbc authorMoritz Kiefer <moritz.kiefer@purelyfunctional.org> dateFri 20 Mar 2020, 14:41 (7 years ago) parent73ad8af
2 files changed+20−11
src/Development/IDE/Core/Compile.hs+16−7 src/Development/IDE/Core/Rules.hs+4−4
src/Development/IDE/Core/Compile.hs+16−7
@@ -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))
src/Development/IDE/Core/Rules.hs+4−4
@@ -351,17 +351,17 @@ typeCheckRule =
351351 addByteCode :: Linkable -> TcModuleResult -> TcModuleResult
352352 addByteCode lm tmr = tmr { tmrModInfo = (tmrModInfo tmr) { hm_linkable = Just lm } }
353353
354−generateCore :: NormalizedFilePath -> Action (IdeResult (SafeHaskellMode, CgGuts, ModDetails))
355−generateCore file = do
354+generateCore :: RunSimplifier -> NormalizedFilePath -> Action (IdeResult (SafeHaskellMode, CgGuts, ModDetails))
355+generateCore runSimplifier file = do
356356 deps <- use_ GetDependencies file
357357 (tm:tms) <- uses_ TypeCheck (file:transitiveModuleDeps deps)
358358 setPriority priorityGenerateCore
359359 packageState <- hscEnv <$> use_ GhcSession file
360− liftIO $ compileModule packageState tms tm
360+ liftIO $ compileModule runSimplifier packageState tms tm
361361
362362generateCoreRule :: Rules ()
363363generateCoreRule =
364− define $ \GenerateCore -> generateCore
364+ define $ \GenerateCore -> generateCore (RunSimplifier True)
365365
366366generateByteCodeRule :: Rules ()
367367generateByteCodeRule =