Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC

Commits:

7 changed files:

Changes:

  • changelog.d/T27308
    1
    +section: compiler
    
    2
    +synopsis: Drop `preloadClosure` from `UnitState`
    
    3
    +issues: #27308
    
    4
    +mrs: !16108
    
    5
    +
    
    6
    +description: {
    
    7
    +    Drop `preloadClosure` from `UnitState` as it is always set to the empty set.
    
    8
    +    This allows to simplify the `UnitState` and related functions.
    
    9
    +}
    
    10
    +

  • compiler/GHC/Driver/Backpack.hs
    ... ... @@ -242,7 +242,6 @@ withBkpSession cid insts deps session_type do_this = do
    242 242
                 -- Synthesize the flags
    
    243 243
                 , packageFlags = packageFlags dflags ++ map (\(uid0, rn) ->
    
    244 244
                   let uid = unwireUnit unit_state
    
    245
    -                        $ improveUnit unit_state
    
    246 245
                             $ renameHoleUnit unit_state (listToUFM insts) uid0
    
    247 246
                   in ExposePackage
    
    248 247
                     (showSDoc dflags
    
    ... ... @@ -311,19 +310,16 @@ buildUnit session cid insts lunit = do
    311 310
         -- The compilation dependencies are just the appropriately filled
    
    312 311
         -- in unit IDs which must be compiled before we can compile.
    
    313 312
         let hsubst = listToUFM insts
    
    314
    -        deps0 = map (renameHoleUnit (hsc_units hsc_env) hsubst) raw_deps
    
    313
    +        deps = map (renameHoleUnit (hsc_units hsc_env) hsubst) raw_deps
    
    315 314
     
    
    316 315
         -- Build dependencies OR make sure they make sense. BUT NOTE,
    
    317 316
         -- we can only check the ones that are fully filled; the rest
    
    318 317
         -- we have to defer until we've typechecked our local signature.
    
    319 318
         -- TODO: work this into GHC.Driver.Make!!
    
    320
    -    forM_ (zip [1..] deps0) $ \(i, dep) ->
    
    319
    +    forM_ (zip [1..] deps) $ \(i, dep) ->
    
    321 320
             case session of
    
    322 321
                 TcSession -> return ()
    
    323
    -            _ -> compileInclude (length deps0) (i, dep)
    
    324
    -
    
    325
    -    -- IMPROVE IT
    
    326
    -    let deps = map (improveUnit (hsc_units hsc_env)) deps0
    
    322
    +            _ -> compileInclude (length deps) (i, dep)
    
    327 323
     
    
    328 324
         mb_old_eps <- case session of
    
    329 325
                         TcSession -> fmap Just getEpsGhc
    

  • compiler/GHC/Iface/Load.hs
    ... ... @@ -914,13 +914,13 @@ findAndReadIface hsc_env doc_str mod wanted_mod hi_boot_file = do
    914 914
                   && not (isOneShot (ghcMode dflags))
    
    915 915
                 then return (Failed (HomeModError mod loc))
    
    916 916
                 else do
    
    917
    -                r <- read_file hooks logger name_cache unit_state dflags wanted_mod (ml_hi_file loc)
    
    917
    +                r <- read_file hooks logger name_cache dflags wanted_mod (ml_hi_file loc)
    
    918 918
                     case r of
    
    919 919
                       Failed err
    
    920 920
                         -> return (Failed $ BadIfaceFile err)
    
    921 921
                       Succeeded (iface,_fp)
    
    922 922
                         -> do
    
    923
    -                        r2 <- load_dynamic_too_maybe hooks logger name_cache unit_state
    
    923
    +                        r2 <- load_dynamic_too_maybe hooks logger name_cache
    
    924 924
                                                      (setDynamicNow dflags) wanted_mod
    
    925 925
                                                      iface loc
    
    926 926
                             case r2 of
    
    ... ... @@ -936,20 +936,20 @@ findAndReadIface hsc_env doc_str mod wanted_mod hi_boot_file = do
    936 936
                                   err
    
    937 937
     
    
    938 938
     -- | Check if we need to try the dynamic interface for -dynamic-too
    
    939
    -load_dynamic_too_maybe :: Hooks -> Logger -> NameCache -> UnitState -> DynFlags
    
    939
    +load_dynamic_too_maybe :: Hooks -> Logger -> NameCache -> DynFlags
    
    940 940
                            -> Module -> ModIface -> ModLocation
    
    941 941
                            -> IO (MaybeErr MissingInterfaceError ())
    
    942
    -load_dynamic_too_maybe hooks logger name_cache unit_state dflags wanted_mod iface loc
    
    942
    +load_dynamic_too_maybe hooks logger name_cache dflags wanted_mod iface loc
    
    943 943
       -- Indefinite interfaces are ALWAYS non-dynamic.
    
    944 944
       | not (moduleIsDefinite (mi_module iface)) = return (Succeeded ())
    
    945
    -  | gopt Opt_BuildDynamicToo dflags = load_dynamic_too hooks logger name_cache unit_state dflags wanted_mod iface loc
    
    945
    +  | gopt Opt_BuildDynamicToo dflags = load_dynamic_too hooks logger name_cache dflags wanted_mod iface loc
    
    946 946
       | otherwise = return (Succeeded ())
    
    947 947
     
    
    948
    -load_dynamic_too :: Hooks -> Logger -> NameCache -> UnitState -> DynFlags
    
    948
    +load_dynamic_too :: Hooks -> Logger -> NameCache -> DynFlags
    
    949 949
                      -> Module -> ModIface -> ModLocation
    
    950 950
                      -> IO (MaybeErr MissingInterfaceError ())
    
    951
    -load_dynamic_too hooks logger name_cache unit_state dflags wanted_mod iface loc = do
    
    952
    -  read_file hooks logger name_cache unit_state dflags wanted_mod (ml_dyn_hi_file loc) >>= \case
    
    951
    +load_dynamic_too hooks logger name_cache dflags wanted_mod iface loc = do
    
    952
    +  read_file hooks logger name_cache dflags wanted_mod (ml_dyn_hi_file loc) >>= \case
    
    953 953
         Succeeded (dynIface, _)
    
    954 954
          | mi_mod_hash iface == mi_mod_hash dynIface
    
    955 955
          -> return (Succeeded ())
    
    ... ... @@ -963,10 +963,10 @@ load_dynamic_too hooks logger name_cache unit_state dflags wanted_mod iface loc
    963 963
     
    
    964 964
     
    
    965 965
     
    
    966
    -read_file :: Hooks -> Logger -> NameCache -> UnitState -> DynFlags
    
    966
    +read_file :: Hooks -> Logger -> NameCache -> DynFlags
    
    967 967
               -> Module -> FilePath
    
    968 968
               -> IO (MaybeErr ReadInterfaceError (ModIface, FilePath))
    
    969
    -read_file hooks logger name_cache unit_state dflags wanted_mod file_path = do
    
    969
    +read_file hooks logger name_cache dflags wanted_mod file_path = do
    
    970 970
     
    
    971 971
       -- Figure out what is recorded in mi_module.  If this is
    
    972 972
       -- a fully definite interface, it'll match exactly, but
    
    ... ... @@ -975,7 +975,7 @@ read_file hooks logger name_cache unit_state dflags wanted_mod file_path = do
    975 975
             case getModuleInstantiation wanted_mod of
    
    976 976
                 (_, Nothing) -> wanted_mod
    
    977 977
                 (_, Just indef_mod) ->
    
    978
    -              instModuleToModule unit_state
    
    978
    +              instModuleToModule
    
    979 979
                     (uninstantiateInstantiatedModule indef_mod)
    
    980 980
       read_result <- readIface hooks logger dflags name_cache wanted_mod' file_path
    
    981 981
       case read_result of
    

  • compiler/GHC/Iface/Recomp.hs
    ... ... @@ -620,7 +620,7 @@ checkMergedSignatures hsc_env mod_summary self_recomp = do
    620 620
             new_merged = case lookupUniqMap (requirementContext unit_state)
    
    621 621
                               (ms_mod_name mod_summary) of
    
    622 622
                             Nothing -> []
    
    623
    -                        Just r -> sort $ map (instModuleToModule unit_state) r
    
    623
    +                        Just r -> sort $ map instModuleToModule r
    
    624 624
         if old_merged == new_merged
    
    625 625
             then up_to_date logger (text "signatures to merge in unchanged" $$ ppr new_merged)
    
    626 626
             else return $ needsRecompileBecause SigsMergeChanged
    

  • compiler/GHC/Unit.hs
    ... ... @@ -226,8 +226,8 @@ on-the-fly:
    226 226
     A 'VirtUnit' may be indefinite or definite, it depends on whether some holes
    
    227 227
     remain in the instantiated unit OR in the instantiating units (recursively).
    
    228 228
     Having a fully instantiated (i.e. definite) virtual unit can lead to some issues
    
    229
    -if there is a matching compiled unit in the preload closure.  See Note [VirtUnit
    
    230
    -to RealUnit improvement]
    
    229
    +if there is a matching compiled unit in the preload closure.
    
    230
    +See Note [VirtUnit to RealUnit improvement]
    
    231 231
     
    
    232 232
     Unit database and indefinite units
    
    233 233
     ----------------------------------
    
    ... ... @@ -314,7 +314,6 @@ field in the SDocContext to pretty-print.
    314 314
           (i.e. GHC doesn't correctly call `pprWithUnitState` before pretty-printing a
    
    315 315
           UnitId), that's what will be shown to the user so it's no big deal.
    
    316 316
     
    
    317
    -
    
    318 317
     Note [VirtUnit to RealUnit improvement]
    
    319 318
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    320 319
     
    
    ... ... @@ -332,6 +331,8 @@ same type-checking session, their names won't match (e.g. "abc:M.X" vs
    332 331
     As we want them to match we just replace the virtual unit with the installed
    
    333 332
     one: for some reason this is called "improvement".
    
    334 333
     
    
    334
    +HISTORICAL:
    
    335
    +
    
    335 336
     There is one last niggle: improvement based on the unit database means
    
    336 337
     that we might end up developing on a unit that is not transitively
    
    337 338
     depended upon by the units the user specified directly via command line
    
    ... ... @@ -340,6 +341,12 @@ instantiations are out of date. The solution is to only improve a
    340 341
     unit id if the new unit id is part of the 'preloadClosure'; i.e., the
    
    341 342
     closure of all the units which were explicitly specified.
    
    342 343
     
    
    344
    +NOTE:
    
    345
    +
    
    346
    +The 'preloadClosure' was completely unused, thus we removed it without
    
    347
    +changing any of the tests. It doesn't seem to be necessary any more.
    
    348
    +It is unclear at which exact point this became redundant.
    
    349
    +
    
    343 350
     Note [Representation of module/name variables]
    
    344 351
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    345 352
     In our ICFP'16, we use <A> to represent module holes, and {A.T} to represent
    

  • compiler/GHC/Unit/State.hs
    ... ... @@ -7,7 +7,6 @@ module GHC.Unit.State (
    7 7
     
    
    8 8
             -- * Reading the package config, and processing cmdline args
    
    9 9
             UnitState(..),
    
    10
    -        PreloadUnitClosure,
    
    11 10
             UnitDatabase (..),
    
    12 11
             UnitErr (..),
    
    13 12
             emptyUnitState,
    
    ... ... @@ -29,7 +28,6 @@ module GHC.Unit.State (
    29 28
     
    
    30 29
             lookupPackageName,
    
    31 30
             resolvePackageImport,
    
    32
    -        improveUnit,
    
    33 31
             searchPackageId,
    
    34 32
             listVisibleModuleNames,
    
    35 33
             lookupModuleInAllUnits,
    
    ... ... @@ -89,7 +87,6 @@ import GHC.Unit.Home
    89 87
     
    
    90 88
     import GHC.Types.Unique.FM
    
    91 89
     import GHC.Types.Unique.DFM
    
    92
    -import GHC.Types.Unique.Set
    
    93 90
     import GHC.Types.Unique.DSet
    
    94 91
     import GHC.Types.Unique.Map
    
    95 92
     import GHC.Types.Unique
    
    ... ... @@ -268,8 +265,6 @@ originEmpty :: ModuleOrigin -> Bool
    268 265
     originEmpty (ModOrigin Nothing [] [] False) = True
    
    269 266
     originEmpty _ = False
    
    270 267
     
    
    271
    -type PreloadUnitClosure = UniqSet UnitId
    
    272
    -
    
    273 268
     -- | 'UniqFM' map from 'Unit' to a 'UnitVisibility'.
    
    274 269
     type VisibilityMap = UniqMap Unit UnitVisibility
    
    275 270
     
    
    ... ... @@ -432,13 +427,6 @@ data UnitState = UnitState {
    432 427
       -- may have the 'exposed' flag be 'False'.)
    
    433 428
       unitInfoMap :: UnitInfoMap,
    
    434 429
     
    
    435
    -  -- | The set of transitively reachable units according
    
    436
    -  -- to the explicitly provided command line arguments.
    
    437
    -  -- A fully instantiated VirtUnit may only be replaced by a RealUnit from
    
    438
    -  -- this set.
    
    439
    -  -- See Note [VirtUnit to RealUnit improvement]
    
    440
    -  preloadClosure :: PreloadUnitClosure,
    
    441
    -
    
    442 430
       -- | A mapping of 'PackageName' to 'UnitId'. If several units have the same
    
    443 431
       -- package name (e.g. different instantiations), then we return one of them...
    
    444 432
       -- This is used when users refer to packages in Backpack includes.
    
    ... ... @@ -491,7 +479,6 @@ data UnitState = UnitState {
    491 479
     emptyUnitState :: UnitState
    
    492 480
     emptyUnitState = UnitState {
    
    493 481
         unitInfoMap    = emptyUniqMap,
    
    494
    -    preloadClosure = emptyUniqSet,
    
    495 482
         packageNameMap = emptyUFM,
    
    496 483
         wireMap        = emptyUniqMap,
    
    497 484
         unwireMap      = emptyUniqMap,
    
    ... ... @@ -517,7 +504,7 @@ type UnitInfoMap = UniqMap UnitId UnitInfo
    517 504
     
    
    518 505
     -- | Find the unit we know about with the given unit, if any
    
    519 506
     lookupUnit :: UnitState -> Unit -> Maybe UnitInfo
    
    520
    -lookupUnit pkgs = lookupUnit' (allowVirtualUnits pkgs) (unitInfoMap pkgs) (preloadClosure pkgs)
    
    507
    +lookupUnit pkgs = lookupUnit' (allowVirtualUnits pkgs) (unitInfoMap pkgs)
    
    521 508
     
    
    522 509
     -- | A more specialized interface, which doesn't require a 'UnitState' (so it
    
    523 510
     -- can be used while we're initializing 'DynFlags')
    
    ... ... @@ -525,16 +512,15 @@ lookupUnit pkgs = lookupUnit' (allowVirtualUnits pkgs) (unitInfoMap pkgs) (prelo
    525 512
     -- Parameters:
    
    526 513
     --    * a boolean specifying whether or not to look for on-the-fly renamed interfaces
    
    527 514
     --    * a 'UnitInfoMap'
    
    528
    ---    * a 'PreloadUnitClosure'
    
    529
    -lookupUnit' :: Bool -> UnitInfoMap -> PreloadUnitClosure -> Unit -> Maybe UnitInfo
    
    530
    -lookupUnit' allowOnTheFlyInst pkg_map closure u = case u of
    
    515
    +lookupUnit' :: Bool -> UnitInfoMap -> Unit -> Maybe UnitInfo
    
    516
    +lookupUnit' allowOnTheFlyInst pkg_map u = case u of
    
    531 517
        HoleUnit   -> error "Hole unit"
    
    532 518
        RealUnit i -> lookupUniqMap pkg_map (unDefinite i)
    
    533 519
        VirtUnit i
    
    534 520
           | allowOnTheFlyInst
    
    535 521
           -> -- lookup UnitInfo of the indefinite unit to be instantiated and
    
    536 522
              -- instantiate it on-the-fly
    
    537
    -         fmap (renameUnitInfo pkg_map closure (instUnitInsts i))
    
    523
    +         fmap (renameUnitInfo pkg_map (instUnitInsts i))
    
    538 524
                (lookupUniqMap pkg_map (instUnitInstanceOf i))
    
    539 525
     
    
    540 526
           | otherwise
    
    ... ... @@ -908,7 +894,6 @@ applyTrustFlag prec_map unusable pkgs flag =
    908 894
     applyPackageFlag
    
    909 895
        :: UnitPrecedenceMap
    
    910 896
        -> UnitInfoMap
    
    911
    -   -> PreloadUnitClosure
    
    912 897
        -> UnusableUnits
    
    913 898
        -> Bool -- if False, if you expose a package, it implicitly hides
    
    914 899
                -- any previously exposed packages with the same name
    
    ... ... @@ -917,10 +902,10 @@ applyPackageFlag
    917 902
        -> PackageFlag             -- flag to apply
    
    918 903
        -> MaybeErr UnitErr VisibilityMap -- Now exposed
    
    919 904
     
    
    920
    -applyPackageFlag prec_map pkg_map closure unusable no_hide_others pkgs vm flag =
    
    905
    +applyPackageFlag prec_map pkg_map unusable no_hide_others pkgs vm flag =
    
    921 906
       case flag of
    
    922 907
         ExposePackage _ arg (ModRenaming b rns) ->
    
    923
    -       case findPackages prec_map pkg_map closure arg pkgs unusable of
    
    908
    +       case findPackages prec_map pkg_map arg pkgs unusable of
    
    924 909
              Left ps     -> Failed (PackageFlagErr flag ps)
    
    925 910
              Right (p:_) -> Succeeded vm'
    
    926 911
               where
    
    ... ... @@ -984,7 +969,7 @@ applyPackageFlag prec_map pkg_map closure unusable no_hide_others pkgs vm flag =
    984 969
              _ -> panic "applyPackageFlag"
    
    985 970
     
    
    986 971
         HidePackage str ->
    
    987
    -       case findPackages prec_map pkg_map closure (PackageArg str) pkgs unusable of
    
    972
    +       case findPackages prec_map pkg_map (PackageArg str) pkgs unusable of
    
    988 973
              Left ps  -> Failed (PackageFlagErr flag ps)
    
    989 974
              Right ps -> Succeeded $ foldl' delFromUniqMap vm (map mkUnit ps)
    
    990 975
     
    
    ... ... @@ -993,12 +978,11 @@ applyPackageFlag prec_map pkg_map closure unusable no_hide_others pkgs vm flag =
    993 978
     -- if the 'UnitArg' has a renaming associated with it.
    
    994 979
     findPackages :: UnitPrecedenceMap
    
    995 980
                  -> UnitInfoMap
    
    996
    -             -> PreloadUnitClosure
    
    997 981
                  -> PackageArg -> [UnitInfo]
    
    998 982
                  -> UnusableUnits
    
    999 983
                  -> Either [(UnitInfo, UnusableUnitReason)]
    
    1000 984
                     [UnitInfo]
    
    1001
    -findPackages prec_map pkg_map closure arg pkgs unusable
    
    985
    +findPackages prec_map pkg_map arg pkgs unusable
    
    1002 986
       = let ps = mapMaybe (finder arg) pkgs
    
    1003 987
         in if null ps
    
    1004 988
             then Left (mapMaybe (\(x,y) -> finder arg x >>= \x' -> return (x',y))
    
    ... ... @@ -1016,7 +1000,7 @@ findPackages prec_map pkg_map closure arg pkgs unusable
    1016 1000
                 -> Just p
    
    1017 1001
               VirtUnit inst
    
    1018 1002
                 | instUnitInstanceOf inst == unitId p
    
    1019
    -            -> Just (renameUnitInfo pkg_map closure (instUnitInsts inst) p)
    
    1003
    +            -> Just (renameUnitInfo pkg_map (instUnitInsts inst) p)
    
    1020 1004
               _ -> Nothing
    
    1021 1005
     
    
    1022 1006
     selectPackages :: UnitPrecedenceMap -> PackageArg -> [UnitInfo]
    
    ... ... @@ -1031,10 +1015,10 @@ selectPackages prec_map arg pkgs unusable
    1031 1015
             else Right (sortByPreference prec_map ps, rest)
    
    1032 1016
     
    
    1033 1017
     -- | Rename a 'UnitInfo' according to some module instantiation.
    
    1034
    -renameUnitInfo :: UnitInfoMap -> PreloadUnitClosure -> [(ModuleName, Module)] -> UnitInfo -> UnitInfo
    
    1035
    -renameUnitInfo pkg_map closure insts conf =
    
    1018
    +renameUnitInfo :: UnitInfoMap -> [(ModuleName, Module)] -> UnitInfo -> UnitInfo
    
    1019
    +renameUnitInfo pkg_map insts conf =
    
    1036 1020
         let hsubst = listToUFM insts
    
    1037
    -        smod  = renameHoleModule' pkg_map closure hsubst
    
    1021
    +        smod  = renameHoleModule' pkg_map hsubst
    
    1038 1022
             new_insts = map (\(k,v) -> (k,smod v)) (unitInstantiations conf)
    
    1039 1023
         in conf {
    
    1040 1024
             unitInstantiations = new_insts,
    
    ... ... @@ -1632,7 +1616,7 @@ mkUnitState logger cfg = do
    1632 1616
       -- user tries to enable an unusable package, we should let them know.
    
    1633 1617
       --
    
    1634 1618
       vis_map2 <- mayThrowUnitErr
    
    1635
    -                $ foldM (applyPackageFlag prec_map prelim_pkg_db emptyUniqSet unusable
    
    1619
    +                $ foldM (applyPackageFlag prec_map prelim_pkg_db unusable
    
    1636 1620
                             (unitConfigHideAll cfg) pkgs1)
    
    1637 1621
                                 vis_map1 other_flags
    
    1638 1622
     
    
    ... ... @@ -1661,7 +1645,7 @@ mkUnitState logger cfg = do
    1661 1645
                             | otherwise = vis_map2
    
    1662 1646
                     plugin_vis_map2
    
    1663 1647
                         <- mayThrowUnitErr
    
    1664
    -                        $ foldM (applyPackageFlag prec_map prelim_pkg_db emptyUniqSet unusable
    
    1648
    +                        $ foldM (applyPackageFlag prec_map prelim_pkg_db unusable
    
    1665 1649
                                     hide_plugin_pkgs pkgs1)
    
    1666 1650
                                  plugin_vis_map1
    
    1667 1651
                                  (reverse (unitConfigFlagsPlugins cfg))
    
    ... ... @@ -1713,7 +1697,7 @@ mkUnitState logger cfg = do
    1713 1697
                         $ closeUnitDeps pkg_db
    
    1714 1698
                         $ zip (map toUnitId preload3) (repeat Nothing)
    
    1715 1699
     
    
    1716
    -  let mod_map1 = mkModuleNameProvidersMap logger cfg pkg_db emptyUniqSet vis_map
    
    1700
    +  let mod_map1 = mkModuleNameProvidersMap logger cfg pkg_db vis_map
    
    1717 1701
           mod_map2 = mkUnusableModuleNameProvidersMap unusable
    
    1718 1702
           mod_map = mod_map2 `plusUniqMap` mod_map1
    
    1719 1703
     
    
    ... ... @@ -1723,9 +1707,8 @@ mkUnitState logger cfg = do
    1723 1707
              , explicitUnits                = explicit_pkgs
    
    1724 1708
              , homeUnitDepends              = home_unit_deps
    
    1725 1709
              , unitInfoMap                  = pkg_db
    
    1726
    -         , preloadClosure               = emptyUniqSet
    
    1727 1710
              , moduleNameProvidersMap       = mod_map
    
    1728
    -         , pluginModuleNameProvidersMap = mkModuleNameProvidersMap logger cfg pkg_db emptyUniqSet plugin_vis_map
    
    1711
    +         , pluginModuleNameProvidersMap = mkModuleNameProvidersMap logger cfg pkg_db plugin_vis_map
    
    1729 1712
              , packageNameMap               = pkgname_map
    
    1730 1713
              , wireMap                      = wired_map
    
    1731 1714
              , unwireMap                    = listToUniqMap [ (v,k) | (k,v) <- nonDetUniqMapToList wired_map ]
    
    ... ... @@ -1765,10 +1748,9 @@ mkModuleNameProvidersMap
    1765 1748
       :: Logger
    
    1766 1749
       -> UnitConfig
    
    1767 1750
       -> UnitInfoMap
    
    1768
    -  -> PreloadUnitClosure
    
    1769 1751
       -> VisibilityMap
    
    1770 1752
       -> ModuleNameProvidersMap
    
    1771
    -mkModuleNameProvidersMap logger cfg pkg_map closure vis_map =
    
    1753
    +mkModuleNameProvidersMap logger cfg pkg_map vis_map =
    
    1772 1754
         -- What should we fold on?  Both situations are awkward:
    
    1773 1755
         --
    
    1774 1756
         --    * Folding on the visibility map means that we won't create
    
    ... ... @@ -1840,7 +1822,7 @@ mkModuleNameProvidersMap logger cfg pkg_map closure vis_map =
    1840 1822
         hiddens = [(m, mkModMap pk m ModHidden) | m <- hidden_mods]
    
    1841 1823
     
    
    1842 1824
         pk = mkUnit pkg
    
    1843
    -    unit_lookup uid = lookupUnit' (unitConfigAllowVirtual cfg) pkg_map closure uid
    
    1825
    +    unit_lookup uid = lookupUnit' (unitConfigAllowVirtual cfg) pkg_map uid
    
    1844 1826
                             `orElse` pprPanic "unit_lookup" (ppr uid)
    
    1845 1827
     
    
    1846 1828
         exposed_mods = unitExposedModules pkg
    
    ... ... @@ -2191,44 +2173,16 @@ fsPackageName info = fs
    2191 2173
        where
    
    2192 2174
           PackageName fs = unitPackageName info
    
    2193 2175
     
    
    2194
    -
    
    2195
    --- | Given a fully instantiated 'InstantiatedUnit', improve it into a
    
    2196
    --- 'RealUnit' if we can find it in the package database.
    
    2197
    -improveUnit :: UnitState -> Unit -> Unit
    
    2198
    -improveUnit state u = improveUnit' (unitInfoMap state) (preloadClosure state) u
    
    2199
    -
    
    2200
    --- | Given a fully instantiated 'InstantiatedUnit', improve it into a
    
    2201
    --- 'RealUnit' if we can find it in the package database.
    
    2202
    -improveUnit' :: UnitInfoMap -> PreloadUnitClosure -> Unit -> Unit
    
    2203
    -improveUnit' _       _       uid@(RealUnit _) = uid -- short circuit
    
    2204
    -improveUnit' pkg_map closure uid =
    
    2205
    -    -- Do NOT lookup indefinite ones, they won't be useful!
    
    2206
    -    case lookupUnit' False pkg_map closure uid of
    
    2207
    -        Nothing  -> uid
    
    2208
    -        Just pkg ->
    
    2209
    -            -- Do NOT improve if the indefinite unit id is not
    
    2210
    -            -- part of the closure unique set.  See
    
    2211
    -            -- Note [VirtUnit to RealUnit improvement]
    
    2212
    -            if unitId pkg `elementOfUniqSet` closure
    
    2213
    -                then mkUnit pkg
    
    2214
    -                else uid
    
    2215
    -
    
    2216
    --- | Check the database to see if we already have an installed unit that
    
    2217
    --- corresponds to the given 'InstantiatedUnit'.
    
    2218
    ---
    
    2219
    --- Return a `UnitId` which either wraps the `InstantiatedUnit` unchanged or
    
    2220
    --- references a matching installed unit.
    
    2221
    ---
    
    2222
    --- See Note [VirtUnit to RealUnit improvement]
    
    2223
    -instUnitToUnit :: UnitState -> InstantiatedUnit -> Unit
    
    2224
    -instUnitToUnit state iuid =
    
    2176
    +-- | Return a `UnitId` which either wraps the `InstantiatedUnit` unchanged.
    
    2177
    +instUnitToUnit :: InstantiatedUnit -> Unit
    
    2178
    +instUnitToUnit iuid =
    
    2225 2179
         -- NB: suppose that we want to compare the instantiated
    
    2226 2180
         -- unit p[H=impl:H] against p+abcd (where p+abcd
    
    2227 2181
         -- happens to be the existing, installed version of
    
    2228 2182
         -- p[H=impl:H].  If we *only* wrap in p[H=impl:H]
    
    2229 2183
         -- VirtUnit, they won't compare equal; only
    
    2230 2184
         -- after improvement will the equality hold.
    
    2231
    -    improveUnit state $ VirtUnit iuid
    
    2185
    +    VirtUnit iuid
    
    2232 2186
     
    
    2233 2187
     
    
    2234 2188
     -- | Substitution on module variables, mapping module names to module
    
    ... ... @@ -2240,30 +2194,30 @@ type ShHoleSubst = ModuleNameEnv Module
    2240 2194
     -- @p[A=\<A>]:B@ maps to @p[A=q():A]:B@ with @A=q():A@;
    
    2241 2195
     -- similarly, @\<A>@ maps to @q():A@.
    
    2242 2196
     renameHoleModule :: UnitState -> ShHoleSubst -> Module -> Module
    
    2243
    -renameHoleModule state = renameHoleModule' (unitInfoMap state) (preloadClosure state)
    
    2197
    +renameHoleModule state = renameHoleModule' (unitInfoMap state)
    
    2244 2198
     
    
    2245 2199
     -- | Substitutes holes in a 'Unit', suitable for renaming when
    
    2246 2200
     -- an include occurs; see Note [Representation of module/name variables].
    
    2247 2201
     --
    
    2248 2202
     -- @p[A=\<A>]@ maps to @p[A=\<B>]@ with @A=\<B>@.
    
    2249 2203
     renameHoleUnit :: UnitState -> ShHoleSubst -> Unit -> Unit
    
    2250
    -renameHoleUnit state = renameHoleUnit' (unitInfoMap state) (preloadClosure state)
    
    2204
    +renameHoleUnit state = renameHoleUnit' (unitInfoMap state)
    
    2251 2205
     
    
    2252
    --- | Like 'renameHoleModule', but requires only 'ClosureUnitInfoMap'
    
    2206
    +-- | Like 'renameHoleModule', but requires only 'UnitInfoMap'
    
    2253 2207
     -- so it can be used by "GHC.Unit.State".
    
    2254
    -renameHoleModule' :: UnitInfoMap -> PreloadUnitClosure -> ShHoleSubst -> Module -> Module
    
    2255
    -renameHoleModule' pkg_map closure env m
    
    2208
    +renameHoleModule' :: UnitInfoMap -> ShHoleSubst -> Module -> Module
    
    2209
    +renameHoleModule' pkg_map env m
    
    2256 2210
       | not (isHoleModule m) =
    
    2257
    -        let uid = renameHoleUnit' pkg_map closure env (moduleUnit m)
    
    2211
    +        let uid = renameHoleUnit' pkg_map env (moduleUnit m)
    
    2258 2212
             in mkModule uid (moduleName m)
    
    2259 2213
       | Just m' <- lookupUFM env (moduleName m) = m'
    
    2260 2214
       -- NB m = <Blah>, that's what's in scope.
    
    2261 2215
       | otherwise = m
    
    2262 2216
     
    
    2263
    --- | Like 'renameHoleUnit, but requires only 'ClosureUnitInfoMap'
    
    2217
    +-- | Like 'renameHoleUnit', but requires only 'UnitInfoMap'
    
    2264 2218
     -- so it can be used by "GHC.Unit.State".
    
    2265
    -renameHoleUnit' :: UnitInfoMap -> PreloadUnitClosure -> ShHoleSubst -> Unit -> Unit
    
    2266
    -renameHoleUnit' pkg_map closure env uid =
    
    2219
    +renameHoleUnit' :: UnitInfoMap -> ShHoleSubst -> Unit -> Unit
    
    2220
    +renameHoleUnit' pkg_map env uid =
    
    2267 2221
         case uid of
    
    2268 2222
           (VirtUnit
    
    2269 2223
             InstantiatedUnit{ instUnitInstanceOf = cid
    
    ... ... @@ -2271,20 +2225,15 @@ renameHoleUnit' pkg_map closure env uid =
    2271 2225
                             , instUnitHoles      = fh })
    
    2272 2226
               -> if isNullUFM (intersectUFM_C const (udfmToUfm (getUniqDSet fh)) env)
    
    2273 2227
                     then uid
    
    2274
    -                -- Functorially apply the substitution to the instantiation,
    
    2275
    -                -- then check the 'ClosureUnitInfoMap' to see if there is
    
    2276
    -                -- a compiled version of this 'InstantiatedUnit' we can improve to.
    
    2277
    -                -- See Note [VirtUnit to RealUnit improvement]
    
    2278
    -                else improveUnit' pkg_map closure $
    
    2279
    -                        mkVirtUnit cid
    
    2280
    -                            (map (\(k,v) -> (k, renameHoleModule' pkg_map closure env v)) insts)
    
    2228
    +                else mkVirtUnit cid
    
    2229
    +                          (map (\(k,v) -> (k, renameHoleModule' pkg_map env v)) insts)
    
    2281 2230
           _ -> uid
    
    2282 2231
     
    
    2283 2232
     -- | Injects an 'InstantiatedModule' to 'Module' (see also
    
    2284 2233
     -- 'instUnitToUnit'.
    
    2285
    -instModuleToModule :: UnitState -> InstantiatedModule -> Module
    
    2286
    -instModuleToModule pkgstate (Module iuid mod_name) =
    
    2287
    -    mkModule (instUnitToUnit pkgstate iuid) mod_name
    
    2234
    +instModuleToModule :: InstantiatedModule -> Module
    
    2235
    +instModuleToModule (Module iuid mod_name) =
    
    2236
    +    mkModule (instUnitToUnit iuid) mod_name
    
    2288 2237
     
    
    2289 2238
     -- | Print unit-ids with UnitInfo found in the given UnitState
    
    2290 2239
     pprWithUnitState :: UnitState -> SDoc -> SDoc
    

  • compiler/GHC/Unit/Types.hs
    ... ... @@ -250,9 +250,7 @@ data GenUnit uid
    250 250
     --
    
    251 251
     -- This unit may be indefinite or not (i.e. with remaining holes or not). If it
    
    252 252
     -- is definite, we don't know if it has already been compiled and installed in a
    
    253
    --- database. Nevertheless, we have a mechanism called "improvement" to try to
    
    254
    --- match a fully instantiated unit with existing compiled and installed units:
    
    255
    --- see Note [VirtUnit to RealUnit improvement].
    
    253
    +-- database.
    
    256 254
     --
    
    257 255
     -- An indefinite unit identifier pretty-prints to something like
    
    258 256
     -- @p[H=<H>,A=aimpl:A>]@ (@p@ is the 'UnitId', and the