[Git][ghc/ghc][wip/T20666] Refactor the treatment of loopy superclass dicts

Simon Peyton Jones (@simonpj) gitlab at gitlab.haskell.org
Fri Jan 6 10:09:40 UTC 2023



Simon Peyton Jones pushed to branch wip/T20666 at Glasgow Haskell Compiler / GHC


Commits:
a7b64fc7 by Richard Eisenberg at 2023-01-06T10:10:04+00:00
Refactor the treatment of loopy superclass dicts

This patch completely re-engineers how we deal with loopy superclass
dictionaries in instance declarations. It fixes #20666.

The highlights are

* Recognise that the loopy-superclass business should use precisely
  the Paterson conditions.  This is much much nicer.  See
  Note [Recursive superclasses] in GHC.Tc.TyCl.Instance

* With that in mind, define "Paterson-smaller" in
  Note [Paterson conditions] in GHC.Tc.Validity, and the new
  data type `PatersonSize` in GHC.Tc.Utils.TcType, along with
  functions to compute and compare PatsonSizes

* Use the new PatersonSize stuff when solving superclass constraints
  See Note [Solving superclass constraints] in GHC.Tc.TyCl.Instance

* In GHC.Tc.Solver.Monad.lookupInInerts, add a missing call to
  prohibitedSuperClassSolve.  This was the original cause of #20666.

* Treat (TypeError "stuff") as having PatersonSize zero. See
  Note [Paterson size for type family applications] in GHC.Tc.Utils.TcType.

* Some refactoring way in which redundant constraints are reported; we
  don't want to complain about the extra, apparently-redundant
  constraints that we must add to an instance decl because of the
  loopy-superclass thing.  I moved some work from GHC.Tc.Errors to
  GHC.Tc.Solver.

* Add a new section to the user manual to describe the loopy
  superclass issue and what rules it follows.

- - - - -


30 changed files:

- compiler/GHC/Core/TyCo/FVs.hs
- compiler/GHC/Tc/Deriv.hs
- compiler/GHC/Tc/Deriv/Infer.hs
- compiler/GHC/Tc/Errors.hs
- compiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Gen/HsType.hs
- compiler/GHC/Tc/Solver.hs
- compiler/GHC/Tc/Solver/Canonical.hs
- compiler/GHC/Tc/Solver/InertSet.hs
- compiler/GHC/Tc/Solver/Interact.hs
- compiler/GHC/Tc/Solver/Monad.hs
- compiler/GHC/Tc/TyCl/Instance.hs
- compiler/GHC/Tc/Types/Constraint.hs
- compiler/GHC/Tc/Types/Origin.hs
- compiler/GHC/Tc/Utils/Backpack.hs
- compiler/GHC/Tc/Utils/Instantiate.hs
- compiler/GHC/Tc/Utils/TcMType.hs
- compiler/GHC/Tc/Utils/TcType.hs
- compiler/GHC/Tc/Utils/Unify.hs
- compiler/GHC/Tc/Validity.hs
- docs/users_guide/exts/instances.rst
- testsuite/tests/deriving/should_compile/T14339.hs
- testsuite/tests/deriving/should_fail/T21302.hs
- testsuite/tests/deriving/should_fail/T8165_fail2.stderr
- testsuite/tests/indexed-types/should_fail/NotRelaxedExamples.stderr
- testsuite/tests/indexed-types/should_fail/T10817.stderr
- testsuite/tests/indexed-types/should_fail/T13271.stderr
- testsuite/tests/indexed-types/should_fail/T15172.stderr
- testsuite/tests/indexed-types/should_fail/TyFamUndec.stderr
- testsuite/tests/typecheck/should_compile/T15473.stderr


The diff was not included because it is too large.


View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a7b64fc7b5c68975280f3f59139d64eacf449fdd

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a7b64fc7b5c68975280f3f59139d64eacf449fdd
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230106/17a495ad/attachment-0001.html>


More information about the ghc-commits mailing list