Clean up Coercible handling, and interaction of data families with newtypes
authorSimon Peyton Jones <simonpj@microsoft.com>
Thu, 18 Sep 2014 15:19:55 +0000 (16:19 +0100)
committerSimon Peyton Jones <simonpj@microsoft.com>
Fri, 19 Sep 2014 10:41:16 +0000 (11:41 +0100)
commit0aaf812ed0a4a4be9528b2e2f6b72bee7cd8002d
treed057ee1278f0ab7a632be9c43484a84a02f044d4
parent24e51b01cf66ffb12ce0b609c81ef9f9617e4629
Clean up Coercible handling, and interaction of data families with newtypes

This patch fixes Trac #9580, in which the Coercible machinery succeeded
even though the relevant data constructor was not in scope.

As usual I got dragged into a raft of refactoring changes,
all for the better.

* Delete TcEvidence.coercionToTcCoercion (now unused)

* Move instNewTyConTF_maybe, instNewTyCon_maybe to FamInst,
  and rename them to tcInstNewTyConTF_maybe, tcInstNewTyCon
  (They both return TcCoercions.)

* tcInstNewTyConTF_maybe also gets more convenient type,
  which improves TcInteract.getCoercibleInst

* Define FamInst.tcLookupDataFamInst, and use it in TcDeriv,
  (as well as in tcInstNewTyConTF_maybe)

* Improve error report for Coercible errors, when data familes
  are involved  Another use of tcLookupDataFamInst

* In TcExpr.tcTagToEnum, use tcLookupDataFamInst to replace
  local hacky code

* Fix Coercion.instNewTyCon_maybe and Type.newTyConInstRhs to deal
  with eta-reduced newtypes, using
  (new) Type.unwrapNewTyConEtad_maybe and (new) Type.applyTysX

Some small refactoring of TcSMonad.matchFam.
17 files changed:
compiler/hsSyn/HsUtils.lhs
compiler/typecheck/FamInst.lhs
compiler/typecheck/TcDeriv.lhs
compiler/typecheck/TcErrors.lhs
compiler/typecheck/TcEvidence.lhs
compiler/typecheck/TcExpr.lhs
compiler/typecheck/TcInteract.lhs
compiler/typecheck/TcSMonad.lhs
compiler/types/Coercion.lhs
compiler/types/FamInstEnv.lhs
compiler/types/TyCon.lhs
compiler/types/Type.lhs
testsuite/tests/indexed-types/should_fail/T9580.hs [new file with mode: 0644]
testsuite/tests/indexed-types/should_fail/T9580.stderr [new file with mode: 0644]
testsuite/tests/indexed-types/should_fail/T9580a.hs [new file with mode: 0644]
testsuite/tests/indexed-types/should_fail/all.T
testsuite/tests/typecheck/should_fail/TcCoercibleFail.stderr