+\begin{code}
+----------------------------------------------------
+-- mk_cls_edges looks only at the context of class decls
+-- Its used when we are figuring out if there's a cycle in the
+-- superclass hierarchy
+
+mk_cls_edges :: RenamedTyClDecl -> Maybe (RenamedTyClDecl, Unique, [Unique])
+
+mk_cls_edges decl@(ClassDecl ctxt name _ _ _ _ _ _ _ _ _ _)
+ = Just (decl, getUnique name, map getUnique (catMaybes (map get_clas ctxt)))
+mk_cls_edges other_decl
+ = Nothing
+
+----------------------------------------------------
+mk_edges :: RenamedTyClDecl -> (RenamedTyClDecl, Unique, [Unique])
+
+mk_edges decl@(TyData _ ctxt name _ condecls _ derivs _ _)
+ = (decl, getUnique name, uniqSetToList (get_ctxt ctxt `unionUniqSets`
+ get_cons condecls `unionUniqSets`
+ get_deriv derivs))
+
+mk_edges decl@(TySynonym name _ rhs _)
+ = (decl, getUnique name, uniqSetToList (get_ty rhs))
+
+mk_edges decl@(ClassDecl ctxt name _ _ sigs _ _ _ _ _ _ _)
+ = (decl, getUnique name, uniqSetToList (get_ctxt ctxt `unionUniqSets`
+ get_sigs sigs))
+
+
+----------------------------------------------------
+get_ctxt ctxt = unionManyUniqSets (map set_name (catMaybes (map get_clas ctxt)))
+get_clas (HsPClass clas _) = Just clas
+get_clas _ = Nothing
+
+----------------------------------------------------
+get_deriv Nothing = emptyUniqSet
+get_deriv (Just clss) = unionManyUniqSets (map set_name clss)
+
+----------------------------------------------------
+get_cons cons = unionManyUniqSets (map get_con cons)
+
+----------------------------------------------------
+get_con (ConDecl _ _ _ ctxt details _)
+ = get_ctxt ctxt `unionUniqSets` get_con_details details
+
+----------------------------------------------------
+get_con_details (VanillaCon btys) = unionManyUniqSets (map get_bty btys)
+get_con_details (InfixCon bty1 bty2) = unionUniqSets (get_bty bty1) (get_bty bty2)
+get_con_details (NewCon ty _) = get_ty ty
+get_con_details (RecCon nbtys) = unionManyUniqSets (map (get_bty.snd) nbtys)
+
+----------------------------------------------------
+get_bty (Banged ty) = get_ty ty
+get_bty (Unbanged ty) = get_ty ty
+get_bty (Unpacked ty) = get_ty ty
+
+----------------------------------------------------
+get_ty (HsTyVar name) | isTvOcc (nameOccName name) = emptyUniqSet
+ | otherwise = set_name name
+get_ty (HsAppTy ty1 ty2) = unionUniqSets (get_ty ty1) (get_ty ty2)
+get_ty (HsFunTy ty1 ty2) = unionUniqSets (get_ty ty1) (get_ty ty2)
+get_ty (HsListTy ty) = set_name listTyCon_name `unionUniqSets` get_ty ty
+get_ty (HsTupleTy (HsTupCon n _) tys) = set_name n `unionUniqSets` get_tys tys
+get_ty (HsUsgTy _ ty) = get_ty ty
+get_ty (HsUsgForAllTy _ ty) = get_ty ty
+get_ty (HsForAllTy _ ctxt mty) = get_ctxt ctxt `unionUniqSets` get_ty mty
+get_ty (HsPredTy (HsPClass name _)) = set_name name
+get_ty (HsPredTy (HsPIParam _ _)) = emptyUniqSet -- I think
+
+----------------------------------------------------
+get_tys tys = unionManyUniqSets (map get_ty tys)
+
+----------------------------------------------------