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

Run simplifier before generating ByteCode #410

Merged
merged 1 commit into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Development/IDE/Core/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,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 @@ -148,9 +149,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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to set -O0 explicitly or does hie-bios set that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the impression that ghcide set all the flags it was interested in. At least on the .hi files branch, I believe this is the case.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t know any code that sets -O0. I think so far it just didn’t matter since we didn’t run the simplifier and don’t do code generation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hie-bios definitely sets it: https://github.com/mpickering/hie-bios/blob/master/src/HIE/Bios/Environment.hs#L41
Assuming, ghcide still uses initSession.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the .hi file branch this will need to be set but for now, initSession does set it.

-- 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
21 changes: 21 additions & 0 deletions test/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,27 @@ thTests =
_ <- openDoc' "A.hs" "haskell" sourceA
_ <- openDoc' "B.hs" "haskell" sourceB
expectDiagnostics [ ( "B.hs", [(DsError, (6, 29), "Variable not in scope: n")] ) ]
, testSessionWait "newtype-closure" $ do
let sourceA =
T.unlines
[ "{-# LANGUAGE DeriveDataTypeable #-}"
,"{-# LANGUAGE TemplateHaskell #-}"
,"module A (a) where"
,"import Data.Data"
,"import Language.Haskell.TH"
,"newtype A = A () deriving (Data)"
,"a :: ExpQ"
,"a = [| 0 |]"]
let sourceB =
T.unlines
[ "{-# LANGUAGE TemplateHaskell #-}"
,"module B where"
,"import A"
,"b :: Int"
,"b = $( a )" ]
_ <- openDoc' "A.hs" "haskell" sourceA
_ <- openDoc' "B.hs" "haskell" sourceB
return ()
]

completionTests :: TestTree
Expand Down