2.1. Version 9.0.1¶
The significant changes to the various parts of the compiler are listed in the following sections.
The LLVM backend of this release is to be used with LLVM 9.
2.1.1. Highlights¶
The
LinearTypesextension enables linear function syntaxa %1 -> b, as described in the Linear Types GHC proposal.The GADT syntax can be used to define data types with linear and nonlinear fields.
This extension is considered experimental: it doesn’t implement the full proposal yet and the details are subject to change.
NCG
The linear register allocator saw improvements reducing the number of redundant move instructions. Rare edge cases can see double digit improvements in runtime for inner loops.
In the mean this improved runtime by about 0.8%. For details see ticket 17823.
Pattern-Match Coverage Checking
The revamp of the pattern-match coverage checker that started in 8.10 concludes with this release and implements the novel *Lower Your Guards* algorithm.
Compared to 8.10, end users might notice improvements to “long-distance information”:
f True = 1 f x = ... case x of { False -> 2; True -> 3 } ...
GHC is now able to detect the case alternative returning
3as redundant.Some more performance improvements in edge cases.
Windows: Use the large address-space allocator.
This improves runtime but causes increased memory usage on Windows versions older than Win 8.1/Server 2012.
Windows: New IO Manager.
A new I/O manager (WinIO) is now available as a community technical preview which is designed to allow experimentation and bootstrapping of third-party packages such as Network. The new I/O manager is off by default and can be enabled with the RTS flag
--io-manager=native. Currently the I/O manager is unoptimized and is focused more on correctness. There is also no support for pipes and sockets. These will be added in the next release. *see more*.Big-number support
GHC now relies on a new
ghc-bignumpackage to provide Integer/Natural implementations. This package supports the following backends:gmp: adapted from integer-gmp package that was used before
native: new Haskell implementation, faster than
integer-simplewhich is not used anymore
All backends now use the same representation for big numbers (the one that was previously used only by
integer-gmp). It led to several compiler simplifications, performance improvements and bug fixes (e.g. 15262, 15286).All backends must provide exactly the same set of functions with deterministic results so that they can be tested one against the other (they can only differ in performance). As a consequence, some functions that were only provided by integer-gmp (prime test, secure powmod, etc.) are no longer provided by ghc-bignum. Note that other packages (e.g.
hgmp) provide these functions.For now GHC still doesn’t allow dynamic selection of the
ghc-bignumbackend to use.
Breaking change: Template Haskell splices now act as separation points between constraint solving passes. It is no longer possible to use an instance of a class before a splice and define that instance after a splice. For example, this code now reports a missing instance for
C Bool:class C a where foo :: a bar :: Bool bar = foo $(return []) instance C Bool where foo = True
Support for 32-bit Windows has officially been dropped as Microsoft has formally discontinued new 32-bit Windows 10 releases in 2020. See 18487 for details.
2.1.2. Full details¶
2.1.2.1. Language¶
Record field selectors are now given type signatures that preserve the user-written order of quantified type variables. Moreover, field selector type signatures no longer make inferred type variables available for explicit type application. See Field selectors and TypeApplications for more details.
In certain situations, this will constitute a breaking change as this can affect
TypeApplications. For instance, given the following definitions:{-# LANGUAGE PolyKinds #-} newtype P a = MkP { unP :: Proxy a } newtype N :: Type -> Type -> Type where MkN :: forall b a. { unN :: Either a b } -> N a b
Previous versions of GHC would give the following types to
unPandunN:unP :: forall k (a :: k). P a -> Proxy a unN :: forall a b. N a b -> Either a b
GHC will now give them the following types instead:
unP :: forall {k} (a :: k). P a -> Proxy a unN :: forall b a. N a b -> Either a b
In obscure scenarios, GHC now rejects programs it previously accepted, but with unhelpful types. For example, if (with
-XPartialTypeSignatures) you were to writex :: forall (f :: forall a (b :: a -> Type). b _). f _, GHC previously would have acceptedx, but its type would have involved the mysteriousAnyinternal type family. Now, GHC rejects, explaining the situation.GHC now more faithfully implements the instance-lookup scheme described with
QuantifiedConstraints. Previous bugs meant that programs like this were accepted:data T (c :: Type -> Constraint) instance (forall h. c h => Functor h) => Functor (T c) instance (forall h. c h => Applicative h) => Applicative (T c)
Note that in the instance declaration for
Applicative (T c), we cannot proveFunctor (T c), because the quantified constraint shadows the global instance. There is an easy workaround, though: just includeFunctor (T c)as an assumption.instance (forall h. c h => Applicative h, Functor (T c)) => Applicative (T c)
There is a chance we will tweak the lookup scheme in the future, to make this workaround unnecessary.
GHC now consistently does eager instantiation during type inference. As a consequence, visible type application (VTA) now only works when the head of the application is:
A variable
An expression with a type signature
For example
(let x = blah in id) @Bool Trueno longer typechecks. You should writelet x = blah in id @Bool Trueinstead.This change prepares the way for Quick Look impredicativity.
GHC now implements simplified subsumption, as described in GHC Proposal #287. This change simplifies the type system, and prevents the possibility of GHC silently changing the semantics of user programs, but it does mean that some libraries may need eta-expansion to typecheck. More info here: Subsumption.
This change also prepares the way for Quick Look impredicativity.
GHC now allows users to manually define the specificity of type variable binders. By marking a variable with braces
{tyvar}or{tyvar :: kind}, it becomes inferred despite appearing in a type signature. This feature effectively allows users to choose which variables can or can’t be instantiated through visible type application. More information can be found here: Manually defining inferred variables.GADT constructor types now properly adhere to The forall-or-nothing rule. As a result, GHC will now reject some GADT constructors that previous versions of GHC would accept, such as the following:
data T where MkT1 :: (forall a. a -> b -> T) MkT2 :: (forall a. a -> T)
MkT1andMkT2are rejected because the lack of an outermostforalltriggers implicit quantification, making the explicitforalls nested. Furthermore, GADT constructors do not permit the use of nestedforalls, as explained in Formal syntax for GADTs.In addition to rejecting nested
foralls, GHC is now more stringent about rejecting uses of nested contexts in GADT constructors. For example, the following example, which previous versions of GHC would accept, is now rejected:data U a where MkU :: (Show a => U a)
GHC more strictly enforces the rule that the type in the top of an instance declaration is not permitted to contain nested
foralls or contexts, as documented in Formal syntax for instance declaration types. For example, the following examples, which previous versions of GHC would accept, are now rejected:instance (forall a. C a) where … instance (Show a => C a) where …
In addition, GHC now enforces the rule that the types in
derivingclauses andviatypes (for instances derived withDerivingVia) cannot contain nestedforalls or contexts. For example, the following examples, which previous versions of GHC would accept, are now rejected:data T = MkT deriving (C1, (forall x. C2 x)) deriving via (forall x. V x) instance C (S x)
A new language extension
QualifiedDois implemented, allowing to qualify a do block to control which operations to use for desugaring do syntax.{-# LANGUAGE QualifiedDo #-} import qualified SomeModule as M f x = M.do -- desugars to: y <- M.return x -- M.return x M.>>= \y -> M.return y -- M.return y M.>> M.return y -- M.return y
See Qualified do-notation for more details.
LexicalNegationis a new extension that detects whether the minus sign stands for negation during lexical analysis by checking for the surrounding whitespace:a = x - y -- subtraction b = f -x -- negation f = (- x) -- operator section c = (-x) -- negation
The behavior of
NegativeLiteralschanged, and now we require that a negative literal must not be preceded by a closing token (see GHC Proposal #229) for the definition of a closing token). In other words, we parsef -123asf (-123), butx-123as(-) x 123. Before this amendment,NegativeLiteralscausedx-123to be parsed asx(-123).GHC is now more sensitive to whitespace between infix operators and their arguments, requiring it in some cases where it was not previously necessary as the result of the whitespace-sensitive operator parsing proposal. It also affects the usage of
!,``~`` and@as BangPatterns, irrefutable patterns and type applications respectively. This means that expressions that were parsed as visible type applications in previous versions when the@was surrounded by whitespace will now be parsed as an operator application. For more details see the migration guide on the wiki.
2.1.2.2. Compiler¶
A new flag
-flink-rtsto enable linking the RTS when linking shared libraries.The
-funfolding-keeness-factorflag has been deprecated as its scaling strategy resulted in unreasonably large discounts in some cases (see 15304). Users who previously used this flag to suggest more aggressive inlining are advised to look at-funfolding-use-threshold=⟨n⟩or useINLINEpragmas to more precisely force inlining.The
-funfolding-keeness-factorflag has been deprecated as its scaling strategy resulted in unreasonably large discounts in some cases (see 15304). Users who previously used this flag to suggest more aggressive inlining are advised to look at-funfolding-use-threshold=⟨n⟩or useINLINEpragmas to more precisely force inlining.
2.1.2.3. GHCi¶
GHCi prompt no longer lists loaded modules. The previous behavior can be restored with
:set prompt "%s> "and:set prompt-cont "%s| ".The
:scriptcommand now allows for file names that contain spaces to passed as arguments: either by enclosing the file names in double quotes or by escaping spaces in file names with a backslash. (18027)The GHCi debugger syntax
:break <qualified.name>now allows to set breakpoints on all functions. The restrictionstop-Levelandexportedhave been removed. Hence it’s now possible to use this syntax to set breakpoints on functions defined in nestedwhereorletclauses.
2.1.2.4. Runtime system¶
-Nwithout a count now tries to respect the number of processors in the process’s affinity mask, making GHC’s behavior more predictable in containerized settings (14781).Support for Windows Vista has been dropped. GHC-compiled programs now require Windows 7 or later.
Windows now uses the large address space allocator by default. In extreme cases we saw improvements by up to 3% decreased runtime.
The downside is that haskell apps run on older (Pre Win-8.1/Server 2012) systems will have higher memory footprints.
2.1.2.5. Template Haskell¶
Implement the Overloaded Quotations proposal (#246). The type of all quotation forms have now been generalised in terms of a minimal interface necessary (the
Quotetype class) for the implementation rather than the overapproximation of theQmonad.Template Haskell quotes now handle fixity declarations in
letandwherebindings properly. Previously, such fixity declarations would be dropped when quoted due to a Template Haskell bug.The
-XTemplateHaskellQuotesextension now allows nested splices as nested splices do not lead directly to compile-time evaluation. (Merge request !2288)
2.1.2.6. Arrow notation¶
When combined with
Arrows, theLambdaCaseextension now additionally allows\casesyntax to be used as a command inprocnotation.When combined with
Arrows, the effects of theBlockArgumentsextension now also apply to applications of arrow control operators in(|banana brackets|):(| untilA (increment -< x + y) do within 0.5 -< x ... |)
2.1.2.7. Haddock¶
Parsing is now more robust to insufficiently indented Haddock comments:
class C a where f :: a -> a -- ^ This comment used to trigger a parse error g :: a -> a
-Winvalid-haddockis a new warning that reports discarded Haddock comments that cannot be associated with AST elements:myValue = -- | Invalid (discarded) comment in an expression 2 + 2
When faced with several comments for a data constructor or a data constructor field, Haddock now picks the first one instead of the last one. The extraneous comment is reported as invalid when
-Winvalid-haddockis enabled:data T -- | First comment = MkT -- ^ Second comment (rejected)
Haddock is now more relaxed about the placement of comments in types relative to the function arrow
->, allowing more formatting styles:f :: Int -> -- ^ comment on Int (no longer a parse error) Bool -- ^ comment on Bool
Haddock can now parse the documentation comment for the first declaration in a module without a module header (17561):
-- | This comment used to trigger a parse error main = putStrLn "Hello"
2.1.2.8. base library¶
Foreign.ForeignPtr.withForeignPtris now less aggressively optimised, avoiding the unsoundness issue reported in 17760 in exchange for a small amount of additional allocation.If your application is impacted significantly by this change and the continuation given to
withForeignPtrwill not provably diverge (via throwing of an exception or looping) then the previous optimisation behavior can be recovered by instead usingGHC.ForeignPtr.unsafeWithForeignPtr.
2.1.2.9. ghc-prim library¶
Add a known-key
cstringLength#toGHC.CStringthat is eligible for constant folding by a built-in rule.A new primop,
keepAlive#, has been introduced to replacetouch#in controlling object lifetime without the soundness issues affecting the latter (see 17760)
2.1.2.10. ghc library¶
The type of the
getAnnotationsfunction has changed to better reflect the fact that it returns two different kinds of annotations, those on names and those on modules:getAnnotations :: Typeable a => ([Word8] -> a) -> ModGuts -> CoreM (ModuleEnv [a], NameEnv [a])
The meaning of the
hs_fixdsfield ofHsGrouphas changed slightly. It now only contains fixity signatures defined for top-level declarations and class methods defined outside of the class itself. Previously,hs_fixdswould also contain fixity signatures for class methods defined inside the class, such as the fixity signature formin the following example:class C a where infixl 4 `m` m :: a -> a -> a
If you wish to attain the previous behavior of
hs_fixds, use the newhsGroupTopLevelFixitySigsfunction, which collects all top-level fixity signatures, including those for class methods defined inside classes.The
Exceptionmodule was boiled down acknowledging the existence of theexceptionsdependency. In particular, theExceptionMonadclass is not a proper class anymore, but a mere synonym forMonadThrow,MonadCatch,MonadMask(all fromexceptions) andMonadIO. All ofg*-functions from the module (gtry,gcatch, etc.) are erased, and theirexceptions-alternatives are meant to be used in the GHC code instead.parseModuleis now the only parser entry point that deals with Haddock comments. The other entry points (parseDeclaration,parseExpression, etc) do not insert the Haddock comments into the AST.
2.1.2.11. base library¶
ForeignPtrContentshas a new nullary data constructorFinalPtr.FinalPtris intended for turning a primitive string literal into aForeignPtr. UnlikePlainForeignPtr,FinalPtrdoes not have a finalizer. ReplacingPlainForeignPtrthat hasNoFinalizerswithFinalPtrreduces allocations, reduces the size of compiled binaries, and unlocks important Core-to-Core optimizations.FinalPtrwill be used in an upcomingbytestringrelease to improve the performance ofByteStringliterals created withOverloadedStrings.
2.1.2.12. Build system¶
2.1.3. Bootstrapping requirements¶
GHC now requires a C compiler which supports
__atomic_op_nbuiltins. This raises the requirement for GCC to 4.7.
2.1.4. Included libraries¶
The package database provided with this distribution also contains a number of packages other than GHC itself. See the changelogs provided with these packages for further change information.
| Package | Version | Reason for inclusion |
|---|---|---|
ghc |
9.0.2 | The compiler itself |
Cabal |
3.4.1.0 | Dependency of |
Win32 |
2.12.0.1 | Dependency of |
array |
0.5.4.0 | Dependency of |
base |
4.15.1.0 | Core library |
binary |
0.8.8.0 | Dependency of |
bytestring |
0.10.12.1 | Dependency of |
containers |
0.6.4.1 | Dependency of |
deepseq |
1.4.5.0 | Dependency of |
directory |
1.3.6.2 | Dependency of |
exceptions |
0.10.4 | Dependency of |
filepath |
1.4.2.1 | Dependency of |
ghc-boot-th |
9.0.2 | Internal compiler library |
ghc-boot |
9.0.2 | Internal compiler library |
ghc-compact |
0.1.0.0 | Core library |
ghc-heap |
9.0.2 | GHC heap-walking library |
ghc-prim |
0.7.0 | Core library |
ghci |
9.0.2 | The REPL interface |
haskeline |
0.8.2 | Dependency of |
hpc |
0.6.1.0 | Dependency of |
integer-gmp |
1.1 | Core library |
libiserv |
9.0.2 | Internal compiler library |
mtl |
2.2.2 | Dependency of |
parsec |
3.1.14.0 | Dependency of |
pretty |
1.1.3.6 | Dependency of |
process |
1.6.16.0 | Dependency of |
stm |
2.5.0.0 | Dependency of |
template-haskell |
2.17.0.0 | Core library |
terminfo |
0.4.1.5 | Dependency of |
text |
1.2.5.0 | Dependency of |
time |
1.9.3 | Dependency of |
transformers |
0.5.6.2 | Dependency of |
unix |
2.7.2.2 | Dependency of |
xhtml |
3000.2.2.1 | Dependency of |