+
+emptyIdSet :: GenIdSet ty
+intersectIdSets :: GenIdSet ty -> GenIdSet ty -> GenIdSet ty
+unionIdSets :: GenIdSet ty -> GenIdSet ty -> GenIdSet ty
+unionManyIdSets :: [GenIdSet ty] -> GenIdSet ty
+idSetToList :: GenIdSet ty -> [GenId ty]
+unitIdSet :: GenId ty -> GenIdSet ty
+addOneToIdSet :: GenIdSet ty -> GenId ty -> GenIdSet ty
+elementOfIdSet :: GenId ty -> GenIdSet ty -> Bool
+minusIdSet :: GenIdSet ty -> GenIdSet ty -> GenIdSet ty
+isEmptyIdSet :: GenIdSet ty -> Bool
+mkIdSet :: [GenId ty] -> GenIdSet ty
+
+emptyIdSet = emptyUniqSet
+unitIdSet = unitUniqSet
+addOneToIdSet = addOneToUniqSet
+intersectIdSets = intersectUniqSets
+unionIdSets = unionUniqSets
+unionManyIdSets = unionManyUniqSets
+idSetToList = uniqSetToList
+elementOfIdSet = elementOfUniqSet
+minusIdSet = minusUniqSet
+isEmptyIdSet = isEmptyUniqSet
+mkIdSet = mkUniqSet
+\end{code}
+
+\begin{code}
+addId, nmbrId, nmbrDataCon :: Id -> NmbrM Id
+
+addId id@(Id u n ty det prag info) nenv@(NmbrEnv ui ut uu idenv tvenv uvenv)
+ = case (lookupUFM_Directly idenv u) of
+ Just xx -> trace "addId: already in map!" $
+ (nenv, xx)
+ Nothing ->
+ if toplevelishId id then
+ trace "addId: can't add toplevelish!" $
+ (nenv, id)
+ else -- alloc a new unique for this guy
+ -- and add an entry in the idenv
+ -- NB: *** KNOT-TYING ***
+ let
+ nenv_plus_id = NmbrEnv (incrUnique ui) ut uu
+ (addToUFM_Directly idenv u new_id)
+ tvenv uvenv
+
+ (nenv2, new_ty) = nmbrType ty nenv_plus_id
+ (nenv3, new_det) = nmbr_details det nenv2
+
+ new_id = Id ui n new_ty new_det prag info
+ in
+ (nenv3, new_id)
+
+nmbrId id@(Id u n ty det prag info) nenv@(NmbrEnv ui ut uu idenv tvenv uvenv)
+ = case (lookupUFM_Directly idenv u) of
+ Just xx -> (nenv, xx)
+ Nothing ->
+ if not (toplevelishId id) then
+ trace "nmbrId: lookup failed" $
+ (nenv, id)
+ else
+ let
+ (nenv2, new_ty) = nmbrType ty nenv
+ (nenv3, new_det) = nmbr_details det nenv2
+
+ new_id = Id u n new_ty new_det prag info
+ in
+ (nenv3, new_id)
+
+ -- used when renumbering TyCons to produce data decls...
+nmbrDataCon id@(Id _ _ _ (TupleConId _) _ _) nenv
+ = (nenv, id) -- nothing to do for tuples
+
+nmbrDataCon id@(Id u n ty (DataConId tag marks fields tvs theta arg_tys tc) prag info) nenv@(NmbrEnv ui ut uu idenv tvenv uvenv)
+ = case (lookupUFM_Directly idenv u) of
+ Just xx -> trace "nmbrDataCon: in env???\n" (nenv, xx)
+ Nothing ->
+ let
+ (nenv2, new_fields) = (mapNmbr nmbrField fields) nenv
+ (nenv3, new_arg_tys) = (mapNmbr nmbrType arg_tys) nenv2
+
+ new_det = DataConId tag marks new_fields (bottom "tvs") (bottom "theta") new_arg_tys tc
+ new_id = Id u n (bottom "ty") new_det prag info
+ in
+ (nenv3, new_id)
+ where
+ bottom msg = panic ("nmbrDataCon"++msg)
+
+------------
+nmbr_details :: IdDetails -> NmbrM IdDetails
+
+nmbr_details (DataConId tag marks fields tvs theta arg_tys tc)
+ = mapNmbr nmbrTyVar tvs `thenNmbr` \ new_tvs ->
+ mapNmbr nmbrField fields `thenNmbr` \ new_fields ->
+ mapNmbr nmbr_theta theta `thenNmbr` \ new_theta ->
+ mapNmbr nmbrType arg_tys `thenNmbr` \ new_arg_tys ->
+ returnNmbr (DataConId tag marks new_fields new_tvs new_theta new_arg_tys tc)
+ where
+ nmbr_theta (c,t)
+ = --nmbrClass c `thenNmbr` \ new_c ->
+ nmbrType t `thenNmbr` \ new_t ->
+ returnNmbr (c, new_t)
+
+ -- ToDo:add more cases as needed
+nmbr_details other_details = returnNmbr other_details
+
+------------
+nmbrField (FieldLabel n ty tag)
+ = nmbrType ty `thenNmbr` \ new_ty ->
+ returnNmbr (FieldLabel n new_ty tag)