Simon Jakobi pushed to branch wip/sjakobi/tweak-mk_mod_usage_info at Glasgow Haskell Compiler / GHC

Commits:

2 changed files:

Changes:

  • compiler/GHC/HsToCore/Usage.hs
    ... ... @@ -219,15 +219,20 @@ mk_mod_usage_info :: UsageConfig
    219 219
                   -> NameSet
    
    220 220
                   -> IfG [Usage]
    
    221 221
     mk_mod_usage_info uc home_unit home_unit_ids this_mod direct_imports imp_decls used_names
    
    222
    -  = mapMaybeM mkUsageM usage_mods
    
    222
    +  = ent_map `seq` mapMaybeM mkUsageM usage_mods
    
    223
    +      -- ent_map is required _lazily_ for several sub-computations, so we force
    
    224
    +      -- it here to ensure it's built only once.
    
    223 225
       where
    
    224 226
         safe_implicit_imps_req = uc_safe_implicit_imps_req uc
    
    225 227
     
    
    226
    -    used_mods    = moduleEnvKeys ent_map
    
    227
    -    dir_imp_mods = Map.keys direct_imports
    
    228
    -    all_mods     = used_mods ++ filter (`notElem` used_mods) dir_imp_mods
    
    229
    -    usage_mods   = sortBy stableModuleCmp all_mods
    
    230
    -                        -- canonical order is imported, to avoid interface-file
    
    228
    +    used_mods     = nonDetModuleEnvKeys ent_map
    
    229
    +                      -- nonDetModuleEnvKeys is OK here, because the
    
    230
    +                      -- resulting usage_mods are sorted explicitly.
    
    231
    +    is_used_mod m = m `elemModuleEnv` ent_map
    
    232
    +    dir_imp_mods  = Map.keys direct_imports
    
    233
    +    all_mods      = filter (not . is_used_mod) dir_imp_mods ++ used_mods
    
    234
    +    usage_mods    = sortBy stableModuleCmp all_mods
    
    235
    +                        -- canonical order is important, to avoid interface-file
    
    231 236
                             -- wobblage.
    
    232 237
     
    
    233 238
         -- ent_map groups together all the things imported and used
    

  • compiler/GHC/Unit/Module/Env.hs
    ... ... @@ -8,7 +8,7 @@ module GHC.Unit.Module.Env
    8 8
        , lookupWithDefaultModuleEnv, mapModuleEnv, mkModuleEnv, emptyModuleEnv
    
    9 9
        , alterModuleEnv
    
    10 10
        , partitionModuleEnv
    
    11
    -   , moduleEnvKeys, moduleEnvElts, moduleEnvToList
    
    11
    +   , moduleEnvKeys, nonDetModuleEnvKeys, moduleEnvElts, moduleEnvToList
    
    12 12
        , unitModuleEnv, isEmptyModuleEnv
    
    13 13
        , extendModuleEnvWith, filterModuleEnv, mapMaybeModuleEnv
    
    14 14
     
    
    ... ... @@ -157,8 +157,15 @@ mkModuleEnv xs = ModuleEnv (Map.fromList [(NDModule k, v) | (k,v) <- xs])
    157 157
     emptyModuleEnv :: ModuleEnv a
    
    158 158
     emptyModuleEnv = ModuleEnv Map.empty
    
    159 159
     
    
    160
    +-- | See Note [ModuleEnv performance and determinism].
    
    161
    +--
    
    162
    +-- If you use this, please provide a justification why it doesn't introduce
    
    163
    +-- nondeterminism.
    
    164
    +nonDetModuleEnvKeys :: ModuleEnv a -> [Module]
    
    165
    +nonDetModuleEnvKeys (ModuleEnv e) = map unNDModule $ Map.keys e
    
    166
    +
    
    160 167
     moduleEnvKeys :: ModuleEnv a -> [Module]
    
    161
    -moduleEnvKeys (ModuleEnv e) = sort $ map unNDModule $ Map.keys e
    
    168
    +moduleEnvKeys = sort . nonDetModuleEnvKeys
    
    162 169
       -- See Note [ModuleEnv performance and determinism]
    
    163 170
     
    
    164 171
     moduleEnvElts :: ModuleEnv a -> [a]