Commit 11f9bffb authored by Simon Peyton Jones's avatar Simon Peyton Jones Committed by Ben Gamari

Kill off redundant SigTv check in occurCheckExpand

This patch simply deletes code, the SigTv check in
occurCheckExpand.  As the new comment says

In the past we also rejected a SigTv matched with a non-tyvar
But it is wrong to reject that for Givens;
and SigTv is in any case handled separately by
   - TcUnify.checkTauTvUpdate (on-the-fly unifier)
   - TcInteract.canSolveByUnification (main constraint solver)

(cherry picked from commit d25cb61a)
parent c448d551
...@@ -1536,7 +1536,6 @@ See also Note [occurCheckExpand] in TcCanonical ...@@ -1536,7 +1536,6 @@ See also Note [occurCheckExpand] in TcCanonical
data OccCheckResult a data OccCheckResult a
= OC_OK a = OC_OK a
| OC_Forall | OC_Forall
| OC_NonTyVar
| OC_Occurs | OC_Occurs
instance Functor OccCheckResult where instance Functor OccCheckResult where
...@@ -1550,7 +1549,6 @@ instance Monad OccCheckResult where ...@@ -1550,7 +1549,6 @@ instance Monad OccCheckResult where
return = pure return = pure
OC_OK x >>= k = k x OC_OK x >>= k = k x
OC_Forall >>= _ = OC_Forall OC_Forall >>= _ = OC_Forall
OC_NonTyVar >>= _ = OC_NonTyVar
OC_Occurs >>= _ = OC_Occurs OC_Occurs >>= _ = OC_Occurs
occurCheckExpand :: DynFlags -> TcTyVar -> Type -> OccCheckResult Type occurCheckExpand :: DynFlags -> TcTyVar -> Type -> OccCheckResult Type
...@@ -1558,17 +1556,19 @@ occurCheckExpand :: DynFlags -> TcTyVar -> Type -> OccCheckResult Type ...@@ -1558,17 +1556,19 @@ occurCheckExpand :: DynFlags -> TcTyVar -> Type -> OccCheckResult Type
-- Check whether -- Check whether
-- a) the given variable occurs in the given type. -- a) the given variable occurs in the given type.
-- b) there is a forall in the type (unless we have -XImpredicativeTypes) -- b) there is a forall in the type (unless we have -XImpredicativeTypes)
-- c) if it's a SigTv, ty should be a tyvar
-- --
-- We may have needed to do some type synonym unfolding in order to -- We may have needed to do some type synonym unfolding in order to
-- get rid of the variable (or forall), so we also return the unfolded -- get rid of the variable (or forall), so we also return the unfolded
-- version of the type, which is guaranteed to be syntactically free -- version of the type, which is guaranteed to be syntactically free
-- of the given type variable. If the type is already syntactically -- of the given type variable. If the type is already syntactically
-- free of the variable, then the same type is returned. -- free of the variable, then the same type is returned.
--
-- NB: in the past we also rejected a SigTv matched with a non-tyvar
-- But it is wrong to reject that for Givens;
-- and SigTv is in any case handled separately by
-- - TcUnify.checkTauTvUpdate (on-the-fly unifier)
-- - TcInteract.canSolveByUnification (main constraint solver)
occurCheckExpand dflags tv ty occurCheckExpand dflags tv ty
| MetaTv { mtv_info = SigTv } <- details
= go_sig_tv ty
| fast_check ty = return ty | fast_check ty = return ty
| otherwise = go emptyVarEnv ty | otherwise = go emptyVarEnv ty
where where
...@@ -1576,14 +1576,6 @@ occurCheckExpand dflags tv ty ...@@ -1576,14 +1576,6 @@ occurCheckExpand dflags tv ty
impredicative = canUnifyWithPolyType dflags details impredicative = canUnifyWithPolyType dflags details
-- Check 'ty' is a tyvar, or can be expanded into one
go_sig_tv ty@(TyVarTy tv')
| fast_check (tyVarKind tv') = return ty
| otherwise = do { k' <- go emptyVarEnv (tyVarKind tv')
; return (mkTyVarTy (setTyVarKind tv' k')) }
go_sig_tv ty | Just ty' <- coreView ty = go_sig_tv ty'
go_sig_tv _ = OC_NonTyVar
-- True => fine -- True => fine
fast_check (LitTy {}) = True fast_check (LitTy {}) = True
fast_check (TyVarTy tv') = tv /= tv' && fast_check (tyVarKind tv') fast_check (TyVarTy tv') = tv /= tv' && fast_check (tyVarKind tv')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment