Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Commit

Permalink
Run simplifier before generating ByteCode
Browse files Browse the repository at this point in the history
Running the simplifier is necessary to do things like inline data
constructor wrappers.

Fixes #256 and #393
  • Loading branch information
mpickering committed Feb 7, 2020
1 parent e59d3e2 commit 2fab0dc
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Development/IDE/Core/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ import qualified GHC
import GhcMonad
import GhcPlugins as GHC hiding (fst3, (<>))
import qualified HeaderInfo as Hdr
import HscMain (hscInteractive)
import HscMain (hscInteractive, hscSimplify)
import MkIface
import StringBuffer as SB
import TcRnMonad (tcg_th_coreplugins)
import TidyPgm

import Control.Monad.Extra
Expand Down Expand Up @@ -144,9 +145,14 @@ compileModule packageState deps tmr =
let pm' = pm{pm_mod_summary = tweak $ pm_mod_summary pm}
let tm' = tm{tm_parsed_module = pm'}
GHC.dm_core_module <$> GHC.desugarModule tm'

let tc_result = fst (tm_internals_ (tmrModule tmr))
-- Have to call the simplifier on the code even if we are at
-- -O0 as otherwise the code generation fails which leads to
-- errors like #256
plugins <- liftIO $ readIORef (tcg_th_coreplugins tc_result)
desugared_guts <- liftIO $ hscSimplify session plugins desugar
-- give variables unique OccNames
(guts, details) <- liftIO $ tidyProgram session desugar
(guts, details) <- liftIO $ tidyProgram session desugared_guts
return (map snd warnings, (mg_safe_haskell desugar, guts, details))

generateByteCode :: HscEnv -> [TcModuleResult] -> TcModuleResult -> CgGuts -> IO (IdeResult Linkable)
Expand Down Expand Up @@ -205,7 +211,7 @@ upgradeWarningToError (nfp, sh, fd) =
hideDiag :: DynFlags -> (WarnReason, FileDiagnostic) -> (WarnReason, FileDiagnostic)
hideDiag originalFlags (Reason warning, (nfp, _sh, fd))
| not (wopt warning originalFlags) = (Reason warning, (nfp, HideDiag, fd))
hideDiag _originalFlags t = t
hideDiag _originalFlags t = t

addRelativeImport :: NormalizedFilePath -> ParsedModule -> DynFlags -> DynFlags
addRelativeImport fp modu dflags = dflags
Expand Down

0 comments on commit 2fab0dc

Please sign in to comment.