Skip to content
Snippets Groups Projects
Commit eeb1400a authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

Add some debug tracing

parent 2d828460
No related branches found
No related tags found
No related merge requests found
...@@ -123,21 +123,24 @@ dmdAnalStar env dmd e ...@@ -123,21 +123,24 @@ dmdAnalStar env dmd e
= (postProcessDmdTypeM defer_and_use dmd_ty, e') = (postProcessDmdTypeM defer_and_use dmd_ty, e')
-- Main Demand Analsysis machinery -- Main Demand Analsysis machinery
dmdAnal :: AnalEnv dmdAnal, dmdAnal' :: AnalEnv
-> CleanDemand -- The main one takes a *CleanDemand* -> CleanDemand -- The main one takes a *CleanDemand*
-> CoreExpr -> (DmdType, CoreExpr) -> CoreExpr -> (DmdType, CoreExpr)
-- The CleanDemand is always strict and not absent -- The CleanDemand is always strict and not absent
-- See Note [Ensure demand is strict] -- See Note [Ensure demand is strict]
dmdAnal _ _ (Lit lit) = (nopDmdType, Lit lit) dmdAnal env d e = -- pprTrace "dmdAnal" (ppr d <+> ppr e) $
dmdAnal _ _ (Type ty) = (nopDmdType, Type ty) -- Doesn't happen, in fact dmdAnal' env d e
dmdAnal _ _ (Coercion co) = (nopDmdType, Coercion co)
dmdAnal env dmd (Var var) dmdAnal' _ _ (Lit lit) = (nopDmdType, Lit lit)
dmdAnal' _ _ (Type ty) = (nopDmdType, Type ty) -- Doesn't happen, in fact
dmdAnal' _ _ (Coercion co) = (nopDmdType, Coercion co)
dmdAnal' env dmd (Var var)
= (dmdTransform env var dmd, Var var) = (dmdTransform env var dmd, Var var)
dmdAnal env dmd (Cast e co) dmdAnal' env dmd (Cast e co)
= (dmd_ty, Cast e' co) = (dmd_ty, Cast e' co)
where where
(dmd_ty, e') = dmdAnal env dmd e (dmd_ty, e') = dmdAnal env dmd e
...@@ -155,24 +158,24 @@ dmdAnal env dmd (Cast e co) ...@@ -155,24 +158,24 @@ dmdAnal env dmd (Cast e co)
-- a fixpoint. So revert to a vanilla Eval demand -- a fixpoint. So revert to a vanilla Eval demand
-} -}
dmdAnal env dmd (Tick t e) dmdAnal' env dmd (Tick t e)
= (dmd_ty, Tick t e') = (dmd_ty, Tick t e')
where where
(dmd_ty, e') = dmdAnal env dmd e (dmd_ty, e') = dmdAnal env dmd e
dmdAnal env dmd (App fun (Type ty)) dmdAnal' env dmd (App fun (Type ty))
= (fun_ty, App fun' (Type ty)) = (fun_ty, App fun' (Type ty))
where where
(fun_ty, fun') = dmdAnal env dmd fun (fun_ty, fun') = dmdAnal env dmd fun
dmdAnal sigs dmd (App fun (Coercion co)) dmdAnal' sigs dmd (App fun (Coercion co))
= (fun_ty, App fun' (Coercion co)) = (fun_ty, App fun' (Coercion co))
where where
(fun_ty, fun') = dmdAnal sigs dmd fun (fun_ty, fun') = dmdAnal sigs dmd fun
-- Lots of the other code is there to make this -- Lots of the other code is there to make this
-- beautiful, compositional, application rule :-) -- beautiful, compositional, application rule :-)
dmdAnal env dmd (App fun arg) -- Non-type arguments dmdAnal' env dmd (App fun arg) -- Non-type arguments
= let -- [Type arg handled above] = let -- [Type arg handled above]
call_dmd = mkCallDmd dmd call_dmd = mkCallDmd dmd
(fun_ty, fun') = dmdAnal env call_dmd fun (fun_ty, fun') = dmdAnal env call_dmd fun
...@@ -190,7 +193,7 @@ dmdAnal env dmd (App fun arg) -- Non-type arguments ...@@ -190,7 +193,7 @@ dmdAnal env dmd (App fun arg) -- Non-type arguments
(res_ty `bothDmdType` arg_ty, App fun' arg') (res_ty `bothDmdType` arg_ty, App fun' arg')
-- this is an anonymous lambda, since @dmdAnalRhs@ uses @collectBinders@ -- this is an anonymous lambda, since @dmdAnalRhs@ uses @collectBinders@
dmdAnal env dmd (Lam var body) dmdAnal' env dmd (Lam var body)
| isTyVar var | isTyVar var
= let = let
(body_ty, body') = dmdAnal env dmd body (body_ty, body') = dmdAnal env dmd body
...@@ -209,7 +212,7 @@ dmdAnal env dmd (Lam var body) ...@@ -209,7 +212,7 @@ dmdAnal env dmd (Lam var body)
in in
(postProcessUnsat defer_and_use lam_ty, Lam var' body') (postProcessUnsat defer_and_use lam_ty, Lam var' body')
dmdAnal env dmd (Case scrut case_bndr ty [alt@(DataAlt dc, _, _)]) dmdAnal' env dmd (Case scrut case_bndr ty [alt@(DataAlt dc, _, _)])
-- Only one alternative with a product constructor -- Only one alternative with a product constructor
| let tycon = dataConTyCon dc | let tycon = dataConTyCon dc
, isProductTyCon tycon , isProductTyCon tycon
...@@ -267,7 +270,7 @@ dmdAnal env dmd (Case scrut case_bndr ty [alt@(DataAlt dc, _, _)]) ...@@ -267,7 +270,7 @@ dmdAnal env dmd (Case scrut case_bndr ty [alt@(DataAlt dc, _, _)])
-- , text "res_ty" <+> ppr res_ty ]) $ -- , text "res_ty" <+> ppr res_ty ]) $
(res_ty, Case scrut' case_bndr' ty [alt']) (res_ty, Case scrut' case_bndr' ty [alt'])
dmdAnal env dmd (Case scrut case_bndr ty alts) dmdAnal' env dmd (Case scrut case_bndr ty alts)
= let -- Case expression with multiple alternatives = let -- Case expression with multiple alternatives
(alt_tys, alts') = mapAndUnzip (dmdAnalAlt env dmd) alts (alt_tys, alts') = mapAndUnzip (dmdAnalAlt env dmd) alts
(scrut_ty, scrut') = dmdAnal env cleanEvalDmd scrut (scrut_ty, scrut') = dmdAnal env cleanEvalDmd scrut
...@@ -281,7 +284,7 @@ dmdAnal env dmd (Case scrut case_bndr ty alts) ...@@ -281,7 +284,7 @@ dmdAnal env dmd (Case scrut case_bndr ty alts)
-- , text "res_ty" <+> ppr res_ty ]) $ -- , text "res_ty" <+> ppr res_ty ]) $
(res_ty, Case scrut' case_bndr' ty alts') (res_ty, Case scrut' case_bndr' ty alts')
dmdAnal env dmd (Let (NonRec id rhs) body) dmdAnal' env dmd (Let (NonRec id rhs) body)
= (body_ty2, Let (NonRec id2 annotated_rhs) body') = (body_ty2, Let (NonRec id2 annotated_rhs) body')
where where
(sig, lazy_fv, id1, rhs') = dmdAnalRhs NotTopLevel Nothing env id rhs (sig, lazy_fv, id1, rhs') = dmdAnalRhs NotTopLevel Nothing env id rhs
...@@ -306,7 +309,7 @@ dmdAnal env dmd (Let (NonRec id rhs) body) ...@@ -306,7 +309,7 @@ dmdAnal env dmd (Let (NonRec id rhs) body)
-- the vanilla call demand seem to be due to (b). So we don't -- the vanilla call demand seem to be due to (b). So we don't
-- bother to re-analyse the RHS. -- bother to re-analyse the RHS.
dmdAnal env dmd (Let (Rec pairs) body) dmdAnal' env dmd (Let (Rec pairs) body)
= let = let
(env', lazy_fv, pairs') = dmdFix NotTopLevel env pairs (env', lazy_fv, pairs') = dmdFix NotTopLevel env pairs
(body_ty, body') = dmdAnal env' dmd body (body_ty, body') = dmdAnal env' dmd body
......
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