[commit: ghc] wip/hie-8.8: HIE: Save module name and module exports (b0f82e5)
git at git.haskell.org
git at git.haskell.org
Sun Feb 17 13:32:28 UTC 2019
Repository : ssh://git@git.haskell.org/ghc
On branch : wip/hie-8.8
Link : http://ghc.haskell.org/trac/ghc/changeset/b0f82e589465479157cfbdcff2fe516294fd8d39/ghc
>---------------------------------------------------------------
commit b0f82e589465479157cfbdcff2fe516294fd8d39
Author: Matthew Pickering <matthewtpickering at gmail.com>
Date: Fri Feb 15 10:14:29 2019 +0000
HIE: Save module name and module exports
>---------------------------------------------------------------
b0f82e589465479157cfbdcff2fe516294fd8d39
compiler/hieFile/HieAst.hs | 12 ++++++++++--
compiler/hieFile/HieTypes.hs | 13 ++++++++++++-
compiler/main/HscMain.hs | 5 +++--
3 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/compiler/hieFile/HieAst.hs b/compiler/hieFile/HieAst.hs
index 432dc36..6dee180 100644
--- a/compiler/hieFile/HieAst.hs
+++ b/compiler/hieFile/HieAst.hs
@@ -32,6 +32,8 @@ import SrcLoc
import TcHsSyn ( hsPatType )
import Type ( Type )
import Var ( Id, Var, setVarName, varName, varType )
+import TcRnTypes
+import MkIface ( mkIfaceExports )
import HieTypes
import HieUtils
@@ -85,17 +87,23 @@ modifyState = foldr go id
type HieM = ReaderT HieState Hsc
-- | Construct an 'HieFile' from the outputs of the typechecker.
-mkHieFile :: ModSummary -> TypecheckedSource -> RenamedSource -> Hsc HieFile
+mkHieFile :: ModSummary
+ -> TcGblEnv
+ -> RenamedSource -> Hsc HieFile
mkHieFile ms ts rs = do
- (asts', arr) <- getCompressedAsts ts rs
+ let tc_binds = tcg_binds ts
+ (asts', arr) <- getCompressedAsts tc_binds rs
let Just src_file = ml_hs_file $ ms_location ms
src <- liftIO $ BS.readFile src_file
return $ HieFile
{ hie_version = curHieVersion
, hie_ghc_version = BSC.pack cProjectVersion
, hie_hs_file = src_file
+ , hie_module = ms_mod ms
, hie_types = arr
, hie_asts = asts'
+ -- mkIfaceExports sorts the AvailInfos for stability
+ , hie_exports = mkIfaceExports (tcg_exports ts)
, hie_hs_src = src
}
diff --git a/compiler/hieFile/HieTypes.hs b/compiler/hieFile/HieTypes.hs
index c20887f..1b1d8c5 100644
--- a/compiler/hieFile/HieTypes.hs
+++ b/compiler/hieFile/HieTypes.hs
@@ -10,10 +10,11 @@ import GhcPrelude
import Binary
import FastString ( FastString )
import IfaceType
-import Module ( ModuleName )
+import Module ( ModuleName, Module )
import Name ( Name )
import Outputable hiding ( (<>) )
import SrcLoc ( RealSrcSpan )
+import Avail
import qualified Data.Array as A
import qualified Data.Map as M
@@ -56,6 +57,9 @@ data HieFile = HieFile
, hie_hs_file :: FilePath
-- ^ Initial Haskell source file path
+ , hie_module :: Module
+ -- ^ The module this HIE file is for
+
, hie_types :: A.Array TypeIndex HieTypeFlat
-- ^ Types referenced in the 'hie_asts'.
--
@@ -64,6 +68,9 @@ data HieFile = HieFile
, hie_asts :: HieASTs TypeIndex
-- ^ Type-annotated abstract syntax trees
+ , hie_exports :: [AvailInfo]
+ -- ^ The names that this module exports
+
, hie_hs_src :: ByteString
-- ^ Raw bytes of the initial Haskell source
}
@@ -73,8 +80,10 @@ instance Binary HieFile where
put_ bh $ hie_version hf
put_ bh $ hie_ghc_version hf
put_ bh $ hie_hs_file hf
+ put_ bh $ hie_module hf
put_ bh $ hie_types hf
put_ bh $ hie_asts hf
+ put_ bh $ hie_exports hf
put_ bh $ hie_hs_src hf
get bh = HieFile
@@ -84,6 +93,8 @@ instance Binary HieFile where
<*> get bh
<*> get bh
<*> get bh
+ <*> get bh
+ <*> get bh
{-
diff --git a/compiler/main/HscMain.hs b/compiler/main/HscMain.hs
index 9a4dd4a..674afc9 100644
--- a/compiler/main/HscMain.hs
+++ b/compiler/main/HscMain.hs
@@ -408,8 +408,9 @@ extract_renamed_stuff mod_summary tc_result = do
-- Create HIE files
when (gopt Opt_WriteHie dflags) $ do
- hieFile <- mkHieFile mod_summary (tcg_binds tc_result)
- (fromJust rn_info)
+ -- I assume this fromJust is safe because `-fwrite-hie-file`
+ -- enables the option which keeps the renamed source.
+ hieFile <- mkHieFile mod_summary tc_result (fromJust rn_info)
let out_file = ml_hie_file $ ms_location mod_summary
liftIO $ writeHieFile out_file hieFile
More information about the ghc-commits
mailing list