X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=compiler%2Fmain%2FInteractiveEval.hs;h=e189a58b404e651d919e7afcdb16226a119bc7ff;hb=3f925833681ee2ecd54b26e473c5b4ac1efbd837;hp=56dfbbd3481a326fd25007bc4cd8d180947fcc1a;hpb=61e253e98937a2b83454f4d5ab3c94ef8c2dc81e;p=ghc-hetmet.git diff --git a/compiler/main/InteractiveEval.hs b/compiler/main/InteractiveEval.hs index 56dfbbd..e189a58 100644 --- a/compiler/main/InteractiveEval.hs +++ b/compiler/main/InteractiveEval.hs @@ -78,6 +78,7 @@ import GHC.Exts import Data.Array import Control.Exception as Exception import Control.Concurrent +import Data.List (sortBy) import Data.IORef import Foreign.StablePtr @@ -131,7 +132,7 @@ data History = History { historyApStack :: HValue, historyBreakInfo :: BreakInfo, - historyEnclosingDecl :: Name + historyEnclosingDecl :: Id -- ^^ A cache of the enclosing top level declaration, for convenience } @@ -154,16 +155,18 @@ getHistorySpan hsc_env hist = _ -> panic "getHistorySpan" -- | Finds the enclosing top level function name -findEnclosingDecl :: HscEnv -> Module -> SrcSpan -> Name +findEnclosingDecl :: HscEnv -> Module -> SrcSpan -> Id findEnclosingDecl hsc_env mod span = case lookupUFM (hsc_HPT hsc_env) (moduleName mod) of Nothing -> panic "findEnclosingDecl" Just hmi -> let - globals = typeEnvIds (md_types (hm_details hmi)) - Just decl = find (\n -> nameSrcSpan n < span) - (reverse $ map idName globals) - -- ^^ assumes md_types is sorted - in decl + globals = typeEnvIds (md_types (hm_details hmi)) + Just decl = + find (\id -> let n = idName id in + nameSrcSpan n < span && isExternalName n) + (reverse$ sortBy (compare `on` (nameSrcSpan.idName)) + globals) + in decl -- | Find the Module corresponding to a FilePath findModuleFromFile :: HscEnv -> FilePath -> Maybe Module