Commit 8d180b0d authored by simonmar's avatar simonmar
Browse files

[project @ 2006-01-03 16:15:37 by simonmar]

setContextAfterLoad: try to load a target if possible, otherwise load
the topmost module in the graph.  Previously we were loading the first
module in the list, which happened to be right a lot of the time, but
not always.

Fixes ticket #642
parent 337b09aa
...@@ -15,7 +15,8 @@ module InteractiveUI ( ...@@ -15,7 +15,8 @@ module InteractiveUI (
-- The GHC interface -- The GHC interface
import qualified GHC import qualified GHC
import GHC ( Session, verbosity, dopt, DynFlag(..), import GHC ( Session, verbosity, dopt, DynFlag(..), Target(..),
TargetId(..),
mkModule, pprModule, Type, Module, SuccessFlag(..), mkModule, pprModule, Type, Module, SuccessFlag(..),
TyThing(..), Name, LoadHowMuch(..), Phase, TyThing(..), Name, LoadHowMuch(..), Phase,
GhcException(..), showGhcException, GhcException(..), showGhcException,
...@@ -30,6 +31,7 @@ import OccName( pprOccName ) ...@@ -30,6 +31,7 @@ import OccName( pprOccName )
import SrcLoc( isGoodSrcLoc, srcLocFile, srcLocLine, srcLocCol ) import SrcLoc( isGoodSrcLoc, srcLocFile, srcLocLine, srcLocCol )
-- Other random utilities -- Other random utilities
import Digraph ( flattenSCCs )
import BasicTypes ( failed, successIf ) import BasicTypes ( failed, successIf )
import Panic ( panic, installSignalHandlers ) import Panic ( panic, installSignalHandlers )
import Config import Config
...@@ -592,7 +594,7 @@ changeDirectory dir = do ...@@ -592,7 +594,7 @@ changeDirectory dir = do
io $ putStr "Warning: changing directory causes all loaded modules to be unloaded,\nbecause the search path has changed.\n" io $ putStr "Warning: changing directory causes all loaded modules to be unloaded,\nbecause the search path has changed.\n"
io (GHC.setTargets session []) io (GHC.setTargets session [])
io (GHC.load session LoadAllTargets) io (GHC.load session LoadAllTargets)
setContextAfterLoad [] setContextAfterLoad session []
io (GHC.workingDirectoryChanged session) io (GHC.workingDirectoryChanged session)
dir <- expandPath dir dir <- expandPath dir
io (setCurrentDirectory dir) io (setCurrentDirectory dir)
...@@ -703,19 +705,39 @@ reloadModule m = do ...@@ -703,19 +705,39 @@ reloadModule m = do
afterLoad ok session = do afterLoad ok session = do
io (revertCAFs) -- always revert CAFs on load. io (revertCAFs) -- always revert CAFs on load.
graph <- io (GHC.getModuleGraph session) graph <- io (GHC.getModuleGraph session)
let mods = map GHC.ms_mod graph graph' <- filterM (io . GHC.isLoaded session . GHC.ms_mod) graph
mods' <- filterM (io . GHC.isLoaded session) mods setContextAfterLoad session graph'
setContextAfterLoad mods' modulesLoadedMsg ok (map GHC.ms_mod graph')
modulesLoadedMsg ok mods'
setContextAfterLoad [] = do setContextAfterLoad session [] = do
session <- getSession
io (GHC.setContext session [] [prelude_mod]) io (GHC.setContext session [] [prelude_mod])
setContextAfterLoad (m:_) = do setContextAfterLoad session ms = do
session <- getSession -- load a target if one is available, otherwise load the topmost module.
b <- io (GHC.moduleIsInterpreted session m) targets <- io (GHC.getTargets session)
if b then io (GHC.setContext session [m] []) case [ m | Just m <- map (findTarget ms) targets ] of
else io (GHC.setContext session [] [prelude_mod,m]) [] ->
let graph' = flattenSCCs (GHC.topSortModuleGraph True ms Nothing) in
load_this (last graph')
(m:_) ->
load_this m
where
findTarget ms t
= case filter (`matches` t) ms of
[] -> Nothing
(m:_) -> Just m
summary `matches` Target (TargetModule m) _
= GHC.ms_mod summary == m
summary `matches` Target (TargetFile f _) _
| Just f' <- GHC.ml_hs_file (GHC.ms_location summary) = f == f'
summary `matches` target
= False
load_this summary | m <- GHC.ms_mod summary = do
b <- io (GHC.moduleIsInterpreted session m)
if b then io (GHC.setContext session [m] [])
else io (GHC.setContext session [] [prelude_mod,m])
modulesLoadedMsg :: SuccessFlag -> [Module] -> GHCi () modulesLoadedMsg :: SuccessFlag -> [Module] -> GHCi ()
modulesLoadedMsg ok mods = do modulesLoadedMsg ok mods = do
......
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