[commit: ghc] wip/ghc-8.8-merges: HIE: Save module name and module exports (612e7dd)

git at git.haskell.org git at git.haskell.org
Thu Feb 21 15:11:19 UTC 2019


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

On branch  : wip/ghc-8.8-merges
Link       : http://ghc.haskell.org/trac/ghc/changeset/612e7dd633f375774e89af3f072721fe4632a806/ghc

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

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

    HIE: Save module name and module exports
    
    (cherry picked from commit 69ebf5cb4592b4c89e268937ef7eb96f7c9d4532)


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

612e7dd633f375774e89af3f072721fe4632a806
 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 0f491f1..8025447 100644
--- a/compiler/hieFile/HieAst.hs
+++ b/compiler/hieFile/HieAst.hs
@@ -33,6 +33,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
@@ -86,17 +88,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