diff options
Diffstat (limited to 'docs/users_guide')
-rw-r--r-- | docs/users_guide/9.2.1-notes.rst | 4 | ||||
-rw-r--r-- | docs/users_guide/expected-undocumented-flags.txt | 1 | ||||
-rw-r--r-- | docs/users_guide/exts/type_families.rst | 45 |
3 files changed, 49 insertions, 1 deletions
diff --git a/docs/users_guide/9.2.1-notes.rst b/docs/users_guide/9.2.1-notes.rst index da0461f982..30a58175f4 100644 --- a/docs/users_guide/9.2.1-notes.rst +++ b/docs/users_guide/9.2.1-notes.rst @@ -44,6 +44,10 @@ Compiler that the compiler automatically insert cost-centres on all call-sites of the named function. +- There is a significant refactoring in the solver; any type-checker plugins + will have to be updated, as GHC no longer uses flattening skolems or + flattening metavariables. + ``ghc-prim`` library ~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/users_guide/expected-undocumented-flags.txt b/docs/users_guide/expected-undocumented-flags.txt index 23b5a4abe7..75a433189c 100644 --- a/docs/users_guide/expected-undocumented-flags.txt +++ b/docs/users_guide/expected-undocumented-flags.txt @@ -57,7 +57,6 @@ -fextended-default-rules -fffi -ffi --fflat-cache -ffloat-all-lams -ffloat-lam-args -ffrontend-opt diff --git a/docs/users_guide/exts/type_families.rst b/docs/users_guide/exts/type_families.rst index 3c09e63a14..4843e35a80 100644 --- a/docs/users_guide/exts/type_families.rst +++ b/docs/users_guide/exts/type_families.rst @@ -581,6 +581,51 @@ If the option :extension:`UndecidableInstances` is passed to the compiler, the above restrictions are not enforced and it is on the programmer to ensure termination of the normalisation of type families during type inference. +Reducing type family applications +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. ghc-flag:: -ffamily-application-cache + :shortdesc: Use a cache when reducing type family applications + :type: dynamic + :reverse: -fno-family-application-cache + :category: + + The flag :ghc-flag:`-ffamily-application-cache` (on by default) instructs + GHC to use a cache when reducing type family applications. In most cases, + this will speed up compilation. The use of this flag will not affect + runtime behaviour. + +When GHC encounters a type family application (like ``F Int a``) in a program, +it must often reduce it in order to complete type checking. Here is a simple +example:: + + type family F a where + F Int = Bool + F (Maybe Double) = Char + + g :: F Int -> Bool + g = not + +Despite the fact that ``g``\'s type mentions ``F Int``, GHC must recognize that +``g``\'s argument really has type ``Bool``. This is done by *reducing* ``F Int`` +to become ``Bool``. Sometimes, there is not enough information to reduce a type +family application; we say such an application is *stuck*. Continuing this example, +an occurrence of ``F (Maybe a)`` (for some type variable ``a``) would be stuck, as +no equation applies. + +During type checking, GHC uses heuristics to determine which type family application +to reduce next; there is no predictable ordering among different type family applications. +The non-determinism rarely matters in practice. In most programs, type family reduction +terminates, and so these choices are immaterial. However, if a type family application +does not terminate, it is possible that type-checking may unpredictably diverge. (GHC +will always take the same path for a given source program, but small changes in that +source program may induce GHC to take a different path. Compiling a given, unchanged +source program is still deterministic.) + +In order to speed up type family reduction, GHC normally uses a cache, remembering what +type family applications it has previously reduced. This feature can be disabled with +:ghc-flag:`-fno-family-application-cache`. + .. _type-wildcards-lhs: Wildcards on the LHS of data and type family instances |