[commit: ghc] master: Handle :cd in external interpreter in a more robust way (f99d898)

git at git.haskell.org git at git.haskell.org
Mon Dec 17 06:17:55 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/f99d898ba384b7d3ace7aae71b0125ba645e09cb/ghc

>---------------------------------------------------------------

commit f99d898ba384b7d3ace7aae71b0125ba645e09cb
Author: Zejun Wu <watashi at fb.com>
Date:   Mon Dec 17 01:16:00 2018 -0500

    Handle :cd in external interpreter in a more robust way
    
    We used to enqueue another command to change directory in the external
    interpreter subprocess, this is not as robust as:
    
    * it can fail with -fno-implict-import-qualified;
    * it doesn't work when we `setGHCiMonad` to something other than `IO`.
    
    Neither of them works if `directory` package is hidden though.
    
    Test Plan:
    ```
    $ inplace/bin/ghc-stage2 --interactive # -fexternal-interpreter
    GHCi, version 8.7.20181213: http://www.haskell.org/ghc/  :? for help
    Prelude> :cd ..
    Prelude> System.Directory.getCurrentDirectory
    "/data/users/watashi"
    Prelude> :!pwd
    /data/users/watashi
    Prelude>
    Leaving GHCi.
    ```
    
      ./validate
    
    Reviewers: simonmar, bgamari, RyanGlScott
    
    Reviewed By: simonmar
    
    Subscribers: rwbarton, carter
    
    Differential Revision: https://phabricator.haskell.org/D5453


>---------------------------------------------------------------

f99d898ba384b7d3ace7aae71b0125ba645e09cb
 ghc/GHCi/UI.hs       | 7 +++++--
 ghc/GHCi/UI/Monad.hs | 2 ++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs
index 13275f8..105324f 100644
--- a/ghc/GHCi/UI.hs
+++ b/ghc/GHCi/UI.hs
@@ -1430,8 +1430,11 @@ changeDirectory dir = do
   dflags <- getDynFlags
   -- With -fexternal-interpreter, we have to change the directory of the subprocess too.
   -- (this gives consistent behaviour with and without -fexternal-interpreter)
-  when (gopt Opt_ExternalInterpreter dflags) $
-    lift $ enqueueCommands ["System.Directory.setCurrentDirectory " ++ show dir']
+  when (gopt Opt_ExternalInterpreter dflags) $ do
+    hsc_env <- GHC.getSession
+    fhv <- compileGHCiExpr $
+      "System.Directory.setCurrentDirectory " ++ show dir'
+    liftIO $ evalIO hsc_env fhv
 
 trySuccess :: GHC.GhcMonad m => m SuccessFlag -> m SuccessFlag
 trySuccess act =
diff --git a/ghc/GHCi/UI/Monad.hs b/ghc/GHCi/UI/Monad.hs
index 45a5271..a3c21d8 100644
--- a/ghc/GHCi/UI/Monad.hs
+++ b/ghc/GHCi/UI/Monad.hs
@@ -24,6 +24,8 @@ module GHCi.UI.Monad (
 
         printForUserNeverQualify, printForUserModInfo,
         printForUser, printForUserPartWay, prettyLocations,
+
+        compileGHCiExpr,
         initInterpBuffering,
         turnOffBuffering, turnOffBuffering_,
         flushInterpBuffers,



More information about the ghc-commits mailing list