Matthew Pickering pushed to branch wip/unit-index at Glasgow Haskell Compiler / GHC

Commits:

24 changed files:

Changes:

  • compiler/GHC.hs
    ... ... @@ -376,7 +376,7 @@ import GHC.Builtin.Types.Prim ( alphaTyVars )
    376 376
     import GHC.Data.StringBuffer
    
    377 377
     import GHC.Data.FastString
    
    378 378
     import qualified GHC.LanguageExtensions as LangExt
    
    379
    -import GHC.Rename.Names (renamePkgQual, renameRawPkgQual)
    
    379
    +import GHC.Rename.Names (hscRenamePkgQual, hscRenameRawPkgQual)
    
    380 380
     
    
    381 381
     import GHC.Tc.Utils.Monad    ( finalSafeMode, fixSafeInstances, initIfaceTcRn )
    
    382 382
     import GHC.Tc.Types
    
    ... ... @@ -663,7 +663,8 @@ setUnitDynFlagsNoCheck uid dflags1 = do
    663 663
     
    
    664 664
       let old_hue = ue_findHomeUnitEnv uid (hsc_unit_env hsc_env)
    
    665 665
       let cached_unit_dbs = homeUnitEnv_unit_dbs old_hue
    
    666
    -  (dbs,unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags1 cached_unit_dbs (hsc_all_home_unit_ids hsc_env)
    
    666
    +  index <- hscUnitIndex <$> getSession
    
    667
    +  (dbs,unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags1 index cached_unit_dbs (hsc_all_home_unit_ids hsc_env)
    
    667 668
       updated_dflags <- liftIO $ updatePlatformConstants dflags1 mconstants
    
    668 669
     
    
    669 670
       let upd hue =
    
    ... ... @@ -747,6 +748,7 @@ setProgramDynFlags_ invalidate_needed dflags = do
    747 748
         then do
    
    748 749
             -- additionally, set checked dflags so we don't lose fixes
    
    749 750
             old_unit_env <- ue_setFlags dflags0 . hsc_unit_env <$> getSession
    
    751
    +        ue_index <- hscUnitIndex <$> getSession
    
    750 752
     
    
    751 753
             home_unit_graph <- forM (ue_home_unit_graph old_unit_env) $ \homeUnitEnv -> do
    
    752 754
               let cached_unit_dbs = homeUnitEnv_unit_dbs homeUnitEnv
    
    ... ... @@ -754,7 +756,7 @@ setProgramDynFlags_ invalidate_needed dflags = do
    754 756
                   old_hpt = homeUnitEnv_hpt homeUnitEnv
    
    755 757
                   home_units = HUG.allUnits (ue_home_unit_graph old_unit_env)
    
    756 758
     
    
    757
    -          (dbs,unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags cached_unit_dbs home_units
    
    759
    +          (dbs,unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags ue_index cached_unit_dbs home_units
    
    758 760
     
    
    759 761
               updated_dflags <- liftIO $ updatePlatformConstants dflags0 mconstants
    
    760 762
               pure HomeUnitEnv
    
    ... ... @@ -773,6 +775,7 @@ setProgramDynFlags_ invalidate_needed dflags = do
    773 775
                   , ue_current_unit    = ue_currentUnit old_unit_env
    
    774 776
                   , ue_module_graph    = ue_module_graph old_unit_env
    
    775 777
                   , ue_eps             = ue_eps old_unit_env
    
    778
    +              , ue_index
    
    776 779
                   }
    
    777 780
             modifySession $ \h -> hscSetFlags dflags1 h{ hsc_unit_env = unit_env }
    
    778 781
         else modifySession (hscSetFlags dflags0)
    
    ... ... @@ -830,6 +833,7 @@ setProgramHUG_ invalidate_needed new_hug0 = do
    830 833
                 , ue_current_unit    = ue_currentUnit unit_env0
    
    831 834
                 , ue_eps             = ue_eps unit_env0
    
    832 835
                 , ue_module_graph    = ue_module_graph unit_env0
    
    836
    +            , ue_index           = ue_index unit_env0
    
    833 837
                 }
    
    834 838
           modifySession $ \h ->
    
    835 839
             -- hscSetFlags takes care of updating the logger as well.
    
    ... ... @@ -878,7 +882,7 @@ setProgramHUG_ invalidate_needed new_hug0 = do
    878 882
               old_hpt = homeUnitEnv_hpt homeUnitEnv
    
    879 883
               home_units = HUG.allUnits (ue_home_unit_graph unit_env)
    
    880 884
     
    
    881
    -      (dbs,unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags cached_unit_dbs home_units
    
    885
    +      (dbs,unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags (ue_index unit_env) cached_unit_dbs home_units
    
    882 886
     
    
    883 887
           updated_dflags <- liftIO $ updatePlatformConstants dflags mconstants
    
    884 888
           pure HomeUnitEnv
    
    ... ... @@ -1700,10 +1704,10 @@ modNotLoadedError dflags m loc = throwGhcExceptionIO $ CmdLineError $ showSDoc d
    1700 1704
        parens (text (expectJust (ml_hs_file loc)))
    
    1701 1705
     
    
    1702 1706
     renamePkgQualM :: GhcMonad m => ModuleName -> Maybe FastString -> m PkgQual
    
    1703
    -renamePkgQualM mn p = withSession $ \hsc_env -> pure (renamePkgQual (hsc_unit_env hsc_env) mn p)
    
    1707
    +renamePkgQualM mn p = withSession $ \hsc_env -> hscRenamePkgQual hsc_env mn p
    
    1704 1708
     
    
    1705 1709
     renameRawPkgQualM :: GhcMonad m => ModuleName -> RawPkgQual -> m PkgQual
    
    1706
    -renameRawPkgQualM mn p = withSession $ \hsc_env -> pure (renameRawPkgQual (hsc_unit_env hsc_env) mn p)
    
    1710
    +renameRawPkgQualM mn p = withSession $ \hsc_env -> hscRenameRawPkgQual hsc_env mn p
    
    1707 1711
     
    
    1708 1712
     -- | Like 'findModule', but differs slightly when the module refers to
    
    1709 1713
     -- a source file, and the file has not been loaded via 'load'.  In
    
    ... ... @@ -1728,7 +1732,8 @@ lookupQualifiedModule NoPkgQual mod_name = withSession $ \hsc_env -> do
    1728 1732
           let dflags = hsc_dflags hsc_env
    
    1729 1733
           let sec    = initSourceErrorContext dflags
    
    1730 1734
           let fopts  = initFinderOpts dflags
    
    1731
    -      res <- findExposedPackageModule fc fopts units mod_name NoPkgQual
    
    1735
    +      query <- hscUnitIndexQuery hsc_env
    
    1736
    +      res <- findExposedPackageModule fc fopts units query mod_name NoPkgQual
    
    1732 1737
           case res of
    
    1733 1738
             Found _ m -> return m
    
    1734 1739
             err       -> throwOneError sec $ noModError hsc_env noSrcSpan mod_name err
    
    ... ... @@ -1778,7 +1783,8 @@ lookupAllQualifiedModuleNames NoPkgQual mod_name = withSession $ \hsc_env -> do
    1778 1783
           let dflags = hsc_dflags hsc_env
    
    1779 1784
           let sec    = initSourceErrorContext dflags
    
    1780 1785
           let fopts  = initFinderOpts dflags
    
    1781
    -      res <- findExposedPackageModule fc fopts units mod_name NoPkgQual
    
    1786
    +      query <- hscUnitIndexQuery hsc_env
    
    1787
    +      res <- findExposedPackageModule fc fopts units query mod_name NoPkgQual
    
    1782 1788
           case res of
    
    1783 1789
             Found _ m -> return [m]
    
    1784 1790
             err       -> throwOneError sec $ noModError hsc_env noSrcSpan mod_name err
    

  • compiler/GHC/Core/Opt/Pipeline.hs
    ... ... @@ -79,8 +79,10 @@ core2core hsc_env guts@(ModGuts { mg_module = mod
    79 79
                                     , mg_loc     = loc
    
    80 80
                                     , mg_rdr_env = rdr_env })
    
    81 81
       = do { hpt_rule_base <- home_pkg_rules
    
    82
    +       ; query <- hscUnitIndexQuery hsc_env
    
    82 83
            ; let builtin_passes = getCoreToDo dflags hpt_rule_base extra_vars
    
    83 84
                  uniq_tag = SimplTag
    
    85
    +             name_ppr_ctx = mkNamePprCtx ptc unit_env query rdr_env
    
    84 86
     
    
    85 87
            ; (guts2, stats) <- runCoreM hsc_env hpt_rule_base uniq_tag mod
    
    86 88
                                         name_ppr_ctx loc $
    
    ... ... @@ -103,7 +105,6 @@ core2core hsc_env guts@(ModGuts { mg_module = mod
    103 105
         extra_vars     = interactiveInScope (hsc_IC hsc_env)
    
    104 106
         home_pkg_rules = hugRulesBelow hsc_env (moduleUnitId mod)
    
    105 107
                           (GWIB { gwib_mod = moduleName mod, gwib_isBoot = NotBoot })
    
    106
    -    name_ppr_ctx   = mkNamePprCtx ptc unit_env rdr_env
    
    107 108
         ptc            = initPromotionTickContext dflags
    
    108 109
         -- mod: get the module out of the current HscEnv so we can retrieve it from the monad.
    
    109 110
         -- This is very convienent for the users of the monad (e.g. plugins do not have to
    
    ... ... @@ -448,6 +449,7 @@ doCorePass pass guts = do
    448 449
       dflags    <- getDynFlags
    
    449 450
       us        <- getUniqueSupplyM
    
    450 451
       p_fam_env <- getPackageFamInstEnv
    
    452
    +  query <- liftIO $ hscUnitIndexQuery hsc_env
    
    451 453
       let platform = targetPlatform dflags
    
    452 454
       let fam_envs = (p_fam_env, mg_fam_inst_env guts)
    
    453 455
       let updateBinds  f = return $ guts { mg_binds = f (mg_binds guts) }
    
    ... ... @@ -461,6 +463,7 @@ doCorePass pass guts = do
    461 463
             mkNamePprCtx
    
    462 464
               (initPromotionTickContext dflags)
    
    463 465
               (hsc_unit_env hsc_env)
    
    466
    +          query
    
    464 467
               rdr_env
    
    465 468
     
    
    466 469
     
    

  • compiler/GHC/Driver/Backpack.hs
    ... ... @@ -438,6 +438,7 @@ addUnit u = do
    438 438
         logger <- getLogger
    
    439 439
         let dflags0 = hsc_dflags hsc_env
    
    440 440
         let old_unit_env = hsc_unit_env hsc_env
    
    441
    +        ue_index = hscUnitIndex hsc_env
    
    441 442
         newdbs <- case ue_unit_dbs old_unit_env of
    
    442 443
             Nothing  -> panic "addUnit: called too early"
    
    443 444
             Just dbs ->
    
    ... ... @@ -446,7 +447,7 @@ addUnit u = do
    446 447
                    , unitDatabaseUnits = [u]
    
    447 448
                    }
    
    448 449
              in return (dbs ++ [newdb]) -- added at the end because ordering matters
    
    449
    -    (dbs,unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags0 (Just newdbs) (hsc_all_home_unit_ids hsc_env)
    
    450
    +    (dbs,unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags0 ue_index (Just newdbs) (hsc_all_home_unit_ids hsc_env)
    
    450 451
     
    
    451 452
         -- update platform constants
    
    452 453
         dflags <- liftIO $ updatePlatformConstants dflags0 mconstants
    
    ... ... @@ -462,6 +463,7 @@ addUnit u = do
    462 463
                         (HUG.mkHomeUnitEnv unit_state (Just dbs) dflags (ue_hpt old_unit_env) (Just home_unit))
    
    463 464
               , ue_eps       = ue_eps old_unit_env
    
    464 465
               , ue_module_graph = ue_module_graph old_unit_env
    
    466
    +          , ue_index
    
    465 467
               }
    
    466 468
         setSession $ hscSetFlags dflags $ hsc_env { hsc_unit_env = unit_env }
    
    467 469
     
    
    ... ... @@ -879,13 +881,15 @@ hsModuleToModSummary home_keys pn hsc_src modname
    879 881
         hi_timestamp <- liftIO $ modificationTimeIfExists (ml_hi_file_ospath location)
    
    880 882
         hie_timestamp <- liftIO $ modificationTimeIfExists (ml_hie_file_ospath location)
    
    881 883
     
    
    884
    +    query <- liftIO $ hscUnitIndexQuery hsc_env
    
    885
    +
    
    882 886
         -- Also copied from 'getImports'
    
    883 887
         let (src_idecls, ord_idecls) = partition ((== IsBoot) . ideclSource . unLoc) imps
    
    884 888
     
    
    885 889
             implicit_prelude = xopt LangExt.ImplicitPrelude dflags
    
    886 890
             generated_imports = mkPrelImports modname implicit_prelude imps
    
    887 891
     
    
    888
    -        rn_pkg_qual = renameRawPkgQual (hsc_unit_env hsc_env) modname
    
    892
    +        rn_pkg_qual = renameRawPkgQual (hsc_unit_env hsc_env) query modname
    
    889 893
             convImport (L _ i) = (convImportLevel (ideclLevelSpec i), rn_pkg_qual (ideclPkgQual i), reLoc $ ideclName i)
    
    890 894
     
    
    891 895
         extra_sig_imports <- liftIO $ findExtraSigImports hsc_env hsc_src modname
    

  • compiler/GHC/Driver/Downsweep.hs
    ... ... @@ -275,7 +275,7 @@ downsweepInteractiveImports hsc_env ic = unsafeInterleaveIO $ do
    275 275
     
    
    276 276
       where
    
    277 277
      --
    
    278
    -    mkEdge :: InteractiveImport -> Either ModuleNodeEdge (UnitId, ImportLevel, PkgQual, GenWithIsBoot (Located ModuleName))
    
    278
    +    mkEdge :: InteractiveImport -> Either ModuleNodeEdge (UnitId, ImportLevel, RawPkgQual, GenWithIsBoot (Located ModuleName))
    
    279 279
         -- A simple edge to a module from the same home unit
    
    280 280
         mkEdge (IIModule n) =
    
    281 281
           let
    
    ... ... @@ -294,12 +294,12 @@ downsweepInteractiveImports hsc_env ic = unsafeInterleaveIO $ do
    294 294
           let lvl = convImportLevel (ideclLevelSpec i)
    
    295 295
               wanted_mod = unLoc (ideclName i)
    
    296 296
               is_boot = ideclSource i
    
    297
    -          mb_pkg = renameRawPkgQual (hsc_unit_env hsc_env) (unLoc $ ideclName i) (ideclPkgQual i)
    
    297
    +          raw_pkg = ideclPkgQual i
    
    298 298
               unitId = homeUnitId $ hsc_home_unit hsc_env
    
    299
    -      in Right (unitId, lvl, mb_pkg, GWIB (noLoc wanted_mod) is_boot)
    
    299
    +      in Right (unitId, lvl, raw_pkg, GWIB (noLoc wanted_mod) is_boot)
    
    300 300
     
    
    301 301
     loopFromInteractive :: HscEnv
    
    302
    -                    -> [Either ModuleNodeEdge (UnitId, ImportLevel, PkgQual, GenWithIsBoot (Located ModuleName))]
    
    302
    +                    -> [Either ModuleNodeEdge (UnitId, ImportLevel, RawPkgQual, GenWithIsBoot (Located ModuleName))]
    
    303 303
                         -> M.Map NodeKey ModuleGraphNode
    
    304 304
                         -> IO ([ModuleNodeEdge],M.Map NodeKey ModuleGraphNode)
    
    305 305
     loopFromInteractive _ [] cached_nodes = return ([], cached_nodes)
    
    ... ... @@ -308,12 +308,13 @@ loopFromInteractive hsc_env (edge:edges) cached_nodes =
    308 308
         Left edge -> do
    
    309 309
             (edges, cached_nodes') <- loopFromInteractive hsc_env edges cached_nodes
    
    310 310
             return (edge : edges, cached_nodes')
    
    311
    -    Right (unitId, lvl, mb_pkg, GWIB wanted_mod is_boot) -> do
    
    311
    +    Right (unitId, lvl, raw_pkg, GWIB wanted_mod is_boot) -> do
    
    312 312
           let home_unit = ue_unitHomeUnit unitId (hsc_unit_env hsc_env)
    
    313 313
           let k _ loc mod =
    
    314 314
                 let key = moduleToMnk mod is_boot
    
    315 315
                 in return $ FoundHome (ModuleNodeFixed key loc)
    
    316
    -      found <- liftIO $ summariseModuleDispatch k hsc_env home_unit is_boot wanted_mod mb_pkg []
    
    316
    +      pkg_qual <- hscRenameRawPkgQual hsc_env (unLoc wanted_mod) raw_pkg
    
    317
    +      found <- liftIO $ summariseModuleDispatch k hsc_env home_unit is_boot wanted_mod pkg_qual []
    
    317 318
           case found of
    
    318 319
             -- Case 1: Home modules have to already be in the cache.
    
    319 320
             FoundHome (ModuleNodeFixed mod _) -> do
    
    ... ... @@ -1541,7 +1542,8 @@ getPreprocessedImports hsc_env src_fn mb_phase maybe_buf = do
    1541 1542
                   sec = initSourceErrorContext pi_local_dflags
    
    1542 1543
               mimps <- getImports popts sec imp_prelude pi_hspp_buf pi_hspp_fn src_fn
    
    1543 1544
               return (first (mkMessages . fmap mkDriverPsHeaderMessage . getMessages) mimps)
    
    1544
    -  let rn_pkg_qual = renameRawPkgQual (hsc_unit_env hsc_env)
    
    1545
    +  query <- liftIO $ hscUnitIndexQuery hsc_env
    
    1546
    +  let rn_pkg_qual = renameRawPkgQual (hsc_unit_env hsc_env) query
    
    1545 1547
       let rn_imps = fmap (\(sp, pk, lmn@(L _ mn)) -> (sp, rn_pkg_qual mn pk, lmn))
    
    1546 1548
       let pi_srcimps = pi_srcimps'
    
    1547 1549
       let pi_theimps = rn_imps pi_theimps'
    

  • compiler/GHC/Driver/Env.hs
    ... ... @@ -9,6 +9,8 @@ module GHC.Driver.Env
    9 9
        , hsc_home_unit
    
    10 10
        , hsc_home_unit_maybe
    
    11 11
        , hsc_units
    
    12
    +   , hscUnitIndex
    
    13
    +   , hscUnitIndexQuery
    
    12 14
        , hsc_HPT
    
    13 15
        , hsc_HUE
    
    14 16
        , hsc_HUG
    
    ... ... @@ -123,6 +125,13 @@ hsc_home_unit_maybe = ue_homeUnit . hsc_unit_env
    123 125
     hsc_units :: HasDebugCallStack => HscEnv -> UnitState
    
    124 126
     hsc_units = ue_homeUnitState . hsc_unit_env
    
    125 127
     
    
    128
    +hscUnitIndex :: HscEnv -> UnitIndex
    
    129
    +hscUnitIndex = ue_index . hsc_unit_env
    
    130
    +
    
    131
    +hscUnitIndexQuery :: HscEnv -> IO UnitIndexQuery
    
    132
    +hscUnitIndexQuery hsc_env =
    
    133
    +  unitIndexQuery (hscUnitIndex hsc_env) (hscActiveUnitId hsc_env)
    
    134
    +
    
    126 135
     hsc_HPT :: HscEnv -> HomePackageTable
    
    127 136
     hsc_HPT = ue_hpt . hsc_unit_env
    
    128 137
     
    

  • compiler/GHC/Driver/Main.hs
    ... ... @@ -2733,9 +2733,10 @@ hscTidy hsc_env guts = do
    2733 2733
         $! {-# SCC "CoreTidy" #-} tidyProgram opts guts
    
    2734 2734
     
    
    2735 2735
       -- post tidy pretty-printing and linting...
    
    2736
    +  query <- hscUnitIndexQuery hsc_env
    
    2736 2737
       let tidy_rules     = md_rules details
    
    2737 2738
       let all_tidy_binds = cg_binds cgguts
    
    2738
    -  let name_ppr_ctx   = mkNamePprCtx ptc (hsc_unit_env hsc_env) (mg_rdr_env guts)
    
    2739
    +  let name_ppr_ctx   = mkNamePprCtx ptc (hsc_unit_env hsc_env) query (mg_rdr_env guts)
    
    2739 2740
           ptc            = initPromotionTickContext (hsc_dflags hsc_env)
    
    2740 2741
     
    
    2741 2742
       endPassHscEnvIO hsc_env name_ppr_ctx CoreTidy all_tidy_binds tidy_rules
    

  • compiler/GHC/Driver/Make.hs
    ... ... @@ -173,12 +173,13 @@ depanalE diag_wrapper msg excluded_mods allow_dup_roots = do
    173 173
         if isEmptyMessages errs
    
    174 174
           then do
    
    175 175
             hsc_env <- getSession
    
    176
    +        query <- liftIO $ hscUnitIndexQuery hsc_env
    
    176 177
             let one_unit_messages get_mod_errs k hue = do
    
    177 178
                   errs <- get_mod_errs
    
    178 179
                   unknown_module_err <- warnUnknownModules (hscSetActiveUnitId k hsc_env) (homeUnitEnv_dflags hue) mod_graph
    
    179 180
     
    
    180 181
                   let unused_home_mod_err = warnMissingHomeModules (homeUnitEnv_dflags hue) (hsc_targets hsc_env) mod_graph
    
    181
    -                  unused_pkg_err = warnUnusedPackages (homeUnitEnv_units hue) (homeUnitEnv_dflags hue) mod_graph
    
    182
    +                  unused_pkg_err = warnUnusedPackages (homeUnitEnv_units hue) query (homeUnitEnv_dflags hue) mod_graph
    
    182 183
     
    
    183 184
     
    
    184 185
                   return $ errs `unionMessages` unused_home_mod_err
    
    ... ... @@ -451,15 +452,15 @@ loadWithCache cache diag_wrapper how_much = do
    451 452
     -- actually loaded packages. All the packages, specified on command line,
    
    452 453
     -- but never loaded, are probably unused dependencies.
    
    453 454
     
    
    454
    -warnUnusedPackages :: UnitState -> DynFlags -> ModuleGraph -> DriverMessages
    
    455
    -warnUnusedPackages us dflags mod_graph =
    
    455
    +warnUnusedPackages :: UnitState -> UnitIndexQuery -> DynFlags -> ModuleGraph -> DriverMessages
    
    456
    +warnUnusedPackages us query dflags mod_graph =
    
    456 457
         let diag_opts = initDiagOpts dflags
    
    457 458
     
    
    458 459
             home_mod_sum = filter (\ms -> homeUnitId_ dflags == ms_unitid ms) (mgModSummaries mod_graph)
    
    459 460
     
    
    460 461
         -- Only need non-source imports here because SOURCE imports are always HPT
    
    461 462
             loadedPackages = concat $
    
    462
    -          mapMaybe (\(_st, fs, mn) -> lookupModulePackage us (unLoc mn) fs)
    
    463
    +          mapMaybe (\(_st, fs, mn) -> lookupModulePackage us query (unLoc mn) fs)
    
    463 464
                 $ concatMap ms_imps home_mod_sum
    
    464 465
     
    
    465 466
             used_args = Set.fromList (map unitId loadedPackages)
    

  • compiler/GHC/Driver/Pipeline/Execute.hs
    ... ... @@ -671,9 +671,10 @@ runHscPhase pipe_env hsc_env0 input_fn src_flavour = do
    671 671
       -- gather the imports and module name
    
    672 672
       (hspp_buf,mod_name,imps,src_imps) <- do
    
    673 673
         buf <- hGetStringBuffer input_fn
    
    674
    +    query <- hscUnitIndexQuery hsc_env
    
    674 675
         let imp_prelude = xopt LangExt.ImplicitPrelude dflags
    
    675 676
             popts = initParserOpts dflags
    
    676
    -        rn_pkg_qual = renameRawPkgQual (hsc_unit_env hsc_env)
    
    677
    +        rn_pkg_qual = renameRawPkgQual (hsc_unit_env hsc_env) query
    
    677 678
             rn_imps = fmap (\(s, rpk, lmn@(L _ mn)) -> (s, rn_pkg_qual mn rpk, lmn))
    
    678 679
             sec = initSourceErrorContext dflags
    
    679 680
         eimps <- getImports popts sec imp_prelude buf input_fn (basename <.> suff)
    

  • compiler/GHC/Driver/Session/Inspect.hs
    ... ... @@ -80,7 +80,8 @@ getInsts = withSession $ \hsc_env ->
    80 80
     
    
    81 81
     getNamePprCtx :: GhcMonad m => m NamePprCtx
    
    82 82
     getNamePprCtx = withSession $ \hsc_env -> do
    
    83
    -  return $ icNamePprCtx (hsc_unit_env hsc_env) (hsc_IC hsc_env)
    
    83
    +  query <- liftIO $ hscUnitIndexQuery hsc_env
    
    84
    +  return $ icNamePprCtx (hsc_unit_env hsc_env) query (hsc_IC hsc_env)
    
    84 85
     
    
    85 86
     -- | Container for information about a 'Module'.
    
    86 87
     data ModuleInfo = ModuleInfo {
    
    ... ... @@ -175,7 +176,8 @@ mkNamePprCtxForModule ::
    175 176
       ModuleInfo ->
    
    176 177
       m NamePprCtx
    
    177 178
     mkNamePprCtxForModule mod minf = withSession $ \hsc_env -> do
    
    178
    -  let name_ppr_ctx = mkNamePprCtx ptc (hsc_unit_env hsc_env) (availsToGlobalRdrEnv hsc_env mod (minf_exports minf))
    
    179
    +  query <- liftIO $ hscUnitIndexQuery hsc_env
    
    180
    +  let name_ppr_ctx = mkNamePprCtx ptc (hsc_unit_env hsc_env) query (availsToGlobalRdrEnv hsc_env mod (minf_exports minf))
    
    179 181
           ptc = initPromotionTickContext (hsc_dflags hsc_env)
    
    180 182
       return name_ppr_ctx
    
    181 183
     
    
    ... ... @@ -196,4 +198,3 @@ modInfoSafe = minf_safe
    196 198
     
    
    197 199
     modInfoModBreaks :: ModuleInfo -> Maybe InternalModBreaks
    
    198 200
     modInfoModBreaks = minf_modBreaks
    199
    -

  • compiler/GHC/Driver/Session/Units.hs
    ... ... @@ -128,11 +128,12 @@ initMulti unitArgsFiles lintDynFlagsAndSrcs = do
    128 128
       (initial_home_graph, mainUnitId) <- liftIO $ createUnitEnvFromFlags unitDflags
    
    129 129
       let home_units = HUG.allUnits initial_home_graph
    
    130 130
     
    
    131
    +  let ue_index = hscUnitIndex hsc_env
    
    131 132
       home_unit_graph <- forM initial_home_graph $ \homeUnitEnv -> do
    
    132 133
         let cached_unit_dbs = homeUnitEnv_unit_dbs homeUnitEnv
    
    133 134
             hue_flags = homeUnitEnv_dflags homeUnitEnv
    
    134 135
             dflags = homeUnitEnv_dflags homeUnitEnv
    
    135
    -    (dbs,unit_state,home_unit,mconstants) <- liftIO $ State.initUnits logger hue_flags cached_unit_dbs home_units
    
    136
    +    (dbs,unit_state,home_unit,mconstants) <- liftIO $ State.initUnits logger hue_flags ue_index cached_unit_dbs home_units
    
    136 137
     
    
    137 138
         updated_dflags <- liftIO $ updatePlatformConstants dflags mconstants
    
    138 139
         emptyHpt <- liftIO $ emptyHomePackageTable
    
    ... ... @@ -244,4 +245,3 @@ createUnitEnvFromFlags unitDflags = do
    244 245
       let activeUnit = fst $ NE.head unitEnvList
    
    245 246
       return (HUG.hugFromList (NE.toList unitEnvList), activeUnit)
    
    246 247
     
    247
    -

  • compiler/GHC/HsToCore.hs
    ... ... @@ -145,7 +145,8 @@ deSugar hsc_env
    145 145
       = do { let dflags = hsc_dflags hsc_env
    
    146 146
                  logger = hsc_logger hsc_env
    
    147 147
                  ptc = initPromotionTickContext (hsc_dflags hsc_env)
    
    148
    -             name_ppr_ctx = mkNamePprCtx ptc (hsc_unit_env hsc_env) rdr_env
    
    148
    +        ; query <- hscUnitIndexQuery hsc_env
    
    149
    +        ; let name_ppr_ctx = mkNamePprCtx ptc (hsc_unit_env hsc_env) query rdr_env
    
    149 150
             ; withTiming logger
    
    150 151
                          (text "Desugar"<+>brackets (ppr mod))
    
    151 152
                          (const ()) $
    

  • compiler/GHC/HsToCore/Monad.hs
    ... ... @@ -87,6 +87,7 @@ import GHC.Data.FastString
    87 87
     
    
    88 88
     import GHC.Unit.Env
    
    89 89
     import GHC.Unit.External
    
    90
    +import GHC.Unit.State (UnitIndexQuery)
    
    90 91
     import GHC.Unit.Module
    
    91 92
     import GHC.Unit.Module.ModGuts
    
    92 93
     
    
    ... ... @@ -284,7 +285,8 @@ mkDsEnvsFromTcGbl hsc_env msg_var tcg_env
    284 285
                  -- in allocations by ~5% if we don't do this.
    
    285 286
                traverse (lookupCompleteMatch type_env hsc_env) =<<
    
    286 287
                  localAndImportedCompleteMatches tcg_comp_env eps
    
    287
    -       ; return $ mkDsEnvs unit_env this_mod rdr_env type_env fam_inst_env ptc
    
    288
    +       ; query <- liftIO $ hscUnitIndexQuery hsc_env
    
    289
    +       ; return $ mkDsEnvs unit_env query this_mod rdr_env type_env fam_inst_env ptc
    
    288 290
                                msg_var cc_st_var statics_var
    
    289 291
                                next_wrapper_num_var ds_complete_matches
    
    290 292
            }
    
    ... ... @@ -336,6 +338,7 @@ initDsWithModGuts hsc_env (ModGuts { mg_module = this_mod, mg_binds = binds
    336 338
            ; msg_var          <- newIORef emptyMessages
    
    337 339
            ; statics_var      <- newIORef nilOL
    
    338 340
            ; eps <- liftIO $ hscEPS hsc_env
    
    341
    +       ; query <- liftIO $ hscUnitIndexQuery hsc_env
    
    339 342
            ; let unit_env = hsc_unit_env hsc_env
    
    340 343
                  type_env = typeEnvFromEntities ids tycons patsyns fam_insts
    
    341 344
                  ptc = initPromotionTickContext (hsc_dflags hsc_env)
    
    ... ... @@ -345,7 +348,7 @@ initDsWithModGuts hsc_env (ModGuts { mg_module = this_mod, mg_binds = binds
    345 348
            ; ds_complete_matches <- traverse (lookupCompleteMatch type_env hsc_env) =<<
    
    346 349
                 localAndImportedCompleteMatches local_complete_matches eps
    
    347 350
            ; let
    
    348
    -             envs  = mkDsEnvs unit_env this_mod rdr_env type_env
    
    351
    +             envs  = mkDsEnvs unit_env query this_mod rdr_env type_env
    
    349 352
                                   fam_inst_env ptc msg_var cc_st_var statics_var
    
    350 353
                                   next_wrapper_num ds_complete_matches
    
    351 354
            ; runDs hsc_env envs thing_inside
    
    ... ... @@ -384,13 +387,13 @@ initTcDsForSolver thing_inside
    384 387
                Just ret -> pure ret
    
    385 388
                Nothing  -> pprPanic "initTcDsForSolver" (vcat $ pprMsgEnvelopeBagWithLocDefault (getErrorMessages msgs)) }
    
    386 389
     
    
    387
    -mkDsEnvs :: UnitEnv -> Module -> GlobalRdrEnv -> TypeEnv -> FamInstEnv
    
    390
    +mkDsEnvs :: UnitEnv -> UnitIndexQuery -> Module -> GlobalRdrEnv -> TypeEnv -> FamInstEnv
    
    388 391
              -> PromotionTickContext
    
    389 392
              -> IORef (Messages DsMessage) -> IORef CostCentreState
    
    390 393
              -> IORef (OrdList (Id,CoreExpr))
    
    391 394
              -> IORef (ModuleEnv Int) -> DsCompleteMatches
    
    392 395
              -> (DsGblEnv, DsLclEnv)
    
    393
    -mkDsEnvs unit_env mod rdr_env type_env fam_inst_env ptc msg_var cc_st_var
    
    396
    +mkDsEnvs unit_env query mod rdr_env type_env fam_inst_env ptc msg_var cc_st_var
    
    394 397
              statics_var next_wrapper_num complete_matches
    
    395 398
       = let if_genv = IfGblEnv { if_doc       = text "mkDsEnvs"
    
    396 399
       -- Failing tests here are `ghci` and `T11985` if you get this wrong.
    
    ... ... @@ -407,7 +410,7 @@ mkDsEnvs unit_env mod rdr_env type_env fam_inst_env ptc msg_var cc_st_var
    407 410
                                , ds_fam_inst_env = fam_inst_env
    
    408 411
                                , ds_gbl_rdr_env  = rdr_env
    
    409 412
                                , ds_if_env  = (if_genv, if_lenv)
    
    410
    -                           , ds_name_ppr_ctx = mkNamePprCtx ptc unit_env rdr_env
    
    413
    +                           , ds_name_ppr_ctx = mkNamePprCtx ptc unit_env query rdr_env
    
    411 414
                                , ds_msgs    = msg_var
    
    412 415
                                , ds_complete_matches = complete_matches
    
    413 416
                                , ds_cc_st   = cc_st_var
    

  • compiler/GHC/Rename/Names.hs
    ... ... @@ -23,6 +23,7 @@ module GHC.Rename.Names (
    23 23
             getMinimalImports,
    
    24 24
             printMinimalImports,
    
    25 25
             renamePkgQual, renameRawPkgQual,
    
    26
    +        hscRenamePkgQual, hscRenameRawPkgQual,
    
    26 27
             classifyGREs,
    
    27 28
             ImportDeclUsage
    
    28 29
         ) where
    
    ... ... @@ -332,7 +333,8 @@ rnImportDecl this_mod
    332 333
     
    
    333 334
         hsc_env <- getTopEnv
    
    334 335
         unit_env <- hsc_unit_env <$> getTopEnv
    
    335
    -    let pkg_qual = renameRawPkgQual unit_env imp_mod_name raw_pkg_qual
    
    336
    +    query <- liftIO $ hscUnitIndexQuery hsc_env
    
    337
    +    let pkg_qual = renameRawPkgQual unit_env query imp_mod_name raw_pkg_qual
    
    336 338
     
    
    337 339
         -- Check for self-import, which confuses the typechecker (#9032)
    
    338 340
         -- ghc --make rejects self-import cycles already, but batch-mode may not
    
    ... ... @@ -442,14 +444,14 @@ rnImportDecl this_mod
    442 444
     
    
    443 445
     
    
    444 446
     -- | Rename raw package imports
    
    445
    -renameRawPkgQual :: UnitEnv -> ModuleName -> RawPkgQual -> PkgQual
    
    446
    -renameRawPkgQual unit_env mn = \case
    
    447
    +renameRawPkgQual :: UnitEnv -> UnitIndexQuery -> ModuleName -> RawPkgQual -> PkgQual
    
    448
    +renameRawPkgQual unit_env query mn = \case
    
    447 449
       NoRawPkgQual -> NoPkgQual
    
    448
    -  RawPkgQual p -> renamePkgQual unit_env mn (Just (sl_fs p))
    
    450
    +  RawPkgQual p -> renamePkgQual unit_env query mn (Just (sl_fs p))
    
    449 451
     
    
    450 452
     -- | Rename raw package imports
    
    451
    -renamePkgQual :: UnitEnv -> ModuleName -> Maybe FastString -> PkgQual
    
    452
    -renamePkgQual unit_env mn mb_pkg = case mb_pkg of
    
    453
    +renamePkgQual :: UnitEnv -> UnitIndexQuery -> ModuleName -> Maybe FastString -> PkgQual
    
    454
    +renamePkgQual unit_env query mn mb_pkg = case mb_pkg of
    
    453 455
       Nothing -> NoPkgQual
    
    454 456
       Just pkg_fs
    
    455 457
         | Just uid <- homeUnitId <$> ue_homeUnit unit_env
    
    ... ... @@ -459,7 +461,7 @@ renamePkgQual unit_env mn mb_pkg = case mb_pkg of
    459 461
         | Just (uid, _) <- find (fromMaybe False . fmap (== pkg_fs) . snd) home_names
    
    460 462
         -> ThisPkg uid
    
    461 463
     
    
    462
    -    | Just uid <- resolvePackageImport unit_state mn (PackageName pkg_fs)
    
    464
    +    | Just uid <- resolvePackageImport (ue_units unit_env) query mn (PackageName pkg_fs)
    
    463 465
         -> OtherPkg uid
    
    464 466
     
    
    465 467
         | otherwise
    
    ... ... @@ -474,6 +476,25 @@ renamePkgQual unit_env mn mb_pkg = case mb_pkg of
    474 476
         hpt_deps :: [UnitId]
    
    475 477
         hpt_deps  = homeUnitDepends unit_state
    
    476 478
     
    
    479
    +hscRenameRawPkgQual ::
    
    480
    +  MonadIO m =>
    
    481
    +  HscEnv ->
    
    482
    +  ModuleName ->
    
    483
    +  RawPkgQual ->
    
    484
    +  m PkgQual
    
    485
    +hscRenameRawPkgQual hsc_env name raw = do
    
    486
    +  query <- liftIO $ hscUnitIndexQuery hsc_env
    
    487
    +  pure (renameRawPkgQual (hsc_unit_env hsc_env) query name raw)
    
    488
    +
    
    489
    +hscRenamePkgQual ::
    
    490
    +  MonadIO m =>
    
    491
    +  HscEnv ->
    
    492
    +  ModuleName ->
    
    493
    +  Maybe FastString ->
    
    494
    +  m PkgQual
    
    495
    +hscRenamePkgQual hsc_env name package = do
    
    496
    +  query <- liftIO $ hscUnitIndexQuery hsc_env
    
    497
    +  pure (renamePkgQual (hsc_unit_env hsc_env) query name package)
    
    477 498
     
    
    478 499
     -- | Calculate the 'ImportAvails' induced by an import of a particular
    
    479 500
     -- interface, but without 'imp_mods'.
    
    ... ... @@ -2557,4 +2578,3 @@ addDupDeclErr gres@(gre :| _)
    2557 2578
     checkConName :: RdrName -> TcRn ()
    
    2558 2579
     checkConName name
    
    2559 2580
       = checkErr (isRdrDataCon name || isRdrTc name) (TcRnIllegalDataCon name)
    2560
    -

  • compiler/GHC/Runtime/Context.hs
    ... ... @@ -26,6 +26,7 @@ import GHC.Runtime.Eval.Types ( IcGlobalRdrEnv(..), Resume )
    26 26
     
    
    27 27
     import GHC.Unit
    
    28 28
     import GHC.Unit.Env
    
    29
    +import GHC.Unit.State (UnitIndexQuery)
    
    29 30
     
    
    30 31
     import GHC.Core.FamInstEnv
    
    31 32
     import GHC.Core.InstEnv
    
    ... ... @@ -397,8 +398,8 @@ icInScopeTTs ictxt = filter in_scope_unqualified (ic_tythings ictxt)
    397 398
             ]
    
    398 399
     
    
    399 400
     -- | Get the NamePprCtx function based on the flags and this InteractiveContext
    
    400
    -icNamePprCtx :: UnitEnv -> InteractiveContext -> NamePprCtx
    
    401
    -icNamePprCtx unit_env ictxt = mkNamePprCtx ptc unit_env (icReaderEnv ictxt)
    
    401
    +icNamePprCtx :: UnitEnv -> UnitIndexQuery -> InteractiveContext -> NamePprCtx
    
    402
    +icNamePprCtx unit_env query ictxt = mkNamePprCtx ptc unit_env query (icReaderEnv ictxt)
    
    402 403
       where ptc = initPromotionTickContext (ic_dflags ictxt)
    
    403 404
     
    
    404 405
     -- | extendInteractiveContext is called with new TyThings recently defined to update the
    

  • compiler/GHC/Tc/Module.hs
    ... ... @@ -265,9 +265,11 @@ tcRnModuleTcRnM hsc_env mod_sum
    265 265
             ; when (notNull prel_imports) $ do
    
    266 266
                 addDiagnostic TcRnImplicitImportOfPrelude
    
    267 267
     
    
    268
    +        ; query <- liftIO $ hscUnitIndexQuery hsc_env
    
    269
    +
    
    268 270
             ; -- TODO This is a little skeevy; maybe handle a bit more directly
    
    269 271
               let { simplifyImport (L _ idecl) =
    
    270
    -                  ( renameRawPkgQual (hsc_unit_env hsc_env) (unLoc $ ideclName idecl) (ideclPkgQual idecl)
    
    272
    +                  ( renameRawPkgQual (hsc_unit_env hsc_env) query (unLoc $ ideclName idecl) (ideclPkgQual idecl)
    
    271 273
                       , reLoc $ ideclName idecl)
    
    272 274
                   }
    
    273 275
             ; raw_sig_imports <- liftIO
    
    ... ... @@ -2122,19 +2124,21 @@ runTcInteractive hsc_env thing_inside
    2122 2124
                                                      , let local_gres = filter isLocalGRE gres
    
    2123 2125
                                                      , not (null local_gres) ]) ]
    
    2124 2126
     
    
    2125
    -       ; let getOrphansForModuleName m mb_pkg = do
    
    2126
    -              iface <- loadSrcInterface (text "runTcInteractive") m NotBoot mb_pkg
    
    2127
    +       ; let getOrphansForModuleName m pkg = do
    
    2128
    +              iface <- loadSrcInterface (text "runTcInteractive") m NotBoot pkg
    
    2127 2129
                   pure $ mi_module iface : dep_orphs (mi_deps iface)
    
    2128 2130
     
    
    2129 2131
                  getOrphansForModule m = do
    
    2130 2132
                   iface <- loadModuleInterface (text "runTcInteractive") m
    
    2131 2133
                   pure $ mi_module iface : dep_orphs (mi_deps iface)
    
    2132 2134
     
    
    2135
    +
    
    2133 2136
            ; !orphs <- fmap (force . concat) . forM (ic_imports icxt) $ \i ->
    
    2134 2137
                 case i of                   -- force above: see #15111
    
    2135 2138
                     IIModule n -> getOrphansForModule n
    
    2136
    -                IIDecl i   -> getOrphansForModuleName (unLoc (ideclName i))
    
    2137
    -                                         (renameRawPkgQual (hsc_unit_env hsc_env) (unLoc $ ideclName i) (ideclPkgQual i))
    
    2139
    +                IIDecl i   -> do
    
    2140
    +                  qual <- hscRenameRawPkgQual hsc_env (unLoc $ ideclName i) (ideclPkgQual i)
    
    2141
    +                  getOrphansForModuleName (unLoc (ideclName i)) qual
    
    2138 2142
     
    
    2139 2143
     
    
    2140 2144
            ; (home_insts, home_fam_insts) <- liftIO $ UnitEnv.hugAllInstances (hsc_unit_env hsc_env)
    

  • compiler/GHC/Tc/Utils/Monad.hs
    ... ... @@ -971,7 +971,8 @@ getNamePprCtx
    971 971
       = do { ptc <- initPromotionTickContext <$> getDynFlags
    
    972 972
            ; rdr_env <- getGlobalRdrEnv
    
    973 973
            ; hsc_env <- getTopEnv
    
    974
    -       ; return $ mkNamePprCtx ptc (hsc_unit_env hsc_env) rdr_env }
    
    974
    +       ; query <- liftIO $ hscUnitIndexQuery hsc_env
    
    975
    +       ; return $ mkNamePprCtx ptc (hsc_unit_env hsc_env) query rdr_env }
    
    975 976
     
    
    976 977
     -- | Like logInfoTcRn, but for user consumption
    
    977 978
     printForUserTcRn :: SDoc -> TcRn ()
    

  • compiler/GHC/Types/Name/Ppr.hs
    ... ... @@ -69,15 +69,16 @@ with some holes, we should try to give the user some more useful information.
    69 69
     
    
    70 70
     -- | Creates some functions that work out the best ways to format
    
    71 71
     -- names for the user according to a set of heuristics.
    
    72
    -mkNamePprCtx :: Outputable info => PromotionTickContext -> UnitEnv -> GlobalRdrEnvX info -> NamePprCtx
    
    73
    -mkNamePprCtx ptc unit_env env
    
    72
    +mkNamePprCtx :: Outputable info => PromotionTickContext -> UnitEnv -> UnitIndexQuery -> GlobalRdrEnvX info -> NamePprCtx
    
    73
    +mkNamePprCtx ptc unit_env index env
    
    74 74
      = QueryQualify
    
    75 75
           (mkQualName env)
    
    76
    -      (mkQualModule unit_state unit_env)
    
    76
    +      (mkQualModule unit_state index home_unit)
    
    77 77
           (mkQualPackage unit_state)
    
    78 78
           (mkPromTick ptc env)
    
    79 79
       where
    
    80 80
       unit_state = ue_homeUnitState unit_env
    
    81
    +  home_unit = ue_homeUnit unit_env
    
    81 82
     
    
    82 83
     mkQualName :: Outputable info => GlobalRdrEnvX info -> QueryQualifyName
    
    83 84
     mkQualName env = qual_name where
    
    ... ... @@ -215,12 +216,10 @@ Side note (int-index):
    215 216
     -- | Creates a function for formatting modules based on two heuristics:
    
    216 217
     -- (1) if the module is the current module, don't qualify, and (2) if there
    
    217 218
     -- is only one exposed package which exports this module, don't qualify.
    
    218
    -mkQualModule :: UnitState -> UnitEnv -> QueryQualifyModule
    
    219
    -mkQualModule unit_state unitEnv mod
    
    220
    -       -- Check whether the unit of the module is in the HomeUnitGraph.
    
    221
    -       -- If it is, then we consider this 'mod' to be "local" and don't
    
    222
    -       -- want to qualify it.
    
    223
    -     | HUG.memberHugUnit (moduleUnit mod) (ue_home_unit_graph unitEnv) = False
    
    219
    +mkQualModule :: UnitState -> UnitIndexQuery -> Maybe HomeUnit -> QueryQualifyModule
    
    220
    +mkQualModule unit_state index mhome_unit mod
    
    221
    +     | Just home_unit <- mhome_unit
    
    222
    +     , isHomeModule home_unit mod = False
    
    224 223
     
    
    225 224
          | [(_, pkgconfig)] <- lookup,
    
    226 225
            mkUnit pkgconfig == moduleUnit mod
    
    ... ... @@ -229,7 +228,7 @@ mkQualModule unit_state unitEnv mod
    229 228
          = False
    
    230 229
     
    
    231 230
          | otherwise = True
    
    232
    -     where lookup = lookupModuleInAllUnits unit_state (moduleName mod)
    
    231
    +     where lookup = lookupModuleInAllUnits unit_state index (moduleName mod)
    
    233 232
     
    
    234 233
     -- | Creates a function for formatting packages based on two heuristics:
    
    235 234
     -- (1) don't qualify if the package in question is "main", and (2) only qualify
    

  • compiler/GHC/Unit/Env.hs
    ... ... @@ -174,6 +174,8 @@ data UnitEnv = UnitEnv
    174 174
     
    
    175 175
         , ue_namever   :: !GhcNameVersion
    
    176 176
             -- ^ GHC name/version (used for dynamic library suffix)
    
    177
    +
    
    178
    +    , ue_index :: !UnitIndex
    
    177 179
         }
    
    178 180
     
    
    179 181
     ueEPS :: UnitEnv -> IO ExternalPackageState
    
    ... ... @@ -182,6 +184,7 @@ ueEPS = eucEPS . ue_eps
    182 184
     initUnitEnv :: UnitId -> HomeUnitGraph -> GhcNameVersion -> Platform -> IO UnitEnv
    
    183 185
     initUnitEnv cur_unit hug namever platform = do
    
    184 186
       eps <- initExternalUnitCache
    
    187
    +  ue_index <- newUnitIndex
    
    185 188
       return $ UnitEnv
    
    186 189
         { ue_eps             = eps
    
    187 190
         , ue_home_unit_graph = hug
    
    ... ... @@ -189,6 +192,7 @@ initUnitEnv cur_unit hug namever platform = do
    189 192
         , ue_current_unit    = cur_unit
    
    190 193
         , ue_platform        = platform
    
    191 194
         , ue_namever         = namever
    
    195
    +    , ue_index
    
    192 196
         }
    
    193 197
     
    
    194 198
     updateHug :: (HomeUnitGraph -> HomeUnitGraph) -> UnitEnv -> UnitEnv
    

  • compiler/GHC/Unit/Finder.hs
    ... ... @@ -181,7 +181,8 @@ findImportedModule hsc_env mod pkg_qual =
    181 181
           dflags    = hsc_dflags hsc_env
    
    182 182
           fopts     = initFinderOpts dflags
    
    183 183
       in do
    
    184
    -    findImportedModuleNoHsc fc fopts (hsc_unit_env hsc_env) mhome_unit mod pkg_qual
    
    184
    +    query <- hscUnitIndexQuery hsc_env
    
    185
    +    findImportedModuleNoHsc fc fopts (hsc_unit_env hsc_env) query mhome_unit mod pkg_qual
    
    185 186
     
    
    186 187
     findImportedModuleWithIsBoot :: HscEnv -> ModuleName -> IsBootInterface -> PkgQual -> IO FindResult
    
    187 188
     findImportedModuleWithIsBoot hsc_env mod is_boot pkg_qual = do
    
    ... ... @@ -194,11 +195,12 @@ findImportedModuleNoHsc
    194 195
       :: FinderCache
    
    195 196
       -> FinderOpts
    
    196 197
       -> UnitEnv
    
    198
    +  -> UnitIndexQuery
    
    197 199
       -> Maybe HomeUnit
    
    198 200
       -> ModuleName
    
    199 201
       -> PkgQual
    
    200 202
       -> IO FindResult
    
    201
    -findImportedModuleNoHsc fc fopts ue mhome_unit mod_name mb_pkg =
    
    203
    +findImportedModuleNoHsc fc fopts ue query mhome_unit mod_name mb_pkg =
    
    202 204
       case mb_pkg of
    
    203 205
         NoPkgQual  -> unqual_import
    
    204 206
         ThisPkg uid | (homeUnitId <$> mhome_unit) == Just uid -> home_import
    
    ... ... @@ -220,7 +222,7 @@ findImportedModuleNoHsc fc fopts ue mhome_unit mod_name mb_pkg =
    220 222
           -- If the module is reexported, then look for it as if it was from the perspective
    
    221 223
           -- of that package which reexports it.
    
    222 224
           | Just real_mod_name <- lookupUniqMap (finder_reexportedModules opts) mod_name =
    
    223
    -        findImportedModuleNoHsc fc opts ue (Just $ DefiniteHomeUnit uid Nothing) real_mod_name NoPkgQual
    
    225
    +        findImportedModuleNoHsc fc opts ue query (Just $ DefiniteHomeUnit uid Nothing) real_mod_name NoPkgQual
    
    224 226
           | elementOfUniqSet mod_name (finder_hiddenModules opts) =
    
    225 227
             return (mkHomeHidden uid)
    
    226 228
           | otherwise =
    
    ... ... @@ -231,11 +233,11 @@ findImportedModuleNoHsc fc fopts ue mhome_unit mod_name mb_pkg =
    231 233
         -- first before looking at the packages in order.
    
    232 234
         any_home_import = foldr1 orIfNotFound (home_import:| map home_pkg_import other_fopts)
    
    233 235
     
    
    234
    -    pkg_import    = findExposedPackageModule fc fopts units  mod_name mb_pkg
    
    236
    +    pkg_import    = findExposedPackageModule fc fopts units query mod_name mb_pkg
    
    235 237
     
    
    236 238
         unqual_import = any_home_import
    
    237 239
                         `orIfNotFound`
    
    238
    -                    findExposedPackageModule fc fopts units mod_name NoPkgQual
    
    240
    +                    findExposedPackageModule fc fopts units query mod_name NoPkgQual
    
    239 241
     
    
    240 242
         units     = case mhome_unit of
    
    241 243
                       Nothing -> ue_homeUnitState ue
    
    ... ... @@ -248,20 +250,21 @@ findImportedModuleNoHsc fc fopts ue mhome_unit mod_name mb_pkg =
    248 250
     -- plugin.  This consults the same set of exposed packages as
    
    249 251
     -- 'findImportedModule', unless @-hide-all-plugin-packages@ or
    
    250 252
     -- @-plugin-package@ are specified.
    
    251
    -findPluginModuleNoHsc :: FinderCache -> FinderOpts -> UnitState -> Maybe HomeUnit -> ModuleName -> IO FindResult
    
    252
    -findPluginModuleNoHsc fc fopts units (Just home_unit) mod_name =
    
    253
    +findPluginModuleNoHsc :: FinderCache -> FinderOpts -> UnitState -> UnitIndexQuery -> Maybe HomeUnit -> ModuleName -> IO FindResult
    
    254
    +findPluginModuleNoHsc fc fopts units query (Just home_unit) mod_name =
    
    253 255
       findHomeModule fc fopts home_unit mod_name
    
    254 256
       `orIfNotFound`
    
    255
    -  findExposedPluginPackageModule fc fopts units mod_name
    
    256
    -findPluginModuleNoHsc fc fopts units Nothing mod_name =
    
    257
    -  findExposedPluginPackageModule fc fopts units mod_name
    
    257
    +  findExposedPluginPackageModule fc fopts units query mod_name
    
    258
    +findPluginModuleNoHsc fc fopts units query Nothing mod_name =
    
    259
    +  findExposedPluginPackageModule fc fopts units query mod_name
    
    258 260
     
    
    259 261
     findPluginModule :: HscEnv -> ModuleName -> IO FindResult
    
    260 262
     findPluginModule hsc_env mod_name = do
    
    261 263
       let fc = hsc_FC hsc_env
    
    262 264
       let units = hsc_units hsc_env
    
    263 265
       let mhome_unit = hsc_home_unit_maybe hsc_env
    
    264
    -  findPluginModuleNoHsc fc (initFinderOpts (hsc_dflags hsc_env)) units mhome_unit mod_name
    
    266
    +  query <- hscUnitIndexQuery hsc_env
    
    267
    +  findPluginModuleNoHsc fc (initFinderOpts (hsc_dflags hsc_env)) units query mhome_unit mod_name
    
    265 268
     
    
    266 269
     
    
    267 270
     -- | A version of findExactModule which takes the exact parts of the HscEnv it needs
    
    ... ... @@ -333,15 +336,15 @@ homeSearchCache fc home_unit mod_name do_this = do
    333 336
       let mod = mkModule home_unit mod_name
    
    334 337
       modLocationCache fc mod do_this
    
    335 338
     
    
    336
    -findExposedPackageModule :: FinderCache -> FinderOpts -> UnitState -> ModuleName -> PkgQual -> IO FindResult
    
    337
    -findExposedPackageModule fc fopts units mod_name mb_pkg =
    
    339
    +findExposedPackageModule :: FinderCache -> FinderOpts -> UnitState -> UnitIndexQuery -> ModuleName -> PkgQual -> IO FindResult
    
    340
    +findExposedPackageModule fc fopts units query mod_name mb_pkg =
    
    338 341
       findLookupResult fc fopts
    
    339
    -    $ lookupModuleWithSuggestions units mod_name mb_pkg
    
    342
    +    $ lookupModuleWithSuggestions units query mod_name mb_pkg
    
    340 343
     
    
    341
    -findExposedPluginPackageModule :: FinderCache -> FinderOpts -> UnitState -> ModuleName -> IO FindResult
    
    342
    -findExposedPluginPackageModule fc fopts units mod_name =
    
    344
    +findExposedPluginPackageModule :: FinderCache -> FinderOpts -> UnitState -> UnitIndexQuery -> ModuleName -> IO FindResult
    
    345
    +findExposedPluginPackageModule fc fopts units query mod_name =
    
    343 346
       findLookupResult fc fopts
    
    344
    -    $ lookupPluginModuleWithSuggestions units mod_name NoPkgQual
    
    347
    +    $ lookupPluginModuleWithSuggestions units query mod_name NoPkgQual
    
    345 348
     
    
    346 349
     findLookupResult :: FinderCache -> FinderOpts -> LookupResult -> IO FindResult
    
    347 350
     findLookupResult fc fopts r = case r of
    

  • compiler/GHC/Unit/State.hs
    1
    +{-# LANGUAGE LambdaCase, RecordWildCards #-}
    
    1 2
     -- (c) The University of Glasgow, 2006
    
    2 3
     
    
    3
    -
    
    4 4
     -- | Unit manipulation
    
    5 5
     module GHC.Unit.State (
    
    6 6
             module GHC.Unit.Info,
    
    ... ... @@ -48,6 +48,14 @@ module GHC.Unit.State (
    48 48
             closeUnitDeps',
    
    49 49
             mayThrowUnitErr,
    
    50 50
     
    
    51
    +        UnitConfig (..),
    
    52
    +        UnitIndex (..),
    
    53
    +        UnitIndexQuery (..),
    
    54
    +        UnitVisibility (..),
    
    55
    +        VisibilityMap,
    
    56
    +        ModuleNameProvidersMap,
    
    57
    +        newUnitIndex,
    
    58
    +
    
    51 59
             -- * Module hole substitution
    
    52 60
             ShHoleSubst,
    
    53 61
             renameHoleUnit,
    
    ... ... @@ -578,10 +586,10 @@ searchPackageId pkgstate pid = filter ((pid ==) . unitPackageId)
    578 586
     -- | Find the UnitId which an import qualified by a package import comes from.
    
    579 587
     -- Compared to 'lookupPackageName', this function correctly accounts for visibility,
    
    580 588
     -- renaming and thinning.
    
    581
    -resolvePackageImport :: UnitState -> ModuleName -> PackageName -> Maybe UnitId
    
    582
    -resolvePackageImport unit_st mn pn = do
    
    589
    +resolvePackageImport :: UnitState -> UnitIndexQuery -> ModuleName -> PackageName -> Maybe UnitId
    
    590
    +resolvePackageImport unit_st query mn pn = do
    
    583 591
       -- 1. Find all modules providing the ModuleName (this accounts for visibility/thinning etc)
    
    584
    -  providers <- filterUniqMap originVisible <$> lookupUniqMap (moduleNameProvidersMap unit_st) mn
    
    592
    +  providers <- filterUniqMap originVisible <$> findOrigin query unit_st mn False
    
    585 593
       -- 2. Get the UnitIds of the candidates
    
    586 594
       let candidates_uid = concatMap to_uid $ sortOn fst $ nonDetUniqMapToList providers
    
    587 595
       -- 3. Get the package names of the candidates
    
    ... ... @@ -639,14 +647,14 @@ listUnitInfo state = nonDetEltsUniqMap (unitInfoMap state)
    639 647
     -- 'initUnits' can be called again subsequently after updating the
    
    640 648
     -- 'packageFlags' field of the 'DynFlags', and it will update the
    
    641 649
     -- 'unitState' in 'DynFlags'.
    
    642
    -initUnits :: Logger -> DynFlags -> Maybe [UnitDatabase UnitId] -> Set.Set UnitId -> IO ([UnitDatabase UnitId], UnitState, HomeUnit, Maybe PlatformConstants)
    
    643
    -initUnits logger dflags cached_dbs home_units = do
    
    650
    +initUnits :: Logger -> DynFlags -> UnitIndex -> Maybe [UnitDatabase UnitId] -> Set.Set UnitId -> IO ([UnitDatabase UnitId], UnitState, HomeUnit, Maybe PlatformConstants)
    
    651
    +initUnits logger dflags index cached_dbs home_units = do
    
    644 652
     
    
    645 653
       let forceUnitInfoMap (state, _) = unitInfoMap state `seq` ()
    
    646 654
     
    
    647 655
       (unit_state,dbs) <- withTiming logger (text "initializing unit database")
    
    648 656
                        forceUnitInfoMap
    
    649
    -                 $ mkUnitState logger (initUnitConfig dflags cached_dbs home_units)
    
    657
    +                 $ mkUnitState logger (homeUnitId_ dflags) (initUnitConfig dflags cached_dbs home_units) index
    
    650 658
     
    
    651 659
       putDumpFileMaybe logger Opt_D_dump_mod_map "Module Map"
    
    652 660
         FormatText (updSDocContext (\ctx -> ctx {sdocLineLength = 200})
    
    ... ... @@ -1480,9 +1488,11 @@ validateDatabase cfg pkg_map1 =
    1480 1488
     
    
    1481 1489
     mkUnitState
    
    1482 1490
         :: Logger
    
    1491
    +    -> UnitId
    
    1483 1492
         -> UnitConfig
    
    1493
    +    -> UnitIndex
    
    1484 1494
         -> IO (UnitState,[UnitDatabase UnitId])
    
    1485
    -mkUnitState logger cfg = do
    
    1495
    +mkUnitState logger unit cfg index = do
    
    1486 1496
     {-
    
    1487 1497
        Plan.
    
    1488 1498
     
    
    ... ... @@ -1538,15 +1548,9 @@ mkUnitState logger cfg = do
    1538 1548
     
    
    1539 1549
       -- if databases have not been provided, read the database flags
    
    1540 1550
       raw_dbs <- case unitConfigDBCache cfg of
    
    1541
    -               Nothing  -> readUnitDatabases logger cfg
    
    1551
    +               Nothing  -> readDatabases index logger unit cfg
    
    1542 1552
                    Just dbs -> return dbs
    
    1543 1553
     
    
    1544
    -  -- distrust all units if the flag is set
    
    1545
    -  let distrust_all db = db { unitDatabaseUnits = distrustAllUnits (unitDatabaseUnits db) }
    
    1546
    -      dbs | unitConfigDistrustAll cfg = map distrust_all raw_dbs
    
    1547
    -          | otherwise                 = raw_dbs
    
    1548
    -
    
    1549
    -
    
    1550 1554
       -- This, and the other reverse's that you will see, are due to the fact that
    
    1551 1555
       -- packageFlags, pluginPackageFlags, etc. are all specified in *reverse* order
    
    1552 1556
       -- than they are on the command line.
    
    ... ... @@ -1558,15 +1562,20 @@ mkUnitState logger cfg = do
    1558 1562
       let home_unit_deps = selectHomeUnits (unitConfigHomeUnits cfg) hpt_flags
    
    1559 1563
     
    
    1560 1564
       -- Merge databases together, without checking validity
    
    1561
    -  (pkg_map1, prec_map) <- mergeDatabases logger dbs
    
    1565
    +  (pkg_map1, prec_map) <- mergeDatabases logger raw_dbs
    
    1562 1566
     
    
    1563 1567
       -- Now that we've merged everything together, prune out unusable
    
    1564 1568
       -- packages.
    
    1565
    -  let (pkg_map2, unusable, sccs) = validateDatabase cfg pkg_map1
    
    1569
    +  let (initial_dbs, unusable, sccs) = validateDatabase cfg pkg_map1
    
    1566 1570
     
    
    1567 1571
       reportCycles   logger sccs
    
    1568 1572
       reportUnusable logger unusable
    
    1569 1573
     
    
    1574
    +  -- distrust all units if the flag is set
    
    1575
    +  let distrust_all info = info {unitIsTrusted = False}
    
    1576
    +      pkg_map2 | unitConfigDistrustAll cfg = distrust_all <$> initial_dbs
    
    1577
    +               | otherwise                 = initial_dbs
    
    1578
    +
    
    1570 1579
       -- Apply trust flags (these flags apply regardless of whether
    
    1571 1580
       -- or not packages are visible or not)
    
    1572 1581
       pkgs1 <- mayThrowUnitErr
    
    ... ... @@ -1671,6 +1680,9 @@ mkUnitState logger cfg = do
    1671 1680
                     -- likely to actually happen.
    
    1672 1681
                     return (updateVisibilityMap wired_map plugin_vis_map2)
    
    1673 1682
     
    
    1683
    +  (moduleNameProvidersMap, pluginModuleNameProvidersMap) <-
    
    1684
    +    computeProviders index logger unit cfg vis_map plugin_vis_map initial_dbs pkg_db (mkUnusableModuleNameProvidersMap unusable)
    
    1685
    +
    
    1674 1686
       let pkgname_map = listToUFM [ (unitPackageName p, unitInstanceOf p)
    
    1675 1687
                                   | p <- pkgs2
    
    1676 1688
                                   ]
    
    ... ... @@ -1683,8 +1695,6 @@ mkUnitState logger cfg = do
    1683 1695
           req_ctx = mapUniqMap (Set.toList)
    
    1684 1696
                   $ plusUniqMapListWith Set.union (map uv_requirements (nonDetEltsUniqMap vis_map))
    
    1685 1697
     
    
    1686
    -
    
    1687
    -  --
    
    1688 1698
       -- Here we build up a set of the packages mentioned in -package
    
    1689 1699
       -- flags on the command line; these are called the "preload"
    
    1690 1700
       -- packages.  we link these packages in eagerly.  The preload set
    
    ... ... @@ -1707,10 +1717,6 @@ mkUnitState logger cfg = do
    1707 1717
                         $ closeUnitDeps pkg_db
    
    1708 1718
                         $ zip (map toUnitId preload3) (repeat Nothing)
    
    1709 1719
     
    
    1710
    -  let mod_map1 = mkModuleNameProvidersMap logger cfg pkg_db emptyUniqSet vis_map
    
    1711
    -      mod_map2 = mkUnusableModuleNameProvidersMap unusable
    
    1712
    -      mod_map = mod_map2 `plusUniqMap` mod_map1
    
    1713
    -
    
    1714 1720
       -- Force the result to avoid leaking input parameters
    
    1715 1721
       let !state = UnitState
    
    1716 1722
              { preloadUnits                 = dep_preload
    
    ... ... @@ -1718,8 +1724,8 @@ mkUnitState logger cfg = do
    1718 1724
              , homeUnitDepends              = Set.toList home_unit_deps
    
    1719 1725
              , unitInfoMap                  = pkg_db
    
    1720 1726
              , preloadClosure               = emptyUniqSet
    
    1721
    -         , moduleNameProvidersMap       = mod_map
    
    1722
    -         , pluginModuleNameProvidersMap = mkModuleNameProvidersMap logger cfg pkg_db emptyUniqSet plugin_vis_map
    
    1727
    +         , moduleNameProvidersMap
    
    1728
    +         , pluginModuleNameProvidersMap
    
    1723 1729
              , packageNameMap               = pkgname_map
    
    1724 1730
              , wireMap                      = wired_map
    
    1725 1731
              , unwireMap                    = listToUniqMap [ (v,k) | (k,v) <- nonDetUniqMapToList wired_map ]
    
    ... ... @@ -1892,6 +1898,76 @@ addListTo = foldl' merge
    1892 1898
     mkModMap :: Unit -> ModuleName -> ModuleOrigin -> UniqMap Module ModuleOrigin
    
    1893 1899
     mkModMap pkg mod = unitUniqMap (mkModule pkg mod)
    
    1894 1900
     
    
    1901
    +-- -----------------------------------------------------------------------------
    
    1902
    +-- Index
    
    1903
    +
    
    1904
    +data UnitIndexQuery =
    
    1905
    +  UnitIndexQuery {
    
    1906
    +    findOrigin :: UnitState -> ModuleName -> Bool -> Maybe (UniqMap Module ModuleOrigin),
    
    1907
    +    moduleProviders :: UnitState -> ModuleNameProvidersMap
    
    1908
    +  }
    
    1909
    +
    
    1910
    +data UnitIndex =
    
    1911
    +  UnitIndex {
    
    1912
    +    unitIndexQuery :: UnitId -> IO UnitIndexQuery,
    
    1913
    +    readDatabases :: Logger -> UnitId -> UnitConfig -> IO [UnitDatabase UnitId],
    
    1914
    +    computeProviders ::
    
    1915
    +      Logger ->
    
    1916
    +      UnitId ->
    
    1917
    +      UnitConfig ->
    
    1918
    +      VisibilityMap ->
    
    1919
    +      VisibilityMap ->
    
    1920
    +      UnitInfoMap ->
    
    1921
    +      UnitInfoMap ->
    
    1922
    +      ModuleNameProvidersMap ->
    
    1923
    +      IO (ModuleNameProvidersMap, ModuleNameProvidersMap)
    
    1924
    +  }
    
    1925
    +
    
    1926
    +queryFindOriginDefault ::
    
    1927
    +  UnitState ->
    
    1928
    +  ModuleName ->
    
    1929
    +  Bool ->
    
    1930
    +  Maybe (UniqMap Module ModuleOrigin)
    
    1931
    +queryFindOriginDefault UnitState {moduleNameProvidersMap, pluginModuleNameProvidersMap} name plugins =
    
    1932
    +  lookupUniqMap source name
    
    1933
    +  where
    
    1934
    +    source = if plugins then pluginModuleNameProvidersMap else moduleNameProvidersMap
    
    1935
    +
    
    1936
    +newUnitIndexQuery :: UnitId -> IO UnitIndexQuery
    
    1937
    +newUnitIndexQuery _ =
    
    1938
    +  pure UnitIndexQuery {
    
    1939
    +    findOrigin = queryFindOriginDefault,
    
    1940
    +    moduleProviders = moduleNameProvidersMap
    
    1941
    +  }
    
    1942
    +
    
    1943
    +readDatabasesDefault :: Logger -> UnitId -> UnitConfig -> IO [UnitDatabase UnitId]
    
    1944
    +readDatabasesDefault logger _ cfg =
    
    1945
    +  readUnitDatabases logger cfg
    
    1946
    +
    
    1947
    +computeProvidersDefault ::
    
    1948
    +  Logger ->
    
    1949
    +  UnitId ->
    
    1950
    +  UnitConfig ->
    
    1951
    +  VisibilityMap ->
    
    1952
    +  VisibilityMap ->
    
    1953
    +  UnitInfoMap ->
    
    1954
    +  UnitInfoMap ->
    
    1955
    +  ModuleNameProvidersMap ->
    
    1956
    +  IO (ModuleNameProvidersMap, ModuleNameProvidersMap)
    
    1957
    +computeProvidersDefault logger _ cfg vis_map plugin_vis_map _initial_dbs pkg_db unusable =
    
    1958
    +  pure (mod_map, plugin_mod_map)
    
    1959
    +  where
    
    1960
    +    mod_map1 = mkModuleNameProvidersMap logger cfg pkg_db emptyUniqSet vis_map
    
    1961
    +    mod_map = unusable `plusUniqMap` mod_map1
    
    1962
    +    plugin_mod_map = mkModuleNameProvidersMap logger cfg pkg_db emptyUniqSet plugin_vis_map
    
    1963
    +
    
    1964
    +newUnitIndex :: IO UnitIndex
    
    1965
    +newUnitIndex =
    
    1966
    +  pure UnitIndex {
    
    1967
    +    unitIndexQuery = newUnitIndexQuery,
    
    1968
    +    readDatabases = readDatabasesDefault,
    
    1969
    +    computeProviders = computeProvidersDefault
    
    1970
    +  }
    
    1895 1971
     
    
    1896 1972
     -- -----------------------------------------------------------------------------
    
    1897 1973
     -- Package Utils
    
    ... ... @@ -1899,10 +1975,11 @@ mkModMap pkg mod = unitUniqMap (mkModule pkg mod)
    1899 1975
     -- | Takes a 'ModuleName', and if the module is in any package returns
    
    1900 1976
     -- list of modules which take that name.
    
    1901 1977
     lookupModuleInAllUnits :: UnitState
    
    1978
    +                          -> UnitIndexQuery
    
    1902 1979
                               -> ModuleName
    
    1903 1980
                               -> [(Module, UnitInfo)]
    
    1904
    -lookupModuleInAllUnits pkgs m
    
    1905
    -  = case lookupModuleWithSuggestions pkgs m NoPkgQual of
    
    1981
    +lookupModuleInAllUnits pkgs query m
    
    1982
    +  = case lookupModuleWithSuggestions pkgs query m NoPkgQual of
    
    1906 1983
           LookupFound a b -> [(a,fst b)]
    
    1907 1984
           LookupMultiple rs -> map f rs
    
    1908 1985
             where f (m,_) = (m, expectJust (lookupUnit pkgs (moduleUnit m)))
    
    ... ... @@ -1928,18 +2005,24 @@ data ModuleSuggestion = SuggestVisible ModuleName Module ModuleOrigin
    1928 2005
                           | SuggestHidden ModuleName Module ModuleOrigin
    
    1929 2006
     
    
    1930 2007
     lookupModuleWithSuggestions :: UnitState
    
    2008
    +                            -> UnitIndexQuery
    
    1931 2009
                                 -> ModuleName
    
    1932 2010
                                 -> PkgQual
    
    1933 2011
                                 -> LookupResult
    
    1934
    -lookupModuleWithSuggestions pkgs
    
    1935
    -  = lookupModuleWithSuggestions' pkgs (moduleNameProvidersMap pkgs)
    
    2012
    +lookupModuleWithSuggestions pkgs query name
    
    2013
    +  = lookupModuleWithSuggestions' pkgs query name False
    
    1936 2014
     
    
    1937 2015
     -- | The package which the module **appears** to come from, this could be
    
    1938 2016
     -- the one which reexports the module from it's original package. This function
    
    1939 2017
     -- is currently only used for -Wunused-packages
    
    1940
    -lookupModulePackage :: UnitState -> ModuleName -> PkgQual -> Maybe [UnitInfo]
    
    1941
    -lookupModulePackage pkgs mn mfs =
    
    1942
    -    case lookupModuleWithSuggestions' pkgs (moduleNameProvidersMap pkgs) mn mfs of
    
    2018
    +lookupModulePackage ::
    
    2019
    +  UnitState ->
    
    2020
    +  UnitIndexQuery ->
    
    2021
    +  ModuleName ->
    
    2022
    +  PkgQual ->
    
    2023
    +  Maybe [UnitInfo]
    
    2024
    +lookupModulePackage pkgs query mn mfs =
    
    2025
    +    case lookupModuleWithSuggestions' pkgs query mn False mfs of
    
    1943 2026
           LookupFound _ (orig_unit, origin) ->
    
    1944 2027
             case origin of
    
    1945 2028
               ModOrigin {fromOrigUnit, fromExposedReexport} ->
    
    ... ... @@ -1955,19 +2038,21 @@ lookupModulePackage pkgs mn mfs =
    1955 2038
           _ -> Nothing
    
    1956 2039
     
    
    1957 2040
     lookupPluginModuleWithSuggestions :: UnitState
    
    2041
    +                                  -> UnitIndexQuery
    
    1958 2042
                                       -> ModuleName
    
    1959 2043
                                       -> PkgQual
    
    1960 2044
                                       -> LookupResult
    
    1961
    -lookupPluginModuleWithSuggestions pkgs
    
    1962
    -  = lookupModuleWithSuggestions' pkgs (pluginModuleNameProvidersMap pkgs)
    
    2045
    +lookupPluginModuleWithSuggestions pkgs query name
    
    2046
    +  = lookupModuleWithSuggestions' pkgs query name True
    
    1963 2047
     
    
    1964 2048
     lookupModuleWithSuggestions' :: UnitState
    
    1965
    -                            -> ModuleNameProvidersMap
    
    2049
    +                            -> UnitIndexQuery
    
    1966 2050
                                 -> ModuleName
    
    2051
    +                            -> Bool
    
    1967 2052
                                 -> PkgQual
    
    1968 2053
                                 -> LookupResult
    
    1969
    -lookupModuleWithSuggestions' pkgs mod_map m mb_pn
    
    1970
    -  = case lookupUniqMap mod_map m of
    
    2054
    +lookupModuleWithSuggestions' pkgs query m onlyPlugins mb_pn
    
    2055
    +  = case findOrigin query pkgs m onlyPlugins of
    
    1971 2056
             Nothing -> LookupNotFound suggestions
    
    1972 2057
             Just xs ->
    
    1973 2058
               case foldl' classify ([],[],[], []) (sortOn fst $ nonDetUniqMapToList xs) of
    
    ... ... @@ -2028,16 +2113,16 @@ lookupModuleWithSuggestions' pkgs mod_map m mb_pn
    2028 2113
         all_mods :: [(String, ModuleSuggestion)]     -- All modules
    
    2029 2114
         all_mods = sortBy (comparing fst) $
    
    2030 2115
             [ (moduleNameString m, suggestion)
    
    2031
    -        | (m, e) <- nonDetUniqMapToList (moduleNameProvidersMap pkgs)
    
    2116
    +        | (m, e) <- nonDetUniqMapToList (moduleProviders query pkgs)
    
    2032 2117
             , suggestion <- map (getSuggestion m) (nonDetUniqMapToList e)
    
    2033 2118
             ]
    
    2034 2119
         getSuggestion name (mod, origin) =
    
    2035 2120
             (if originVisible origin then SuggestVisible else SuggestHidden)
    
    2036 2121
                 name mod origin
    
    2037 2122
     
    
    2038
    -listVisibleModuleNames :: UnitState -> [ModuleName]
    
    2039
    -listVisibleModuleNames state =
    
    2040
    -    map fst (filter visible (nonDetUniqMapToList (moduleNameProvidersMap state)))
    
    2123
    +listVisibleModuleNames :: UnitState -> UnitIndexQuery -> [ModuleName]
    
    2124
    +listVisibleModuleNames unit_state query =
    
    2125
    +    map fst (filter visible (nonDetUniqMapToList (moduleProviders query unit_state)))
    
    2041 2126
       where visible (_, ms) = anyUniqMap originVisible ms
    
    2042 2127
     
    
    2043 2128
     -- | Takes a list of UnitIds (and their "parent" dependency, used for error
    

  • ghc/GHCi/UI.hs
    ... ... @@ -87,6 +87,7 @@ import qualified GHC.Parser.Header as Header
    87 87
     import GHC.Types.PkgQual
    
    88 88
     
    
    89 89
     import GHC.Unit
    
    90
    +import GHC.Unit.State (UnitIndex)
    
    90 91
     import GHC.Unit.Finder as Finder
    
    91 92
     import GHC.Unit.Module.Graph (filterToposortToModules)
    
    92 93
     import GHC.Unit.Module.ModSummary
    
    ... ... @@ -764,8 +765,9 @@ installInteractiveHomeUnits = do
    764 765
           S.insert interactiveSessionUnitId $
    
    765 766
           hsc_all_home_unit_ids hsc_env
    
    766 767
     
    
    767
    -  ghciPromptUnit  <- setupHomeUnitFor logger dflagsPrompt  all_unit_ids cached_unit_dbs
    
    768
    -  ghciSessionUnit <- setupHomeUnitFor logger dflagsSession all_unit_ids cached_unit_dbs
    
    768
    +  let unit_index = hscUnitIndex hsc_env
    
    769
    +  ghciPromptUnit  <- setupHomeUnitFor logger dflagsPrompt  unit_index all_unit_ids cached_unit_dbs
    
    770
    +  ghciSessionUnit <- setupHomeUnitFor logger dflagsSession unit_index all_unit_ids cached_unit_dbs
    
    769 771
       let
    
    770 772
         -- Setup up the HUG, install the interactive home units
    
    771 773
         withInteractiveUnits =
    
    ... ... @@ -787,10 +789,10 @@ installInteractiveHomeUnits = do
    787 789
     
    
    788 790
       pure ()
    
    789 791
       where
    
    790
    -    setupHomeUnitFor :: GHC.GhcMonad m => Logger -> DynFlags -> S.Set UnitId -> [UnitDatabase UnitId] -> m HomeUnitEnv
    
    791
    -    setupHomeUnitFor logger dflags all_home_units cached_unit_dbs = do
    
    792
    +    setupHomeUnitFor :: GHC.GhcMonad m => Logger -> DynFlags -> UnitIndex -> S.Set UnitId -> [UnitDatabase UnitId] -> m HomeUnitEnv
    
    793
    +    setupHomeUnitFor logger dflags index all_home_units cached_unit_dbs = do
    
    792 794
           (dbs,unit_state,home_unit,_mconstants) <-
    
    793
    -        liftIO $ initUnits logger dflags (Just cached_unit_dbs) all_home_units
    
    795
    +        liftIO $ initUnits logger dflags index (Just cached_unit_dbs) all_home_units
    
    794 796
           hpt <- liftIO emptyHomePackageTable
    
    795 797
           pure (HUG.mkHomeUnitEnv unit_state (Just dbs) dflags hpt (Just home_unit))
    
    796 798
     
    
    ... ... @@ -4087,19 +4089,21 @@ completeBreakpoint = wrapCompleter spaces $ \w -> do -- #3000
    4087 4089
     
    
    4088 4090
     completeModule = wrapIdentCompleterMod $ \w -> do
    
    4089 4091
       hsc_env <- GHC.getSession
    
    4090
    -  let pkg_mods = allVisibleModules (hsc_units hsc_env)
    
    4092
    +  query <- liftIO $ hscUnitIndexQuery hsc_env
    
    4093
    +  let pkg_mods = allVisibleModules (hsc_units hsc_env) query
    
    4091 4094
       loaded_mods <- liftM (map GHC.moduleNodeInfoModuleName) getLoadedModules
    
    4092 4095
       return $ filter (w `isPrefixOf`)
    
    4093 4096
             $ map (showPpr (hsc_dflags hsc_env)) $ loaded_mods ++ pkg_mods
    
    4094 4097
     
    
    4095 4098
     completeSetModule = wrapIdentCompleterWithModifier "+-" $ \m w -> do
    
    4096 4099
       hsc_env <- GHC.getSession
    
    4100
    +  query <- liftIO $ hscUnitIndexQuery hsc_env
    
    4097 4101
       modules <- case m of
    
    4098 4102
         Just '-' -> do
    
    4099 4103
           imports <- GHC.getContext
    
    4100 4104
           return $ map iiModuleName imports
    
    4101 4105
         _ -> do
    
    4102
    -      let pkg_mods = allVisibleModules (hsc_units hsc_env)
    
    4106
    +      let pkg_mods = allVisibleModules (hsc_units hsc_env) query
    
    4103 4107
           loaded_mods <- liftM (map GHC.moduleNodeInfoModuleName) getLoadedModules
    
    4104 4108
           return $ loaded_mods ++ pkg_mods
    
    4105 4109
       return $ filter (w `isPrefixOf`) $ map (showPpr (hsc_dflags hsc_env)) modules
    
    ... ... @@ -4167,8 +4171,8 @@ wrapIdentCompleterWithModifier modifChars fun = completeWordWithPrev Nothing wor
    4167 4171
     
    
    4168 4172
     -- | Return a list of visible module names for autocompletion.
    
    4169 4173
     -- (NB: exposed != visible)
    
    4170
    -allVisibleModules :: UnitState -> [ModuleName]
    
    4171
    -allVisibleModules unit_state = listVisibleModuleNames unit_state
    
    4174
    +allVisibleModules :: UnitState -> UnitIndexQuery -> [ModuleName]
    
    4175
    +allVisibleModules us query = listVisibleModuleNames us query
    
    4172 4176
     
    
    4173 4177
     completeExpression = completeQuotedWord (Just '\\') "\"" listFiles
    
    4174 4178
                             completeIdentifier
    

  • ghc/GHCi/UI/Monad.hs
    ... ... @@ -365,7 +365,6 @@ unsetOption opt
    365 365
      = do st <- getGHCiState
    
    366 366
           setGHCiState (st{ options = filter (/= opt) (options st) })
    
    367 367
     
    
    368
    -
    
    369 368
     -- | Run a single Haskell expression
    
    370 369
     runStmt
    
    371 370
       :: GhciMonad m
    

  • ghc/GHCi/UI/Print.hs
    ... ... @@ -18,6 +18,7 @@ import GHC.Driver.Env
    18 18
     import GHC.Driver.Session
    
    19 19
     import GHC.Driver.Errors
    
    20 20
     import GHC.Driver.Config.Diagnostic
    
    21
    +import GHC.Driver.Env (hsc_unit_env, hscUnitIndexQuery)
    
    21 22
     
    
    22 23
     import GHC.Utils.Logger
    
    23 24
     import GHC.Utils.Error
    
    ... ... @@ -45,10 +46,11 @@ printForUserGlobalRdrEnv mb_rdr_env doc = do
    45 46
         where
    
    46 47
           mkNamePprCtxFromGlobalRdrEnv _ Nothing = GHC.getNamePprCtx
    
    47 48
           mkNamePprCtxFromGlobalRdrEnv dflags (Just rdr_env) =
    
    48
    -        withSession $ \ hsc_env ->
    
    49
    -        let unit_env = hsc_unit_env hsc_env
    
    50
    -            ptc = initPromotionTickContext dflags
    
    51
    -        in  return $ Ppr.mkNamePprCtx ptc unit_env rdr_env
    
    49
    +        withSession $ \ hsc_env -> do
    
    50
    +          query <- liftIO $ hscUnitIndexQuery hsc_env
    
    51
    +          let unit_env = hsc_unit_env hsc_env
    
    52
    +              ptc = initPromotionTickContext dflags
    
    53
    +          return $ Ppr.mkNamePprCtx ptc unit_env query rdr_env
    
    52 54
     
    
    53 55
     printForUser :: GhcMonad m => SDoc -> m ()
    
    54 56
     printForUser doc = do
    

  • ghc/Main.hs
    ... ... @@ -339,6 +339,7 @@ doMake units targets = do
    339 339
           ok_flag <- GHC.load LoadAllTargets
    
    340 340
           when (failed ok_flag) (liftIO $ exitWith (ExitFailure 1))
    
    341 341
     
    
    342
    +
    
    342 343
     -- ---------------------------------------------------------------------------
    
    343 344
     -- Various banners and verbosity output.
    
    344 345
     
    
    ... ... @@ -524,4 +525,3 @@ abiHash strs = do
    524 525
       f <- fingerprintBinMem bh
    
    525 526
     
    
    526 527
       putStrLn (showPpr dflags f)
    527
    -