[commit: ghc] wip/14691: Implement zonkCoreExpr (2a4c06b)
git at git.haskell.org
git at git.haskell.org
Sun Jan 21 13:39:18 UTC 2018
Repository : ssh://git@git.haskell.org/ghc
On branch : wip/14691
Link : http://ghc.haskell.org/trac/ghc/changeset/2a4c06be668091182f36377f076a48925a6f2cb5/ghc
>---------------------------------------------------------------
commit 2a4c06be668091182f36377f076a48925a6f2cb5
Author: Joachim Breitner <mail at joachim-breitner.de>
Date: Sat Jan 20 14:03:22 2018 -0500
Implement zonkCoreExpr
>---------------------------------------------------------------
2a4c06be668091182f36377f076a48925a6f2cb5
compiler/typecheck/TcHsSyn.hs | 117 +++++++++++++++++++++++-------------------
1 file changed, 63 insertions(+), 54 deletions(-)
diff --git a/compiler/typecheck/TcHsSyn.hs b/compiler/typecheck/TcHsSyn.hs
index d56416c..d1d58aa 100644
--- a/compiler/typecheck/TcHsSyn.hs
+++ b/compiler/typecheck/TcHsSyn.hs
@@ -71,6 +71,7 @@ import Bag
import Outputable
import Util
import UniqFM
+import CoreSyn
import Control.Monad
import Data.List ( partition )
@@ -952,7 +953,7 @@ zonkCoFn env (WpCast co) = do { co' <- zonkCoToCo env co
; return (env, WpCast co') }
zonkCoFn env (WpEvLam ev) = do { (env', ev') <- zonkEvBndrX env ev
; return (env', WpEvLam ev') }
-zonkCoFn env (WpEvApp arg) = do { arg' <- zonkEvTerm env arg
+zonkCoFn env (WpEvApp arg) = do { arg' <- zonkCoreExpr env arg
; return (env, WpEvApp arg') }
zonkCoFn env (WpTyLam tv) = ASSERT( isImmutableTyVar tv )
do { (env', tv') <- zonkTyBndrX env tv
@@ -1419,59 +1420,67 @@ zonkVect _ (HsVectInstIn _) = panic "TcHsSyn.zonkVect: HsVectInstIn"
************************************************************************
-}
-zonkEvTerm env et = error "zonkEvTerm"
-{-
-zonkEvTerm :: ZonkEnv -> EvTerm -> TcM EvTerm
-zonkEvTerm env (EvId v) = ASSERT2( isId v, ppr v )
- zonkEvVarOcc env v
-zonkEvTerm env (EvCoercion co) = do { co' <- zonkCoToCo env co
- ; return (EvCoercion co') }
-zonkEvTerm env (EvCast tm co) = do { tm' <- zonkEvTerm env tm
- ; co' <- zonkCoToCo env co
- ; return (mkEvCast tm' co') }
-zonkEvTerm _ (EvLit l) = return (EvLit l)
-
-zonkEvTerm env (EvTypeable ty ev) =
- do { ev' <- zonkEvTypeable env ev
- ; ty' <- zonkTcTypeToType env ty
- ; return (EvTypeable ty' ev') }
-zonkEvTerm env (EvCallStack cs)
- = case cs of
- EvCsEmpty -> return (EvCallStack cs)
- EvCsPushCall n l tm -> do { tm' <- zonkEvTerm env tm
- ; return (EvCallStack (EvCsPushCall n l tm')) }
-
-zonkEvTerm env (EvSuperClass d n) = do { d' <- zonkEvTerm env d
- ; return (EvSuperClass d' n) }
-zonkEvTerm env (EvDFunApp df tys tms)
- = do { tys' <- zonkTcTypeToTypes env tys
- ; tms' <- mapM (zonkEvTerm env) tms
- ; return (EvDFunApp (zonkIdOcc env df) tys' tms') }
-zonkEvTerm env (EvDelayedError ty msg)
- = do { ty' <- zonkTcTypeToType env ty
- ; return (EvDelayedError ty' msg) }
-zonkEvTerm env (EvSelector sel_id tys tms)
- = do { sel_id' <- zonkIdBndr env sel_id
- ; tys' <- zonkTcTypeToTypes env tys
- ; tms' <- mapM (zonkEvTerm env) tms
- ; return (EvSelector sel_id' tys' tms') }
--}
+zonkCoreExpr :: ZonkEnv -> CoreExpr -> TcM CoreExpr
+zonkCoreExpr env (Var v)
+ | isCoVar v
+ = Coercion <$> zonkCoVarOcc env v
+ | otherwise
+ = return (Var $ zonkIdOcc env v)
+zonkCoreExpr _ (Lit l)
+ = return $ Lit l
+zonkCoreExpr env (Coercion co)
+ = Coercion <$> zonkCoToCo env co
+zonkCoreExpr env (Type ty)
+ = Type <$> zonkTcTypeToType env ty
+
+zonkCoreExpr env (Cast e co)
+ = Cast <$> zonkCoreExpr env e <*> zonkCoToCo env co
+zonkCoreExpr env (Tick t e)
+ = Tick t <$> zonkCoreExpr env e -- Do we need to zonk in ticks?
+
+zonkCoreExpr env (App e1 e2)
+ = App <$> zonkCoreExpr env e1 <*> zonkCoreExpr env e2
+zonkCoreExpr env (Lam v e)
+ = do v' <- zonkIdBndr env v
+ let env1 = extendIdZonkEnv1 env v'
+ Lam v' <$> zonkCoreExpr env1 e
+zonkCoreExpr env (Let bind e)
+ = do (env1, bind') <- zonkCoreBind env bind
+ Let bind'<$> zonkCoreExpr env1 e
+zonkCoreExpr env (Case scrut b ty alts)
+ = do scrut' <- zonkCoreExpr env scrut
+ ty' <- zonkTcTypeToType env ty
+ b' <- zonkIdBndr env b
+ let env1 = extendIdZonkEnv1 env b'
+ alts' <- mapM (zonkCoreAlt env1) alts
+ return $ Case scrut' b' ty' alts'
+
+zonkCoreAlt :: ZonkEnv -> CoreAlt -> TcM CoreAlt
+zonkCoreAlt env (dc, pats, rhs)
+ = do pats' <- mapM (zonkIdBndr env) pats
+ let env1 = extendZonkEnv env pats'
+ rhs' <- zonkCoreExpr env1 rhs
+ return $ (dc, pats', rhs')
+
+zonkCoreBind :: ZonkEnv -> CoreBind -> TcM (ZonkEnv, CoreBind)
+zonkCoreBind env (NonRec v e)
+ = do v' <- zonkIdBndr env v
+ e' <- zonkCoreExpr env e
+ let env1 = extendIdZonkEnv1 env v'
+ return (env1, NonRec v' e')
+zonkCoreBind env (Rec pairs)
+ = do (env1, pairs') <- fixM go
+ return (env1, Rec pairs')
+ where
+ go ~(_, new_pairs) = do
+ let env1 = extendIdZonkEnvRec env (map fst new_pairs)
+ pairs' <- mapM (zonkCorePair env1) pairs
+ return (env1, pairs')
+
+zonkCorePair :: ZonkEnv -> (CoreBndr, CoreExpr) -> TcM (CoreBndr, CoreExpr)
+zonkCorePair env (v,e) = (,) <$> zonkIdBndr env v <*> zonkCoreExpr env e
+
-zonkEvTypeable :: ZonkEnv -> EvTypeable -> TcM EvTypeable
-zonkEvTypeable env (EvTypeableTyCon tycon e)
- = do { e' <- mapM (zonkEvTerm env) e
- ; return $ EvTypeableTyCon tycon e' }
-zonkEvTypeable env (EvTypeableTyApp t1 t2)
- = do { t1' <- zonkEvTerm env t1
- ; t2' <- zonkEvTerm env t2
- ; return (EvTypeableTyApp t1' t2') }
-zonkEvTypeable env (EvTypeableTrFun t1 t2)
- = do { t1' <- zonkEvTerm env t1
- ; t2' <- zonkEvTerm env t2
- ; return (EvTypeableTrFun t1' t2') }
-zonkEvTypeable env (EvTypeableTyLit t1)
- = do { t1' <- zonkEvTerm env t1
- ; return (EvTypeableTyLit t1') }
zonkTcEvBinds_s :: ZonkEnv -> [TcEvBinds] -> TcM (ZonkEnv, [TcEvBinds])
zonkTcEvBinds_s env bs = do { (env, bs') <- mapAccumLM zonk_tc_ev_binds env bs
@@ -1513,7 +1522,7 @@ zonkEvBind env bind@(EvBind { eb_lhs = var, eb_rhs = term })
; term' <- case getEqPredTys_maybe (idType var') of
Just (r, ty1, ty2) | ty1 `eqType` ty2
-> return (evCoercion (mkTcReflCo r ty1))
- _other -> zonkEvTerm env term
+ _other -> zonkCoreExpr env term
; return (bind { eb_lhs = var', eb_rhs = term' }) }
More information about the ghc-commits
mailing list