diff options
author | Bodigrim <andrew.lelechenko@gmail.com> | 2022-09-28 00:15:53 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-09-28 17:50:28 -0400 |
commit | 2f050687e75ffe6fbf140cacd15fd916d2997499 (patch) | |
tree | acd68576f0210c85f69b392cb10a7048ee97d17e /compiler/GHC/Rename/Names.hs | |
parent | b0c89dfaf9f8aeda9dd69a9583fd29150099aa27 (diff) | |
download | haskell-2f050687e75ffe6fbf140cacd15fd916d2997499.tar.gz |
Avoid Data.List.group; prefer Data.List.NonEmpty.group
This allows to avoid further partiality, e. g., map head . group is
replaced by map NE.head . NE.group, and there are less panic calls.
Diffstat (limited to 'compiler/GHC/Rename/Names.hs')
-rw-r--r-- | compiler/GHC/Rename/Names.hs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/compiler/GHC/Rename/Names.hs b/compiler/GHC/Rename/Names.hs index edc0af5f52..ca710744de 100644 --- a/compiler/GHC/Rename/Names.hs +++ b/compiler/GHC/Rename/Names.hs @@ -93,7 +93,9 @@ import Data.Either ( partitionEithers ) import Data.Map ( Map ) import qualified Data.Map as Map import Data.Ord ( comparing ) -import Data.List ( partition, (\\), find, sortBy, groupBy, sortOn ) +import Data.List ( partition, (\\), find, sortBy ) +import Data.List.NonEmpty (NonEmpty(..)) +import qualified Data.List.NonEmpty as NE import Data.Function ( on ) import qualified Data.Set as S import Data.Foldable ( toList ) @@ -1968,7 +1970,7 @@ getMinimalImports = fmap combine . mapM mk_minimal all_non_overloaded = all (not . flIsOverloaded) combine :: [LImportDecl GhcRn] -> [LImportDecl GhcRn] - combine = map merge . groupBy ((==) `on` getKey) . sortOn getKey + combine = map merge . NE.groupAllWith getKey getKey :: LImportDecl GhcRn -> (Bool, Maybe ModuleName, ModuleName) getKey decl = @@ -1980,10 +1982,9 @@ getMinimalImports = fmap combine . mapM mk_minimal idecl :: ImportDecl GhcRn idecl = unLoc decl - merge :: [LImportDecl GhcRn] -> LImportDecl GhcRn - merge [] = error "getMinimalImports: unexpected empty list" - merge decls@((L l decl) : _) = L l (decl { ideclImportList = Just (Exactly, L (noAnnSrcSpan (locA l)) lies) }) - where lies = concatMap (unLoc . snd) $ mapMaybe (ideclImportList . unLoc) decls + merge :: NonEmpty (LImportDecl GhcRn) -> LImportDecl GhcRn + merge decls@((L l decl) :| _) = L l (decl { ideclImportList = Just (Exactly, L (noAnnSrcSpan (locA l)) lies) }) + where lies = concatMap (unLoc . snd) $ mapMaybe (ideclImportList . unLoc) $ NE.toList decls printMinimalImports :: HscSource -> [ImportDeclUsage] -> RnM () |