--
-- -----------------------------------------------------------------------------
-{-# OPTIONS -w #-}
--- The above warning supression flag is a temporary kludge.
--- While working on this module you are encouraged to remove it and fix
--- any warnings in the module. See
--- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
--- for details
-
module InteractiveEval (
#ifdef GHCI
RunResult(..), Status(..), Resume(..), History(..),
import SrcLoc
import BreakArray
import RtClosureInspect
-import Packages
import BasicTypes
import Outputable
+import FastString
import Data.Dynamic
import Data.List (find)
| SingleStep
| RunAndLogSteps
+isStep :: SingleStep -> Bool
isStep RunToCompletion = False
isStep _ = True
handleRunStatus expr ref bindings ids
breakMVar statusMVar status emptyHistory
-
+emptyHistory :: BoundedList History
emptyHistory = nilBL 50 -- keep a log of length 50
+handleRunStatus :: String -> IORef HscEnv -> ([Id], TyVarSet) -> [Id]
+ -> MVar () -> MVar Status -> Status -> BoundedList History
+ -> IO RunResult
handleRunStatus expr ref bindings final_ids breakMVar statusMVar status
history =
case status of
writeIORef ref hsc_env'
return (RunOk final_names)
-
+traceRunStatus :: String -> IORef HscEnv -> ([Id], TyVarSet) -> [Id]
+ -> MVar () -> MVar Status -> Status -> BoundedList History
+ -> IO RunResult
traceRunStatus expr ref bindings final_ids
breakMVar statusMVar status history = do
hsc_env <- readIORef ref
foreign import ccall "&rts_stop_next_breakpoint" stepFlag :: Ptr CInt
foreign import ccall "&rts_stop_on_exception" exceptionFlag :: Ptr CInt
-setStepFlag = poke stepFlag 1
+setStepFlag :: IO ()
+setStepFlag = poke stepFlag 1
+resetStepFlag :: IO ()
resetStepFlag = poke stepFlag 0
-- this points to the IO action that is executed when a breakpoint is hit
-- resets everything when the computation has stopped running. This
-- is a not-very-good way to ensure that only the interactive
-- evaluation should generate breakpoints.
+withBreakAction :: Bool -> DynFlags -> MVar () -> MVar Status -> IO a -> IO a
withBreakAction step dflags breakMVar statusMVar io
= bracket setBreakAction resetBreakAction (\_ -> io)
where
resetStepFlag
freeStablePtr stablePtr
+noBreakStablePtr :: StablePtr (Bool -> BreakInfo -> HValue -> IO ())
noBreakStablePtr = unsafePerformIO $ newStablePtr noBreakAction
-noBreakAction False info apStack = putStrLn "*** Ignoring breakpoint"
-noBreakAction True info apStack = return () -- exception: just continue
+noBreakAction :: Bool -> BreakInfo -> HValue -> IO ()
+noBreakAction False _ _ = putStrLn "*** Ignoring breakpoint"
+noBreakAction True _ _ = return () -- exception: just continue
resume :: Session -> SingleStep -> IO RunResult
resume (Session ref) step
forward :: Session -> IO ([Name], Int, SrcSpan)
forward = moveHist (subtract 1)
+moveHist :: (Int -> Int) -> Session -> IO ([Name], Int, SrcSpan)
moveHist fn (Session ref) = do
hsc_env <- readIORef ref
case ic_resume (hsc_IC hsc_env) of
-- -----------------------------------------------------------------------------
-- After stopping at a breakpoint, add free variables to the environment
-result_fs = FSLIT("_result")
-
+result_fs :: FastString
+result_fs = fsLit "_result"
+
bindLocalsAtBreakpoint
:: HscEnv
-> HValue
-- bind, all we can do is bind a local variable to the exception
-- value.
bindLocalsAtBreakpoint hsc_env apStack Nothing = do
- let exn_fs = FSLIT("_exception")
+ let exn_fs = fsLit "_exception"
exn_name = mkInternalName (getUnique exn_fs) (mkVarOccFS exn_fs) span
- e_fs = FSLIT("e")
+ e_fs = fsLit "e"
e_name = mkInternalName (getUnique e_fs) (mkTyVarOcc e_fs) span
e_tyvar = mkTcTyVar e_name liftedTypeKind (SkolemTv RuntimeUnkSkol)
exn_id = Id.mkGlobalId VanillaGlobal exn_name (mkTyVarTy e_tyvar)
ictxt0 = hsc_IC hsc_env
ictxt1 = extendInteractiveContext ictxt0 [exn_id] new_tyvars
- span = mkGeneralSrcSpan FSLIT("<exception thrown>")
+ span = mkGeneralSrcSpan (fsLit "<exception thrown>")
--
Linker.extendLinkEnv [(exn_name, unsafeCoerce# apStack)]
return (hsc_env{ hsc_IC = ictxt1 }, [exn_name], span)
-- So that we don't fall over in a heap when this happens, just don't
-- bind any free variables instead, and we emit a warning.
mb_hValues <- mapM (getIdValFromApStack apStack) offsets
- let filtered_ids = [ id | (id, Just hv) <- zip ids mb_hValues ]
+ let filtered_ids = [ id | (id, Just _hv) <- zip ids mb_hValues ]
when (any isNothing mb_hValues) $
debugTraceMsg (hsc_dflags hsc_env) 1 $
text "Warning: _result has been evaluated, some bindings have been lost"
tys <- reconstructType hsc_env 10 `mapM` incompletelyTypedIds
-- map termType `fmap` (obtainTerm hsc_env False `mapM` incompletelyTypedIds)
- let substs = [unifyRTTI ty ty'
+ improvs <- sequence [improveRTTIType hsc_env ty ty'
| (ty, Just ty') <- zip (map idType incompletelyTypedIds) tys]
- ic' = foldr (flip substInteractiveContext) ic
- (map skolemiseSubst substs)
+ let ic' = foldr (\mb_subst ic' ->
+ maybe (WARN(True, text ("RTTI failed to calculate the "
+ ++ "improvement for a type")) ic')
+ (substInteractiveContext ic' . skolemiseSubst)
+ mb_subst)
+ ic
+ improvs
return hsc_env{hsc_IC=ic'}
+skolemiseSubst :: TvSubst -> TvSubst
skolemiseSubst subst = subst `setTvSubstEnv`
mapVarEnv (fst.skolemiseTy) (getTvSubstEnv subst)
nilBL :: Int -> BoundedList a
nilBL bound = BL 0 bound [] []
+consBL :: a -> BoundedList a -> BoundedList a
consBL a (BL len bound left right)
| len < bound = BL (len+1) bound (a:left) right
| null right = BL len bound [a] $! tail (reverse left)
| otherwise = BL len bound (a:left) $! tail right
+toListBL :: BoundedList a -> [a]
toListBL (BL _ _ left right) = left ++ reverse right
+fromListBL :: Int -> [a] -> BoundedList a
fromListBL bound l = BL (length l) bound l []
-- lenBL (BL len _ _ _) = len
-> [Module] -- entire top level scope of these modules
-> [Module] -- exports only of these modules
-> IO ()
-setContext sess@(Session ref) toplev_mods export_mods = do
+setContext (Session ref) toplev_mods export_mods = do
hsc_env <- readIORef ref
let old_ic = hsc_IC hsc_env
hpt = hsc_HPT hsc_env
hvals <- (unsafeCoerce# hval) :: IO [HValue]
case (ids,hvals) of
- ([n],[hv]) -> return (Just hv)
+ ([_],[hv]) -> return (Just hv)
_ -> panic "compileExpr"
-- -----------------------------------------------------------------------------