summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDivam <dfordivam@gmail.com>2021-06-01 15:51:30 +0900
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-06-02 04:40:34 -0400
commitc5a9e32ee0b372c2a044bce0e9009dcff21ee909 (patch)
treee58eefcf2848fb3151981c8878bf27406991bd66
parentadddf2484b2bef05ea8d7b17b926e874d9d2e833 (diff)
downloadhaskell-c5a9e32ee0b372c2a044bce0e9009dcff21ee909.tar.gz
Specify the reason for import for the backpack's extra imports
-rw-r--r--compiler/GHC/Rename/Names.hs10
-rw-r--r--compiler/GHC/Tc/Module.hs12
2 files changed, 13 insertions, 9 deletions
diff --git a/compiler/GHC/Rename/Names.hs b/compiler/GHC/Rename/Names.hs
index fa19bdc600..a50701b764 100644
--- a/compiler/GHC/Rename/Names.hs
+++ b/compiler/GHC/Rename/Names.hs
@@ -185,14 +185,14 @@ with yes we have gone with no for now.
-- the return types represent.
-- Note: Do the non SOURCE ones first, so that we get a helpful warning
-- for SOURCE ones that are unnecessary
-rnImports :: [LImportDecl GhcPs]
+rnImports :: [(LImportDecl GhcPs, SDoc)]
-> RnM ([LImportDecl GhcRn], GlobalRdrEnv, ImportAvails, AnyHpcUsage)
rnImports imports = do
tcg_env <- getGblEnv
-- NB: want an identity module here, because it's OK for a signature
-- module to import from its implementor
let this_mod = tcg_mod tcg_env
- let (source, ordinary) = partition is_source_import imports
+ let (source, ordinary) = partition (is_source_import . fst) imports
is_source_import d = ideclSource (unLoc d) == IsBoot
stuff1 <- mapAndReportM (rnImportDecl this_mod) ordinary
stuff2 <- mapAndReportM (rnImportDecl this_mod) source
@@ -293,14 +293,14 @@ Running generateModules from #14693 with DEPTH=16, WIDTH=30 finishes in
--
-- 4. A boolean 'AnyHpcUsage' which is true if the imported module
-- used HPC.
-rnImportDecl :: Module -> LImportDecl GhcPs
+rnImportDecl :: Module -> (LImportDecl GhcPs, SDoc)
-> RnM (LImportDecl GhcRn, GlobalRdrEnv, ImportAvails, AnyHpcUsage)
rnImportDecl this_mod
(L loc decl@(ImportDecl { ideclName = loc_imp_mod_name
, ideclPkgQual = mb_pkg
, ideclSource = want_boot, ideclSafe = mod_safe
, ideclQualified = qual_style, ideclImplicit = implicit
- , ideclAs = as_mod, ideclHiding = imp_details }))
+ , ideclAs = as_mod, ideclHiding = imp_details }), import_reason)
= setSrcSpanA loc $ do
when (isJust mb_pkg) $ do
@@ -312,7 +312,7 @@ rnImportDecl this_mod
-- If there's an error in loadInterface, (e.g. interface
-- file not found) we get lots of spurious errors from 'filterImports'
let imp_mod_name = unLoc loc_imp_mod_name
- doc = ppr imp_mod_name <+> text "is directly imported"
+ doc = ppr imp_mod_name <+> import_reason
-- Check for self-import, which confuses the typechecker (#9032)
-- ghc --make rejects self-import cycles already, but batch-mode may not
diff --git a/compiler/GHC/Tc/Module.hs b/compiler/GHC/Tc/Module.hs
index 450e97819a..d5e0f3255d 100644
--- a/compiler/GHC/Tc/Module.hs
+++ b/compiler/GHC/Tc/Module.hs
@@ -6,6 +6,7 @@
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiWayIf #-}
+{-# LANGUAGE TupleSections #-}
{-# OPTIONS_GHC -Wno-incomplete-record-updates #-}
@@ -278,8 +279,11 @@ tcRnModuleTcRnM hsc_env mod_sum
$ (simpleImportDecl mod_name)
{ ideclHiding = Just (False, noLocA [])}
; mkImport _ = panic "mkImport" }
- ; let { all_imports = prel_imports ++ import_decls
- ++ map mkImport (raw_sig_imports ++ raw_req_imports) }
+ ; let { withReason t imps = map (,text t) imps }
+ ; let { all_imports = withReason "is implicitly imported" prel_imports
+ ++ withReason "is directly imported" import_decls
+ ++ withReason "is an extra sig import" (map mkImport raw_sig_imports)
+ ++ withReason "is an implicit req import" (map mkImport raw_req_imports) }
; -- OK now finally rename the imports
tcg_env <- {-# SCC "tcRnImports" #-}
tcRnImports hsc_env all_imports
@@ -360,7 +364,7 @@ implicitPreludeWarn
************************************************************************
-}
-tcRnImports :: HscEnv -> [LImportDecl GhcPs] -> TcM TcGblEnv
+tcRnImports :: HscEnv -> [(LImportDecl GhcPs, SDoc)] -> TcM TcGblEnv
tcRnImports hsc_env import_decls
= do { (rn_imports, rdr_env, imports, hpc_info) <- rnImports import_decls ;
@@ -2610,7 +2614,7 @@ tcRnImportDecls :: HscEnv
tcRnImportDecls hsc_env import_decls
= runTcInteractive hsc_env $
do { gbl_env <- updGblEnv zap_rdr_env $
- tcRnImports hsc_env import_decls
+ tcRnImports hsc_env $ map (,text "is directly imported") import_decls
; return (tcg_rdr_env gbl_env) }
where
zap_rdr_env gbl_env = gbl_env { tcg_rdr_env = emptyGlobalRdrEnv }