Commit 5e9e07a3 authored by dterei's avatar dterei
Browse files

Have :load work under -XSafe in GHCi.

parent e5272d9b
...@@ -1655,7 +1655,9 @@ checkAdd :: Bool -> String -> GHCi (InteractiveImport) ...@@ -1655,7 +1655,9 @@ checkAdd :: Bool -> String -> GHCi (InteractiveImport)
checkAdd star mstr = do checkAdd star mstr = do
dflags <- getDynFlags dflags <- getDynFlags
case safeLanguageOn dflags of case safeLanguageOn dflags of
True | star -> ghcError $ CmdLineError "can't use * imports with Safe Haskell" True | star -> do
liftIO $ putStrLn "Warning: can't use * imports with Safe Haskell; ignoring *"
checkAdd False mstr
True -> do m <- lookupModule mstr True -> do m <- lookupModule mstr
s <- GHC.isModuleTrusted m s <- GHC.isModuleTrusted m
...@@ -1685,8 +1687,8 @@ checkAdd star mstr = do ...@@ -1685,8 +1687,8 @@ checkAdd star mstr = do
setGHCContextFromGHCiState :: GHCi () setGHCContextFromGHCiState :: GHCi ()
setGHCContextFromGHCiState = do setGHCContextFromGHCiState = do
st <- getGHCiState st <- getGHCiState
goodTran <- filterM (tryBool . ok) $ transient_ctx st goodTran <- mapMaybeM (tryBool . ok) $ transient_ctx st
goodRemb <- filterM (tryBool . ok) $ remembered_ctx st goodRemb <- mapMaybeM (tryBool . ok) $ remembered_ctx st
-- drop bad imports so we don't keep replaying it to the user! -- drop bad imports so we don't keep replaying it to the user!
modifyGHCiState $ \s -> s { transient_ctx = goodTran } modifyGHCiState $ \s -> s { transient_ctx = goodTran }
modifyGHCiState $ \s -> s { remembered_ctx = goodRemb } modifyGHCiState $ \s -> s { remembered_ctx = goodRemb }
...@@ -1696,6 +1698,8 @@ setGHCContextFromGHCiState = do ...@@ -1696,6 +1698,8 @@ setGHCContextFromGHCiState = do
ok (IIModule m) = checkAdd True (moduleNameString (moduleName m)) ok (IIModule m) = checkAdd True (moduleNameString (moduleName m))
ok (IIDecl d) = checkAdd False (moduleNameString (unLoc (ideclName d))) ok (IIDecl d) = checkAdd False (moduleNameString (unLoc (ideclName d)))
mapMaybeM f xs = catMaybes `fmap` sequence (map f xs)
setContext :: [String] -> [String] -> GHCi () setContext :: [String] -> [String] -> GHCi ()
setContext starred not_starred = do setContext starred not_starred = do
is1 <- mapM (checkAdd True) starred is1 <- mapM (checkAdd True) starred
...@@ -2752,12 +2756,12 @@ ghciHandle h m = Haskeline.catch m $ \e -> unblock (h e) ...@@ -2752,12 +2756,12 @@ ghciHandle h m = Haskeline.catch m $ \e -> unblock (h e)
ghciTry :: GHCi a -> GHCi (Either SomeException a) ghciTry :: GHCi a -> GHCi (Either SomeException a)
ghciTry (GHCi m) = GHCi $ \s -> gtry (m s) ghciTry (GHCi m) = GHCi $ \s -> gtry (m s)
tryBool :: GHCi a -> GHCi Bool tryBool :: GHCi a -> GHCi (Maybe a)
tryBool m = do tryBool m = do
r <- ghciTry m r <- ghciTry m
case r of case r of
Left e -> showException e >> return False Left e -> showException e >> return Nothing
Right _ -> return True Right a -> return $ Just a
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
-- Utils -- Utils
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment