diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2015-10-28 17:16:55 +0000 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2015-10-30 09:45:47 +0000 |
commit | 9376249b6b78610db055a10d05f6592d6bbbea2f (patch) | |
tree | 67526c534565bcf9e20fd0872fc87a8be2e74f8a /compiler/rename | |
parent | 9b3a0588e7523db54443270005ba2c6016e56ab8 (diff) | |
download | haskell-9376249b6b78610db055a10d05f6592d6bbbea2f.tar.gz |
Fix unused-import stuff in a better way
The fix for Trac #10890 in commit 1818b48, namely
Fix incorrect import warnings when methods with identical names are imported
was wrong, as demonstrated by the new test T10890_2. It suppressed
far too many warnings!
This patch fixes the original problem in a different way, by making
RdrName.greUsedRdrName a bit cleverer.
But this too is not really the Right Thing. I think the Right Thing is
to store the /GRE/ in the tcg_used_rdrnames, not the /RdrName/. That
would be a lot simpler and more direct.
But one step at a time.
Diffstat (limited to 'compiler/rename')
-rw-r--r-- | compiler/rename/RnNames.hs | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/compiler/rename/RnNames.hs b/compiler/rename/RnNames.hs index 12f9024331..e0b06839e5 100644 --- a/compiler/rename/RnNames.hs +++ b/compiler/rename/RnNames.hs @@ -1548,8 +1548,8 @@ findImportUsage imports rdr_env rdrs sel_names import_usage :: ImportMap import_usage = foldr (extendImportMap_Field rdr_env) - (foldr (extendImportMap rdr_env) Map.empty rdrs) - (Set.elems sel_names) + (foldr (extendImportMap rdr_env) Map.empty rdrs) + (Set.elems sel_names) unused_decl decl@(L loc (ImportDecl { ideclHiding = imps })) = (decl, nubAvails used_avails, nameSetElems unused_imps) @@ -1608,11 +1608,12 @@ extendImportMap_Field rdr_env (FieldOcc rdr sel) = -- the RdrName in that import decl's entry in the ImportMap extendImportMap_GRE :: [GlobalRdrElt] -> ImportMap -> ImportMap extendImportMap_GRE gres imp_map - = foldr recordRdrName imp_map nonLocalGREs + | (gre:_) <- gres + , not (isLocalGRE gre) -- Should always be true, because we only need record + -- uses of imported things, but that's not true yet + = add_imp gre (bestImport (gre_imp gre)) imp_map + | otherwise = imp_map where - recordRdrName gre m = add_imp gre (bestImport (gre_imp gre)) m - nonLocalGREs = filter (not . gre_lcl) gres - add_imp :: GlobalRdrElt -> ImportSpec -> ImportMap -> ImportMap add_imp gre (ImpSpec { is_decl = imp_decl_spec }) imp_map = Map.insertWith add decl_loc [avail] imp_map @@ -1622,21 +1623,6 @@ extendImportMap_GRE gres imp_map -- For srcSpanEnd see Note [The ImportMap] avail = availFromGRE gre - bestImport :: [ImportSpec] -> ImportSpec - bestImport iss - = case partition isImpAll iss of - ([], imp_somes) -> textuallyFirst imp_somes - (imp_alls, _) -> textuallyFirst imp_alls - - textuallyFirst :: [ImportSpec] -> ImportSpec - textuallyFirst iss = case sortWith (is_dloc . is_decl) iss of - [] -> pprPanic "textuallyFirst" (ppr iss) - (is:_) -> is - - isImpAll :: ImportSpec -> Bool - isImpAll (ImpSpec { is_item = ImpAll }) = True - isImpAll _other = False - warnUnusedImport :: NameEnv (FieldLabelString, Name) -> ImportDeclUsage -> RnM () warnUnusedImport fld_env (L loc decl, used, unused) |