Hannes Siebenhandl pushed to branch wip/sort-usages at Glasgow Haskell Compiler / GHC

Commits:

3 changed files:

Changes:

  • compiler/GHC/HsToCore/Usage.hs
    ... ... @@ -32,7 +32,7 @@ import GHC.Unit.Module.Deps
    32 32
     import GHC.Data.Maybe
    
    33 33
     import GHC.Data.FastString
    
    34 34
     
    
    35
    -import Data.List (sortBy)
    
    35
    +import Data.List (sortBy, sortOn)
    
    36 36
     import Data.Map (Map)
    
    37 37
     import qualified Data.Map as Map
    
    38 38
     import qualified Data.Set as Set
    
    ... ... @@ -69,6 +69,8 @@ data UsageConfig = UsageConfig
    69 69
       { uc_safe_implicit_imps_req :: !Bool -- ^ Are all implicit imports required to be safe for this Safe Haskell mode?
    
    70 70
       }
    
    71 71
     
    
    72
    +-- | Build the list of 'Usage's that drives recompilation checking.
    
    73
    +-- The resulting list is deterministically sorted (see 'usageFingerprint').
    
    72 74
     mkUsageInfo :: UsageConfig -> Plugins -> FinderCache -> UnitEnv
    
    73 75
                 -> Module -> ImportedMods -> [ImportUserSpec] -> NameSet
    
    74 76
                 -> [FilePath] -> [FilePath] -> [(Module, Fingerprint)] -> [LinkableUsage] -> PkgsLoaded
    
    ... ... @@ -99,7 +101,10 @@ mkUsageInfo uc plugins fc unit_env
    99 101
                                         }
    
    100 102
                                    | (mod, hash) <- merged ]
    
    101 103
                                 ++ object_usages
    
    102
    -    usages `seqList` return usages
    
    104
    +
    
    105
    +    -- Sort all the Usages to ensure a deterministic ordering.
    
    106
    +    let sorted_usages = sortOn usageFingerprint usages
    
    107
    +    sorted_usages `seqList` return sorted_usages
    
    103 108
         -- seq the list of Usages returned: occasionally these
    
    104 109
         -- don't get evaluated for a while and we can end up hanging on to
    
    105 110
         -- the entire collection of Ifaces.
    

  • compiler/GHC/Unit/Module/Deps.hs
    ... ... @@ -17,6 +17,7 @@ module GHC.Unit.Module.Deps
    17 17
        , noDependencies
    
    18 18
        , pprDeps
    
    19 19
        , Usage (..)
    
    20
    +   , usageFingerprint
    
    20 21
        , HomeModImport (..)
    
    21 22
        , HomeModImportedAvails (..)
    
    22 23
        , ImportAvails (..)
    
    ... ... @@ -497,6 +498,17 @@ instance Binary Usage where
    497 498
     
    
    498 499
               i -> error ("Binary.get(Usage): " ++ show i)
    
    499 500
     
    
    501
    +-- | Extract the distinguishing fingerprint carried by a particular 'Usage'
    
    502
    +-- constructor.  Every constructor stores a hash capturing the bit of state
    
    503
    +-- that drives recompilation decisions, so we can sort on it directly.
    
    504
    +usageFingerprint :: Usage -> Fingerprint
    
    505
    +usageFingerprint UsagePackageModule{ usg_mod_hash = fp } = fp
    
    506
    +usageFingerprint UsageHomeModule{ usg_mod_hash = fp } = fp
    
    507
    +usageFingerprint UsageFile{ usg_file_hash = fp } = fp
    
    508
    +usageFingerprint UsageDirectory{ usg_dir_hash = fp } = fp
    
    509
    +usageFingerprint UsageHomeModuleBytecode{ usg_bytecode_hash = fp } = fp
    
    510
    +usageFingerprint UsageMergedRequirement{ usg_mod_hash = fp } = fp
    
    511
    +
    
    500 512
     -- | Records the imports that we depend on from a home module,
    
    501 513
     -- for recompilation checking.
    
    502 514
     --
    

  • testsuite/tests/driver/recomp016/recomp016.stdout
    ... ... @@ -9,4 +9,4 @@ second run
    9 9
     [2 of 5] Compiling B                ( B.hs, B.o ) [Source file changed]
    
    10 10
     [3 of 5] Compiling C                ( C.hs, C.o ) [B changed]
    
    11 11
     [4 of 5] Compiling D                ( D.hs, D.o ) [C changed]
    
    12
    -[5 of 5] Compiling E                ( E.hs, E.o ) [B changed]
    12
    +[5 of 5] Compiling E                ( E.hs, E.o ) [D changed]