diff options
author | Simon Marlow <marlowsd@gmail.com> | 2011-08-26 16:36:05 +0100 |
---|---|---|
committer | Simon Marlow <marlowsd@gmail.com> | 2011-08-26 22:52:06 +0100 |
commit | 79d6745f66c678de5e104b2146d3dd3e2f006c3e (patch) | |
tree | 3df82bcb611af028542f639340d0cb5662fa87a9 /ghc/GhciMonad.hs | |
parent | 3b8d128701afe572969abb1dbd8af2a095b9b661 (diff) | |
download | haskell-79d6745f66c678de5e104b2146d3dd3e2f006c3e.tar.gz |
Clean up the handling of the import and :module commands in GHCi
Previously we remembered the whole history of commands and replayed
them on every :load/:reload, which lead to some non-linear performance
characteristics (#5317). The handling of the implicit Prelude import
and the implicit imports of recently loaded modules was also
complicated and wrong in various obscure ways.
The Prelude import works just like the implicit Prelude import in a
Haskell module: it can be overriden with an explicit Prelude
import.
I have added a new ":show imports" command to show which imports are
currently in force.
Prelude> :show imports
import Prelude -- implicit
Prelude> import Prelude ()
Prelude> :show imports
import Prelude ()
Prelude> map
<interactive>:0:1: Not in scope: `map'
Prelude>
Full documentation in the User's Guide.
There are various other little tweaks and improvements, such as when a
module is imported with 'as', we now show the 'as' name in the prompt
rather than the original name.
Diffstat (limited to 'ghc/GhciMonad.hs')
-rw-r--r-- | ghc/GhciMonad.hs | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/ghc/GhciMonad.hs b/ghc/GhciMonad.hs index 52b28efdff..ba58d8c21f 100644 --- a/ghc/GhciMonad.hs +++ b/ghc/GhciMonad.hs @@ -56,7 +56,6 @@ data GHCiState = GHCiState editor :: String, stop :: String, options :: [GHCiOption], - prelude :: GHC.ModuleName, line_number :: !Int, -- input line break_ctr :: !Int, breaks :: ![(Int, BreakLocation)], @@ -68,23 +67,27 @@ data GHCiState = GHCiState -- remember is here: last_command :: Maybe Command, cmdqueue :: [String], - remembered_ctx :: [CtxtCmd], - -- we remember the :module commands between :loads, so that - -- on a :reload we can replay them. See bugs #2049, - -- \#1873, #1360. Previously we tried to remember modules that - -- were supposed to be in the context but currently had errors, - -- but this was complicated. Just replaying the :module commands - -- seems to be the right thing. + + remembered_ctx :: [InteractiveImport], + -- the imports that the user has asked for, via import + -- declarations and :module commands. This list is + -- persistent over :reloads (but any imports for modules + -- that are not loaded are temporarily ignored). After a + -- :load, all the home-package imports are stripped from + -- this list. + + -- See bugs #2049, #1873, #1360 + + transient_ctx :: [InteractiveImport], + -- An import added automatically after a :load, usually of + -- the most recently compiled module. May be empty if + -- there are no modules loaded. This list is replaced by + -- :load, :reload, and :add. In between it may be modified + -- by :module. + ghc_e :: Bool -- True if this is 'ghc -e' (or runghc) } -data CtxtCmd -- In each case, the first [String] are the starred modules - -- and the second are the unstarred ones - = SetContext [String] [String] - | AddModules [String] [String] - | RemModules [String] [String] - | Import String - type TickArray = Array Int [(BreakIndex,SrcSpan)] data GHCiOption @@ -161,6 +164,8 @@ getGHCiState :: GHCi GHCiState getGHCiState = GHCi $ \r -> liftIO $ readIORef r setGHCiState :: GHCiState -> GHCi () setGHCiState s = GHCi $ \r -> liftIO $ writeIORef r s +modifyGHCiState :: (GHCiState -> GHCiState) -> GHCi () +modifyGHCiState f = GHCi $ \r -> liftIO $ readIORef r >>= writeIORef r . f liftGhc :: Ghc a -> GHCi a liftGhc m = GHCi $ \_ -> m @@ -209,10 +214,6 @@ instance ExceptionMonad (InputT GHCi) where gblock = Haskeline.block gunblock = Haskeline.unblock --- for convenience... -getPrelude :: GHCi ModuleName -getPrelude = getGHCiState >>= return . prelude - getDynFlags :: GhcMonad m => m DynFlags getDynFlags = do GHC.getSessionDynFlags |