Skip to content
Snippets Groups Projects
Commit d697a6c2 authored by Stefan Holdermans's avatar Stefan Holdermans
Browse files

Refactor uses of `partitionEithers . map`

This patch changes occurences of the idiom
`partitionEithers (map f xs)` by the simpler form
`partitionWith f xs` where `partitionWith` is the utility function
defined in `GHC.Utils.Misc`.

Resolves: #23953
parent 6a896ce8
No related branches found
No related tags found
No related merge requests found
...@@ -47,7 +47,7 @@ import GHC.Utils.Outputable ...@@ -47,7 +47,7 @@ import GHC.Utils.Outputable
import GHC.Utils.Panic import GHC.Utils.Panic
import GHC.Types.SrcLoc import GHC.Types.SrcLoc
import GHC.Types.Tickish import GHC.Types.Tickish
import GHC.Utils.Misc ( seqList ) import GHC.Utils.Misc ( partitionWith, seqList )
import GHC.Cmm.Dataflow.Block import GHC.Cmm.Dataflow.Block
import GHC.Cmm.Dataflow.Collections import GHC.Cmm.Dataflow.Collections
...@@ -58,7 +58,6 @@ import Data.Maybe ...@@ -58,7 +58,6 @@ import Data.Maybe
import Data.List ( minimumBy, nubBy ) import Data.List ( minimumBy, nubBy )
import Data.Ord ( comparing ) import Data.Ord ( comparing )
import qualified Data.Map as Map import qualified Data.Map as Map
import Data.Either ( partitionEithers )
-- | Debug information about a block of code. Ticks scope over nested -- | Debug information about a block of code. Ticks scope over nested
-- blocks. -- blocks.
...@@ -110,7 +109,7 @@ cmmDebugGen modLoc decls = map (blocksForScope Nothing) topScopes ...@@ -110,7 +109,7 @@ cmmDebugGen modLoc decls = map (blocksForScope Nothing) topScopes
-- Analyse tick scope structure: Each one is either a top-level -- Analyse tick scope structure: Each one is either a top-level
-- tick scope, or the child of another. -- tick scope, or the child of another.
(topScopes, childScopes) (topScopes, childScopes)
= partitionEithers $ map (\a -> findP a a) $ Map.keys blockCtxs = partitionWith (\a -> findP a a) $ Map.keys blockCtxs
findP tsc GlobalScope = Left tsc -- top scope findP tsc GlobalScope = Left tsc -- top scope
findP tsc scp | scp' `Map.member` blockCtxs = Right (scp', tsc) findP tsc scp | scp' `Map.member` blockCtxs = Right (scp', tsc)
| otherwise = findP tsc scp' | otherwise = findP tsc scp'
......
...@@ -91,7 +91,6 @@ import Control.Monad (foldM, forM, guard, mzero, when, filterM) ...@@ -91,7 +91,6 @@ import Control.Monad (foldM, forM, guard, mzero, when, filterM)
import Control.Monad.Trans.Class (lift) import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.State.Strict import Control.Monad.Trans.State.Strict
import Data.Coerce import Data.Coerce
import Data.Either (partitionEithers)
import Data.Foldable (foldlM, minimumBy, toList) import Data.Foldable (foldlM, minimumBy, toList)
import Data.Monoid (Any(..)) import Data.Monoid (Any(..))
import Data.List (sortBy, find) import Data.List (sortBy, find)
...@@ -608,7 +607,7 @@ addPhiCts nabla cts = runMaybeT $ do ...@@ -608,7 +607,7 @@ addPhiCts nabla cts = runMaybeT $ do
inhabitationTest initFuel (nabla_ty_st nabla) nabla'' inhabitationTest initFuel (nabla_ty_st nabla) nabla''
partitionPhiCts :: PhiCts -> ([PredType], [PhiCt]) partitionPhiCts :: PhiCts -> ([PredType], [PhiCt])
partitionPhiCts = partitionEithers . map to_either . toList partitionPhiCts = partitionWith to_either . toList
where where
to_either (PhiTyCt pred_ty) = Left pred_ty to_either (PhiTyCt pred_ty) = Left pred_ty
to_either ct = Right ct to_either ct = Right ct
......
...@@ -55,7 +55,6 @@ import Control.Applicative ...@@ -55,7 +55,6 @@ import Control.Applicative
import qualified Data.Set as Set import qualified Data.Set as Set
import qualified Data.Map as M import qualified Data.Map as M
import Data.List (isSuffixOf) import Data.List (isSuffixOf)
import Data.Either
import System.FilePath import System.FilePath
import System.Directory import System.Directory
...@@ -131,7 +130,7 @@ get_link_deps opts pls maybe_normal_osuf span mods = do ...@@ -131,7 +130,7 @@ get_link_deps opts pls maybe_normal_osuf span mods = do
let let
-- 2. Exclude ones already linked -- 2. Exclude ones already linked
-- Main reason: avoid findModule calls in get_linkable -- Main reason: avoid findModule calls in get_linkable
(mods_needed, links_got) = partitionEithers (map split_mods mods_s) (mods_needed, links_got) = partitionWith split_mods mods_s
pkgs_needed = eltsUDFM $ getUniqDSet pkgs_s `minusUDFM` pkgs_loaded pls pkgs_needed = eltsUDFM $ getUniqDSet pkgs_s `minusUDFM` pkgs_loaded pls
split_mods mod = split_mods mod =
......
...@@ -130,7 +130,6 @@ import Control.Monad ...@@ -130,7 +130,6 @@ import Control.Monad
import Control.Monad.Catch as MC import Control.Monad.Catch as MC
import Data.Array import Data.Array
import Data.Dynamic import Data.Dynamic
import Data.Either
import Data.IntMap (IntMap) import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap import qualified Data.IntMap as IntMap
import Data.List (find,intercalate) import Data.List (find,intercalate)
...@@ -808,7 +807,7 @@ findGlobalRdrEnv :: HscEnv -> [InteractiveImport] ...@@ -808,7 +807,7 @@ findGlobalRdrEnv :: HscEnv -> [InteractiveImport]
findGlobalRdrEnv hsc_env imports findGlobalRdrEnv hsc_env imports
= do { idecls_env <- hscRnImportDecls hsc_env idecls = do { idecls_env <- hscRnImportDecls hsc_env idecls
-- This call also loads any orphan modules -- This call also loads any orphan modules
; return $ case partitionEithers (map mkEnv imods) of ; return $ case partitionWith mkEnv imods of
(err : _, _) -> Left err (err : _, _) -> Left err
([], imods_env0) -> ([], imods_env0) ->
-- Need to rehydrate the 'GlobalRdrEnv' to recover the 'GREInfo's. -- Need to rehydrate the 'GlobalRdrEnv' to recover the 'GREInfo's.
......
...@@ -496,9 +496,10 @@ optimizeFree offset ids = do ...@@ -496,9 +496,10 @@ optimizeFree offset ids = do
l = length ids' l = length ids'
slots <- drop offset . take l . (++repeat SlotUnknown) <$> getSlots slots <- drop offset . take l . (++repeat SlotUnknown) <$> getSlots
let slm = M.fromList (zip slots [0..]) let slm = M.fromList (zip slots [0..])
(remaining, fixed) = partitionEithers $ (remaining, fixed) = partitionWith (\inp@(i,n) -> maybe (Left inp)
map (\inp@(i,n) -> maybe (Left inp) (\j -> Right (i,n,j,True)) (\j -> Right (i,n,j,True))
(M.lookup (SlotId i n) slm)) ids' (M.lookup (SlotId i n) slm))
ids'
takenSlots = S.fromList (fmap (\(_,_,x,_) -> x) fixed) takenSlots = S.fromList (fmap (\(_,_,x,_) -> x) fixed)
freeSlots = filter (`S.notMember` takenSlots) [0..l-1] freeSlots = filter (`S.notMember` takenSlots) [0..l-1]
remaining' = zipWith (\(i,n) j -> (i,n,j,False)) remaining freeSlots remaining' = zipWith (\(i,n) j -> (i,n,j,False)) remaining freeSlots
......
...@@ -15,10 +15,10 @@ import GHC.Unit.Module ...@@ -15,10 +15,10 @@ import GHC.Unit.Module
import GHC.Types.Literal import GHC.Types.Literal
import GHC.Data.Graph.Directed import GHC.Data.Graph.Directed
import GHC.Utils.Misc (partitionWith)
import GHC.StgToJS.Utils import GHC.StgToJS.Utils
import Data.Char import Data.Char
import Data.Either
import Data.List (partition) import Data.List (partition)
import Data.Maybe import Data.Maybe
...@@ -38,7 +38,7 @@ sinkPgm m pgm = (sunk, map StgTopLifted pgm'' ++ stringLits) ...@@ -38,7 +38,7 @@ sinkPgm m pgm = (sunk, map StgTopLifted pgm'' ++ stringLits)
where where
selectLifted (StgTopLifted b) = Left b selectLifted (StgTopLifted b) = Left b
selectLifted x = Right x selectLifted x = Right x
(pgm', stringLits) = partitionEithers (map selectLifted pgm) (pgm', stringLits) = partitionWith selectLifted pgm
(sunk, pgm'') = sinkPgm' m pgm' (sunk, pgm'') = sinkPgm' m pgm'
sinkPgm' sinkPgm'
......
...@@ -58,6 +58,7 @@ import GHC.Types.SourceFile ( hscSourceString ) ...@@ -58,6 +58,7 @@ import GHC.Types.SourceFile ( hscSourceString )
import GHC.Unit.Module.ModSummary import GHC.Unit.Module.ModSummary
import GHC.Unit.Types import GHC.Unit.Types
import GHC.Utils.Outputable import GHC.Utils.Outputable
import GHC.Utils.Misc ( partitionWith )
import System.FilePath import System.FilePath
import qualified Data.Map as Map import qualified Data.Map as Map
...@@ -68,7 +69,6 @@ import GHC.Unit.Module ...@@ -68,7 +69,6 @@ import GHC.Unit.Module
import GHC.Linker.Static.Utils import GHC.Linker.Static.Utils
import Data.Bifunctor import Data.Bifunctor
import Data.Either
import Data.Function import Data.Function
import Data.List (sort) import Data.List (sort)
import GHC.Data.List.SetOps import GHC.Data.List.SetOps
...@@ -336,7 +336,7 @@ moduleGraphNodes drop_hs_boot_nodes summaries = ...@@ -336,7 +336,7 @@ moduleGraphNodes drop_hs_boot_nodes summaries =
(graphFromEdgedVerticesUniq nodes, lookup_node) (graphFromEdgedVerticesUniq nodes, lookup_node)
where where
-- Map from module to extra boot summary dependencies which need to be merged in -- Map from module to extra boot summary dependencies which need to be merged in
(boot_summaries, nodes) = bimap Map.fromList id $ partitionEithers (map go numbered_summaries) (boot_summaries, nodes) = bimap Map.fromList id $ partitionWith go numbered_summaries
where where
go (s, key) = go (s, key) =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment