Skip to content
Snippets Groups Projects
Commit 3a0019e3 authored by Iavor S. Diatchki's avatar Iavor S. Diatchki
Browse files

Improve `Typeable` solver.

parent d832b6b4
No related branches found
No related tags found
No related merge requests found
...@@ -1845,23 +1845,19 @@ isCallStackIP _ _ _ ...@@ -1845,23 +1845,19 @@ isCallStackIP _ _ _
matchTypeableClass :: Class -> Kind -> Type -> CtLoc -> TcS LookupInstResult matchTypeableClass :: Class -> Kind -> Type -> CtLoc -> TcS LookupInstResult
matchTypeableClass clas k t loc matchTypeableClass clas k t loc
| isForAllTy k = return NoInstance | isForAllTy k = return NoInstance
| Just (tc, ks_tys) <- splitTyConApp_maybe t = doTyConApp tc ks_tys | Just (tc, ks) <- splitTyConApp_maybe t
, all isKind ks = doTyCon tc ks
| Just (f,kt) <- splitAppTy_maybe t = doTyApp f kt | Just (f,kt) <- splitAppTy_maybe t = doTyApp f kt
| Just _ <- isNumLitTy t = mkEv [] (EvTypeableTyLit t) | Just _ <- isNumLitTy t = mkSimpEv (EvTypeableTyLit t)
| Just _ <- isStrLitTy t = mkEv [] (EvTypeableTyLit t) | Just _ <- isStrLitTy t = mkSimpEv (EvTypeableTyLit t)
| otherwise = return NoInstance | otherwise = return NoInstance
where where
-- Representation for type constructor applied to some kinds and some types. -- Representation for type constructor applied to some kinds
doTyConApp tc ks_ts = doTyCon tc ks =
case mapM kindRep ks of case mapM kindRep ks of
Nothing -> return NoInstance -- Not concrete kinds Nothing -> return NoInstance
Just kReps -> Just kReps -> mkSimpEv (EvTypeableTyCon tc kReps [])
do tCts <- mapM subGoal ts
mkEv tCts (EvTypeableTyCon tc kReps (map ctEvTerm tCts `zip` ts))
where
(ks,ts) = span isKind ks_ts
{- Representation for an application of a type to a type-or-kind. {- Representation for an application of a type to a type-or-kind.
This may happen when the type expression starts with a type variable. This may happen when the type expression starts with a type variable.
...@@ -1876,7 +1872,9 @@ matchTypeableClass clas k t loc ...@@ -1876,7 +1872,9 @@ matchTypeableClass clas k t loc
| otherwise = | otherwise =
do ct1 <- subGoal f do ct1 <- subGoal f
ct2 <- subGoal tk ct2 <- subGoal tk
mkEv [ct1,ct2] (EvTypeableTyApp (ctEvTerm ct1,f) (ctEvTerm ct2,tk)) let realSubs = [ c | (c,Fresh) <- [ct1,ct2] ]
return $ GenInst realSubs
$ EvTypeable $ EvTypeableTyApp (getEv ct1,f) (getEv ct2,tk)
-- Representation for concrete kinds. We just use the kind itself, -- Representation for concrete kinds. We just use the kind itself,
...@@ -1886,13 +1884,11 @@ matchTypeableClass clas k t loc ...@@ -1886,13 +1884,11 @@ matchTypeableClass clas k t loc
mapM_ kindRep ks mapM_ kindRep ks
return ki return ki
getEv (ct,_fresh) = ctEvTerm ct
-- Emit a `Typeable` constraint for the given type. -- Emit a `Typeable` constraint for the given type.
subGoal ty = do let goal = mkClassPred clas [ typeKind ty, ty ] subGoal ty = do let goal = mkClassPred clas [ typeKind ty, ty ]
ev <- newWantedEvVarNC loc goal newWantedEvVar loc goal
return ev
mkEv subs ev = return (GenInst subs (EvTypeable ev))
mkSimpEv ev = return (GenInst [] (EvTypeable ev))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment