on master help sign in
Run simplifier before generating ByteCode (#410)

Running the simplifier is necessary to do things like inline data constructor wrappers. Fixes #256 and #393

commit2d71599faf5e93d4ee848043ddd68f10dd295260 authorMatthew Pickering <matthewtpickering@gmail.com> dateWed 12 Feb 2020, 12:09 (7 years ago) parentf717cd4
2 files changed+30−3
src/Development/IDE/Core/Compile.hs+9−3 test/exe/Main.hs+21
src/Development/IDE/Core/Compile.hs+9−3
@@ -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)
test/exe/Main.hs+21
@@ -1374,6 +1374,27 @@ thTests =
13741374 _ <- openDoc' "A.hs" "haskell" sourceA
13751375 _ <- openDoc' "B.hs" "haskell" sourceB
13761376 expectDiagnostics [ ( "B.hs", [(DsError, (6, 29), "Variable not in scope: n")] ) ]
1377+ , testSessionWait "newtype-closure" $ do
1378+ let sourceA =
1379+ T.unlines
1380+ [ "{-# LANGUAGE DeriveDataTypeable #-}"
1381+ ,"{-# LANGUAGE TemplateHaskell #-}"
1382+ ,"module A (a) where"
1383+ ,"import Data.Data"
1384+ ,"import Language.Haskell.TH"
1385+ ,"newtype A = A () deriving (Data)"
1386+ ,"a :: ExpQ"
1387+ ,"a = [| 0 |]"]
1388+ let sourceB =
1389+ T.unlines
1390+ [ "{-# LANGUAGE TemplateHaskell #-}"
1391+ ,"module B where"
1392+ ,"import A"
1393+ ,"b :: Int"
1394+ ,"b = $( a )" ]
1395+ _ <- openDoc' "A.hs" "haskell" sourceA
1396+ _ <- openDoc' "B.hs" "haskell" sourceB
1397+ return ()
13771398 ]
13781399
13791400completionTests :: TestTree