summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2020-12-19 23:41:59 +0000
committerMatthew Pickering <matthewtpickering@gmail.com>2020-12-19 23:43:45 +0000
commit27abc46b120cddf6650cd281e6c5ec8da9362c48 (patch)
tree140ed6b7e50d2a68072b21a76297319e3877d389
parent659fcb14937e60510e3eea4c1211ea117419905b (diff)
downloadhaskell-wip/t19004.tar.gz
Revert "Delete some superfluous helper functions in HscMain"wip/t19004
This reverts commit eb629fab96fbff43f79190767731501d8642f524. Fixes #19004
-rw-r--r--compiler/GHC/Driver/Main.hs51
1 files changed, 35 insertions, 16 deletions
diff --git a/compiler/GHC/Driver/Main.hs b/compiler/GHC/Driver/Main.hs
index 8685462e7d..f6214302fe 100644
--- a/compiler/GHC/Driver/Main.hs
+++ b/compiler/GHC/Driver/Main.hs
@@ -76,12 +76,12 @@ module GHC.Driver.Main
-- * Low-level exports for hooks
, hscCompileCoreExpr'
-- We want to make sure that we export enough to be able to redefine
- -- hsc_typecheck in client code
+ -- hscFileFrontEnd in client code
, hscParse', hscSimplify', hscDesugar', tcRnModule', doCodeGen
, getHscEnv
, hscSimpleIface'
, oneShotMsg
- , dumpIfaceStats
+ , hscFileFrontEnd, genericHscFrontend, dumpIfaceStats
, ioMsgMaybe
, showModuleIndex
, hscAddSptEntries
@@ -509,17 +509,23 @@ extract_renamed_stuff mod_summary tc_result = do
-- | Rename and typecheck a module, additionally returning the renamed syntax
hscTypecheckRename :: HscEnv -> ModSummary -> HsParsedModule
-> IO (TcGblEnv, RenamedStuff)
-hscTypecheckRename hsc_env mod_summary rdr_module = runHsc hsc_env $
- hsc_typecheck True mod_summary (Just rdr_module)
+hscTypecheckRename hsc_env mod_summary rdr_module = runHsc hsc_env $ do
+ tc_result <- hsc_typecheck True mod_summary (Just rdr_module)
+ rn_info <- extract_renamed_stuff mod_summary tc_result
+ return (tc_result, rn_info)
+-- | Rename and typecheck a module, but don't return the renamed syntax
+hscTypecheck :: Bool -- ^ Keep renamed source?
+ -> ModSummary -> Maybe HsParsedModule
+ -> Hsc TcGblEnv
+hscTypecheck keep_rn mod_summary mb_rdr_module = do
+ tc_result <- hsc_typecheck keep_rn mod_summary mb_rdr_module
+ _ <- extract_renamed_stuff mod_summary tc_result
+ return tc_result
--- | A bunch of logic piled around @tcRnModule'@, concerning a) backpack
--- b) concerning dumping rename info and hie files. It would be nice to further
--- separate this stuff out, probably in conjunction better separating renaming
--- and type checking (#17781).
hsc_typecheck :: Bool -- ^ Keep renamed source?
-> ModSummary -> Maybe HsParsedModule
- -> Hsc (TcGblEnv, RenamedStuff)
+ -> Hsc TcGblEnv
hsc_typecheck keep_rn mod_summary mb_rdr_module = do
hsc_env <- getHscEnv
let hsc_src = ms_hsc_src mod_summary
@@ -533,7 +539,7 @@ hsc_typecheck keep_rn mod_summary mb_rdr_module = do
real_loc = realSrcLocSpan $ mkRealSrcLoc (mkFastString src_filename) 1 1
keep_rn' = gopt Opt_WriteHie dflags || keep_rn
MASSERT( isHomeModule home_unit outer_mod )
- tc_result <- if hsc_src == HsigFile && not (isHoleModule inner_mod)
+ if hsc_src == HsigFile && not (isHoleModule inner_mod)
then ioMsgMaybe $ tcRnInstantiateSignature hsc_env outer_mod' real_loc
else
do hpm <- case mb_rdr_module of
@@ -545,10 +551,6 @@ hsc_typecheck keep_rn mod_summary mb_rdr_module = do
ioMsgMaybe $
tcRnMergeSignatures hsc_env hpm tc_result0 iface
else return tc_result0
- -- TODO are we extracting anything when we merely instantiate a signature?
- -- If not, try to move this into the "else" case above.
- rn_info <- extract_renamed_stuff mod_summary tc_result
- return (tc_result, rn_info)
-- wrapper around tcRnModule to handle safe haskell extras
tcRnModule' :: ModSummary -> Bool -> HsParsedModule
@@ -707,8 +709,8 @@ hscIncrementalFrontend
compile mb_old_hash reason = do
liftIO $ msg reason
- (tc_result, _) <- hsc_typecheck False mod_summary Nothing
- return $ Right (FrontendTypecheck tc_result, mb_old_hash)
+ result <- genericHscFrontend mod_summary
+ return $ Right (result, mb_old_hash)
stable = case source_modified of
SourceUnmodifiedAndStable -> True
@@ -755,6 +757,14 @@ hscIncrementalFrontend
Just tc_result ->
return $ Right (FrontendTypecheck tc_result, mb_old_hash)
+genericHscFrontend :: ModSummary -> Hsc FrontendResult
+genericHscFrontend mod_summary =
+ getHooked hscFrontendHook genericHscFrontend' >>= ($ mod_summary)
+
+genericHscFrontend' :: ModSummary -> Hsc FrontendResult
+genericHscFrontend' mod_summary
+ = FrontendTypecheck `fmap` hscFileFrontEnd mod_summary
+
--------------------------------------------------------------
-- Compilers
--------------------------------------------------------------
@@ -1044,6 +1054,15 @@ batchMsg hsc_env mod_index recomp mod_summary =
<> reason
--------------------------------------------------------------
+-- FrontEnds
+--------------------------------------------------------------
+
+-- | Given a 'ModSummary', parses and typechecks it, returning the
+-- 'TcGblEnv' resulting from type-checking.
+hscFileFrontEnd :: ModSummary -> Hsc TcGblEnv
+hscFileFrontEnd mod_summary = hscTypecheck False mod_summary Nothing
+
+--------------------------------------------------------------
-- Safe Haskell
--------------------------------------------------------------