3. バージョン 8.4.1 のリリースノート¶
コンパイラのさまざまな部分での重要な変更は以降の節で一覧表にしてあります. 8.2.1 リリースに対して大量のバグ修正と性能改善を行いました.
注釈
このバージョンのリリースをコンパイルするには GCC 4.7 以降が必要です. Trac #14244 参照
3.1. ハイライト¶
8.2.1 リリースからの変更のハイライトは以下のとおりです.
- GHC はより多くのインスタンスを導出できるようなりました.
-XTypeInTypeの手順を改良し型エラーのメッセージを改善しました..- コード生成をさらに改善しました.
- Semigroup-Monoid提案のフェーズ2を含むライブラリ変更を行いました.
- さまざまな Windows 互換性を改善しました.
- 大量のバグを修正しました.
3.2. 詳細¶
3.2.1. 言語¶
- データ族は少し一般化されました.
データ族宣言では,
Typeではなくカインド変数kで終端できます. さらに,data/newtype のインスタンスは,不要であれば,その族のすべてのパターンを並べなくてもよくなりました. これは,カインドシグネチャを持つ通常のデータ型ではいくつかの型変数を省略できるのと同じことです.
カインド変数がデータ族あるいは型族のインスタンスの右辺に現れるかどうかに関する制限はほとんどなくなりました. 以前は,右辺にあるすべてのカインド変数が左辺の型パターンによって明示的に束縛されていなければならないという厳しい要件がありましたが, カインド変数を暗黙に束縛できるようになりました.これにより,次のような構成が可能になります。
data family Nat :: k -> k -> * -- k is implicitly bound by an invisible kind pattern newtype instance Nat :: (k -> *) -> (k -> *) -> * where Nat :: (forall xx. f xx -> g xx) -> Nat f g class Funct f where type Codomain f :: * instance Funct ('KProxy :: KProxy o) where -- o is implicitly bound by the kind signature -- of the LHS type pattern ('KProxy) type Codomain 'KProxy = NatTr (Proxy :: o -> *)
暗黙に双方向のパターンシノニムは,右辺では,バンパターン(
!)あるいは反駁可能なパターン(~)を使えなくなりました. 以前は使えていましたが,式コンテキストで使用すると,バンパターンと不可反駁パターンは暗黙のうちに無視されていました. これは今や適切にエラーになります. 代わりに明示的に双方向のパターンシノニムを使うべきです. すなわち,エラーになるようなdata StrictJust a = Just !a
は使わず.以下のように
data StrictJust a <- Just !a where StrictJust !a = Just a
を使うべきです.
カインド多相の型引数をもつ GADT を扱うには
-XTypeInTypeが有効でなければなりません. たとえいば,以下のdata G :: k -> * where GInt :: G Int GMaybe :: G Maybe
の宣言を考えましょう. 一つ前のリリースでは,
-XPolyKindsだけを有効にすれば,コンパイルできましたが,これはバグ Trac #13391 でした. しかしながら,GHC 8.4 では,-XTypeInTypeが必要です. GADT のカインドシグネチャは一般化されていませんので,カインド引数kを 明示的に限量化して, CUSK を提供する必要があります.data G :: forall k. k -> * where GInt :: G Int GMaybe :: G Maybe
GADT 構成子の型シグネチャで型変数が限量化される順番が変更になりました. 以前は,以下のように
MkTを書いたとすればdata T a where MkT :: forall b a. b -> T a
MkTの型は直感に反してforall a b. b -> T aでした. GHC は型変数をユーザが書いた順序で限量化するようになったので,MkTの型は,forall b a. b -> T aです(:ghc-flag:`-XTypeApplications`の場合).
新たに追加された
-XEmptyDataDeriving拡張により,空のデータ型に対するEq,Ord,Read,Showのインスタンスをdata Empty deriving Eqのように 直接導出できるようになりました. (以前は-XStandaloneDerivingを有効にしなければなりませんでした.)また
-XStandaloneDerivingを使わなくても,空のデータ型に対してDataインスタンスを (data Empty deriving Dataのように)直接導出できるようになりました. とはいえ,この導出には-XDeriveDataTypeableという GHC拡張が必要であり,それが有効になっていれば, あらためて-XEmptyDataDerivingを有効しなくてもすみます. 同じことが-XDeriveFunctorなどの拡張を必要する他の型クラスについてもいえます.
-XHexFloatLiteralsを有効にすると16進浮動小数点数リテラル(たとえば0x0.1p4)表記が可能になります. 詳細については Hexadecimal floating point literals を参照してください.
3.2.2. Compiler¶
LLVM code generator (e.g.
-fllvm) compatible with LLVM releases in the 5.0 series.Add warning flag
-Wmissing-export-listswhich causes the type checker to warn when a module does not include an explicit export list.The
configurescript now no longer accepts--with-TOOLflags (e.g.--with-nm,--with-ld, etc.). Instead, these are taken from environment variables, as is typical inautoconfscripts. For instance,./configure --with-nm=/usr/local/bin/nmturns into./configure NM=/usr/local/bin/nm.Derived
Functor,Foldable, andTraversableinstances are now optimized when their last type parameters have phantom roles. Specifically,fmap _ = coerce traverse _ x = pure (coerce x) foldMap _ _ = mempty
These definitions of
foldMapandtraverseare lazier than the ones we would otherwise derive, as they may produce results without inspecting their arguments at all.See also Deriving Functor instances, Deriving Foldable instances, and Deriving Traversable instances.
Derived instances for empty data types are now substantially different than before. Here is an overview of what has changed. These examples will use a running example of
data Empty ato describe what happens when an instance is derived forEmpty:Derived
EqandOrdinstances would previously emit code that usederror:instance Eq (Empty a) where (==) = error "Void ==" instance Ord (Empty a) where compare = error "Void compare"
Now, they emit code that uses maximally defined, lazier semantics:
instance Eq (Empty a) where _ == _ = True instance Ord (Empty a) where compare _ _ = EQ
Derived
Readinstances would previous emit code that usedparens:instance Read (Empty a) where readPrec = parens pfail
But
parensforces parts of the parsed string that it doesn't need to. Now, the derived instance will not useparens(that it, parsingEmptywill always fail, without reading any input):instance Read (Empty a) where readPrec = pfail
Derived
Showinstances would previously emit code that usederror:instance Show (Empty a) where showsPrec = error "Void showsPrec"
Now, they emit code that inspects the argument. That is, if the argument diverges, then showing it will also diverge:
instance Show (Empty a) where showsPrec _ x = case x of {}
Derived
Functor,Foldable,Traversable,Generic,Generic1,Lift, andDatainstances previously emitted code that usederror:instance Functor Empty where fmap = error "Void fmap" instance Foldable Empty where foldMap = error "Void foldMap" instance Traversable Empty where traverse = error "Void traverse" instance Generic (Empty a) where from = M1 (error "No generic representation for empty datatype Empty") to (M1 _) = error "No values for empty datatype Empty" -- Similarly for Generic1 instance Lift (Empty a) where lift _ = error "Can't lift value of empty datatype Empty" instance Data a => Data (Empty a) where gfoldl _ _ _ = error "Void gfoldl" toConstr _ = error "Void toConstr" ...
Now, derived
Functor,Traversable, ``Generic,Generic1,Lift, andDatainstances emit code which inspects their arguments:instance Functor Empty where fmap _ x = case x of {} instance Traversable Empty where traverse _ x = pure (case x of {}) instance Generic (Empty a) where from x = M1 (case x of {}) to (M1 x) = case x of {} -- Similarly for Generic1 instance Lift (Empty a) where lift x = pure (case x of {}) instance Data a => Data (Empty a) where gfoldl _ x = case x of {} toConstr x = case x of {} ...
Derived
Foldableinstances now are maximally lazy:instance Foldable Empty where foldMap _ _ = mempty
Derived
Foldableinstances now derive custom definitions fornullinstead of using the default one. This leads to asymptotically better performance for recursive types not shaped like cons-lists, and allowsnullto terminate for more (but not all) infinitely large structures.Configure on Windows now supports the
--enable-distro-toolchainconfigureflag, which can be used to build a GHC using compilers on yourPATHinstead of using the bundled bindist. See Trac #13792GHC now enables
-fllvm-pass-vectors-in-regsby default. This means that GHC will now use native vector registers to pass vector arguments across function calls.The optional
instancekeyword is now usable in type family instance declarations. See Trac #13747Lots of other bugs. See Trac for a complete list.
New flags
-fignore-optim-changesand-fignore-hpc-changesallow GHC to reuse previously compiled modules even if they were compiled with different optimisation or HPC flags. These options are enabled by default by--interactive. See Trac #13604
3.2.3. Runtime system¶
- Function
hs_add_root()was removed. It was a no-op since GHC-7.2.1 where module initialisation stopped requiring a call tohs_add_root(). - Proper import library support added to GHC which can handle all of the libraries produced
by
dlltool. The limitation of them needing to be named with the suffix.dll.ais also removed. See Trac #13606, Trac #12499, Trac #12498 - The GHCi runtime linker on Windows now supports the
big-objfile format. - The runtime system's native stack backtrace support
on POSIX platforms is now triggered by
SIGQUITinstead ofSIGUSR2as it was in previous releases. This change is to bring GHC's behavior into compliance with the model set by the most Java virtual machine implementations. - The GHC runtime on Windows now uses Continue handlers instead of Vectorized
handlers to trap exceptions. This change gives other exception handlers a chance
to handle the exception before the runtime does. Furthermore The RTS flag
--install-seh-handlers=Can be used on Wndows to completely disable the runtime's handling of exceptions. See Trac #13911, Trac #12110. - The GHC runtime on Windows can now generate crash dumps on unhandled exceptions
using the RTS flag
--generate-crash-dumps. - The GHCi runtime linker now avoid calling GCC to find libraries as much as possible by caching the list of search directories of GCC and querying the file system directly. This results in much better performance, especially on Windows.
- The GHC runtime on Windows can now generate stack traces on unhandled exceptions. When running in GHCi more information is displayed about the symbols if available. This behavior can be controlled with the RTS flag --generate-stack-traces=<yes|no>.
3.2.4. Template Haskell¶
Template Haskell now reifies data types with GADT syntax accurately. Previously, TH used heuristics to determine whether a data type should be reified using GADT syntax, which could lead to incorrect results, such as
data T1 a = (a ~ Int) => MkT1being reified as a GADT anddata T2 a where MkT2 :: Show a => T2 anot being reified as a GADT.In addition, reified GADT constructors now more accurately track the order in which users write type variables. Before, if you reified
MkTas below:data T a where MkT :: forall b a. b -> T a
Then the reified type signature of
MkTwould have been headed byForallC [PlainTV a, PlainTV b]. Now, reifyingMkTwill give a type headed byForallC [PlainTV b, PlainTV a], as one would expect.Language.Haskell.TH.FamFlavour, which was deprecated in GHC 8.2, has been removed.
3.2.5. base library¶
- Blank strings can now be used as values for environment variables using the
System.Environment.Blankmodule. See Trac #12494 Data.Type.Equality.==is now a closed type family. It works for all kinds out of the box. Any modules that previously declared instances of this family will need to remove them. Whereas the previous definition was somewhat ad hoc, the behavior is now completely uniform. As a result, some applications that used to reduce no longer do, and conversely. Most notably,(==)no longer treats the*,j -> k, or()kinds specially; equality is tested structurally in all cases.
3.2.6. Build system¶
dll-splithas been removed and replaced with an automatic partitioning utilitygen-dll. This utility can transparently split and compile any DLLs that require this. Note that thertsandbasecan not be split at this point because of the mutual recursion betweenbaseandrts. There is currently no explicit dependency between the two in the build system and such there is no way to notifybasethat thertshas been split, or vice versa. (see Trac #5987).
3.3. 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 | 8.4.3 | The compiler itself |
| Cabal | 2.2.0.1 | Dependency of ghc-pkg utility |
| Win32 | 2.6.1.0 | Dependency of ghc library |
| array | 0.5.2.0 | Dependency of ghc library |
| base | 4.11.1.0 | Core library |
| binary | 0.8.5.1 | Dependency of ghc library |
| bytestring | 0.10.8.2 | Deppendency of ghc library |
| containers | 0.5.11.0 | Dependency of ghc library |
| deepseq | 1.4.3.0 | Dependency of ghc library |
| directory | 1.3.1.5 | Dependency of ghc library |
| filepath | 1.4.2 | Dependency of ghc library |
| ghc-boot | 8.4.3 | Internal compiler library |
| ghc-compact | 0.1.0.0 | Core library |
| ghc-prim | 0.5.2.0 | Core library |
| ghci | 8.4.3 | The REPL interface |
| haskeline | 0.7.4.2 | Dependency of ghci executable |
| hpc | 0.6.0.3 | Dependency of hpc executable |
| integer-gmp | 1.0.2.0 | Core library |
| mtl | 2.2.2 | Dependency of Cabal library |
| parsec | 3.1.13.0 | Dependency of Cabal library |
| process | 1.6.3.0 | Dependency of ghc library |
| template-haskell | 2.13.0.0 | Core library |
| text | 1.2.3.0 | Dependency of Cabal library |
| time | 1.8.0.2 | Dependency of ghc library |
| transformers | 0.5.5.0 | Dependency of ghc library |
| unix | 2.7.2.2 | Dependency of ghc library |
| xhtml | 3000.2.2.1 | Dependency of haddock executable |