[commit: ghc] wip/tdammers/disable-defer-type-errors-ghci: Documentation (8f97095)

git at git.haskell.org git at git.haskell.org
Tue Jun 12 10:41:12 UTC 2018


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

On branch  : wip/tdammers/disable-defer-type-errors-ghci
Link       : http://ghc.haskell.org/trac/ghc/changeset/8f9709553ac86e00c9e2640b3f9e668ec3cf93f6/ghc

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

commit 8f9709553ac86e00c9e2640b3f9e668ec3cf93f6
Author: Tobias Dammers <tdammers at gmail.com>
Date:   Tue Jun 12 10:40:22 2018 +0200

    Documentation


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

8f9709553ac86e00c9e2640b3f9e668ec3cf93f6
 ghc/GHCi/UI.hs       | 21 ++++++++++++++++++++-
 ghc/GHCi/UI/Monad.hs |  2 ++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs
index 6e22d9e..80d0083 100644
--- a/ghc/GHCi/UI.hs
+++ b/ghc/GHCi/UI.hs
@@ -1078,13 +1078,13 @@ enqueueCommands cmds = do
 -- The return value True indicates success, as in `runOneCommand`.
 runStmt :: String -> SingleStep -> GHCi (Maybe GHC.ExecResult)
 runStmt stmt step = do
+  -- Override session DynFlags. See Note [Disabling defer-type-errors in GHCi]
   sdflags <- GHC.getSessionDynFlags
   let sdflags' =
         sdflags
           `gopt_unset` Opt_DeferTypeErrors
           `gopt_unset` Opt_DeferTypedHoles
           `gopt_unset` Opt_DeferOutOfScopeVariables
-          `wopt_unset` Opt_WarnDeferredTypeErrors
   bracketGHCi_
     (GHC.setSessionDynFlags sdflags')
     (GHC.setSessionDynFlags sdflags)
@@ -1309,6 +1309,25 @@ getCurrentBreakModule = do
                 let hist = GHC.resumeHistory r !! (ix-1)
                 return $ Just $ GHC.getHistoryModule  hist
 
+-- Note [Disabling defer-type-errors in GHCi]
+-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+--
+-- In Trac:#14963, we saw that a recent fix causes deferring type errors, typed
+-- holes, and out-of-scope variables (all three implied by the
+-- -fdefer-type-errors flag) to produce incorrect Core when compiling
+-- interactive statements for immediate execution in GHCi, which in turn causes
+-- a compiler panic, even for some perfectly simple and well-typed programs.
+--
+-- We don't have a fix for the underlying problem yet, however considering how
+-- deferring errors in interactive statements doesn't really buy the user
+-- anything (the deferred errors would just pop up immediately after compiling
+-- anyway), we decided on a workaround: we simply disable the three offending
+-- DynFlags options temporarily while running interactive statements.
+--
+-- This avoids the panic, but still allows users to enable deferring for all
+-- things that are not interactively issued statements, particularly modules
+-- loaded into GHCi.
+
 -----------------------------------------------------------------------------
 --
 -- Commands
diff --git a/ghc/GHCi/UI/Monad.hs b/ghc/GHCi/UI/Monad.hs
index 83af305..e1425ca 100644
--- a/ghc/GHCi/UI/Monad.hs
+++ b/ghc/GHCi/UI/Monad.hs
@@ -226,6 +226,7 @@ reifyGHCi f = GHCi f'
     -- f'' :: IORef GHCiState -> Session -> IO a
     f'' gs s = f (s, gs)
 
+-- | 'bracket', lifted to the `GHCi` monad.
 bracketGHCi :: GHCi a -> (a -> GHCi c) -> (a -> GHCi b) -> GHCi b
 bracketGHCi acquire release run =
   GHCi (\gs ->
@@ -235,6 +236,7 @@ bracketGHCi acquire release run =
         (\a -> reflectGHCi (s, gs) (release a))
         (\a -> reflectGHCi (s, gs) (run a))))
 
+-- | 'bracket_', lifted to the `GHCi` monad.
 bracketGHCi_ :: GHCi a -> GHCi c -> GHCi b -> GHCi b
 bracketGHCi_ acquire release run =
   bracketGHCi acquire (const release) (const run)



More information about the ghc-commits mailing list