summaryrefslogtreecommitdiff
path: root/compiler/main/PipelineMonad.hs
diff options
context:
space:
mode:
authorÖmer Sinan Ağacan <omeragacan@gmail.com>2019-10-16 14:44:44 +0300
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-10-29 03:47:44 -0400
commitbbdd54aab2f727bd90efe237eeb72e5e014b0cb2 (patch)
tree8157e1014bae7f99018d25d4a41404c6f3174766 /compiler/main/PipelineMonad.hs
parent3bd3456f144fa801a409147a80673f88360c16a2 (diff)
downloadhaskell-bbdd54aab2f727bd90efe237eeb72e5e014b0cb2.tar.gz
Return ModIface in compilation pipeline, remove IORef hack for generating ModIfaces
The compilation phases now optionally return ModIface (for phases that generate an interface, currently only HscOut when (re)compiling a file). The value is then used by compileOne' to return the generated interface with HomeModInfo (which is then used by the batch mode compiler when building rest of the tree). hscIncrementalMode also returns a DynFlags with plugin info, to be used in the rest of the pipeline. Unfortunately this introduces a (perhaps less bad) hack in place of the previous IORef: we now record the DynFlags used to generate the partial infterface in HscRecomp and use the same DynFlags when generating the full interface. I spent almost three days trying to understand what's changing in DynFlags that causes a backpack test to fail, but I couldn't figure it out. There's a FIXME added next to the field so hopefully someone who understands this better than I do will fix it leter.
Diffstat (limited to 'compiler/main/PipelineMonad.hs')
-rw-r--r--compiler/main/PipelineMonad.hs21
1 files changed, 17 insertions, 4 deletions
diff --git a/compiler/main/PipelineMonad.hs b/compiler/main/PipelineMonad.hs
index d152d04530..bdda19ceac 100644
--- a/compiler/main/PipelineMonad.hs
+++ b/compiler/main/PipelineMonad.hs
@@ -7,7 +7,8 @@ module PipelineMonad (
CompPipeline(..), evalP
, PhasePlus(..)
, PipeEnv(..), PipeState(..), PipelineOutput(..)
- , getPipeEnv, getPipeState, setDynFlags, setModLocation, setForeignOs
+ , getPipeEnv, getPipeState, setDynFlags, setModLocation, setForeignOs, setIface
+ , pipeStateDynFlags, pipeStateModIface
) where
import GhcPrelude
@@ -25,8 +26,8 @@ import Control.Monad
newtype CompPipeline a = P { unP :: PipeEnv -> PipeState -> IO (PipeState, a) }
deriving (Functor)
-evalP :: CompPipeline a -> PipeEnv -> PipeState -> IO a
-evalP f env st = liftM snd $ unP f env st
+evalP :: CompPipeline a -> PipeEnv -> PipeState -> IO (PipeState, a)
+evalP (P f) env st = f env st
instance Applicative CompPipeline where
pure a = P $ \_env state -> return (state, a)
@@ -67,12 +68,21 @@ data PipeState = PipeState {
maybe_loc :: Maybe ModLocation,
-- ^ the ModLocation. This is discovered during compilation,
-- in the Hsc phase where we read the module header.
- foreign_os :: [FilePath]
+ foreign_os :: [FilePath],
-- ^ additional object files resulting from compiling foreign
-- code. They come from two sources: foreign stubs, and
-- add{C,Cxx,Objc,Objcxx}File from template haskell
+ iface :: Maybe ModIface
+ -- ^ Interface generated by HscOut phase. Only available after the
+ -- phase runs.
}
+pipeStateDynFlags :: PipeState -> DynFlags
+pipeStateDynFlags = hsc_dflags . hsc_env
+
+pipeStateModIface :: PipeState -> Maybe ModIface
+pipeStateModIface = iface
+
data PipelineOutput
= Temporary TempFileLifetime
-- ^ Output should be to a temporary file: we're going to
@@ -107,3 +117,6 @@ setModLocation loc = P $ \_env state ->
setForeignOs :: [FilePath] -> CompPipeline ()
setForeignOs os = P $ \_env state ->
return (state{ foreign_os = os }, ())
+
+setIface :: ModIface -> CompPipeline ()
+setIface iface = P $ \_env state -> return (state{ iface = Just iface }, ())