[commit: ghc] master: Fix ghci crash when starting with -fno-implicit-import-qualified (a0fb20b)

git at git.haskell.org git at git.haskell.org
Tue Dec 18 04:37:19 UTC 2018


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

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

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

commit a0fb20bae31ed7a50d1a6e4e15c42ba25d836bfc
Author: Zejun Wu <watashi at fb.com>
Date:   Mon Dec 17 23:35:44 2018 -0500

    Fix ghci crash when starting with -fno-implicit-import-qualified
    
    `ghci -fno-implicit-import-qualified` didn't start with error message:
    
    ```
    GHCi, version 8.6.2: http://www.haskell.org/ghc/  :? for help
    
    <interactive>:1:6: error:
        Not in scope: ‘System.IO.hSetBuffering’
            No module named ‘System.IO’ is imported.
    
    ...
    ```
    
    This change fixes it and update test T2452 to cover this.
    
    Test Plan:
      TEST=T2452 make accept
    
    harbormaster build runs
    
    Reviewers: simonmar, bgamari, RyanGlScott
    
    Reviewed By: simonmar
    
    Subscribers: rwbarton, carter
    
    Differential Revision: https://phabricator.haskell.org/D5452


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

a0fb20bae31ed7a50d1a6e4e15c42ba25d836bfc
 ghc/GHCi/UI/Monad.hs                      | 25 +++++++++++++------------
 testsuite/tests/ghci/scripts/T2452.script |  3 +++
 testsuite/tests/ghci/scripts/T2452.stderr |  4 ++++
 testsuite/tests/ghci/scripts/T2452.stdout |  2 ++
 testsuite/tests/ghci/scripts/all.T        |  3 ++-
 5 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/ghc/GHCi/UI/Monad.hs b/ghc/GHCi/UI/Monad.hs
index a3c21d8..969111b 100644
--- a/ghc/GHCi/UI/Monad.hs
+++ b/ghc/GHCi/UI/Monad.hs
@@ -458,15 +458,16 @@ mkEvalWrapper progname args =
     "(System.Environment.withArgs " ++ show args ++ " m)"
 
 compileGHCiExpr :: GhcMonad m => String -> m ForeignHValue
-compileGHCiExpr expr = do
-  hsc_env <- getSession
-  let dflags = hsc_dflags hsc_env
-      -- RebindableSyntax can wreak havoc with GHCi in several ways
-      -- (see #13385 and #14342 for examples), so we take care to disable it
-      -- for the duration of running expressions that are internal to GHCi.
-      no_rb_hsc_env =
-        hsc_env { hsc_dflags = xopt_unset dflags LangExt.RebindableSyntax }
-  setSession no_rb_hsc_env
-  res <- GHC.compileExprRemote expr
-  setSession hsc_env
-  pure res
+compileGHCiExpr expr =
+  withTempSession mkTempSession $ GHC.compileExprRemote expr
+  where
+    mkTempSession hsc_env = hsc_env
+      { hsc_dflags = (hsc_dflags hsc_env)
+          -- RebindableSyntax can wreak havoc with GHCi in several ways
+          -- (see #13385 and #14342 for examples), so we take care to disable it
+          -- for the duration of running expressions that are internal to GHCi.
+          `xopt_unset` LangExt.RebindableSyntax
+          -- We heavily depend on -fimplicit-import-qualified to compile expr
+          -- with fully qualified names without imports.
+          `gopt_set` Opt_ImplicitImportQualified
+      }
diff --git a/testsuite/tests/ghci/scripts/T2452.script b/testsuite/tests/ghci/scripts/T2452.script
index 28d2bdc..ef60f82 100644
--- a/testsuite/tests/ghci/scripts/T2452.script
+++ b/testsuite/tests/ghci/scripts/T2452.script
@@ -1,2 +1,5 @@
+:t System.IO.hPutStrLn
+:set -fimplicit-import-qualified
+:t System.IO.hPutStrLn
 :set -fno-implicit-import-qualified
 :t System.IO.hPutStrLn
diff --git a/testsuite/tests/ghci/scripts/T2452.stderr b/testsuite/tests/ghci/scripts/T2452.stderr
index 663742f..99b0acb 100644
--- a/testsuite/tests/ghci/scripts/T2452.stderr
+++ b/testsuite/tests/ghci/scripts/T2452.stderr
@@ -2,3 +2,7 @@
 <interactive>:1:1: error:
     Not in scope: ‘System.IO.hPutStrLn’
     No module named ‘System.IO’ is imported.
+
+<interactive>:1:1: error:
+    Not in scope: ‘System.IO.hPutStrLn’
+    No module named ‘System.IO’ is imported.
diff --git a/testsuite/tests/ghci/scripts/T2452.stdout b/testsuite/tests/ghci/scripts/T2452.stdout
new file mode 100644
index 0000000..b2dc3f6
--- /dev/null
+++ b/testsuite/tests/ghci/scripts/T2452.stdout
@@ -0,0 +1,2 @@
+System.IO.hPutStrLn
+  :: GHC.IO.Handle.Types.Handle -> String -> IO ()
diff --git a/testsuite/tests/ghci/scripts/all.T b/testsuite/tests/ghci/scripts/all.T
index c58f587..13753cd 100755
--- a/testsuite/tests/ghci/scripts/all.T
+++ b/testsuite/tests/ghci/scripts/all.T
@@ -108,7 +108,8 @@ test('ghci062', [extra_files(['ghci062/', 'ghci062/Test.hs']),
 		ghci_script, ['ghci062.script'])
 test('ghci063', normal, ghci_script, ['ghci063.script'])
 
-test('T2452', normal, ghci_script, ['T2452.script'])
+test('T2452', [extra_hc_opts("-fno-implicit-import-qualified")],
+    ghci_script, ['T2452.script'])
 test('T2766', normal, ghci_script, ['T2766.script'])
 
 test('T1914', [], ghci_script, ['T1914.script'])



More information about the ghc-commits mailing list