Hannes Siebenhandl pushed to branch wip/fendor/ghci-multiple-home-units at Glasgow Haskell Compiler / GHC
Commits:
-
d0a36c84
by fendor at 2025-04-17T17:31:58+02:00
8 changed files:
- compiler/GHC.hs
- compiler/GHC/Rename/Unbound.hs
- compiler/GHC/Runtime/Context.hs
- compiler/GHC/Runtime/Eval.hs
- compiler/GHC/Tc/Module.hs
- compiler/GHC/Unit/Home/Graph.hs
- ghc/GHCi/UI.hs
- testsuite/tests/ghci/linking/dyn/T3372.hs
Changes:
| ... | ... | @@ -157,7 +157,7 @@ module GHC ( |
| 157 | 157 | getBindings, getInsts, getNamePprCtx,
|
| 158 | 158 | findModule, lookupModule,
|
| 159 | 159 | findQualifiedModule, lookupQualifiedModule,
|
| 160 | - lookupLoadedHomeModuleByModuleName, lookupAnyQualifiedModule,
|
|
| 160 | + lookupLoadedHomeModuleByModuleName, lookupAllQualifiedModuleNames,
|
|
| 161 | 161 | renamePkgQualM, renameRawPkgQualM,
|
| 162 | 162 | isModuleTrusted, moduleTrustReqs,
|
| 163 | 163 | getNamesInScope,
|
| ... | ... | @@ -1496,8 +1496,8 @@ getModuleGraph = liftM hsc_mod_graph getSession |
| 1496 | 1496 | -- TODO: this function should likely be deleted.
|
| 1497 | 1497 | isLoaded :: GhcMonad m => ModuleName -> m Bool
|
| 1498 | 1498 | isLoaded m = withSession $ \hsc_env -> liftIO $ do
|
| 1499 | - hmi <- HUG.lookupAnyHug (hsc_HUG hsc_env) m
|
|
| 1500 | - return $! isJust hmi
|
|
| 1499 | + hmis <- HUG.lookupAllHug (hsc_HUG hsc_env) m
|
|
| 1500 | + return $! not (null hmis)
|
|
| 1501 | 1501 | |
| 1502 | 1502 | isLoadedModule :: GhcMonad m => UnitId -> ModuleName -> m Bool
|
| 1503 | 1503 | isLoadedModule uid m = withSession $ \hsc_env -> liftIO $ do
|
| ... | ... | @@ -1896,17 +1896,16 @@ lookupLoadedHomeModule uid mod_name = withSession $ \hsc_env -> liftIO $ do |
| 1896 | 1896 | _not_a_home_module -> return Nothing
|
| 1897 | 1897 | |
| 1898 | 1898 | -- TODO: this is incorrect, what if we have mulitple 'ModuleName's in our HPTs?
|
| 1899 | -lookupLoadedHomeModuleByModuleName :: GhcMonad m => ModuleName -> m (Maybe Module)
|
|
| 1899 | +lookupLoadedHomeModuleByModuleName :: GhcMonad m => ModuleName -> m (Maybe [Module])
|
|
| 1900 | 1900 | lookupLoadedHomeModuleByModuleName mod_name = withSession $ \hsc_env -> liftIO $ do
|
| 1901 | 1901 | trace_if (hsc_logger hsc_env) (text "lookupLoadedHomeModuleByModuleName" <+> ppr mod_name)
|
| 1902 | - HUG.lookupAnyHug (hsc_HUG hsc_env) mod_name >>= \case
|
|
| 1903 | - Just mod_info -> return (Just (mi_module (hm_iface mod_info)))
|
|
| 1904 | - _not_a_home_module -> return Nothing
|
|
| 1902 | + HUG.lookupAllHug (hsc_HUG hsc_env) mod_name >>= \case
|
|
| 1903 | + [] -> return Nothing
|
|
| 1904 | + mod_infos -> return (Just (mi_module . hm_iface <$> mod_infos))
|
|
| 1905 | 1905 | |
| 1906 | -lookupAnyQualifiedModule :: GhcMonad m => PkgQual -> ModuleName -> m Module
|
|
| 1907 | -lookupAnyQualifiedModule NoPkgQual mod_name = withSession $ \hsc_env -> do
|
|
| 1906 | +lookupAllQualifiedModuleNames :: GhcMonad m => PkgQual -> ModuleName -> m [Module]
|
|
| 1907 | +lookupAllQualifiedModuleNames NoPkgQual mod_name = withSession $ \hsc_env -> do
|
|
| 1908 | 1908 | home <- lookupLoadedHomeModuleByModuleName mod_name
|
| 1909 | - liftIO $ trace_if (hsc_logger hsc_env) (ppr home <+> ppr (fmap moduleUnitId home))
|
|
| 1910 | 1909 | case home of
|
| 1911 | 1910 | Just m -> return m
|
| 1912 | 1911 | Nothing -> liftIO $ do
|
| ... | ... | @@ -1916,11 +1915,12 @@ lookupAnyQualifiedModule NoPkgQual mod_name = withSession $ \hsc_env -> do |
| 1916 | 1915 | let fopts = initFinderOpts dflags
|
| 1917 | 1916 | res <- findExposedPackageModule fc fopts units mod_name NoPkgQual
|
| 1918 | 1917 | case res of
|
| 1919 | - Found _ m -> return m
|
|
| 1918 | + Found _ m -> return [m]
|
|
| 1920 | 1919 | err -> throwOneError $ noModError hsc_env noSrcSpan mod_name err
|
| 1921 | -lookupAnyQualifiedModule pkgqual mod_name =
|
|
| 1920 | +lookupAllQualifiedModuleNames pkgqual mod_name = do
|
|
| 1922 | 1921 | -- TODO: definitely wrong.
|
| 1923 | - findQualifiedModule pkgqual mod_name
|
|
| 1922 | + m <- findQualifiedModule pkgqual mod_name
|
|
| 1923 | + pure [m]
|
|
| 1924 | 1924 | |
| 1925 | 1925 | -- | Check that a module is safe to import (according to Safe Haskell).
|
| 1926 | 1926 | --
|
| ... | ... | @@ -364,7 +364,7 @@ importSuggestions looking_for ic currMod imports rdr_name |
| 364 | 364 | pick_interactive :: InteractiveImport -> Bool
|
| 365 | 365 | pick_interactive (IIDecl d) | mod_name == Just (unLoc (ideclName d)) = True
|
| 366 | 366 | | mod_name == fmap unLoc (ideclAs d) = True
|
| 367 | - pick_interactive (IIModule m) | mod_name == Just m = True
|
|
| 367 | + pick_interactive (IIModule m) | mod_name == Just (moduleName m) = True
|
|
| 368 | 368 | pick_interactive _ = False
|
| 369 | 369 | |
| 370 | 370 | -- We want to keep only one for each original module; preferably one with an
|
| ... | ... | @@ -296,9 +296,7 @@ data InteractiveImport |
| 296 | 296 | -- ^ Bring the exports of a particular module
|
| 297 | 297 | -- (filtered by an import decl) into scope
|
| 298 | 298 | |
| 299 | - | IIModule ModuleName
|
|
| 300 | - -- TODO: change this to 'Module', does this work?
|
|
| 301 | - -- Much more precise
|
|
| 299 | + | IIModule Module
|
|
| 302 | 300 | -- ^ Bring into scope the entire top-level envt of
|
| 303 | 301 | -- of this module, including the things imported
|
| 304 | 302 | -- into it.
|
| ... | ... | @@ -822,17 +822,12 @@ findGlobalRdrEnv hsc_env imports |
| 822 | 822 | idecls :: [LImportDecl GhcPs]
|
| 823 | 823 | idecls = [noLocA d | IIDecl d <- imports]
|
| 824 | 824 | |
| 825 | - imods :: [ModuleName]
|
|
| 825 | + imods :: [Module]
|
|
| 826 | 826 | imods = [m | IIModule m <- imports]
|
| 827 | 827 | |
| 828 | - mkEnv modl = do
|
|
| 829 | - -- TODO: revisit this, is this how we want to do it?
|
|
| 830 | - mMod <- HUG.lookupAnyHug (hsc_HUG hsc_env) modl
|
|
| 831 | - let mod = case mMod of
|
|
| 832 | - Nothing -> mkModule (RealUnit $ Definite $ hscActiveUnitId hsc_env) modl
|
|
| 833 | - Just m -> mi_module $ hm_iface m
|
|
| 828 | + mkEnv mod = do
|
|
| 834 | 829 | mkTopLevEnv hsc_env mod >>= \case
|
| 835 | - Left err -> pure $ Left (modl, err)
|
|
| 830 | + Left err -> pure $ Left (moduleName mod, err)
|
|
| 836 | 831 | Right env -> pure $ Right env
|
| 837 | 832 | |
| 838 | 833 | mkTopLevEnv :: HscEnv -> Module -> IO (Either String GlobalRdrEnv)
|
| ... | ... | @@ -2098,7 +2098,7 @@ runTcInteractive hsc_env thing_inside |
| 2098 | 2098 | |
| 2099 | 2099 | ; !orphs <- fmap (force . concat) . forM (ic_imports icxt) $ \i ->
|
| 2100 | 2100 | case i of -- force above: see #15111
|
| 2101 | - IIModule n -> getOrphans n NoPkgQual
|
|
| 2101 | + IIModule n -> getOrphans (moduleName n) NoPkgQual -- TODO: wrong
|
|
| 2102 | 2102 | IIDecl i -> getOrphans (unLoc (ideclName i))
|
| 2103 | 2103 | (renameRawPkgQual (hsc_unit_env hsc_env) (unLoc $ ideclName i) (ideclPkgQual i))
|
| 2104 | 2104 |
| ... | ... | @@ -34,7 +34,7 @@ module GHC.Unit.Home.Graph |
| 34 | 34 | , lookupHug
|
| 35 | 35 | , lookupHugByModule
|
| 36 | 36 | , lookupHugUnit
|
| 37 | - , lookupAnyHug
|
|
| 37 | + , lookupAllHug
|
|
| 38 | 38 | , memberHugHomeModule
|
| 39 | 39 | , memberHugHomeInstalledModule
|
| 40 | 40 | |
| ... | ... | @@ -91,6 +91,7 @@ import GHC.Data.Graph.Directed |
| 91 | 91 | import GHC.Types.Annotations
|
| 92 | 92 | import GHC.Types.CompleteMatch
|
| 93 | 93 | import GHC.Core.InstEnv
|
| 94 | +import GHC.Utils.Monad (mapMaybeM)
|
|
| 94 | 95 | |
| 95 | 96 | |
| 96 | 97 | -- | Get all 'CompleteMatches' (arising from COMPLETE pragmas) present across
|
| ... | ... | @@ -255,21 +256,14 @@ lookupHug hug uid mod = do |
| 255 | 256 | Just hue -> lookupHpt (homeUnitEnv_hpt hue) mod
|
| 256 | 257 | |
| 257 | 258 | -- TODO: this should not be merged, where else could we try to search for modules?
|
| 258 | -lookupAnyHug :: HomeUnitGraph -> ModuleName -> IO (Maybe HomeModInfo)
|
|
| 259 | -lookupAnyHug hug mod = firstJustM $ flip fmap (Set.toList $ unitEnv_keys hug) $ \uid -> do
|
|
| 260 | - case unitEnv_lookup_maybe uid hug of
|
|
| 261 | - -- Really, here we want "lookup HPT" rather than unitEnvLookup
|
|
| 262 | - Nothing -> pure Nothing
|
|
| 263 | - Just hue -> lookupHpt (homeUnitEnv_hpt hue) mod
|
|
| 259 | +lookupAllHug :: HomeUnitGraph -> ModuleName -> IO [HomeModInfo]
|
|
| 260 | +lookupAllHug hug mod = mapMaybeM lookupModuleName (Set.toList $ unitEnv_keys hug)
|
|
| 264 | 261 | where
|
| 265 | - firstJustM :: Monad f => [f (Maybe a)] -> f (Maybe a)
|
|
| 266 | - firstJustM [] = pure Nothing
|
|
| 267 | - firstJustM (x:xs) = do
|
|
| 268 | - ma <- x
|
|
| 269 | - case ma of
|
|
| 270 | - Nothing -> firstJustM xs
|
|
| 271 | - Just a -> pure $ Just a
|
|
| 272 | - |
|
| 262 | + lookupModuleName uid =
|
|
| 263 | + case unitEnv_lookup_maybe uid hug of
|
|
| 264 | + -- Really, here we want "lookup HPT" rather than unitEnvLookup
|
|
| 265 | + Nothing -> pure Nothing
|
|
| 266 | + Just hue -> lookupHpt (homeUnitEnv_hpt hue) mod
|
|
| 273 | 267 | |
| 274 | 268 | -- | Lookup the 'HomeModInfo' of a 'Module' in the 'HomeUnitGraph' (via the 'HomePackageTable' of the corresponding unit)
|
| 275 | 269 | lookupHugByModule :: Module -> HomeUnitGraph -> IO (Maybe HomeModInfo)
|
| ... | ... | @@ -558,7 +558,7 @@ interactiveUI config srcs maybe_exprs = do |
| 558 | 558 | hsc_env <- GHC.getSession
|
| 559 | 559 | let !in_multi = length (hsc_all_home_unit_ids hsc_env) > 3
|
| 560 | 560 | -- We force this to make sure we don't retain the hsc_env when reloading
|
| 561 | - -- The check is `> 2`, since we now always have at least two home units.
|
|
| 561 | + -- The check is `> 3`, since we now always have at least two home units.
|
|
| 562 | 562 | -- TODO: if everything goes well, this check should be deleted once
|
| 563 | 563 | -- this PR has lifted the multiple home unit restrictions
|
| 564 | 564 | empty_cache <- liftIO newIfaceCache
|
| ... | ... | @@ -1023,7 +1023,7 @@ getInfoForPrompt = do |
| 1023 | 1023 | | otherwise = unLoc (ideclName d)
|
| 1024 | 1024 | |
| 1025 | 1025 | modules_names =
|
| 1026 | - ['*':(moduleNameString m) | IIModule m <- rev_imports] ++
|
|
| 1026 | + ['*':(moduleNameString (moduleName m)) | IIModule m <- rev_imports] ++
|
|
| 1027 | 1027 | [moduleNameString (myIdeclName d) | IIDecl d <- rev_imports]
|
| 1028 | 1028 | line = 1 + line_number st
|
| 1029 | 1029 | |
| ... | ... | @@ -2279,7 +2279,7 @@ setContextAfterLoad keep_ctxt (Just graph) = do |
| 2279 | 2279 | -- We import the module with a * iff
|
| 2280 | 2280 | -- - it is interpreted, and
|
| 2281 | 2281 | -- - -XSafe is off (it doesn't allow *-imports)
|
| 2282 | - let new_ctx | star_ok = [mkIIModule (GHC.moduleName m)]
|
|
| 2282 | + let new_ctx | star_ok = [mkIIModule m]
|
|
| 2283 | 2283 | | otherwise = [mkIIDecl (GHC.moduleName m)]
|
| 2284 | 2284 | setContextKeepingPackageModules keep_ctxt new_ctx
|
| 2285 | 2285 | |
| ... | ... | @@ -2699,7 +2699,7 @@ guessCurrentModule cmd = do |
| 2699 | 2699 | imports <- GHC.getContext
|
| 2700 | 2700 | case imports of
|
| 2701 | 2701 | [] -> throwGhcException $ CmdLineError (':' : cmd ++ ": no current module")
|
| 2702 | - IIModule m : _ -> GHC.findQualifiedModule NoPkgQual m
|
|
| 2702 | + IIModule m : _ -> pure m
|
|
| 2703 | 2703 | IIDecl d : _ -> do
|
| 2704 | 2704 | pkgqual <- GHC.renameRawPkgQualM (unLoc $ ideclName d) (ideclPkgQual d)
|
| 2705 | 2705 | GHC.findQualifiedModule pkgqual (unLoc (ideclName d))
|
| ... | ... | @@ -2829,8 +2829,9 @@ addModulesToContext starred unstarred = restoreContextOnFailure $ do |
| 2829 | 2829 | |
| 2830 | 2830 | addModulesToContext_ :: GhciMonad m => [ModuleName] -> [ModuleName] -> m ()
|
| 2831 | 2831 | addModulesToContext_ starred unstarred = do
|
| 2832 | - mapM_ addII (map mkIIModule starred ++ map mkIIDecl unstarred)
|
|
| 2833 | - setGHCContextFromGHCiState
|
|
| 2832 | + starredModules <- traverse lookupModuleName starred
|
|
| 2833 | + mapM_ addII (map mkIIModule starredModules ++ map mkIIDecl unstarred)
|
|
| 2834 | + setGHCContextFromGHCiState
|
|
| 2834 | 2835 | |
| 2835 | 2836 | remModulesFromContext :: GhciMonad m => [ModuleName] -> [ModuleName] -> m ()
|
| 2836 | 2837 | remModulesFromContext starred unstarred = do
|
| ... | ... | @@ -2896,9 +2897,9 @@ checkAdd ii = do |
| 2896 | 2897 | dflags <- getDynFlags
|
| 2897 | 2898 | let safe = safeLanguageOn dflags
|
| 2898 | 2899 | case ii of
|
| 2899 | - IIModule modname
|
|
| 2900 | + IIModule mod
|
|
| 2900 | 2901 | | safe -> throwGhcException $ CmdLineError "can't use * imports with Safe Haskell"
|
| 2901 | - | otherwise -> wantInterpretedModuleName modname >> return ()
|
|
| 2902 | + | otherwise -> checkInterpretedModule mod >> return ()
|
|
| 2902 | 2903 | |
| 2903 | 2904 | IIDecl d -> do
|
| 2904 | 2905 | let modname = unLoc (ideclName d)
|
| ... | ... | @@ -2966,13 +2967,13 @@ getImplicitPreludeImports iidecls = do |
| 2966 | 2967 | -- -----------------------------------------------------------------------------
|
| 2967 | 2968 | -- Utils on InteractiveImport
|
| 2968 | 2969 | |
| 2969 | -mkIIModule :: ModuleName -> InteractiveImport
|
|
| 2970 | +mkIIModule :: Module -> InteractiveImport
|
|
| 2970 | 2971 | mkIIModule = IIModule
|
| 2971 | 2972 | |
| 2972 | 2973 | mkIIDecl :: ModuleName -> InteractiveImport
|
| 2973 | 2974 | mkIIDecl = IIDecl . simpleImportDecl
|
| 2974 | 2975 | |
| 2975 | -iiModules :: [InteractiveImport] -> [ModuleName]
|
|
| 2976 | +iiModules :: [InteractiveImport] -> [Module]
|
|
| 2976 | 2977 | iiModules is = [m | IIModule m <- is]
|
| 2977 | 2978 | |
| 2978 | 2979 | isIIModule :: InteractiveImport -> Bool
|
| ... | ... | @@ -2980,7 +2981,7 @@ isIIModule (IIModule _) = True |
| 2980 | 2981 | isIIModule _ = False
|
| 2981 | 2982 | |
| 2982 | 2983 | iiModuleName :: InteractiveImport -> ModuleName
|
| 2983 | -iiModuleName (IIModule m) = m
|
|
| 2984 | +iiModuleName (IIModule m) = moduleName m
|
|
| 2984 | 2985 | iiModuleName (IIDecl d) = unLoc (ideclName d)
|
| 2985 | 2986 | |
| 2986 | 2987 | preludeModuleName :: ModuleName
|
| ... | ... | @@ -3428,7 +3429,7 @@ showImports = do |
| 3428 | 3429 | trans_ctx = transient_ctx st
|
| 3429 | 3430 | |
| 3430 | 3431 | show_one (IIModule star_m)
|
| 3431 | - = ":module +*" ++ moduleNameString star_m
|
|
| 3432 | + = ":module +*" ++ moduleNameString (moduleName star_m)
|
|
| 3432 | 3433 | show_one (IIDecl imp) = showPpr dflags imp
|
| 3433 | 3434 | |
| 3434 | 3435 | prel_iidecls <- getImplicitPreludeImports (rem_ctx ++ trans_ctx)
|
| ... | ... | @@ -3734,11 +3735,11 @@ completeBreakpoint = wrapCompleter spaces $ \w -> do -- #3000 |
| 3734 | 3735 | filterM GHC.moduleIsInterpreted hmods
|
| 3735 | 3736 | |
| 3736 | 3737 | -- Return all possible bids for a given Module
|
| 3737 | - bidsByModule :: GhciMonad m => [ModuleName] -> Module -> m [String]
|
|
| 3738 | + bidsByModule :: GhciMonad m => [Module] -> Module -> m [String]
|
|
| 3738 | 3739 | bidsByModule nonquals mod = do
|
| 3739 | 3740 | (_, decls) <- getModBreak mod
|
| 3740 | 3741 | let bids = nub $ declPath <$> elems decls
|
| 3741 | - pure $ case (moduleName mod) `elem` nonquals of
|
|
| 3742 | + pure $ case mod `elem` nonquals of
|
|
| 3742 | 3743 | True -> bids
|
| 3743 | 3744 | False -> (combineModIdent (showModule mod)) <$> bids
|
| 3744 | 3745 | |
| ... | ... | @@ -4143,8 +4144,7 @@ breakSwitch (arg1:rest) |
| 4143 | 4144 | | all isDigit arg1 = do
|
| 4144 | 4145 | imports <- GHC.getContext
|
| 4145 | 4146 | case iiModules imports of
|
| 4146 | - (mn : _) -> do
|
|
| 4147 | - md <- lookupModuleName mn
|
|
| 4147 | + (md : _) -> do
|
|
| 4148 | 4148 | breakByModuleLine md (read arg1) rest
|
| 4149 | 4149 | [] -> do
|
| 4150 | 4150 | liftIO $ putStrLn "No modules are loaded with debugging support."
|
| ... | ... | @@ -4276,8 +4276,7 @@ list2 [arg] | all isDigit arg = do |
| 4276 | 4276 | case iiModules imports of
|
| 4277 | 4277 | [] -> liftIO $ putStrLn "No module to list"
|
| 4278 | 4278 | (mn : _) -> do
|
| 4279 | - md <- lookupModuleName mn
|
|
| 4280 | - listModuleLine md (read arg)
|
|
| 4279 | + listModuleLine mn (read arg)
|
|
| 4281 | 4280 | list2 [arg1,arg2] | looksLikeModuleName arg1, all isDigit arg2 = do
|
| 4282 | 4281 | md <- wantInterpretedModule arg1
|
| 4283 | 4282 | listModuleLine md (read arg2)
|
| ... | ... | @@ -4536,7 +4535,17 @@ lookupModuleName :: GHC.GhcMonad m => ModuleName -> m Module |
| 4536 | 4535 | lookupModuleName mName = lookupQualifiedModuleName NoPkgQual mName
|
| 4537 | 4536 | |
| 4538 | 4537 | lookupQualifiedModuleName :: GHC.GhcMonad m => PkgQual -> ModuleName -> m Module
|
| 4539 | -lookupQualifiedModuleName = GHC.lookupAnyQualifiedModule
|
|
| 4538 | +lookupQualifiedModuleName qual modl = do
|
|
| 4539 | + GHC.lookupAllQualifiedModuleNames qual modl >>= \case
|
|
| 4540 | + [] -> throwGhcException (CmdLineError ("module '" ++ str ++ "' could not be found."))
|
|
| 4541 | + [m] -> pure m
|
|
| 4542 | + ms -> throwGhcException (CmdLineError ("module name '" ++ str ++ "' is ambiguous;\n" ++ errorMsg ms))
|
|
| 4543 | + where
|
|
| 4544 | + str = moduleNameString modl
|
|
| 4545 | + errorMsg ms = intercalate "\n"
|
|
| 4546 | + [ "- " ++ unitIdString (toUnitId (moduleUnit m)) ++ ":" ++ moduleNameString (moduleName m)
|
|
| 4547 | + | m <- ms
|
|
| 4548 | + ]
|
|
| 4540 | 4549 | |
| 4541 | 4550 | isMainUnitModule :: Module -> Bool
|
| 4542 | 4551 | isMainUnitModule m = GHC.moduleUnit m == mainUnit
|
| ... | ... | @@ -4586,15 +4595,19 @@ wantInterpretedModule str = wantInterpretedModuleName (GHC.mkModuleName str) |
| 4586 | 4595 | |
| 4587 | 4596 | wantInterpretedModuleName :: GHC.GhcMonad m => ModuleName -> m Module
|
| 4588 | 4597 | wantInterpretedModuleName modname = do
|
| 4589 | - modl <- lookupModuleName modname
|
|
| 4590 | - let str = moduleNameString modname
|
|
| 4591 | - hug <- hsc_HUG <$> GHC.getSession
|
|
| 4592 | - unless (HUG.memberHugHomeModule modl hug) $
|
|
| 4593 | - throwGhcException (CmdLineError ("module '" ++ str ++ "' is from another package;\nthis command requires an interpreted module"))
|
|
| 4594 | - is_interpreted <- GHC.moduleIsInterpreted modl
|
|
| 4595 | - when (not is_interpreted) $
|
|
| 4596 | - throwGhcException (CmdLineError ("module '" ++ str ++ "' is not interpreted; try \':add *" ++ str ++ "' first"))
|
|
| 4597 | - return modl
|
|
| 4598 | + modl <- lookupModuleName modname
|
|
| 4599 | + checkInterpretedModule modl
|
|
| 4600 | + |
|
| 4601 | +checkInterpretedModule :: GHC.GhcMonad m => Module -> m Module
|
|
| 4602 | +checkInterpretedModule modl = do
|
|
| 4603 | + let str = moduleNameString $ moduleName modl
|
|
| 4604 | + hug <- hsc_HUG <$> GHC.getSession
|
|
| 4605 | + unless (HUG.memberHugHomeModule modl hug) $
|
|
| 4606 | + throwGhcException (CmdLineError ("module '" ++ str ++ "' is from another package;\nthis command requires an interpreted module"))
|
|
| 4607 | + is_interpreted <- GHC.moduleIsInterpreted modl
|
|
| 4608 | + when (not is_interpreted) $
|
|
| 4609 | + throwGhcException (CmdLineError ("module '" ++ str ++ "' is not interpreted; try \':add *" ++ str ++ "' first"))
|
|
| 4610 | + return modl
|
|
| 4598 | 4611 | |
| 4599 | 4612 | wantNameFromInterpretedModule :: GHC.GhcMonad m
|
| 4600 | 4613 | => (Name -> SDoc -> m ())
|
| ... | ... | @@ -60,7 +60,7 @@ load (f,mn) = do target <- GHC.guessTarget f Nothing Nothing |
| 60 | 60 | GHC.liftIO $ putStrLn ("Load " ++ showSuccessFlag res)
|
| 61 | 61 | --
|
| 62 | 62 | m <- GHC.findModule (GHC.mkModuleName mn) Nothing
|
| 63 | - GHC.setContext [GHC.IIModule $ GHC.moduleName $ m]
|
|
| 63 | + GHC.setContext [GHC.IIModule m]
|
|
| 64 | 64 | where showSuccessFlag GHC.Succeeded = "succeeded"
|
| 65 | 65 | showSuccessFlag GHC.Failed = "failed"
|
| 66 | 66 |