diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2017-12-21 13:31:13 +0000 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2017-12-21 14:14:21 +0000 |
commit | a492af06d3264530d134584f22ffb726a16c78ec (patch) | |
tree | 294b0c21775d6a7cb9b79c86145d7b6ca47c81ea /compiler/typecheck/TcRnTypes.hs | |
parent | 72938f5890dac81afad52bf58175c1e29ffbc6dd (diff) | |
download | haskell-a492af06d3264530d134584f22ffb726a16c78ec.tar.gz |
Refactor coercion holes
In fixing Trac #14584 I found that it would be /much/ more
convenient if a "hole" in a coercion (much like a unification
variable in a type) acutally had a CoVar associated with it
rather than just a Unique. Then I can ask what the free variables
of a coercion is, and get a set of CoVars including those
as-yet-un-filled in holes.
Once that is done, it makes no sense to stuff coercion holes
inside UnivCo. They were there before so we could know the
kind and role of a "hole" coercion, but once there is a CoVar
we can get that info from the CoVar. So I removed HoleProv
from UnivCoProvenance and added HoleCo to Coercion.
In summary:
* Add HoleCo to Coercion and remove HoleProv from UnivCoProvanance
* Similarly in IfaceCoercion
* Make CoercionHole have a CoVar in it, not a Unique
* Make tyCoVarsOfCo return the free coercion-hole variables
as well as the ordinary free CoVars. Similarly, remember
to zonk the CoVar in a CoercionHole
We could go further, and remove CoercionHole as a distinct type
altogther, just collapsing it into HoleCo. But I have not done
that yet.
Diffstat (limited to 'compiler/typecheck/TcRnTypes.hs')
-rw-r--r-- | compiler/typecheck/TcRnTypes.hs | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/compiler/typecheck/TcRnTypes.hs b/compiler/typecheck/TcRnTypes.hs index f9e29a1142..4d7a8e8390 100644 --- a/compiler/typecheck/TcRnTypes.hs +++ b/compiler/typecheck/TcRnTypes.hs @@ -74,11 +74,11 @@ module TcRnTypes( isGivenCt, isHoleCt, isOutOfScopeCt, isExprHoleCt, isTypeHoleCt, isUserTypeErrorCt, getUserTypeErrorMsg, ctEvidence, ctLoc, setCtLoc, ctPred, ctFlavour, ctEqRel, ctOrigin, - mkTcEqPredLikeEv, + ctEvId, mkTcEqPredLikeEv, mkNonCanonical, mkNonCanonicalCt, mkGivens, mkIrredCt, mkInsolubleCt, ctEvPred, ctEvLoc, ctEvOrigin, ctEvEqRel, - ctEvTerm, ctEvCoercion, ctEvId, + ctEvTerm, ctEvCoercion, ctEvEvId, tyCoVarsOfCt, tyCoVarsOfCts, tyCoVarsOfCtList, tyCoVarsOfCtsList, @@ -151,6 +151,7 @@ import TcEvidence import Type import Class ( Class ) import TyCon ( TyCon, tyConKind ) +import TyCoRep ( CoercionHole(..), coHoleCoVar ) import Coercion ( Coercion, mkHoleCo ) import ConLike ( ConLike(..) ) import DataCon ( DataCon, dataConUserType, dataConOrigArgTys ) @@ -1790,6 +1791,10 @@ ctPred :: Ct -> PredType -- See Note [Ct/evidence invariant] ctPred ct = ctEvPred (cc_ev ct) +ctEvId :: Ct -> EvVar +-- The evidence Id for this Ct +ctEvId ct = ctEvEvId (ctEvidence ct) + -- | Makes a new equality predicate with the same role as the given -- evidence. mkTcEqPredLikeEv :: CtEvidence -> TcType -> TcType -> TcType @@ -2644,26 +2649,26 @@ ctEvRole = eqRelRole . ctEvEqRel ctEvTerm :: CtEvidence -> EvTerm ctEvTerm ev@(CtWanted { ctev_dest = HoleDest _ }) = EvCoercion $ ctEvCoercion ev -ctEvTerm ev = EvId (ctEvId ev) +ctEvTerm ev = EvId (ctEvEvId ev) -- Always returns a coercion whose type is precisely ctev_pred of the CtEvidence. -- See also Note [Given in ctEvCoercion] ctEvCoercion :: CtEvidence -> Coercion ctEvCoercion (CtGiven { ctev_pred = pred_ty, ctev_evar = ev_id }) = mkTcCoVarCo (setVarType ev_id pred_ty) -- See Note [Given in ctEvCoercion] -ctEvCoercion (CtWanted { ctev_dest = dest, ctev_pred = pred }) +ctEvCoercion (CtWanted { ctev_dest = dest }) | HoleDest hole <- dest - , Just (role, ty1, ty2) <- getEqPredTys_maybe pred = -- ctEvCoercion is only called on type equalities -- and they always have HoleDests - mkHoleCo hole role ty1 ty2 + mkHoleCo hole ctEvCoercion ev = pprPanic "ctEvCoercion" (ppr ev) -ctEvId :: CtEvidence -> TcId -ctEvId (CtWanted { ctev_dest = EvVarDest ev }) = ev -ctEvId (CtGiven { ctev_evar = ev }) = ev -ctEvId ctev = pprPanic "ctEvId:" (ppr ctev) +ctEvEvId :: CtEvidence -> EvVar +ctEvEvId (CtWanted { ctev_dest = EvVarDest ev }) = ev +ctEvEvId (CtWanted { ctev_dest = HoleDest h }) = coHoleCoVar h +ctEvEvId (CtGiven { ctev_evar = ev }) = ev +ctEvEvId ctev@(CtDerived {}) = pprPanic "ctEvId:" (ppr ctev) instance Outputable TcEvDest where ppr (HoleDest h) = text "hole" <> ppr h |