Matthew Pickering pushed to branch wip/sort-usages at Glasgow Haskell Compiler / GHC

Commits:

2 changed files:

Changes:

  • compiler/GHC/HsToCore/Usage.hs
    ... ... @@ -36,7 +36,7 @@ import GHC.Data.Maybe
    36 36
     import GHC.Data.FastString
    
    37 37
     
    
    38 38
     import Data.IORef
    
    39
    -import Data.List (sortBy)
    
    39
    +import Data.List (sortBy, sortOn)
    
    40 40
     import Data.Map (Map)
    
    41 41
     import qualified Data.Map as Map
    
    42 42
     import qualified Data.Set as Set
    
    ... ... @@ -73,6 +73,8 @@ data UsageConfig = UsageConfig
    73 73
       { uc_safe_implicit_imps_req :: !Bool -- ^ Are all implicit imports required to be safe for this Safe Haskell mode?
    
    74 74
       }
    
    75 75
     
    
    76
    +-- | Build the list of 'Usage's that drives recompilation checking.
    
    77
    +-- The resulting list is deterministically sorted (see 'usageFingerprint').
    
    76 78
     mkUsageInfo :: UsageConfig -> Plugins -> FinderCache -> UnitEnv
    
    77 79
                 -> Module -> ImportedMods -> [ImportUserSpec] -> NameSet
    
    78 80
                 -> [FilePath] -> [FilePath] -> [(Module, Fingerprint)] -> [Linkable] -> PkgsLoaded
    
    ... ... @@ -105,7 +107,10 @@ mkUsageInfo uc plugins fc unit_env
    105 107
                                         }
    
    106 108
                                    | (mod, hash) <- merged ]
    
    107 109
                                 ++ object_usages
    
    108
    -    usages `seqList` return usages
    
    110
    +
    
    111
    +    -- Sort all the Usages to ensure a deterministic ordering.
    
    112
    +    let sorted_usages = sortOn usageFingerprint usages
    
    113
    +    sorted_usages `seqList` return sorted_usages
    
    109 114
         -- seq the list of Usages returned: occasionally these
    
    110 115
         -- don't get evaluated for a while and we can end up hanging on to
    
    111 116
         -- 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 (..)
    
    ... ... @@ -492,6 +493,17 @@ instance Binary Usage where
    492 493
     
    
    493 494
               i -> error ("Binary.get(Usage): " ++ show i)
    
    494 495
     
    
    496
    +-- | Extract the distinguishing fingerprint carried by a particular 'Usage'
    
    497
    +-- constructor.  Every constructor stores a hash capturing the bit of state
    
    498
    +-- that drives recompilation decisions, so we can sort on it directly.
    
    499
    +usageFingerprint :: Usage -> Fingerprint
    
    500
    +usageFingerprint UsagePackageModule{ usg_mod_hash = fp } = fp
    
    501
    +usageFingerprint UsageHomeModule{ usg_mod_hash = fp } = fp
    
    502
    +usageFingerprint UsageFile{ usg_file_hash = fp } = fp
    
    503
    +usageFingerprint UsageDirectory{ usg_dir_hash = fp } = fp
    
    504
    +usageFingerprint UsageHomeModuleInterface{ usg_iface_hash = fp } = fp
    
    505
    +usageFingerprint UsageMergedRequirement{ usg_mod_hash = fp } = fp
    
    506
    +
    
    495 507
     -- | Records the imports that we depend on from a home module,
    
    496 508
     -- for recompilation checking.
    
    497 509
     --