sheaf pushed to branch wip/romes/27514 at Glasgow Haskell Compiler / GHC

Commits:

18 changed files:

Changes:

  • compiler/GHC.hs
    ... ... @@ -1693,14 +1693,14 @@ findQualifiedModule pkgqual mod_name = withSession $ \hsc_env -> do
    1693 1693
           case home of
    
    1694 1694
             Just m  -> return m
    
    1695 1695
             Nothing -> liftIO $ do
    
    1696
    -           res <- findImportedModule hsc_env LookupUser mod_name pkgqual
    
    1696
    +           res <- runFinderM $ findImportedModule hsc_env LookupUser mod_name pkgqual
    
    1697 1697
                case res of
    
    1698 1698
                  Found loc m | notHomeModuleMaybe mhome_unit m -> return m
    
    1699 1699
                              | otherwise -> modNotLoadedError dflags m loc
    
    1700 1700
                  err -> throwOneError sec $ noModError hsc_env noSrcSpan mod_name err
    
    1701 1701
     
    
    1702 1702
         _ -> liftIO $ do
    
    1703
    -      res <- findImportedModule hsc_env LookupUser mod_name pkgqual
    
    1703
    +      res <- runFinderM $ findImportedModule hsc_env LookupUser mod_name pkgqual
    
    1704 1704
           case res of
    
    1705 1705
             Found _ m -> return m
    
    1706 1706
             err       -> throwOneError sec $ noModError hsc_env noSrcSpan mod_name err
    
    ... ... @@ -1741,7 +1741,7 @@ lookupQualifiedModule NoPkgQual mod_name = withSession $ \hsc_env -> do
    1741 1741
           let dflags = hsc_dflags hsc_env
    
    1742 1742
           let sec    = initSourceErrorContext dflags
    
    1743 1743
           let fopts  = initFinderOpts dflags
    
    1744
    -      res <- findExposedPackageModule fc fopts units LookupUser mod_name NoPkgQual
    
    1744
    +      res <- runFinderM $ findExposedPackageModule fc fopts units LookupUser mod_name NoPkgQual
    
    1745 1745
           case res of
    
    1746 1746
             Found _ m -> return m
    
    1747 1747
             err       -> throwOneError sec $ noModError hsc_env noSrcSpan mod_name err
    
    ... ... @@ -1791,7 +1791,7 @@ lookupAllQualifiedModuleNames NoPkgQual mod_name = withSession $ \hsc_env -> do
    1791 1791
           let dflags = hsc_dflags hsc_env
    
    1792 1792
           let sec    = initSourceErrorContext dflags
    
    1793 1793
           let fopts  = initFinderOpts dflags
    
    1794
    -      res <- findExposedPackageModule fc fopts units LookupUser mod_name NoPkgQual
    
    1794
    +      res <- runFinderM $ findExposedPackageModule fc fopts units LookupUser mod_name NoPkgQual
    
    1795 1795
           case res of
    
    1796 1796
             Found _ m -> return [m]
    
    1797 1797
             err       -> throwOneError sec $ noModError hsc_env noSrcSpan mod_name err
    

  • compiler/GHC/Driver/Concurrency.hs
    ... ... @@ -3,7 +3,7 @@
    3 3
     {-# LANGUAGE BlockArguments #-}
    
    4 4
     
    
    5 5
     module GHC.Driver.Concurrency
    
    6
    -  ( -- * Worker limit and concurrency
    
    6
    +  ( -- * Worker limit
    
    7 7
         WorkerLimit(..)
    
    8 8
     
    
    9 9
         -- * Concurrent worker scheduling
    
    ... ... @@ -17,7 +17,7 @@ module GHC.Driver.Concurrency
    17 17
       , runCoordinatingWorkers
    
    18 18
       , WorkerCoordination(runBlockingAction)
    
    19 19
     
    
    20
    -    -- ** Demand-driven work
    
    20
    +    -- ** Demand-driven work (push-based concurrency)
    
    21 21
       , Demand
    
    22 22
       , Rule
    
    23 23
       , RuleAnswer(..)
    

  • compiler/GHC/Driver/Downsweep.hs
    ... ... @@ -348,7 +348,7 @@ downsweepInteractiveImports hsc_env ic = unsafeInterleaveIO $ do
    348 348
           home_uid = homeUnitId (hsc_home_unit hsc_env)
    
    349 349
           env = DownsweepEnv
    
    350 350
             { ds_hsc_env   = hsc_env
    
    351
    -        , ds_mode      = DownsweepUseGiven
    
    351
    +        , ds_mode      = DownsweepUseFixed
    
    352 352
             , ds_prior     = Map.empty
    
    353 353
             , ds_excl_mods = []
    
    354 354
             }
    
    ... ... @@ -407,7 +407,7 @@ downsweepInstalledModules hsc_env mods = do
    407 407
         -- to this function should already know that we can find the modules we need
    
    408 408
         -- to load.
    
    409 409
         for_ installed_mods $ \ i ->
    
    410
    -      findExactModule hsc_env i NotBoot >>= \case
    
    410
    +      runFinderM (findExactModule hsc_env i NotBoot) >>= \case
    
    411 411
             InstalledFound {} -> return ()
    
    412 412
             _ -> throwGhcException $ ProgramError $ showSDoc (hsc_dflags hsc_env) $
    
    413 413
                    text "downsweepInstalledModules: Could not find installed module" <+> ppr i
    
    ... ... @@ -543,13 +543,14 @@ instance Outputable (Some DownsweepQuery) where
    543 543
     data DownsweepMode
    
    544 544
       -- | @--make@: home modules are summarised from source and compiled.
    
    545 545
       = DownsweepUseCompile
    
    546
    -  -- | One-shot mode: home modules are taken from their interface files, which
    
    547
    -  -- must already exist on disk.
    
    546
    +  -- | Home modules are taken from their interface files (one-shot mode), or
    
    547
    +  -- from the module graph when already present there (GHCi's interactive
    
    548
    +  -- imports, see Note [runTcInteractive module graph]).
    
    549
    +  --
    
    550
    +  -- Whether a module actually exists is decided by its 'Fixed' query: a
    
    551
    +  -- module whose interface cannot be found or read produces no graph node,
    
    552
    +  -- and imports resolving to it produce no edge.
    
    548 553
       | DownsweepUseFixed
    
    549
    -  -- | GHCi's interactive imports: home modules are assumed to be in the module
    
    550
    -  -- graph already, so their interfaces are taken as given rather than looked
    
    551
    -  -- for on disk. See Note [runTcInteractive module graph].
    
    552
    -  | DownsweepUseGiven
    
    553 554
     
    
    554 555
     -- | A 'ModSummary's provenance during downsweep: an old previously constructed
    
    555 556
     -- ModSummary, that might be potentially outdated, or a freshly constructed one
    
    ... ... @@ -725,13 +726,19 @@ downsweepRule :: DownsweepEnv -> Demand DownsweepQuery -> Rule DownsweepQuery
    725 726
     downsweepRule env demand query =
    
    726 727
       case query of
    
    727 728
     
    
    728
    -    Resolve home_uid lkp -> pure $ AnswerDefer \ worker_env -> do
    
    729
    -      -- NB: it might be worth answering inline when the resolution is
    
    730
    -      -- immediately available from the finder cache.
    
    731
    -      resolution <-
    
    732
    -        resolveDownsweepImport (worker_local_env worker_env) home_uid lkp
    
    733
    -      demandResolution demand home_uid resolution
    
    734
    -      return resolution
    
    729
    +    Resolve home_uid lkp -> do
    
    730
    +      mbCached <- runFinderCacheM $ resolveDownsweepImport env home_uid lkp
    
    731
    +      case mbCached of
    
    732
    +        InCache resolution -> do
    
    733
    +          demandResolution demand home_uid resolution
    
    734
    +          return $ AnswerInline resolution
    
    735
    +        NotInCache search -> return $ AnswerDefer \ _worker_env -> do
    
    736
    +          -- The search closes over the downsweep environment rather than the
    
    737
    +          -- worker-local one; that is fine because it neither logs nor uses
    
    738
    +          -- temporary files.
    
    739
    +          resolution <- search
    
    740
    +          demandResolution demand home_uid resolution
    
    741
    +          return resolution
    
    735 742
     
    
    736 743
         Summarise uid path -> pure $ AnswerDefer \ worker_env -> do
    
    737 744
           result <- summariseHomeSourceFile (worker_local_env worker_env) uid path
    
    ... ... @@ -805,41 +812,41 @@ moduleDiscoveries ms = moduleEdgeImports ms ++ boot_source
    805 812
                       | IsBoot <- [isBootSummary ms] ]
    
    806 813
     
    
    807 814
     -- | Resolve a module lookup made from the given home unit.
    
    808
    -resolveDownsweepImport :: DownsweepEnv -> UnitId -> UnresolvedImport PkgQual -> IO ImportResolution
    
    815
    +resolveDownsweepImport :: DownsweepEnv -> UnitId -> UnresolvedImport PkgQual -> FinderM ImportResolution
    
    809 816
     resolveDownsweepImport env home_uid lkp
    
    810 817
       | ui_mod_name lkp `elem` ds_excl_mods env
    
    811
    -  = return ResolvedNotFound
    
    818
    +  = pure ResolvedNotFound
    
    812 819
       | otherwise
    
    813
    -  = do
    
    814
    -      found <- resolveImport hsc_env lkp
    
    815
    -      case found of
    
    816
    -        Found location mod
    
    817
    -          | moduleUnitId mod `Set.member` hsc_all_home_unit_ids hsc_env
    
    818
    -          -> home_module location mod
    
    819
    -          | VirtUnit iud <- moduleUnit mod
    
    820
    -          , not (isHomeModule home_unit mod)
    
    821
    -          -> return $ ResolvedInstantiation iud
    
    822
    -          | otherwise
    
    823
    -          -> return $ ResolvedExternal (moduleUnitId mod)
    
    824
    -        _ -> return ResolvedNotFound
    
    825
    -             -- Not found. If it is TRULY not found at all, we'll error when we
    
    826
    -             -- actually try to compile.
    
    820
    +  = classify =<< resolveImport hsc_env lkp
    
    827 821
       where
    
    828 822
         home_unit = ue_unitHomeUnit home_uid (hsc_unit_env (ds_hsc_env env))
    
    829 823
         -- All operations happen relative to the home unit the import was made from.
    
    830 824
         hsc_env = hscSetActiveHomeUnit home_unit (ds_hsc_env env)
    
    831 825
     
    
    826
    +    classify :: FindResult -> FinderM ImportResolution
    
    827
    +    classify = \case
    
    828
    +      Found location mod
    
    829
    +        | moduleUnitId mod `Set.member` hsc_all_home_unit_ids hsc_env
    
    830
    +        -> home_module location mod
    
    831
    +        | VirtUnit iud <- moduleUnit mod
    
    832
    +        , not (isHomeModule home_unit mod)
    
    833
    +        -> pure $ ResolvedInstantiation iud
    
    834
    +        | otherwise
    
    835
    +        -> pure $ ResolvedExternal (moduleUnitId mod)
    
    836
    +      _ -> pure ResolvedNotFound
    
    837
    +           -- Not found. If it is TRULY not found at all, we'll error when we
    
    838
    +           -- actually try to compile.
    
    839
    +
    
    840
    +    home_module :: ModLocation -> Module -> FinderM ImportResolution
    
    832 841
         home_module location mod = case ds_mode env of
    
    833 842
           DownsweepUseCompile ->
    
    834
    -        return $ case ml_hs_file_ospath location of
    
    843
    +        pure $ case ml_hs_file_ospath location of
    
    835 844
               Just path -> ResolvedHome key path
    
    836 845
               Nothing   -> ResolvedNotFound
    
    837
    -      DownsweepUseFixed -> do
    
    838
    -        -- The finder returns a path to the .hi(-boot) file even if it doesn't
    
    839
    -        -- actually exist, so check before concluding it's there.
    
    840
    -        exists <- doesFileExist (ml_hi_file location)
    
    841
    -        return $ if exists then ResolvedFixed key else ResolvedNotFound
    
    842
    -      DownsweepUseGiven -> return $ ResolvedFixed key
    
    846
    +      DownsweepUseFixed ->
    
    847
    +        -- The resulting 'Fixed' query will determine whether the
    
    848
    +        -- interface file actually exists (see 'DownsweepUseFixed').
    
    849
    +        pure $ ResolvedFixed key
    
    843 850
           where
    
    844 851
             key = moduleToMnk mod (ui_boot lkp)
    
    845 852
     
    
    ... ... @@ -856,7 +863,7 @@ summariseHomeSourceFile env uid path =
    856 863
     -- it records.
    
    857 864
     readFixedModule :: DownsweepEnv -> ModNodeKeyWithUid -> IO (Maybe FixedModule)
    
    858 865
     readFixedModule (DownsweepEnv { ds_hsc_env = hsc_env }) key =
    
    859
    -  findExactModule hsc_env (mnkToInstalledModule key) (mnkIsBoot key) >>= \case
    
    866
    +  runFinderM (findExactModule hsc_env (mnkToInstalledModule key) (mnkIsBoot key)) >>= \case
    
    860 867
         InstalledFound loc -> do
    
    861 868
           -- MP: TODO, we should just read the dependency info from the interface rather than either
    
    862 869
           -- a. Loading the whole thing into the EPS (this might never nececssary and causes lots of things to be permanently loaded into memory)
    
    ... ... @@ -909,9 +916,16 @@ downsweepEdgeTarget answers home_uid lkp =
    909 916
         Nothing -> Nothing
    
    910 917
         Just (Identity resolution) -> case resolution of
    
    911 918
           ResolvedNotFound          -> Nothing
    
    912
    -      ResolvedFixed key         -> Just (NodeKey_Module key)
    
    913 919
           ResolvedExternal uid      -> Just (NodeKey_ExternalUnit uid)
    
    914 920
           ResolvedInstantiation iud -> Just (NodeKey_Unit iud)
    
    921
    +      ResolvedFixed key         ->
    
    922
    +        -- Only emit an edge if the target node actually materialised
    
    923
    +        -- (the interface file of a 'Fixed' node might turn out not to exist,
    
    924
    +        -- e.g. due to the self-boot check).
    
    925
    +        case lookupDMap (Fixed key) answers of
    
    926
    +          Just (Identity (Just {}))
    
    927
    +            -> Just (NodeKey_Module key)
    
    928
    +          _ -> Nothing
    
    915 929
           ResolvedHome key path     ->
    
    916 930
             case lookupDMap (Summarise (mnkUnitId key) path) answers of
    
    917 931
               Just (Identity (SummariseFound ms)) | msKey ms == key
    
    ... ... @@ -1043,7 +1057,7 @@ getRootSummary env target =
    1043 1057
                            { ui_pkg_qual = ThisPkg (homeUnitId home_unit) }
    
    1044 1058
               -- A module target has to name a home module we can compile.
    
    1045 1059
               not_found = return $ Left (moduleNotFoundErr uid modl)
    
    1046
    -      resolution <- resolveDownsweepImport env uid root_imp
    
    1060
    +      resolution <- runFinderM $ resolveDownsweepImport env uid root_imp
    
    1047 1061
           case resolution of
    
    1048 1062
             ResolvedHome key path ->
    
    1049 1063
               summarise (Just (uid, root_imp, resolution)) (mnkUnitId key) path
    

  • compiler/GHC/Driver/Make.hs
    ... ... @@ -318,7 +318,7 @@ warnUnknownModules hsc_env dflags mod_graph = do
    318 318
     
    
    319 319
         hidden_warns = hidden_mods `minusUniqSet` unit_mods
    
    320 320
     
    
    321
    -    lookupModule mn = findImportedModule hsc_env LookupUser mn NoPkgQual
    
    321
    +    lookupModule mn = runFinderM $ findImportedModule hsc_env LookupUser mn NoPkgQual
    
    322 322
     
    
    323 323
         check_reexport mn = do
    
    324 324
           fr <- lookupModule (reexportFrom mn)
    

  • compiler/GHC/Driver/MakeFile.hs
    ... ... @@ -300,7 +300,7 @@ findDependency :: HscEnv
    300 300
     findDependency hsc_env (L srcloc imp) include_pkg_deps = do
    
    301 301
       -- Find the module; this will be fast because
    
    302 302
       -- we've done it once during downsweep.
    
    303
    -  r <- resolveImport hsc_env imp
    
    303
    +  r <- runFinderM $ resolveImport hsc_env imp
    
    304 304
       case r of
    
    305 305
         Found loc _
    
    306 306
             -- Home package: just depend on the .hi or hi-boot file
    

  • compiler/GHC/Iface/Load.hs
    ... ... @@ -293,7 +293,7 @@ lookupKnownName kk_ns name
    293 293
     loadKnownKeyOccMaps :: IfM lcl (MaybeErr IfaceMessage KnownKeyNameMaps)
    
    294 294
     loadKnownKeyOccMaps
    
    295 295
       = do { hsc_env <- getTopEnv
    
    296
    -       ; fr <- liftIO $
    
    296
    +       ; fr <- liftIO $ runFinderM $
    
    297 297
                findImportedModule hsc_env LookupSystem eSSENTIALS_NAME NoPkgQual
    
    298 298
            ; case fr of
    
    299 299
                Found _ mod -> Succeeded <$> known_key_maps mod
    
    ... ... @@ -650,7 +650,7 @@ loadSrcInterface_maybe doc scope mod want_boot maybe_pkg
    650 650
       -- interface; it will call the Finder again, but the ModLocation will be
    
    651 651
       -- cached from the first search.
    
    652 652
       = do hsc_env <- getTopEnv
    
    653
    -       res <- liftIO $ findImportedModule hsc_env scope mod maybe_pkg
    
    653
    +       res <- liftIO $ runFinderM $ findImportedModule hsc_env scope mod maybe_pkg
    
    654 654
            case res of
    
    655 655
                Found _ mod -> initIfaceTcRn $ loadInterface doc mod (ImportByUser want_boot)
    
    656 656
                -- TODO: Make sure this error message is good
    
    ... ... @@ -1237,7 +1237,7 @@ findAndReadIface hsc_env doc_str mod wanted_mod hi_boot_file = do
    1237 1237
                          nest 4 (text "reason:" <+> doc_str)])
    
    1238 1238
     
    
    1239 1239
       -- Look for the file
    
    1240
    -  mb_found <- liftIO (findExactModule hsc_env mod hi_boot_file)
    
    1240
    +  mb_found <- liftIO $ runFinderM $ findExactModule hsc_env mod hi_boot_file
    
    1241 1241
       case mb_found of
    
    1242 1242
           InstalledFound loc -> do
    
    1243 1243
               -- See Note [Home module load error]
    

  • compiler/GHC/Iface/Recomp.hs
    ... ... @@ -658,7 +658,7 @@ checkDependencies hsc_env summary iface
    658 658
        classify_imports imports =
    
    659 659
         liftIO $ traverse (\ (L _ e) ->
    
    660 660
                let reason = ModuleChanged (ui_mod_name e)
    
    661
    -           in classify (ui_level e) reason <$> resolveImport hsc_env e)
    
    661
    +           in classify (ui_level e) reason <$> runFinderM (resolveImport hsc_env e))
    
    662 662
                imports
    
    663 663
     
    
    664 664
        logger        = hsc_logger hsc_env
    

  • compiler/GHC/Linker/Deps.hs
    ... ... @@ -168,7 +168,7 @@ get_link_deps opts pls maybe_normal_osuf span mods = do
    168 168
     
    
    169 169
                   let fc = ldFinderCache opts
    
    170 170
                   let fopts = ldFinderOpts opts
    
    171
    -              mb_stuff <- findHomeModule fc fopts home_unit (moduleName mod)
    
    171
    +              mb_stuff <- runFinderM $ findHomeModule fc fopts home_unit (moduleName mod)
    
    172 172
                   case mb_stuff of
    
    173 173
                     Found loc _ -> do
    
    174 174
                       from_bc <- ldLoadByteCode opts mod loc
    
    ... ... @@ -179,7 +179,7 @@ get_link_deps opts pls maybe_normal_osuf span mods = do
    179 179
                 fallback_no_bytecode home_unit mod = do
    
    180 180
                   let fc = ldFinderCache opts
    
    181 181
                   let fopts = ldFinderOpts opts
    
    182
    -              mb_stuff <- findHomeModule fc fopts home_unit (moduleName mod)
    
    182
    +              mb_stuff <- runFinderM $ findHomeModule fc fopts home_unit (moduleName mod)
    
    183 183
                   case mb_stuff of
    
    184 184
                     Found loc _ -> do
    
    185 185
                       mb_lnk <- findObjectLinkableMaybe mod loc
    

  • compiler/GHC/Runtime/Loader.hs
    ... ... @@ -57,7 +57,7 @@ import GHC.Types.Name.Occurrence ( OccName, mkVarOccFS )
    57 57
     import GHC.Types.Name.Reader
    
    58 58
     import GHC.Types.Unique.DFM
    
    59 59
     
    
    60
    -import GHC.Unit.Finder         ( findPluginModule, FindResult(..) )
    
    60
    +import GHC.Unit.Finder ( FindResult(..), runFinderM, findPluginModule )
    
    61 61
     import GHC.Driver.Config.Diagnostic ( initIfaceMessageOpts )
    
    62 62
     import GHC.Unit.Module   ( Module, ModuleName, thisGhcUnit, GenModule(moduleUnit), IsBootInterface(NotBoot) )
    
    63 63
     import GHC.Unit.Module.ModIface
    
    ... ... @@ -345,7 +345,7 @@ lookupRdrNameInModuleForPlugins :: HasDebugCallStack
    345 345
     lookupRdrNameInModuleForPlugins hsc_env mod_name rdr_name = do
    
    346 346
         let dflags     = hsc_dflags hsc_env
    
    347 347
         -- First find the unit the module resides in by searching exposed units and home modules
    
    348
    -    found_module <- findPluginModule hsc_env mod_name
    
    348
    +    found_module <- runFinderM $ findPluginModule hsc_env mod_name
    
    349 349
         case found_module of
    
    350 350
             Found _ mod -> do
    
    351 351
                 -- Find the exports of the module
    

  • compiler/GHC/StgToJS/Linker/Linker.hs
    ... ... @@ -118,7 +118,7 @@ import System.Directory ( createDirectoryIfMissing
    118 118
                             )
    
    119 119
     
    
    120 120
     import GHC.Unit.Finder.Types
    
    121
    -import GHC.Unit.Finder (findObjectLinkableMaybe, findHomeModule)
    
    121
    +import GHC.Unit.Finder (findObjectLinkableMaybe, findHomeModule, runFinderM)
    
    122 122
     import GHC.Driver.Config.Finder (initFinderOpts)
    
    123 123
     import qualified GHC.Unit.Home.Graph as HUG
    
    124 124
     
    
    ... ... @@ -491,7 +491,7 @@ computeLinkDependencies cfg unit_env link_spec finder_opts finder_cache ar_cache
    491 491
                   case ue_homeUnit unit_env of
    
    492 492
                     Nothing -> pprPanic "getDeps: No home-unit: " (pprModule mod)
    
    493 493
                     Just home_unit -> do
    
    494
    -                    mb_stuff <- findHomeModule finder_cache finder_opts home_unit (moduleName mod)
    
    494
    +                    mb_stuff <- runFinderM $ findHomeModule finder_cache finder_opts home_unit (moduleName mod)
    
    495 495
                         case mb_stuff of
    
    496 496
                           Found loc mod -> found loc mod
    
    497 497
                           _ -> pprPanic "getDeps: Couldn't find home-module: " (pprModule mod)
    

  • compiler/GHC/Tc/Gen/Splice.hs
    ... ... @@ -1633,7 +1633,7 @@ metaHandlersTcM runInIO = TH.MetaHandlers {
    1633 1633
             let home_unit = hsc_home_unit hsc_env
    
    1634 1634
             let dflags    = hsc_dflags hsc_env
    
    1635 1635
             let fopts     = initFinderOpts dflags
    
    1636
    -        r <- liftIO $ findHomeModule fc fopts home_unit (mkModuleName plugin)
    
    1636
    +        r <- liftIO $ runFinderM $ findHomeModule fc fopts home_unit (mkModuleName plugin)
    
    1637 1637
             let err = TcRnTHError $ AddInvalidCorePlugin plugin
    
    1638 1638
             case r of
    
    1639 1639
               Found {} -> addErr err
    

  • compiler/GHC/Tc/Plugin.hs
    ... ... @@ -104,7 +104,8 @@ tcPluginTrace a b = unsafeTcPluginTcM (traceTc a b)
    104 104
     findImportedModule :: ModuleName -> PkgQual -> TcPluginM Finder.FindResult
    
    105 105
     findImportedModule mod_name mb_pkg = do
    
    106 106
         hsc_env <- getTopEnv
    
    107
    -    tcPluginIO $ Finder.findImportedModule hsc_env Finder.LookupUser mod_name mb_pkg
    
    107
    +    tcPluginIO $ Finder.runFinderM $
    
    108
    +      Finder.findImportedModule hsc_env Finder.LookupUser mod_name mb_pkg
    
    108 109
     
    
    109 110
     lookupOrig :: Module -> OccName -> TcPluginM Name
    
    110 111
     lookupOrig mod = unsafeTcPluginTcM . IfaceEnv.lookupOrig mod
    

  • compiler/GHC/Tc/Utils/Backpack.hs
    ... ... @@ -284,7 +284,7 @@ implicitRequirements :: HscEnv
    284 284
     implicitRequirements hsc_env normal_imports
    
    285 285
       = fmap concat $
    
    286 286
         forM normal_imports $ \e -> do
    
    287
    -        found <- resolveImport hsc_env e
    
    287
    +        found <- runFinderM $ resolveImport hsc_env e
    
    288 288
             case found of
    
    289 289
                 Found _ mod | notHomeModuleMaybe mhome_unit mod ->
    
    290 290
                     return (uniqDSetToList (moduleFreeHoles mod))
    
    ... ... @@ -306,7 +306,7 @@ implicitRequirementsShallow hsc_env normal_imports = go [] normal_imports
    306 306
     
    
    307 307
       go acc [] = pure acc
    
    308 308
       go accR (e:imports) = do
    
    309
    -    found <- resolveImport hsc_env e
    
    309
    +    found <- runFinderM $ resolveImport hsc_env e
    
    310 310
         let acc' = case found of
    
    311 311
               Found _ mod | notHomeModuleMaybe mhome_unit mod ->
    
    312 312
                   case moduleUnit mod of
    

  • compiler/GHC/Unit/Finder.hs
    ... ... @@ -4,18 +4,28 @@
    4 4
     -}
    
    5 5
     
    
    6 6
     
    
    7
    -{-# LANGUAGE RecordWildCards  #-}
    
    7
    +{-# LANGUAGE RecordWildCards #-}
    
    8 8
     
    
    9 9
     -- | Module finder
    
    10 10
     module GHC.Unit.Finder (
    
    11
    +
    
    12
    +    -- * Finder result
    
    11 13
         FindResult(..),
    
    12 14
         InstalledFindResult(..),
    
    15
    +
    
    16
    +    -- * Finder cache
    
    13 17
         FinderOpts(..),
    
    14 18
         FinderCache(..),
    
    15 19
         initFinderCache,
    
    20
    +
    
    21
    +    -- ** Finder monad
    
    22
    +    FinderM, runFinderCacheM, runFinderM,
    
    23
    +    InCache(..),
    
    24
    +
    
    25
    +    -- * Finder operations
    
    26
    +    ModuleLookupScope(..),
    
    16 27
         findImportedModule,
    
    17 28
         resolveImport,
    
    18
    -    ModuleLookupScope(..),
    
    19 29
         findPluginModule,
    
    20 30
         findExactModule,
    
    21 31
         findHomeModule,
    
    ... ... @@ -85,6 +95,9 @@ import qualified System.Directory as SD
    85 95
     import qualified System.OsPath as OsPath
    
    86 96
     import qualified Data.List.NonEmpty as NE
    
    87 97
     
    
    98
    +import GHC.TypeError (ErrorMessage(..), Unsatisfiable, unsatisfiable)
    
    99
    +import Control.Monad.IO.Class
    
    100
    +
    
    88 101
     type FileExt = OsString -- Filename extension
    
    89 102
     type BaseName = OsPath  -- Basename of file
    
    90 103
     
    
    ... ... @@ -173,6 +186,96 @@ getDirHash dir = do
    173 186
       let hash    = fingerprintFingerprints s_hashes
    
    174 187
       return hash
    
    175 188
     
    
    189
    +-- -----------------------------------------------------------------------------
    
    190
    +-- Finder monad, handling finder cache hits
    
    191
    +
    
    192
    +-- | The result of a lookup that consults the finder caches before searching
    
    193
    +-- the file system.
    
    194
    +data InCache a
    
    195
    +  -- | The result was in a cache; no filesystem access was performed.
    
    196
    +  = InCache !a
    
    197
    +  -- | The result was not cached.
    
    198
    +  | NotInCache (IO a) -- ^ search action to compute the result
    
    199
    +                      -- (may perform filesystem access)
    
    200
    +  deriving stock Functor
    
    201
    +
    
    202
    +-- | Monad for finder operations.
    
    203
    +--
    
    204
    +-- A finder operation is split into two phases:
    
    205
    +--
    
    206
    +--  - a cache-only phase with no filesystem access,
    
    207
    +--  - from the first cache miss onwards, a residual 'IO' computation that may
    
    208
    +--    access the filesystem.
    
    209
    +newtype FinderM a =
    
    210
    +  FinderM (IO (InCache a))
    
    211
    +    -- ^ Invariant: the I/O action only performs benign I/O (such as reading
    
    212
    +    -- from the finder cache, i.e. 'lookupFinderCache').
    
    213
    +    --
    
    214
    +    -- It is not allowed to perform any filesystem access.
    
    215
    +
    
    216
    +-- | Like 'runFinderM', but separates the finder action into the cache lookup
    
    217
    +-- and the search action.
    
    218
    +runFinderCacheM :: FinderM a -> IO (InCache a)
    
    219
    +runFinderCacheM (FinderM f) = f
    
    220
    +
    
    221
    +-- | Run a finder action.
    
    222
    +runFinderM :: FinderM a -> IO a
    
    223
    +runFinderM = inCache_result <=< runFinderCacheM
    
    224
    +
    
    225
    +instance Functor FinderM where
    
    226
    +  fmap f (FinderM io) = FinderM $ fmap (fmap f) io
    
    227
    +
    
    228
    +instance Applicative FinderM where
    
    229
    +  pure = FinderM . pure . InCache
    
    230
    +  (<*>) = ap
    
    231
    +
    
    232
    +-- | Sequencing of finder computations: the overall computation remains
    
    233
    +-- "in the cache" as long as every individual step completes "in the cache".
    
    234
    +--
    
    235
    +-- After the first cache miss, all residual operations (including further
    
    236
    +-- cache lookups) move into the search action.
    
    237
    +instance Monad FinderM where
    
    238
    +  FinderM io >>= f = FinderM $ io >>= \ case
    
    239
    +    InCache a -> runFinderCacheM (f a)
    
    240
    +    NotInCache go -> pure $ NotInCache $
    
    241
    +      go >>= \ a -> inCache_result =<< runFinderCacheM (f a)
    
    242
    +
    
    243
    +-- | There is no lawful 'MonadIO' instance for 'FinderM': to guarantee that
    
    244
    +-- @liftIO . pure = pure@, 'liftIO' would have to run the action in the
    
    245
    +-- cache-only phase, defeating the guarantee that 'InCache' results involve
    
    246
    +-- no filesystem access.
    
    247
    +--
    
    248
    +-- All I/O in 'FinderM' enters through 'withCacheOrElse'.
    
    249
    +instance
    
    250
    +  Unsatisfiable
    
    251
    +    (     Text "No (lawful) 'MonadIO' instance for 'FinderM'."
    
    252
    +     :$$: Text "Use 'withCacheOrElse' to embed an I/O operation into the search phase of 'FinderM'."
    
    253
    +    )
    
    254
    +  => MonadIO FinderM where
    
    255
    +  liftIO = unsatisfiable
    
    256
    +
    
    257
    +-- | Obtain the result from an 'InCache' value, running the inner search
    
    258
    +-- operation in case of a cache miss.
    
    259
    +inCache_result :: InCache a -> IO a
    
    260
    +inCache_result (InCache a)     = pure a
    
    261
    +inCache_result (NotInCache go) = go
    
    262
    +
    
    263
    +-- | Look up an 'InstalledModule' in the finder cache, falling back to the
    
    264
    +-- given search action in case of cache miss (recording its result in the cache).
    
    265
    +withCacheOrElse
    
    266
    +  :: FinderCache
    
    267
    +  -> InstalledModule
    
    268
    +  -> IO InstalledFindResult -- ^ search action (only executed on cache miss)
    
    269
    +  -> FinderM InstalledFindResult
    
    270
    +withCacheOrElse fc mod search = FinderM $ do
    
    271
    +  m <- lookupFinderCache fc mod
    
    272
    +  case m of
    
    273
    +    Just result -> pure $ InCache result
    
    274
    +    Nothing     -> pure $ NotInCache $ do
    
    275
    +      result <- search
    
    276
    +      addToFinderCache fc mod result
    
    277
    +      return result
    
    278
    +
    
    176 279
     -- -----------------------------------------------------------------------------
    
    177 280
     --External entry points
    
    178 281
     
    
    ... ... @@ -180,7 +283,7 @@ getDirHash dir = do
    180 283
     --
    
    181 284
     -- Handles user-written module imports, @SOURCE@ imports, plugin module imports,
    
    182 285
     -- system imports, etc.
    
    183
    -resolveImport :: HscEnv -> UnresolvedImport PkgQual -> IO FindResult
    
    286
    +resolveImport :: HscEnv -> UnresolvedImport PkgQual -> FinderM FindResult
    
    184 287
     resolveImport hsc_env (UnresolvedImport { ui_scope, ui_pkg_qual, ui_boot, ui_mod_name }) = do
    
    185 288
       res <- findImportedModule hsc_env ui_scope ui_mod_name ui_pkg_qual
    
    186 289
       case (res, ui_boot) of
    
    ... ... @@ -196,7 +299,7 @@ findImportedModule
    196 299
          -- ^ The module name to look up
    
    197 300
       -> PkgQual
    
    198 301
          -- ^ Optional PackageImports package name
    
    199
    -  -> IO FindResult
    
    302
    +  -> FinderM FindResult
    
    200 303
     findImportedModule hsc_env scope mod pkg_qual =
    
    201 304
       let fc           = hsc_FC hsc_env
    
    202 305
           mb_home_unit = hsc_home_unit_maybe hsc_env
    
    ... ... @@ -223,7 +326,7 @@ findImportedModuleNoHsc
    223 326
       -> ModuleLookupScope
    
    224 327
       -> ModuleName
    
    225 328
       -> PkgQual
    
    226
    -  -> IO FindResult
    
    329
    +  -> FinderM FindResult
    
    227 330
     findImportedModuleNoHsc fc fopts ue home_module_name_providers_map mb_home_unit scope mod_name mb_pkg
    
    228 331
       | LookupPlugin <- scope
    
    229 332
       = findPluginModuleNoHsc fc fopts ue home_module_name_providers_map mb_home_unit mod_name
    
    ... ... @@ -254,19 +357,19 @@ findImportedModuleNoHsc fc fopts ue home_module_name_providers_map mb_home_unit
    254 357
             Nothing           -> other_fopts
    
    255 358
             Just home_unit_id -> (home_unit_id, fopts) : other_fopts
    
    256 359
     
    
    257
    -    home_import :: IO FindResult
    
    360
    +    home_import :: FinderM FindResult
    
    258 361
         home_import = case mb_home_unit of
    
    259 362
             Just home_unit -> findHomeModule fc fopts home_unit mod_name
    
    260 363
             Nothing        -> pure $
    
    261 364
                               NoPackage (panic "findImportedModule: no home-unit")
    
    262 365
     
    
    263
    -    home_pkg_import :: (UnitId, FinderOpts) -> IO FindResult
    
    366
    +    home_pkg_import :: (UnitId, FinderOpts) -> FinderM FindResult
    
    264 367
         home_pkg_import = findHomeUnitDepModule fc ue home_module_name_providers_map scope mod_name
    
    265 368
     
    
    266
    -    pkg_import :: IO FindResult
    
    369
    +    pkg_import :: FinderM FindResult
    
    267 370
         pkg_import = findExposedPackageModule fc fopts unit_state scope mod_name mb_pkg
    
    268 371
     
    
    269
    -    unqual_import :: IO FindResult
    
    372
    +    unqual_import :: FinderM FindResult
    
    270 373
         unqual_import = findHomeOrRegularPackageModule fc fopts ue
    
    271 374
                             home_module_name_providers_map mb_home_unit scope mod_name
    
    272 375
     
    
    ... ... @@ -291,7 +394,7 @@ findPluginModuleNoHsc
    291 394
       -> HomeModuleNameProvidersMap
    
    292 395
       -> Maybe HomeUnit
    
    293 396
       -> ModuleName
    
    294
    -  -> IO FindResult
    
    397
    +  -> FinderM FindResult
    
    295 398
     findPluginModuleNoHsc fc fopts ue home_module_name_providers_map mb_home_unit@(Just home_unit) mod_name =
    
    296 399
         findHomeModuleAmongDeps fc fopts ue home_module_name_providers_map
    
    297 400
                                 mb_home_unit LookupUser mod_name
    
    ... ... @@ -303,7 +406,7 @@ findPluginModuleNoHsc fc fopts ue home_module_name_providers_map mb_home_unit@(J
    303 406
     findPluginModuleNoHsc fc fopts ue _ Nothing mod_name =
    
    304 407
       findExposedPluginPackageModule fc fopts (ue_homeUnitState ue) mod_name
    
    305 408
     
    
    306
    -findPluginModule :: HscEnv -> ModuleName -> IO FindResult
    
    409
    +findPluginModule :: HscEnv -> ModuleName -> FinderM FindResult
    
    307 410
     findPluginModule hsc_env mod_name = do
    
    308 411
       let fc           = hsc_FC hsc_env
    
    309 412
           mb_home_unit = hsc_home_unit_maybe hsc_env
    
    ... ... @@ -375,7 +478,7 @@ findHomeUnitDepModule
    375 478
       -> ModuleLookupScope
    
    376 479
       -> ModuleName
    
    377 480
       -> (UnitId, FinderOpts)
    
    378
    -  -> IO FindResult
    
    481
    +  -> FinderM FindResult
    
    379 482
     findHomeUnitDepModule fc ue home_module_name_providers_map scope mod_name (uid, opts)
    
    380 483
         -- If the module is reexported, then look for it as if it was from the
    
    381 484
         -- perspective of the package which reexports it.
    
    ... ... @@ -402,7 +505,7 @@ findHomeModuleAmongDeps
    402 505
       -> Maybe HomeUnit
    
    403 506
       -> ModuleLookupScope
    
    404 507
       -> ModuleName
    
    405
    -  -> IO FindResult
    
    508
    +  -> FinderM FindResult
    
    406 509
     findHomeModuleAmongDeps fc fopts ue home_module_name_providers_map mb_home_unit scope mod_name =
    
    407 510
         foldr1 orIfNotFound (home_import :| map home_pkg_import other_fopts)
    
    408 511
         -- Do not try to be smart and change this to `foldr orIfNotFound home_import
    
    ... ... @@ -433,7 +536,7 @@ findHomeOrRegularPackageModule
    433 536
       -> Maybe HomeUnit
    
    434 537
       -> ModuleLookupScope
    
    435 538
       -> ModuleName
    
    436
    -  -> IO FindResult
    
    539
    +  -> FinderM FindResult
    
    437 540
     findHomeOrRegularPackageModule fc fopts ue home_module_name_providers_map mb_home_unit scope mod_name =
    
    438 541
         findHomeModuleAmongDeps fc fopts ue home_module_name_providers_map
    
    439 542
                                 mb_home_unit scope mod_name
    
    ... ... @@ -448,7 +551,15 @@ findHomeOrRegularPackageModule fc fopts ue home_module_name_providers_map mb_hom
    448 551
     
    
    449 552
     -- | A version of findExactModule which takes the exact parts of the HscEnv it needs
    
    450 553
     -- directly.
    
    451
    -findExactModuleNoHsc :: FinderCache -> FinderOpts -> UnitEnvGraph FinderOpts -> UnitState -> Maybe HomeUnit -> InstalledModule -> IsBootInterface -> IO InstalledFindResult
    
    554
    +findExactModuleNoHsc
    
    555
    +  :: FinderCache
    
    556
    +  -> FinderOpts
    
    557
    +  -> UnitEnvGraph FinderOpts
    
    558
    +  -> UnitState
    
    559
    +  -> Maybe HomeUnit
    
    560
    +  -> InstalledModule
    
    561
    +  -> IsBootInterface
    
    562
    +  -> FinderM InstalledFindResult
    
    452 563
     findExactModuleNoHsc fc fopts other_fopts unit_state mb_home_unit mod is_boot = do
    
    453 564
       res <- case mb_home_unit of
    
    454 565
         Just home_unit
    
    ... ... @@ -461,13 +572,12 @@ findExactModuleNoHsc fc fopts other_fopts unit_state mb_home_unit mod is_boot =
    461 572
         (InstalledFound loc, IsBoot) -> return (InstalledFound (addBootSuffixLocn loc))
    
    462 573
         _ -> return res
    
    463 574
     
    
    464
    -
    
    465 575
     -- | Locate a specific 'Module'.  The purpose of this function is to
    
    466 576
     -- create a 'ModLocation' for a given 'Module', that is to find out
    
    467 577
     -- where the files associated with this module live.  It is used when
    
    468 578
     -- reading the interface for a module mentioned by another interface,
    
    469 579
     -- for example (a "system import").
    
    470
    -findExactModule :: HscEnv -> InstalledModule -> IsBootInterface -> IO InstalledFindResult
    
    580
    +findExactModule :: HscEnv -> InstalledModule -> IsBootInterface -> FinderM InstalledFindResult
    
    471 581
     findExactModule hsc_env mod is_boot = do
    
    472 582
       let dflags = hsc_dflags hsc_env
    
    473 583
       let fc = hsc_FC hsc_env
    
    ... ... @@ -476,7 +586,6 @@ findExactModule hsc_env mod is_boot = do
    476 586
       let other_fopts = initFinderOpts . homeUnitEnv_dflags <$> (hsc_HUG hsc_env)
    
    477 587
       findExactModuleNoHsc fc (initFinderOpts dflags) other_fopts unit_state home_unit mod is_boot
    
    478 588
     
    
    479
    -
    
    480 589
     -- -----------------------------------------------------------------------------
    
    481 590
     -- Helpers
    
    482 591
     
    
    ... ... @@ -504,28 +613,17 @@ orIfNotFound this or_this = do
    504 613
                  _other -> return res2
    
    505 614
         _other -> return res
    
    506 615
     
    
    507
    --- | Helper function for 'findHomeModule': this function wraps an IO action
    
    508
    --- which would look up @mod_name@ in the file system (the home package),
    
    509
    --- and first consults the 'hsc_FC' cache to see if the lookup has already
    
    510
    --- been done.  Otherwise, do the lookup (with the IO action) and save
    
    511
    --- the result in the finder cache and the module location cache (if it
    
    512
    --- was successful.)
    
    513
    -homeSearchCache :: FinderCache -> UnitId -> ModuleName -> IO InstalledFindResult -> IO InstalledFindResult
    
    514
    -homeSearchCache fc home_unit mod_name do_this = do
    
    515
    -  let mod = mkModule home_unit mod_name
    
    516
    -  modLocationCache fc mod do_this
    
    517
    -
    
    518
    -findExposedPackageModule :: FinderCache -> FinderOpts -> UnitState -> ModuleLookupScope -> ModuleName -> PkgQual -> IO FindResult
    
    616
    +findExposedPackageModule :: FinderCache -> FinderOpts -> UnitState -> ModuleLookupScope -> ModuleName -> PkgQual -> FinderM FindResult
    
    519 617
     findExposedPackageModule fc fopts units scope mod_name mb_pkg =
    
    520 618
       findLookupResult fc fopts
    
    521 619
         $ lookupModuleWithSuggestions units scope mod_name mb_pkg
    
    522 620
     
    
    523
    -findExposedPluginPackageModule :: FinderCache -> FinderOpts -> UnitState -> ModuleName -> IO FindResult
    
    621
    +findExposedPluginPackageModule :: FinderCache -> FinderOpts -> UnitState -> ModuleName -> FinderM FindResult
    
    524 622
     findExposedPluginPackageModule fc fopts units mod_name =
    
    525 623
       findLookupResult fc fopts
    
    526 624
         $ lookupPluginModuleWithSuggestions units LookupUser mod_name NoPkgQual
    
    527 625
     
    
    528
    -findLookupResult :: FinderCache -> FinderOpts -> LookupResult -> IO FindResult
    
    626
    +findLookupResult :: FinderCache -> FinderOpts -> LookupResult -> FinderM FindResult
    
    529 627
     findLookupResult fc fopts r = case r of
    
    530 628
          LookupFound m pkg_conf -> do
    
    531 629
            let im = fst (getModuleInstantiation m)
    
    ... ... @@ -570,16 +668,6 @@ findLookupResult fc fopts r = case r of
    570 668
                            , fr_unusables = []
    
    571 669
                            , fr_suggestions = suggest' })
    
    572 670
     
    
    573
    -modLocationCache :: FinderCache -> InstalledModule -> IO InstalledFindResult -> IO InstalledFindResult
    
    574
    -modLocationCache fc mod do_this = do
    
    575
    -  m <- lookupFinderCache fc mod
    
    576
    -  case m of
    
    577
    -    Just result -> return result
    
    578
    -    Nothing     -> do
    
    579
    -        result <- do_this
    
    580
    -        addToFinderCache fc mod result
    
    581
    -        return result
    
    582
    -
    
    583 671
     addModuleToFinder :: FinderCache -> Module -> ModLocation -> HscSource -> IO ()
    
    584 672
     addModuleToFinder fc mod loc src_flavour = do
    
    585 673
       let imod = toUnitId <$> mod
    
    ... ... @@ -597,7 +685,7 @@ addHomeModuleToFinder fc home_unit mod_name loc src_flavour = do
    597 685
     -- -----------------------------------------------------------------------------
    
    598 686
     --      The internal workers
    
    599 687
     
    
    600
    -findHomeModule :: FinderCache -> FinderOpts -> HomeUnit -> ModuleName -> IO FindResult
    
    688
    +findHomeModule :: FinderCache -> FinderOpts -> HomeUnit -> ModuleName -> FinderM FindResult
    
    601 689
     findHomeModule fc fopts  home_unit mod_name = do
    
    602 690
       let uid       = homeUnitAsUnit home_unit
    
    603 691
       r <- findInstalledHomeModule fc fopts (homeUnitId home_unit) mod_name
    
    ... ... @@ -622,7 +710,7 @@ mkHomeHidden uid =
    622 710
                , fr_unusables = []
    
    623 711
                , fr_suggestions = []}
    
    624 712
     
    
    625
    -findHomePackageModule :: FinderCache -> FinderOpts -> UnitId -> ModuleName -> IO FindResult
    
    713
    +findHomePackageModule :: FinderCache -> FinderOpts -> UnitId -> ModuleName -> FinderM FindResult
    
    626 714
     findHomePackageModule fc fopts  home_unit mod_name = do
    
    627 715
       let uid       = RealUnit (Definite home_unit)
    
    628 716
       r <- findInstalledHomeModule fc fopts home_unit mod_name
    
    ... ... @@ -655,9 +743,9 @@ findHomePackageModule fc fopts home_unit mod_name = do
    655 743
     --
    
    656 744
     --  4. Some special-case code in GHCi (ToDo: Figure out why that needs to
    
    657 745
     --  call this.)
    
    658
    -findInstalledHomeModule :: FinderCache -> FinderOpts -> UnitId -> ModuleName -> IO InstalledFindResult
    
    659
    -findInstalledHomeModule fc fopts home_unit mod_name = do
    
    660
    -  homeSearchCache fc home_unit mod_name $
    
    746
    +findInstalledHomeModule :: FinderCache -> FinderOpts -> UnitId -> ModuleName -> FinderM InstalledFindResult
    
    747
    +findInstalledHomeModule fc fopts home_unit mod_name =
    
    748
    +  withCacheOrElse fc (mkModule home_unit mod_name) $
    
    661 749
        let
    
    662 750
          maybe_working_dir = finder_workingDirectory fopts
    
    663 751
          home_path = case maybe_working_dir of
    
    ... ... @@ -701,7 +789,7 @@ augmentImports work_dir (fp:fps)
    701 789
       | otherwise            = (work_dir </> fp) : augmentImports work_dir fps
    
    702 790
     
    
    703 791
     -- | Search for a module in external packages only.
    
    704
    -findPackageModule :: FinderCache -> UnitState -> FinderOpts -> InstalledModule -> IO InstalledFindResult
    
    792
    +findPackageModule :: FinderCache -> UnitState -> FinderOpts -> InstalledModule -> FinderM InstalledFindResult
    
    705 793
     findPackageModule fc unit_state fopts mod = do
    
    706 794
       let pkg_id = moduleUnit mod
    
    707 795
       case lookupUnitId unit_state pkg_id of
    
    ... ... @@ -715,11 +803,11 @@ findPackageModule fc unit_state fopts mod = do
    715 803
     -- the 'UnitInfo' must be consistent with the unit id in the 'Module'.
    
    716 804
     -- The redundancy is to avoid an extra lookup in the package state
    
    717 805
     -- for the appropriate config.
    
    718
    -findPackageModule_ :: FinderCache -> FinderOpts -> InstalledModule -> UnitInfo -> IO InstalledFindResult
    
    806
    +findPackageModule_ :: FinderCache -> FinderOpts -> InstalledModule -> UnitInfo -> FinderM InstalledFindResult
    
    719 807
     findPackageModule_ fc fopts mod pkg_conf = do
    
    720 808
       massertPpr (moduleUnit mod == unitId pkg_conf)
    
    721 809
                  (ppr (moduleUnit mod) <+> ppr (unitId pkg_conf))
    
    722
    -  modLocationCache fc mod $
    
    810
    +  withCacheOrElse fc mod $
    
    723 811
         let
    
    724 812
            tag = waysBuildTag (finder_ways fopts)
    
    725 813
     
    

  • ghc/GHCi/UI.hs
    ... ... @@ -2378,7 +2378,7 @@ addModule files = do
    2378 2378
         checkTargetModule :: GhciMonad m => ModuleName -> m Bool
    
    2379 2379
         checkTargetModule m = do
    
    2380 2380
           hsc_env <- GHC.getSession
    
    2381
    -      result <- liftIO $
    
    2381
    +      result <- liftIO $ Finder.runFinderM $
    
    2382 2382
             Finder.findImportedModule hsc_env Finder.LookupUser m NoPkgQual
    
    2383 2383
           case result of
    
    2384 2384
             Found _ _ -> return True
    

  • ghc/Main.hs
    ... ... @@ -45,7 +45,7 @@ import GHC.Runtime.Loader ( loadFrontendPlugin, initializeSessionPlugins )
    45 45
     import GHC.Unit.Module ( ModuleName, mkModuleName )
    
    46 46
     import GHC.Unit.Module.ModIface
    
    47 47
     import GHC.Unit.State  ( pprUnits, pprUnitsSimple )
    
    48
    -import GHC.Unit.Finder ( findImportedModule, FindResult(..) )
    
    48
    +import GHC.Unit.Finder ( findImportedModule, runFinderM, FindResult(..) )
    
    49 49
     import GHC.Unit.Types  ( IsBootInterface(..) )
    
    50 50
     
    
    51 51
     import GHC.Types.Basic     ( failed )
    
    ... ... @@ -492,7 +492,7 @@ abiHash strs = do
    492 492
     
    
    493 493
       let find_it str = do
    
    494 494
              let modname = mkModuleName str
    
    495
    -         r <- findImportedModule hsc_env LookupUser modname NoPkgQual
    
    495
    +         r <- runFinderM $ findImportedModule hsc_env LookupUser modname NoPkgQual
    
    496 496
              case r of
    
    497 497
                Found _ m -> return m
    
    498 498
                _error    ->
    

  • linters/lint-codes/LintCodes/Static.hs
    ... ... @@ -67,7 +67,7 @@ import GHC.Types.PkgQual
    67 67
     import GHC.Tc.Utils.Monad
    
    68 68
       ( initIfaceLoad )
    
    69 69
     import GHC.Unit.Finder
    
    70
    -  ( FindResult(..), ModuleLookupScope(..), findImportedModule )
    
    70
    +  ( FindResult(..), ModuleLookupScope(..), findImportedModule, runFinderM )
    
    71 71
     import GHC.Utils.Outputable
    
    72 72
       ( text )
    
    73 73
     import Language.Haskell.Syntax.Module.Name
    
    ... ... @@ -157,7 +157,7 @@ ghcDiagnosticCodeTyCon mb_libDir =
    157 157
          ; liftIO
    
    158 158
     
    
    159 159
       -- STEP 2: look up the module "GHC.Types.Error.Codes"
    
    160
    -  do { res <- findImportedModule hsc_env LookupUser (mkModuleName "GHC.Types.Error.Codes") NoPkgQual
    
    160
    +  do { res <- runFinderM $ findImportedModule hsc_env LookupUser (mkModuleName "GHC.Types.Error.Codes") NoPkgQual
    
    161 161
          ; case res of
    
    162 162
          { Found _ modl ->
    
    163 163
     
    

  • utils/haddock/haddock-api/src/Haddock/Interface.hs
    ... ... @@ -69,7 +69,7 @@ import GHC.Tc.Utils.Monad (initIfaceLoad, initIfaceLcl)
    69 69
     import GHC.Tc.Utils.Env (lookupGlobal_maybe)
    
    70 70
     import GHC.Types.Error (mkUnknownDiagnostic)
    
    71 71
     import GHC.Types.Name.Occurrence (emptyOccEnv)
    
    72
    -import GHC.Unit.Finder (findImportedModule, ModuleLookupScope(..), FindResult(Found))
    
    72
    +import GHC.Unit.Finder (findImportedModule, runFinderM, ModuleLookupScope(..), FindResult(Found))
    
    73 73
     import GHC.Unit.Home.ModInfo
    
    74 74
     import GHC.Unit.Home.PackageTable
    
    75 75
     import GHC.Unit.Module.Graph (ModuleGraphNode (..), ModuleNodeInfo(..))
    
    ... ... @@ -386,7 +386,7 @@ createOneShotIface verbosity flags instIfaceMap moduleNameStr = do
    386 386
                       Nothing -> dflags
    
    387 387
     
    
    388 388
       -- We should find the module here, otherwise there would have been an error earlier.
    
    389
    -  res <- liftIO $ findImportedModule hsc_env LookupUser moduleNm NoPkgQual
    
    389
    +  res <- liftIO $ runFinderM $ findImportedModule hsc_env LookupUser moduleNm NoPkgQual
    
    390 390
       let hieFilePath = case res of
    
    391 391
                           Found ml _ -> ml_hie_file ml
    
    392 392
                           _ -> throwE "createOneShotIface: module not found"