- my_zipEqual doc xs ys
- | debugIsOn && not (equalLength xs ys)
- = pprPanic "my_zipEqual" (vcat
- [ ppr xs, ppr ys
- , ppr fn <+> ppr call_ts
- , ppr (idType fn), ppr theta
- , ppr n_dicts, ppr rhs_dicts
- , ppr rhs])
- | otherwise = zipEqual doc xs ys
+ my_zipEqual xs ys zs
+ | debugIsOn && not (equalLength xs ys && equalLength ys zs)
+ = pprPanic "my_zipEqual" (vcat [ ppr xs, ppr ys
+ , ppr fn <+> ppr call_ts
+ , ppr (idType fn), ppr theta
+ , ppr n_dicts, ppr rhs_dict_ids
+ , ppr rhs])
+ | otherwise = zip3 xs ys zs
+
+bindAuxiliaryDicts
+ :: Subst
+ -> [(DictId,DictId,CoreExpr)] -- (orig_dict, inst_dict, dx)
+ -> (Subst, -- Substitute for all orig_dicts
+ [(DictId, CoreExpr)]) -- Auxiliary bindings
+-- Bind any dictionary arguments to fresh names, to preserve sharing
+-- Substitution already substitutes orig_dict -> inst_dict
+bindAuxiliaryDicts subst triples = go subst [] triples
+ where
+ go subst binds [] = (subst, binds)
+ go subst binds ((d, dx_id, dx) : pairs)
+ | exprIsTrivial dx = go (extendIdSubst subst d dx) binds pairs
+ -- No auxiliary binding necessary
+ | otherwise = go subst_w_unf ((dx_id,dx) : binds) pairs
+ where
+ dx_id1 = dx_id `setIdUnfolding` mkUnfolding False dx
+ subst_w_unf = extendIdSubst subst d (Var dx_id1)
+ -- Important! We're going to substitute dx_id1 for d
+ -- and we want it to look "interesting", else we won't gather *any*
+ -- consequential calls. E.g.
+ -- f d = ...g d....
+ -- If we specialise f for a call (f (dfun dNumInt)), we'll get
+ -- a consequent call (g d') with an auxiliary definition
+ -- d' = df dNumInt
+ -- We want that consequent call to look interesting