Make GHCi work when RebindableSyntax is enabled
authorRyan Scott <ryan.gl.scott@gmail.com>
Fri, 2 Jun 2017 15:49:47 +0000 (11:49 -0400)
committerBen Gamari <ben@smart-cactus.org>
Fri, 2 Jun 2017 16:27:45 +0000 (12:27 -0400)
Previously, we were running some blocks of code at the start of every
GHCi sessions which use do-notation, something which doesn't work well
if you start GHCi with the `-XRebindableSyntax` flag on. This tweaks the
code to avoid the use of do-notation so that `-XRebindableSyntax` won't
reject it.

Test Plan: make test TEST=T13385

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie

GHC Trac Issues: #13385

Differential Revision: https://phabricator.haskell.org/D3621

ghc/GHCi/UI/Monad.hs
testsuite/tests/ghci/scripts/T13385.script [new file with mode: 0644]
testsuite/tests/ghci/scripts/all.T

index 244595b..b57a5a0 100644 (file)
@@ -420,13 +420,15 @@ foreign import ccall "revertCAFs" rts_revertCAFs  :: IO ()
 -- | Compile "hFlush stdout; hFlush stderr" once, so we can use it repeatedly
 initInterpBuffering :: Ghc (ForeignHValue, ForeignHValue)
 initInterpBuffering = do
+  -- We take great care not to use do-notation in the expressions below, as
+  -- they are fragile in the presence of RebindableSyntax (Trac #13385).
   nobuf <- GHC.compileExprRemote $
-   "do { System.IO.hSetBuffering System.IO.stdin System.IO.NoBuffering; " ++
-       " System.IO.hSetBuffering System.IO.stdout System.IO.NoBuffering; " ++
-       " System.IO.hSetBuffering System.IO.stderr System.IO.NoBuffering }"
+   "                  System.IO.hSetBuffering System.IO.stdin  System.IO.NoBuffering" ++
+   "`GHC.Base.thenIO` System.IO.hSetBuffering System.IO.stdout System.IO.NoBuffering" ++
+   "`GHC.Base.thenIO` System.IO.hSetBuffering System.IO.stderr System.IO.NoBuffering"
   flush <- GHC.compileExprRemote $
-   "do { System.IO.hFlush System.IO.stdout; " ++
-       " System.IO.hFlush System.IO.stderr }"
+   "                  System.IO.hFlush System.IO.stdout" ++
+   "`GHC.Base.thenIO` System.IO.hFlush System.IO.stderr"
   return (nobuf, flush)
 
 -- | Invoke "hFlush stdout; hFlush stderr" in the interpreter
diff --git a/testsuite/tests/ghci/scripts/T13385.script b/testsuite/tests/ghci/scripts/T13385.script
new file mode 100644 (file)
index 0000000..e69de29
index 8ef45fe..8c3a2f5 100755 (executable)
@@ -251,6 +251,7 @@ test('T12550', normal, ghci_script, ['T12550.script'])
 test('StaticPtr', normal, ghci_script, ['StaticPtr.script'])
 test('T13202', normal, ghci_script, ['T13202.script'])
 test('T13202a', normal, ghci_script, ['T13202a.script'])
+test('T13385', [extra_hc_opts("-XRebindableSyntax")], ghci_script, ['T13385.script'])
 test('T13420', normal, ghci_script, ['T13420.script'])
 test('T13466', normal, ghci_script, ['T13466.script'])
 test('GhciCurDir', normal, ghci_script, ['GhciCurDir.script'])