summaryrefslogtreecommitdiff
path: root/docs/users_guide
diff options
context:
space:
mode:
authorRichard Eisenberg <rae@richarde.dev>2022-02-18 23:29:52 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-02-23 08:16:07 -0500
commita599abbad939820c666ced00ae9eb33706a4f360 (patch)
tree7b3811972a50da9e81018056cdcdeef158bc22e3 /docs/users_guide
parent558c7d554b9724abfaa2bcc1f42050e67b36a988 (diff)
downloadhaskell-a599abbad939820c666ced00ae9eb33706a4f360.tar.gz
Kill derived constraints
Co-authored by: Sam Derbyshire Previously, GHC had three flavours of constraint: Wanted, Given, and Derived. This removes Derived constraints. Though serving a number of purposes, the most important role of Derived constraints was to enable better error messages. This job has been taken over by the new RewriterSets, as explained in Note [Wanteds rewrite wanteds] in GHC.Tc.Types.Constraint. Other knock-on effects: - Various new Notes as I learned about under-described bits of GHC - A reshuffling around the AST for implicit-parameter bindings, with better integration with TTG. - Various improvements around fundeps. These were caused by the fact that, previously, fundep constraints were all Derived, and Derived constraints would get dropped. Thus, an unsolved Derived didn't stop compilation. Without Derived, this is no longer possible, and so we have to be considerably more careful around fundeps. - A nice little refactoring in GHC.Tc.Errors to center the work on a new datatype called ErrorItem. Constraints are converted into ErrorItems at the start of processing, and this allows for a little preprocessing before the main classification. - This commit also cleans up the behavior in generalisation around functional dependencies. Now, if a variable is determined by functional dependencies, it will not be quantified. This change is user facing, but it should trim down GHC's strange behavior around fundeps. - Previously, reportWanteds did quite a bit of work, even on an empty WantedConstraints. This commit adds a fast path. - Now, GHC will unconditionally re-simplify constraints during quantification. See Note [Unconditionally resimplify constraints when quantifying], in GHC.Tc.Solver. Close #18398. Close #18406. Solve the fundep-related non-confluence in #18851. Close #19131. Close #19137. Close #20922. Close #20668. Close #19665. ------------------------- Metric Decrease: LargeRecord T9872b T9872b_defer T9872d TcPlugin_RewritePerf -------------------------
Diffstat (limited to 'docs/users_guide')
-rw-r--r--docs/users_guide/9.4.1-notes.rst37
1 files changed, 37 insertions, 0 deletions
diff --git a/docs/users_guide/9.4.1-notes.rst b/docs/users_guide/9.4.1-notes.rst
index 85662049c4..594d1035c2 100644
--- a/docs/users_guide/9.4.1-notes.rst
+++ b/docs/users_guide/9.4.1-notes.rst
@@ -3,6 +3,39 @@
Version 9.4.1
==============
+Language
+~~~~~~~~
+
+- A small change has been made to the way GHC infers types for definitions
+ with no type signature: GHC will no longer generalize a function over
+ a type variable determined by a functional dependency. For example::
+
+ class C a b | a -> b where
+ op :: a -> b -> ()
+ f x = op True x
+
+ Previously, GHC inferred ``f :: C Bool b => b -> ()``. However, the functional
+ dependency says that only one type could ever be used for ``b``: this function
+ is hardly valid "for all" ``b``\ s. With the change, GHC will reject, looking
+ for the (non-existent) instance for ``C Bool b``.
+
+ If you want to retain the old behavior, add a (backward-compatible) type signature,
+ explicitly requesting this unusual quantification.
+
+- GHC no longer checks for ``-XGADTs`` or ``-XTypeFamilies`` in order to use
+ an equality constraint in a type. This is part of accepted proposal
+ `#371 <https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0371-non-magical-eq.md>`_.
+
+- There were previously cases around functional dependencies and injective
+ type families where the result of type inference would depend on the order
+ of constraints, as written in a source file. These cases are fundamentally ambiguous.
+ While GHC previously made an arbitrary decision, it now notices the ambiguity
+ and rejects the program. This means that some previously accepted programs are
+ now rejected. The solution is to add a type annotation or type application to
+ resolve the ambiguity.
+
+ This is the fix for :ghc-ticket:`18851`.
+
Compiler
~~~~~~~~
@@ -313,3 +346,7 @@ Compiler
For authors of type-checking plugins, this means you don't need to wrap
a call to ``newWanted`` in ``setCtLocM`` to create a new Wanted constraint
with the provided ``CtLoc``.
+
+- GHC no longer carries ``Derived`` constraints. Accordingly, several functions
+ in the plugin architecture that previously passed or received three sets of
+ constraints (givens, deriveds, and wanteds) now work with two such sets. \ No newline at end of file