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 and #19690 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. * Treat the head of a Wanted quantified constraint in the same way as the superclass of an instance decl; this is what fixes #19690. See GHC.Tc.Solver.Canonical Note [Solving a Wanted forall-constraint] (Thanks to Matthew Craven for this insight.) This entailed refactoring the GivenSc constructor of CtOrigin a bit, to say whether it comes from an instance decl or quantified constraint. * 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.
Showing
- compiler/GHC/Core/InstEnv.hs 1 addition, 3 deletionscompiler/GHC/Core/InstEnv.hs
- compiler/GHC/Core/TyCo/FVs.hs 4 additions, 3 deletionscompiler/GHC/Core/TyCo/FVs.hs
- compiler/GHC/Tc/Deriv.hs 1 addition, 1 deletioncompiler/GHC/Tc/Deriv.hs
- compiler/GHC/Tc/Deriv/Infer.hs 21 additions, 36 deletionscompiler/GHC/Tc/Deriv/Infer.hs
- compiler/GHC/Tc/Errors.hs 1 addition, 30 deletionscompiler/GHC/Tc/Errors.hs
- compiler/GHC/Tc/Errors/Ppr.hs 22 additions, 3 deletionscompiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Gen/HsType.hs 3 additions, 1 deletioncompiler/GHC/Tc/Gen/HsType.hs
- compiler/GHC/Tc/Solver.hs 66 additions, 14 deletionscompiler/GHC/Tc/Solver.hs
- compiler/GHC/Tc/Solver/Canonical.hs 75 additions, 39 deletionscompiler/GHC/Tc/Solver/Canonical.hs
- compiler/GHC/Tc/Solver/InertSet.hs 11 additions, 6 deletionscompiler/GHC/Tc/Solver/InertSet.hs
- compiler/GHC/Tc/Solver/Interact.hs 35 additions, 36 deletionscompiler/GHC/Tc/Solver/Interact.hs
- compiler/GHC/Tc/Solver/Monad.hs 15 additions, 3 deletionscompiler/GHC/Tc/Solver/Monad.hs
- compiler/GHC/Tc/TyCl/Instance.hs 120 additions, 84 deletionscompiler/GHC/Tc/TyCl/Instance.hs
- compiler/GHC/Tc/Types/Constraint.hs 2 additions, 3 deletionscompiler/GHC/Tc/Types/Constraint.hs
- compiler/GHC/Tc/Types/Origin.hs 70 additions, 57 deletionscompiler/GHC/Tc/Types/Origin.hs
- compiler/GHC/Tc/Utils/Backpack.hs 10 additions, 21 deletionscompiler/GHC/Tc/Utils/Backpack.hs
- compiler/GHC/Tc/Utils/Instantiate.hs 20 additions, 6 deletionscompiler/GHC/Tc/Utils/Instantiate.hs
- compiler/GHC/Tc/Utils/TcMType.hs 2 additions, 2 deletionscompiler/GHC/Tc/Utils/TcMType.hs
- compiler/GHC/Tc/Utils/TcType.hs 280 additions, 79 deletionscompiler/GHC/Tc/Utils/TcType.hs
- compiler/GHC/Tc/Utils/Unify.hs 5 additions, 3 deletionscompiler/GHC/Tc/Utils/Unify.hs
Loading
Please register or sign in to comment