- maybe_datacons = tyConDataCons_maybe tycon
- Just datacons = maybe_datacons -- [C, D]
-
- tyvars = tyConTyVars tycon -- [a, b, c]
- tycon_ty = mkTyConApp tycon tyvar_tys -- T a b c
- tyvar_tys = mkTyVarTys tyvars
-
- from_id_info = noCafNoTyGenIdInfo `setUnfoldingInfo` mkTopUnfolding from_fn
- `setArityInfo` exprArity from_fn
- to_id_info = noCafNoTyGenIdInfo `setUnfoldingInfo` mkTopUnfolding to_fn
- `setArityInfo` exprArity to_fn
- -- It's important to set the arity info, so that
- -- the calling convention (gotten from arity)
- -- matches reality.
-
- from_ty = mkForAllTys tyvars (mkFunTy tycon_ty rep_ty)
- to_ty = mkForAllTys tyvars (mkFunTy rep_ty tycon_ty)
-
- (from_fn, to_fn, rep_ty)
- | isNewTyCon tycon
- = ( mkLams tyvars $ Lam x $ mkNewTypeBody tycon newrep_ty (Var x),
- Var (dataConWrapId the_datacon),
- newrep_ty )
-
- | otherwise
- = ( mkLams tyvars $ Lam x $ Case (Var x) x from_alts,
- mkLams tyvars $ Lam rep_var to_inner,
- idType rep_var )
-
- -- x :: T a b c
- x = mkGenericLocal u1 tycon_ty
- (u1 : uniqs) = builtinUniques
-
- ----------------------
- -- Newtypes only
- [the_datacon] = datacons
- (_, newrep_ty) = newTyConRep tycon
-
- ----------------------
- -- Non-newtypes only
+ from_matches = [mkSimpleHsAlt pat rhs | (pat,rhs) <- from_alts]
+ to_matches = [mkSimpleHsAlt to_pat to_body]
+ loc = srcLocSpan (getSrcLoc tycon)
+ datacons = tyConDataCons tycon
+ (from_RDR, to_RDR) = mkGenericNames tycon
+