[commit: ghc] wip/hie-module: HIE: Save module name and module exports (e8d8c73)

git at git.haskell.org git at git.haskell.org
Fri Feb 15 10:16:01 UTC 2019


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/hie-module
Link       : http://ghc.haskell.org/trac/ghc/changeset/e8d8c738e75dc9d23a287a8fab2392333c5cc6a5/ghc

>---------------------------------------------------------------

commit e8d8c738e75dc9d23a287a8fab2392333c5cc6a5
Author: Matthew Pickering <matthewtpickering at gmail.com>
Date:   Fri Feb 15 10:14:29 2019 +0000

    HIE: Save module name and module exports


>---------------------------------------------------------------

e8d8c738e75dc9d23a287a8fab2392333c5cc6a5
 compiler/hieFile/HieAst.hs   | 12 ++++++++++--
 compiler/hieFile/HieTypes.hs | 15 ++++++++++++++-
 compiler/main/HscMain.hs     |  5 +++--
 3 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/compiler/hieFile/HieAst.hs b/compiler/hieFile/HieAst.hs
index 0040b30..7fd217c 100644
--- a/compiler/hieFile/HieAst.hs
+++ b/compiler/hieFile/HieAst.hs
@@ -34,6 +34,8 @@ import TcHsSyn                    ( hsLitType, hsPatType )
 import Type                       ( mkFunTys, Type )
 import TysWiredIn                 ( mkListTy, mkSumTy )
 import Var                        ( Id, Var, setVarName, varName, varType )
+import TcRnTypes
+import MkIface                    ( mkIfaceExports )
 
 import HieTypes
 import HieUtils
@@ -87,17 +89,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..b22ee19 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,17 +68,24 @@ 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
     }
 
+type HieExports = [(HieASTs TypeIndex, Avails)]
+
 instance Binary HieFile where
   put_ bh hf = do
     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 +95,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