Rewrite `Coercible` solver
authorRichard Eisenberg <eir@cis.upenn.edu>
Fri, 12 Dec 2014 22:19:21 +0000 (17:19 -0500)
committerRichard Eisenberg <eir@cis.upenn.edu>
Fri, 12 Dec 2014 22:24:37 +0000 (17:24 -0500)
commit0cc47eb90805f3e166ac4d3991e66d3346ca05e7
tree1ed6c6dd440e1dcdd32f16d547b3e0c4ceeddbda
parent058262bac0bbcd65f40703bf8047238ffa30d2c3
Rewrite `Coercible` solver

Summary:
This is a rewrite of the algorithm to solve for Coercible "instances".

A preliminary form of these ideas is at
https://ghc.haskell.org/trac/ghc/wiki/Design/NewCoercibleSolver

The basic idea here is that the `EqPred` constructor of `PredTree`
now is parameterised by a new type `EqRel` (where
`data EqRel = NomEq | ReprEq`). Thus, every equality constraint can
now talk about nominal equality (the usual case) or representational
equality (the `Coercible` case).

This is a change from the previous
behavior where `Coercible` was just considered a regular class with
a special case in `matchClassInst`.

Because of this change, representational equalities are now
canonicalized just like nominal ones, allowing more equalities
to be solved -- in particular, the case at the top of #9117.

A knock-on effect is that the flattener must be aware of the
choice of equality relation, because the inert set now stores
both representational inert equalities alongside the nominal
inert equalities. Of course, we can use representational equalities
to rewrite only within another representational equality --
thus the parameterization of the flattener.

A nice side effect of this change is that I've introduced a new
type `CtFlavour`, which tracks G vs. W vs. D, removing some ugliness
in the flattener.

This commit includes some refactoring as discussed on D546.
It also removes the ability of Deriveds to rewrite Deriveds.

This fixes bugs #9117 and #8984.

Reviewers: simonpj, austin, nomeata

Subscribers: carter, thomie

Differential Revision: https://phabricator.haskell.org/D546

GHC Trac Issues: #9117, #8984
48 files changed:
compiler/basicTypes/DataCon.hs
compiler/deSugar/DsBinds.hs
compiler/typecheck/FamInst.hs
compiler/typecheck/FunDeps.hs
compiler/typecheck/Inst.hs
compiler/typecheck/TcCanonical.hs
compiler/typecheck/TcDeriv.hs
compiler/typecheck/TcErrors.hs
compiler/typecheck/TcEvidence.hs
compiler/typecheck/TcFlatten.hs
compiler/typecheck/TcHsSyn.hs
compiler/typecheck/TcInteract.hs
compiler/typecheck/TcMType.hs
compiler/typecheck/TcRnTypes.hs
compiler/typecheck/TcSMonad.hs
compiler/typecheck/TcSimplify.hs
compiler/typecheck/TcType.hs
compiler/typecheck/TcValidity.hs
compiler/types/Coercion.hs
compiler/types/FamInstEnv.hs
compiler/types/Type.hs
compiler/utils/MonadUtils.hs
compiler/utils/Util.hs
testsuite/tests/deriving/should_fail/T1496.stderr
testsuite/tests/deriving/should_fail/T4846.stderr
testsuite/tests/deriving/should_fail/T5498.stderr
testsuite/tests/deriving/should_fail/T6147.stderr
testsuite/tests/deriving/should_fail/T7148.stderr
testsuite/tests/deriving/should_fail/T7148a.stderr
testsuite/tests/deriving/should_fail/T8851.stderr
testsuite/tests/deriving/should_fail/T8984.hs [new file with mode: 0644]
testsuite/tests/deriving/should_fail/T8984.stderr [new file with mode: 0644]
testsuite/tests/deriving/should_fail/all.T
testsuite/tests/gadt/CasePrune.stderr
testsuite/tests/ghci/scripts/GhciKinds.hs
testsuite/tests/ghci/scripts/GhciKinds.script
testsuite/tests/ghci/scripts/GhciKinds.stdout
testsuite/tests/ghci/scripts/ghci051.stderr
testsuite/tests/indexed-types/should_fail/T9580.stderr
testsuite/tests/roles/should_fail/Roles10.stderr
testsuite/tests/roles/should_fail/RolesIArray.stderr
testsuite/tests/typecheck/should_compile/T9117_3.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_compile/T9708.hs
testsuite/tests/typecheck/should_compile/all.T
testsuite/tests/typecheck/should_fail/TcCoercibleFail.hs
testsuite/tests/typecheck/should_fail/TcCoercibleFail.stderr
testsuite/tests/typecheck/should_fail/TcCoercibleFail3.stderr
testsuite/tests/typecheck/should_run/TcCoercible.hs