summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2020-01-29 08:46:30 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-02-08 10:24:43 -0500
commit5d83d9489f383cc940ce123d9385c5cad1af517d (patch)
tree94535bd2f5986b28c37aaa4e3e9ba56310697c4e
parentfb5c19122ea59d1c6758762cb47e1a451bc3b9bf (diff)
downloadhaskell-5d83d9489f383cc940ce123d9385c5cad1af517d.tar.gz
Add mkHieFileWithSource which doesn't read the source file from disk
cc/ @pepeiborra
-rw-r--r--compiler/GHC/Iface/Ext/Ast.hs19
1 files changed, 14 insertions, 5 deletions
diff --git a/compiler/GHC/Iface/Ext/Ast.hs b/compiler/GHC/Iface/Ext/Ast.hs
index 022cc6cb2b..10986769ed 100644
--- a/compiler/GHC/Iface/Ext/Ast.hs
+++ b/compiler/GHC/Iface/Ext/Ast.hs
@@ -12,10 +12,9 @@ Main functions for .hie file generation
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE DeriveDataTypeable #-}
-
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
-module GHC.Iface.Ext.Ast ( mkHieFile ) where
+module GHC.Iface.Ext.Ast ( mkHieFile, mkHieFileWithSource, getCompressedAsts) where
import GhcPrelude
@@ -42,6 +41,7 @@ import Var ( Id, Var, setVarName, varName, varType )
import TcRnTypes
import GHC.Iface.Utils ( mkIfaceExports )
import Panic
+import Maybes
import GHC.Iface.Ext.Types
import GHC.Iface.Ext.Utils
@@ -52,7 +52,6 @@ import qualified Data.Map as M
import qualified Data.Set as S
import Data.Data ( Data, Typeable )
import Data.List ( foldl1' )
-import Data.Maybe ( listToMaybe )
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Class ( lift )
@@ -226,10 +225,20 @@ mkHieFile :: ModSummary
-> TcGblEnv
-> RenamedSource -> Hsc HieFile
mkHieFile ms ts rs = do
+ let src_file = expectJust "mkHieFile" (ml_hs_file $ ms_location ms)
+ src <- liftIO $ BS.readFile src_file
+ mkHieFileWithSource src_file src ms ts rs
+
+-- | Construct an 'HieFile' from the outputs of the typechecker but don't
+-- read the source file again from disk.
+mkHieFileWithSource :: FilePath
+ -> BS.ByteString
+ -> ModSummary
+ -> TcGblEnv
+ -> RenamedSource -> Hsc HieFile
+mkHieFileWithSource src_file src ms ts rs = do
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_hs_file = src_file
, hie_module = ms_mod ms