summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2014-05-06 08:20:28 +0100
committerAustin Seipp <austin@well-typed.com>2014-06-23 02:38:16 -0500
commitf98d2c279e5757d3156427c834281d2ce2ab92db (patch)
treef91ffe5c84bd02f8216e05360081b5ada03aa140
parenta35a0315e3e928b4d9758c71e1a7ef8e034d16f9 (diff)
downloadhaskell-f98d2c279e5757d3156427c834281d2ce2ab92db.tar.gz
Second go at fixing #9061
My first attempt introduce a bug in -fprint-minimal-imports, but fortunately a regression test caught it. (cherry picked from commit 5b73dc5fda1941d51827ea72614782c10a355a3d)
-rw-r--r--compiler/rename/RnNames.lhs46
1 files changed, 24 insertions, 22 deletions
diff --git a/compiler/rename/RnNames.lhs b/compiler/rename/RnNames.lhs
index bddafe06e1..2fb7d4fe4e 100644
--- a/compiler/rename/RnNames.lhs
+++ b/compiler/rename/RnNames.lhs
@@ -1285,11 +1285,14 @@ type ImportDeclUsage
warnUnusedImportDecls :: TcGblEnv -> RnM ()
warnUnusedImportDecls gbl_env
= do { uses <- readMutVar (tcg_used_rdrnames gbl_env)
- ; let imports = filterOut un_warnable_import (tcg_rn_imports gbl_env)
+ ; let user_imports = filterOut (ideclImplicit . unLoc) (tcg_rn_imports gbl_env)
+ -- This whole function deals only with *user* imports
+ -- both for warning about unnecessary ones, and for
+ -- deciding the minimal ones
rdr_env = tcg_rdr_env gbl_env
; let usage :: [ImportDeclUsage]
- usage = findImportUsage imports rdr_env (Set.elems uses)
+ usage = findImportUsage user_imports rdr_env (Set.elems uses)
; traceRn (vcat [ ptext (sLit "Uses:") <+> ppr (Set.elems uses)
, ptext (sLit "Import usage") <+> ppr usage])
@@ -1298,28 +1301,8 @@ warnUnusedImportDecls gbl_env
; whenGOptM Opt_D_dump_minimal_imports $
printMinimalImports usage }
- where
- un_warnable_import (L _ decl) -- See Note [Un-warnable import decls]
- | ideclImplicit decl
- = True
- | Just (True, hides) <- ideclHiding decl
- , not (null hides)
- , pRELUDE_NAME == unLoc (ideclName decl)
- = True
- | otherwise
- = False
\end{code}
-Note [Un-warnable import decls]
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-We do not warn about the implicit import of Prelude, since the user can't remove it
-
-We do not warn about
- import Prelude hiding( x, y )
-because even if nothing else from Prelude is used, it may be essential to hide
-x,y to avoid name-shadowing warnings. Example (Trac #9061)
- import Prelude hiding( log )
- f x = log where log = ()
Note [The ImportMap]
~~~~~~~~~~~~~~~~~~~~
@@ -1433,6 +1416,11 @@ warnUnusedImport :: ImportDeclUsage -> RnM ()
warnUnusedImport (L loc decl, used, unused)
| Just (False,[]) <- ideclHiding decl
= return () -- Do not warn for 'import M()'
+
+ | Just (True, hides) <- ideclHiding decl
+ , not (null hides)
+ , pRELUDE_NAME == unLoc (ideclName decl)
+ = return () -- Note [Do not warn about Prelude hiding]
| null used = addWarnAt loc msg1 -- Nothing used; drop entire decl
| null unused = return () -- Everything imported is used; nop
| otherwise = addWarnAt loc msg2 -- Some imports are unused
@@ -1452,6 +1440,19 @@ warnUnusedImport (L loc decl, used, unused)
pp_not_used = text "is redundant"
\end{code}
+Note [Do not warn about Prelude hiding]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+We do not warn about
+ import Prelude hiding( x, y )
+because even if nothing else from Prelude is used, it may be essential to hide
+x,y to avoid name-shadowing warnings. Example (Trac #9061)
+ import Prelude hiding( log )
+ f x = log where log = ()
+
+
+
+Note [Printing minimal imports]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To print the minimal imports we walk over the user-supplied import
decls, and simply trim their import lists. NB that
@@ -1462,6 +1463,7 @@ decls, and simply trim their import lists. NB that
\begin{code}
printMinimalImports :: [ImportDeclUsage] -> RnM ()
+-- See Note [Printing minimal imports]
printMinimalImports imports_w_usage
= do { imports' <- mapM mk_minimal imports_w_usage
; this_mod <- getModule