summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoachim Breitner <mail@joachim-breitner.de>2021-03-10 15:28:40 -0500
committerBen Gamari <ben@smart-cactus.org>2021-03-10 16:57:59 -0500
commit30ccf9ed1f592531dac9f3d750278fac6303c3e4 (patch)
tree4b325e15f5fdba50d0bab2924354628ce2ccbd49
parent8a59f49ae2204dbf58ef50ea8c0a50ee2c7aa64a (diff)
downloadhaskell-30ccf9ed1f592531dac9f3d750278fac6303c3e4.tar.gz
Introduce GHC2021 language
This adds support for -XGHC2021, as described in Proposal 0380 [1]. [1] https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0380-ghc2021.rst
-rw-r--r--compiler/GHC/Driver/Flags.hs2
-rw-r--r--compiler/GHC/Driver/Session.hs53
-rw-r--r--docs/users_guide/9.2.1-notes.rst15
-rw-r--r--docs/users_guide/bugs.rst27
-rw-r--r--docs/users_guide/exts/control.rst64
-rw-r--r--ghc/GHCi/UI.hs8
6 files changed, 144 insertions, 25 deletions
diff --git a/compiler/GHC/Driver/Flags.hs b/compiler/GHC/Driver/Flags.hs
index 3a31e55ff1..2b86c0f266 100644
--- a/compiler/GHC/Driver/Flags.hs
+++ b/compiler/GHC/Driver/Flags.hs
@@ -534,7 +534,7 @@ instance ToJson WarnReason where
json (ErrReason (Just wf)) = JSString (show wf)
-data Language = Haskell98 | Haskell2010
+data Language = Haskell98 | Haskell2010 | GHC2021
deriving (Eq, Enum, Show, Bounded)
instance Outputable Language where
diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs
index 8b7ddd321d..b4218d29ba 100644
--- a/compiler/GHC/Driver/Session.hs
+++ b/compiler/GHC/Driver/Session.hs
@@ -1351,6 +1351,56 @@ languageExtensions (Just Haskell2010)
LangExt.FieldSelectors,
LangExt.RelaxedPolyRec]
+languageExtensions (Just GHC2021)
+ = [LangExt.ImplicitPrelude,
+ -- See Note [When is StarIsType enabled]
+ LangExt.StarIsType,
+ LangExt.MonomorphismRestriction,
+ LangExt.TraditionalRecordSyntax,
+ LangExt.EmptyDataDecls,
+ LangExt.ForeignFunctionInterface,
+ LangExt.PatternGuards,
+ LangExt.DoAndIfThenElse,
+ LangExt.FieldSelectors,
+ LangExt.RelaxedPolyRec,
+ -- Now the new extensions (not in Haskell2010)
+ LangExt.BangPatterns,
+ LangExt.BinaryLiterals,
+ LangExt.ConstrainedClassMethods,
+ LangExt.ConstraintKinds,
+ LangExt.DeriveDataTypeable,
+ LangExt.DeriveFoldable,
+ LangExt.DeriveFunctor,
+ LangExt.DeriveGeneric,
+ LangExt.DeriveLift,
+ LangExt.DeriveTraversable,
+ LangExt.EmptyCase,
+ LangExt.EmptyDataDeriving,
+ LangExt.ExistentialQuantification,
+ LangExt.ExplicitForAll,
+ LangExt.FlexibleContexts,
+ LangExt.FlexibleInstances,
+ LangExt.GADTSyntax,
+ LangExt.GeneralizedNewtypeDeriving,
+ LangExt.HexFloatLiterals,
+ LangExt.ImportQualifiedPost,
+ LangExt.InstanceSigs,
+ LangExt.KindSignatures,
+ LangExt.MultiParamTypeClasses,
+ LangExt.RecordPuns,
+ LangExt.NamedWildCards,
+ LangExt.NumericUnderscores,
+ LangExt.PolyKinds,
+ LangExt.PostfixOperators,
+ LangExt.RankNTypes,
+ LangExt.ScopedTypeVariables,
+ LangExt.StandaloneDeriving,
+ LangExt.StandaloneKindSignatures,
+ LangExt.TupleSections,
+ LangExt.TypeApplications,
+ LangExt.TypeOperators,
+ LangExt.TypeSynonymInstances]
+
hasPprDebug :: DynFlags -> Bool
hasPprDebug = dopt Opt_D_ppr_debug
@@ -3401,7 +3451,8 @@ supportedLanguagesAndExtensions arch_os =
languageFlagsDeps :: [(Deprecation, FlagSpec Language)]
languageFlagsDeps = [
flagSpec "Haskell98" Haskell98,
- flagSpec "Haskell2010" Haskell2010
+ flagSpec "Haskell2010" Haskell2010,
+ flagSpec "GHC2021" GHC2021
]
-- | These -X<blah> flags cannot be reversed with -XNo<blah>
diff --git a/docs/users_guide/9.2.1-notes.rst b/docs/users_guide/9.2.1-notes.rst
index 131f694f6b..6e36f1dbeb 100644
--- a/docs/users_guide/9.2.1-notes.rst
+++ b/docs/users_guide/9.2.1-notes.rst
@@ -57,6 +57,21 @@ Language
This is now fixed, but it means that some programs will newly require
``-XFlexibleContexts``.
+* The :extension:`GHC2021` language is supported now. It builds on top of
+ Haskell2010, adding several stable and conservative extensions, and removing
+ deprecated ones. It is now also the “default” langauge set that is active
+ when no other language set, such as :extension:`Haskell98` or
+ :extension:`Haskell2010`, is explicitly loaded (e.g via Cabal’s
+ ``default-language``).
+
+ Because :extension:`GHC2021` includes
+ :extension:`GeneralizedNewtypeDeriving`, which is not safe for Safe Haskell,
+ users of Safe Haskell are advised to use :extension:`Haskell2010` explicitly.
+
+ The default mode of GHC until 9.0 included
+ :extension:`NondecreasingIndentation`, but :extension:`GHC2021` does not.
+ This may break code implicitly using this extension.
+
* Various records-related extensions have been improved:
- A new extension :extension:`NoFieldSelectors` hides record field selector
diff --git a/docs/users_guide/bugs.rst b/docs/users_guide/bugs.rst
index 2f6eecd54a..2b533fa42f 100644
--- a/docs/users_guide/bugs.rst
+++ b/docs/users_guide/bugs.rst
@@ -24,12 +24,11 @@ The limitations here are listed in Haskell Report order (roughly).
Divergence from Haskell 98 and Haskell 2010
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-By default, GHC mainly aims to behave (mostly) like a Haskell 2010
-compiler, although you can tell it to try to behave like a particular
-version of the language with the :extension:`Haskell98` and
-:extension:`Haskell2010` flags. The known deviations from the standards are
-described below. Unless otherwise stated, the deviation applies in Haskell 98,
-Haskell 2010 and the default modes.
+GHC aims to be able to behave (mostly) like a Haskell 98 or Haskell 2010
+compiler, if you tell it to try to behave like that with the
+:extension:`Haskell98` and :extension:`Haskell2010` flags. The known deviations
+from the standards are described below. Unless otherwise stated, the deviation
+applies in both Haskell 98 and Haskell 2010 mode.
.. _infelicities-lexical:
@@ -100,7 +99,7 @@ Lexical syntax
Context-free syntax
^^^^^^^^^^^^^^^^^^^
-- In Haskell 98 mode and by default (but not in Haskell 2010 mode), GHC
+- In Haskell 98 mode (but not in Haskell 2010 mode), GHC
is a little less strict about the layout rule when used in ``do``
expressions. Specifically, the restriction that "a nested context
must be indented further to the right than the enclosing context" is
@@ -150,8 +149,8 @@ Context-free syntax
Expressions and patterns
^^^^^^^^^^^^^^^^^^^^^^^^
-In its default mode, GHC makes some programs slightly more defined than
-they should be. For example, consider ::
+By default, GHC makes some programs slightly more defined than they should be.
+For example, consider ::
f :: [a] -> b -> b
f [] = error "urk"
@@ -203,16 +202,6 @@ Will warn you with
And indeed, since the `Monad <https://hackage.haskell.org/package/base-4.14.1.0/docs/Control-Monad.html#t:Monad>`__ class does not have the ``fail`` method anymore,
we need to explicitly add ``(MonadFail m)`` to the constraints of the function.
-.. _infelicities-decls:
-
-Declarations and bindings
-^^^^^^^^^^^^^^^^^^^^^^^^^
-
-In its default mode, GHC does not accept datatype contexts, as it has
-been decided to remove them from the next version of the language
-standard. This behaviour can be controlled with the ``DatatypeContexts``
-extension. See :ref:`datatype-contexts`.
-
.. _infelicities-recursive-groups:
Typechecking of recursive binding groups
diff --git a/docs/users_guide/exts/control.rst b/docs/users_guide/exts/control.rst
index fff8107b13..a94def72b5 100644
--- a/docs/users_guide/exts/control.rst
+++ b/docs/users_guide/exts/control.rst
@@ -17,6 +17,70 @@ Language extensions can be controlled (i.e. allowed or not) in two ways:
- Language extensions can also be enabled using the ``LANGUAGE`` pragma, thus
``{-# LANGUAGE TemplateHaskell #-}`` (see :ref:`language-pragma`).
+.. extension:: GHC2021
+ :shortdesc: Use GHC’s set of default languages from 2021
+
+ GHC blesses a number of extensions, beyond Haskell 2010, to be suitable to
+ turned on by default. These extensions are considered to be stable and
+ conservative.
+
+ ``GHC2021`` is used by GHC if neither ``Haskell98`` nor ``Haskell2010`` is
+ turned on explicitly. Since later versions of GHC may use a later
+ ``GHC20xx`` by default, users are advised to declare the language set
+ explicitly with ``-XGHC2021``.
+
+
+ The ``GHC2021`` language set comprises the following extensions:
+
+ .. hlist::
+
+ * :extension:`ImplicitPrelude`
+ * :extension:`StarIsType`
+ * :extension:`MonomorphismRestriction`
+ * :extension:`TraditionalRecordSyntax`
+ * :extension:`EmptyDataDecls`
+ * :extension:`ForeignFunctionInterface`
+ * :extension:`PatternGuards`
+ * :extension:`DoAndIfThenElse`
+ * :extension:`RelaxedPolyRec`
+ * :extension:`BangPatterns`
+ * :extension:`BinaryLiterals`
+ * :extension:`ConstrainedClassMethods`
+ * :extension:`ConstraintKinds`
+ * :extension:`DeriveDataTypeable`
+ * :extension:`DeriveFoldable`
+ * :extension:`DeriveFunctor`
+ * :extension:`DeriveGeneric`
+ * :extension:`DeriveLift`
+ * :extension:`DeriveTraversable`
+ * :extension:`EmptyCase`
+ * :extension:`EmptyDataDeriving`
+ * :extension:`ExistentialQuantification`
+ * :extension:`ExplicitForAll`
+ * :extension:`FlexibleContexts`
+ * :extension:`FlexibleInstances`
+ * :extension:`GADTSyntax`
+ * :extension:`GeneralisedNewtypeDeriving`
+ * :extension:`HexFloatLiterals`
+ * :extension:`ImportQualifiedPost`
+ * :extension:`InstanceSigs`
+ * :extension:`KindSignatures`
+ * :extension:`MultiParamTypeClasses`
+ * :extension:`NamedFieldPuns`
+ * :extension:`NamedWildCards`
+ * :extension:`NumericUnderscores`
+ * :extension:`PolyKinds`
+ * :extension:`PostfixOperators`
+ * :extension:`RankNTypes`
+ * :extension:`ScopedTypeVariables`
+ * :extension:`StandaloneDeriving`
+ * :extension:`StandaloneKindSignatures`
+ * :extension:`TupleSections`
+ * :extension:`TypeApplications`
+ * :extension:`TypeOperators`
+ * :extension:`TypeSynonymInstances`
+
+
.. extension:: Haskell2010
:shortdesc: Use the Haskell 2010 language variant.
diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs
index 0ac6fe4d9c..720f57a4e3 100644
--- a/ghc/GHCi/UI.hs
+++ b/ghc/GHCi/UI.hs
@@ -3348,10 +3348,10 @@ showLanguages' :: Bool -> DynFlags -> IO ()
showLanguages' show_all dflags =
putStrLn $ showSDoc dflags $ vcat
[ text "base language is: " <>
- case language dflags of
- Nothing -> text "Haskell2010"
- Just Haskell98 -> text "Haskell98"
- Just Haskell2010 -> text "Haskell2010"
+ case lang of
+ Haskell98 -> text "Haskell98"
+ Haskell2010 -> text "Haskell2010"
+ GHC2021 -> text "GHC2021"
, (if show_all then text "all active language options:"
else text "with the following modifiers:") $$
nest 2 (vcat (map (setting xopt) DynFlags.xFlags))