[project @ 2003-07-21 14:33:19 by simonmar]
authorsimonmar <unknown>
Mon, 21 Jul 2003 14:33:19 +0000 (14:33 +0000)
committersimonmar <unknown>
Mon, 21 Jul 2003 14:33:19 +0000 (14:33 +0000)
:cd now causes all modules to be unloaded.

This is the easy fix for a problem whereby changing directories will
cause GHC to try to demand-load objects from the wrong place, because
it is using relative pathnames.

It's not obvious what the "right" thing to do is if the user changes
directory with :cd and then does a :reload.  Perhaps the right thing
to do is to make the search path "sticky", so that it stays relative
to the original current directory.  This would probably require some
re-engineering of GHC to only use absolute paths internally.

ghc/compiler/ghci/InteractiveUI.hs

index f74285c..5c014be 100644 (file)
@@ -1,6 +1,6 @@
 {-# OPTIONS -#include "Linker.h" #-}
 -----------------------------------------------------------------------------
--- $Id: InteractiveUI.hs,v 1.156 2003/07/02 19:41:43 ross Exp $
+-- $Id: InteractiveUI.hs,v 1.157 2003/07/21 14:33:19 simonmar Exp $
 --
 -- GHC Interactive User Interface
 --
@@ -542,6 +542,14 @@ addModule files = do
 
 changeDirectory :: String -> GHCi ()
 changeDirectory dir = do
+  state    <- getGHCiState
+  when (targets state /= []) $
+       io $ putStr "Warning: changing directory causes all loaded modules to be unloaded, \n\ 
+       \because the search path has changed.\n"
+  dflags   <- io getDynFlags
+  cmstate1 <- io (cmUnload (cmstate state) dflags)
+  setGHCiState state{ cmstate = cmstate1, targets = [] }
+  setContextAfterLoad []
   dir <- expandPath dir
   io (setCurrentDirectory dir)