Rodrigo Mesquita pushed to branch wip/fix-26953 at Glasgow Haskell Compiler / GHC

Commits:

9 changed files:

Changes:

  • compiler/GHC/CmmToAsm/BlockLayout.hs
    ... ... @@ -36,6 +36,7 @@ import GHC.Utils.Outputable
    36 36
     import GHC.Utils.Panic
    
    37 37
     import GHC.Utils.Misc
    
    38 38
     
    
    39
    +import Data.Containers.ListUtils (nubOrd)
    
    39 40
     import Data.List (sortOn, sortBy, nub)
    
    40 41
     import Data.List.NonEmpty (nonEmpty)
    
    41 42
     import qualified Data.List.NonEmpty as NE
    
    ... ... @@ -426,7 +427,7 @@ combineNeighbourhood edges chains
    426 427
             applyEdges :: [CfgEdge] -> FrontierMap -> FrontierMap -> Set.Set (BlockId, BlockId)
    
    427 428
                        -> ([BlockChain], Set.Set (BlockId,BlockId))
    
    428 429
             applyEdges [] chainEnds _chainFronts combined =
    
    429
    -            (ordNub $ map snd $ mapElems chainEnds, combined)
    
    430
    +            (nubOrd $ map snd $ mapElems chainEnds, combined)
    
    430 431
             applyEdges ((CfgEdge from to _w):edges) chainEnds chainFronts combined
    
    431 432
                 | Just (c1_e,c1) <- mapLookup from chainEnds
    
    432 433
                 , Just (c2_f,c2) <- mapLookup to chainFronts
    

  • compiler/GHC/Driver/Backpack.hs
    ... ... @@ -76,6 +76,7 @@ import GHC.Data.FastString
    76 76
     import qualified GHC.Data.EnumSet as EnumSet
    
    77 77
     import qualified GHC.Data.ShortText as ST
    
    78 78
     
    
    79
    +import Data.Containers.ListUtils (nubOrd)
    
    79 80
     import Data.List ( partition )
    
    80 81
     import System.Exit
    
    81 82
     import Control.Monad
    
    ... ... @@ -763,14 +764,14 @@ hsunitModuleGraph do_link unit = do
    763 764
         let inodes = instantiationNodes (homeUnitId $ hsc_home_unit hsc_env) (hsc_units hsc_env)
    
    764 765
         -- TODO: Backpack mode does not properly support ExternalPackage nodes yet
    
    765 766
         -- Module nodes do not get given package dependencies (see hsModuleToModSummary).
    
    766
    -    let pkg_nodes =  ordNub $ map (\(_, iud) -> UnitNode [] (instUnitInstanceOf iud)) inodes
    
    767
    +    let pkg_nodes =  nubOrd $ map (\(_, iud) -> UnitNode [] (instUnitInstanceOf iud)) inodes
    
    767 768
         let graph_nodes = nodes ++ req_nodes ++ (map (uncurry InstantiationNode) $ inodes) ++ pkg_nodes
    
    768 769
             key_nodes = map mkNodeKey graph_nodes
    
    769 770
             all_nodes = graph_nodes ++ [LinkNode key_nodes (homeUnitId $ hsc_home_unit hsc_env) | do_link]
    
    770 771
         -- This error message is not very good but .bkp mode is just for testing so
    
    771 772
         -- better to be direct rather than pretty.
    
    772 773
         when
    
    773
    -      (length key_nodes /= length (ordNub key_nodes))
    
    774
    +      (length key_nodes /= length (nubOrd key_nodes))
    
    774 775
           (pprPanic "Duplicate nodes keys in backpack file" (ppr key_nodes))
    
    775 776
     
    
    776 777
         -- 3. Return the kaboodle
    

  • compiler/GHC/Driver/Session/Units.hs
    ... ... @@ -25,7 +25,6 @@ import qualified GHC.Unit.State as State
    25 25
     import GHC.Types.SrcLoc
    
    26 26
     import GHC.Types.SourceError
    
    27 27
     
    
    28
    -import GHC.Utils.Misc
    
    29 28
     import GHC.Utils.Panic
    
    30 29
     import GHC.Utils.Outputable as Outputable
    
    31 30
     import GHC.Utils.Monad       ( liftIO, mapMaybeM )
    
    ... ... @@ -35,6 +34,7 @@ import System.IO
    35 34
     import System.Exit
    
    36 35
     import System.FilePath
    
    37 36
     import Control.Monad
    
    37
    +import Data.Containers.ListUtils (nubOrdOn)
    
    38 38
     import Data.List ( partition, (\\) )
    
    39 39
     import qualified Data.Set as Set
    
    40 40
     import GHC.Prelude
    
    ... ... @@ -204,7 +204,7 @@ checkDuplicateUnits dflags flags =
    204 204
     
    
    205 205
       where
    
    206 206
         uids = map (second homeUnitId_) flags
    
    207
    -    deduplicated_uids = ordNubOn snd uids
    
    207
    +    deduplicated_uids = nubOrdOn snd uids
    
    208 208
         duplicate_ids = Set.fromList (map snd uids \\ map snd deduplicated_uids)
    
    209 209
     
    
    210 210
         duplicate_flags = filter (flip Set.member duplicate_ids . snd) uids
    

  • compiler/GHC/HsToCore/Usage.hs
    ... ... @@ -32,6 +32,7 @@ import GHC.Unit.Module.Deps
    32 32
     import GHC.Data.Maybe
    
    33 33
     import GHC.Data.FastString
    
    34 34
     
    
    35
    +import Data.Containers.ListUtils (nubOrdOn)
    
    35 36
     import Data.List (sortBy)
    
    36 37
     import Data.Map (Map)
    
    37 38
     import qualified Data.Map as Map
    
    ... ... @@ -180,7 +181,7 @@ the TH splice.
    180 181
     -- modules and direct object files for pkg dependencies
    
    181 182
     mkObjectUsage :: Plugins -> FinderCache -> [LinkableUsage] -> PkgsLoaded -> IO [Usage]
    
    182 183
     mkObjectUsage plugins fc th_links_needed th_pkgs_needed = do
    
    183
    -      let ls = ordNubOn linkableModule (th_links_needed ++ plugins_links_needed)
    
    184
    +      let ls = nubOrdOn linkableModule (th_links_needed ++ plugins_links_needed)
    
    184 185
               ds = concatMap loaded_pkg_hs_objs $ eltsUDFM (plusUDFM th_pkgs_needed plugin_pkgs_needed) -- TODO possibly record loaded_pkg_non_hs_objs as well
    
    185 186
               (plugins_links_needed, plugin_pkgs_needed) = loadedPluginDeps plugins
    
    186 187
           concat <$> sequence (map linkableToUsage ls ++ map librarySpecToUsage ds)
    

  • compiler/GHC/Linker/Unit.hs
    ... ... @@ -25,6 +25,7 @@ import qualified GHC.Data.ShortText as ST
    25 25
     import GHC.Settings
    
    26 26
     
    
    27 27
     import Control.Monad
    
    28
    +import Data.Containers.ListUtils (nubOrd)
    
    28 29
     import Data.List (nub)
    
    29 30
     import Data.Semigroup ( Semigroup(..) )
    
    30 31
     import System.Directory
    
    ... ... @@ -95,7 +96,7 @@ collectArchives namever ways pc =
    95 96
       filterM doesFileExist [ searchPath </> ("lib" ++ lib ++ ".a")
    
    96 97
                             | searchPath <- searchPaths
    
    97 98
                             , lib <- libs ]
    
    98
    -  where searchPaths = ordNub . filter notNull . libraryDirsForWay ways $ pc
    
    99
    +  where searchPaths = nubOrd . filter notNull . libraryDirsForWay ways $ pc
    
    99 100
             libs        = unitHsLibs namever ways pc ++ (map ST.unpack . unitExtDepLibsStaticSys $ pc)
    
    100 101
     
    
    101 102
     getLibs :: GhcNameVersion -> Ways -> UnitEnv -> [UnitId] -> IO [(String,String)]
    

  • compiler/GHC/Rename/Pat.hs
    ... ... @@ -78,6 +78,7 @@ import GHC.Core.TyCon ( isKindName )
    78 78
     import qualified GHC.LanguageExtensions as LangExt
    
    79 79
     
    
    80 80
     import Control.Monad       ( when, ap, guard, unless )
    
    81
    +import Data.Containers.ListUtils (nubOrdOn)
    
    81 82
     import Data.Foldable
    
    82 83
     import Data.Function       ( on )
    
    83 84
     import Data.Functor.Identity ( Identity (..) )
    
    ... ... @@ -666,7 +667,7 @@ rnPatAndThen mk (OrPat _ pats)
    666 667
            ; pats' <- rnLPatsAndThen mk pats
    
    667 668
            ; let bndrs = collectPatsBinders CollVarTyVarBinders (NE.toList pats')
    
    668 669
            ; liftCps $ setSrcSpan loc $ checkErr (null bndrs) $
    
    669
    -           TcRnOrPatBindsVariables (NE.fromList (ordNubOn getOccName bndrs))
    
    670
    +           TcRnOrPatBindsVariables (NE.fromList (nubOrdOn getOccName bndrs))
    
    670 671
            ; return (OrPat noExtField pats') }
    
    671 672
     
    
    672 673
     rnPatAndThen mk (SumPat _ pat alt arity)
    

  • compiler/GHC/Unit/Info.hs
    ... ... @@ -49,6 +49,7 @@ import GHC.Unit.Database
    49 49
     
    
    50 50
     import GHC.Settings
    
    51 51
     
    
    52
    +import Data.Containers.ListUtils (nubOrd)
    
    52 53
     import Data.Version
    
    53 54
     import Data.Bifunctor
    
    54 55
     import Data.List (isPrefixOf, stripPrefix)
    
    ... ... @@ -185,7 +186,7 @@ mkUnitPprInfo ufs i = UnitPprInfo
    185 186
     
    
    186 187
     -- | Find all the include directories in the given units
    
    187 188
     collectIncludeDirs :: [UnitInfo] -> [FilePath]
    
    188
    -collectIncludeDirs ps = map ST.unpack $ ordNub (filter (not . ST.null) (concatMap unitIncludeDirs ps))
    
    189
    +collectIncludeDirs ps = map ST.unpack $ nubOrd (filter (not . ST.null) (concatMap unitIncludeDirs ps))
    
    189 190
     
    
    190 191
     -- | Find all the C-compiler options in the given units
    
    191 192
     collectExtraCcOpts :: [UnitInfo] -> [String]
    
    ... ... @@ -193,7 +194,7 @@ collectExtraCcOpts ps = map ST.unpack (concatMap unitCcOptions ps)
    193 194
     
    
    194 195
     -- | Find all the library directories in the given units for the given ways
    
    195 196
     collectLibraryDirs :: Ways -> [UnitInfo] -> [FilePath]
    
    196
    -collectLibraryDirs ws = ordNub . filter notNull . concatMap (libraryDirsForWay ws)
    
    197
    +collectLibraryDirs ws = nubOrd . filter notNull . concatMap (libraryDirsForWay ws)
    
    197 198
     
    
    198 199
     -- | Find all the frameworks in the given units
    
    199 200
     collectFrameworks :: [UnitInfo] -> [String]
    
    ... ... @@ -201,7 +202,7 @@ collectFrameworks ps = map ST.unpack (concatMap unitExtDepFrameworks ps)
    201 202
     
    
    202 203
     -- | Find all the package framework paths in these and the preload packages
    
    203 204
     collectFrameworksDirs :: [UnitInfo] -> [String]
    
    204
    -collectFrameworksDirs ps = map ST.unpack (ordNub (filter (not . ST.null) (concatMap unitExtDepFrameworkDirs ps)))
    
    205
    +collectFrameworksDirs ps = map ST.unpack (nubOrd (filter (not . ST.null) (concatMap unitExtDepFrameworkDirs ps)))
    
    205 206
     
    
    206 207
     -- | Either the 'unitLibraryDirs' or 'unitLibraryDynDirs' as appropriate for the way.
    
    207 208
     libraryDirsForWay :: Ways -> UnitInfo -> [String]
    

  • compiler/GHC/Unit/State.hs
    ... ... @@ -112,6 +112,7 @@ import GHC.Utils.Exception
    112 112
     import System.Directory
    
    113 113
     import System.FilePath as FilePath
    
    114 114
     import Control.Monad
    
    115
    +import Data.Containers.ListUtils (nubOrd)
    
    115 116
     import Data.Graph (stronglyConnComp, SCC(..))
    
    116 117
     import Data.Char ( toUpper )
    
    117 118
     import Data.List ( intersperse, partition, sortBy, sortOn, sort )
    
    ... ... @@ -1705,7 +1706,7 @@ mkUnitState logger cfg = do
    1705 1706
           basicLinkedUnits = fmap (RealUnit . Definite)
    
    1706 1707
                              $ filter (flip elemUniqMap pkg_db)
    
    1707 1708
                              $ unitConfigAutoLink cfg
    
    1708
    -      preload3 = ordNub $ (basicLinkedUnits ++ preload1)
    
    1709
    +      preload3 = nubOrd $ (basicLinkedUnits ++ preload1)
    
    1709 1710
     
    
    1710 1711
       -- Close the preload packages with their dependencies
    
    1711 1712
       dep_preload <- mayThrowUnitErr
    

  • compiler/GHC/Utils/Misc.hs
    ... ... @@ -59,7 +59,7 @@ module GHC.Utils.Misc (
    59 59
             replaceAt, dropTail, capitalise,
    
    60 60
     
    
    61 61
             -- * Sorting
    
    62
    -        sortWith, minWith, nubSort, ordNub, ordNubOn,
    
    62
    +        sortWith, minWith, nubSort,
    
    63 63
     
    
    64 64
             -- * Comparisons
    
    65 65
             isEqual,
    
    ... ... @@ -570,23 +570,6 @@ minWith get_key xs = assert (not (null xs) )
    570 570
     nubSort :: Ord a => [a] -> [a]
    
    571 571
     nubSort = Set.toAscList . Set.fromList
    
    572 572
     
    
    573
    --- | Remove duplicates but keep elements in order.
    
    574
    ---   O(n * log n)
    
    575
    -ordNub :: Ord a => [a] -> [a]
    
    576
    -ordNub xs = ordNubOn id xs
    
    577
    -
    
    578
    --- | Remove duplicates but keep elements in order.
    
    579
    ---   O(n * log n)
    
    580
    -ordNubOn :: Ord b => (a -> b) -> [a] -> [a]
    
    581
    -ordNubOn f xs
    
    582
    -  = go Set.empty xs
    
    583
    -  where
    
    584
    -    go _ [] = []
    
    585
    -    go s (x:xs)
    
    586
    -      | Set.member (f x) s = go s xs
    
    587
    -      | otherwise = x : go (Set.insert (f x) s) xs
    
    588
    -
    
    589
    -
    
    590 573
     {-
    
    591 574
     ************************************************************************
    
    592 575
     *                                                                      *