[Git][ghc/ghc][master] Recognize file-header pragmas in GHCi (#21507)
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Sun Aug 21 20:51:55 UTC 2022
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
9939e95f by MorrowM at 2022-08-21T16:51:38-04:00
Recognize file-header pragmas in GHCi (#21507)
- - - - -
5 changed files:
- docs/users_guide/9.6.1-notes.rst
- docs/users_guide/ghci.rst
- ghc/GHCi/UI.hs
- + testsuite/tests/ghci/scripts/T21507.script
- testsuite/tests/ghci/scripts/all.T
Changes:
=====================================
docs/users_guide/9.6.1-notes.rst
=====================================
@@ -66,6 +66,21 @@ Compiler
- The :extension:`TypeInType` is now marked as deprecated. Its meaning has been included
in :extension:`PolyKinds` and :extension:`DataKinds`.
+
+GHCi
+~~~~
+
+- GHCi will now accept any file-header pragmas it finds, such as
+ ``{-# OPTIONS_GHC ... #-}`` and ``{-# LANGUAGE ... #-}`` (see :ref:`pragmas`). For example,
+ instead of using :ghci-cmd:`:set` to enable :ghc-flag:`-Wmissing-signatures`,
+ you could instead write:
+
+ .. code-block:: none
+
+ ghci> {-# OPTIONS_GHC -Wmissing-signatures #-}
+
+This can be convenient when pasting large multi-line blocks of code into GHCi.
+
``base`` library
~~~~~~~~~~~~~~~~
=====================================
docs/users_guide/ghci.rst
=====================================
@@ -3173,6 +3173,15 @@ example, to turn on :ghc-flag:`-Wmissing-signatures`, you would say:
ghci> :set -Wmissing-signatures
+GHCi will also accept any file-header pragmas it finds, such as
+``{-# OPTIONS_GHC ... #-}`` and ``{-# LANGUAGE ... #-}`` (see :ref:`pragmas`). For example,
+instead of using :ghci-cmd:`:set` to enable :ghc-flag:`-Wmissing-signatures`,
+you could instead write:
+
+.. code-block:: none
+
+ ghci> {-# OPTIONS_GHC -Wmissing-signatures #-}
+
Any GHC command-line option that is designated as dynamic (see the table
in :ref:`flag-reference`), may be set using :ghci-cmd:`:set`. To unset an
option, you can set the reverse option:
=====================================
ghc/GHCi/UI.hs
=====================================
@@ -78,6 +78,7 @@ import GHC.Types.Name.Reader as RdrName ( getGRE_NameQualifier_maybes, getRdrNam
import GHC.Types.SrcLoc as SrcLoc
import qualified GHC.Parser.Lexer as Lexer
import GHC.Parser.Header ( toArgs )
+import qualified GHC.Parser.Header as Header
import GHC.Types.PkgQual
import GHC.Unit
@@ -1249,6 +1250,9 @@ runStmt input step = do
let source = progname st
let line = line_number st
+ -- Add any LANGUAGE/OPTIONS_GHC pragmas we find find.
+ set_pragmas pflags
+
if | GHC.isStmt pflags input -> do
hsc_env <- GHC.getSession
mb_stmt <- liftIO (runInteractiveHsc hsc_env (hscParseStmtWithLocation source line input))
@@ -1282,6 +1286,12 @@ runStmt input step = do
run_imports imports = mapM_ (addImportToContext . unLoc) imports
+ set_pragmas pflags =
+ let stringbuf = stringToStringBuffer input
+ (_msgs, loc_opts) = Header.getOptions pflags stringbuf "<interactive>"
+ opts = unLoc <$> loc_opts
+ in setOptions opts
+
run_stmt :: GhciMonad m => GhciLStmt GhcPs -> m (Maybe GHC.ExecResult)
run_stmt stmt = do
m_result <- GhciMonad.runStmt stmt input step
=====================================
testsuite/tests/ghci/scripts/T21507.script
=====================================
@@ -0,0 +1,5 @@
+:{
+{-# LANGUAGE TypeFamilies #-}
+type family T21507 a where
+ T21507 a = a
+:}
=====================================
testsuite/tests/ghci/scripts/all.T
=====================================
@@ -368,3 +368,4 @@ test('T21110', [extra_files(['T21110A.hs'])], ghci_script,
['T21110.script'])
test('T17830', [filter_stdout_lines(r'======.*')], ghci_script, ['T17830.script'])
test('T21294a', normal, ghci_script, ['T21294a.script'])
+test('T21507', normal, ghci_script, ['T21507.script'])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9939e95fb7b808b68aca00dfabbb99079927f482
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9939e95fb7b808b68aca00dfabbb99079927f482
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20220821/b8ddedc3/attachment-0001.html>
More information about the ghc-commits
mailing list