[switch to using Name.Id everywhere. use IdSets instead of Sets of Ints or Ids, get rid of all references to tvrNum in favor of tvrIdent
John Meacham <john@repetae.net>**20060408062603] hunk ./E/Annotate.hs 15
+import Name.Id
hunk ./E/Annotate.hs 108
-        vs = [ tvrNum x | x <- ts ]
+        vs = [ tvrIdent x | x <- ts ]
hunk ./E/E.hs 23
+import Name.Id
+import Util.SetLike as S
hunk ./E/E.hs 31
-type Id = Int
hunk ./E/E.hs 148
-tvrNum TVr { tvrIdent =  n } = n
hunk ./E/E.hs 275
-tvrShowName t = maybe ('x':(show $ tvrNum t)) show (tvrName t)
+tvrShowName t = maybe ('x':(show $ tvrIdent t)) show (tvrName t)
hunk ./E/E.hs 333
+instance BuildSet IdSet (TVr' e) where
+    fromList xs = fromList (map tvrIdent xs)
+    fromDistinctAscList xs = fromDistinctAscList (map tvrIdent xs)
+    member x s = member (tvrIdent x) s
+    insert x s = S.insert (tvrIdent x) s
+    delete x s = S.delete (tvrIdent x) s
+    singleton x = singleton (tvrIdent x)
+
+
+
hunk ./E/Eta.hs 133
-        f (ELam t (EAp x (EVar t'))) | t == t' && not (tvrNum t `Set.member` freeVars x) = f x
+        f (ELam t (EAp x (EVar t'))) | t == t' && not (tvrIdent t `Set.member` freeVars x) = f x
hunk ./E/Eta.hs 142
-        f (ELam t (EAp x (EVar t'))) n | n `seq` True, t == t' && not (tvrNum t `Set.member` freeVars x) = f x (n + 1)
+        f (ELam t (EAp x (EVar t'))) n | n `seq` True, t == t' && not (tvrIdent t `Set.member` freeVars x) = f x (n + 1)
hunk ./E/FreeVars.hs 2
-module E.FreeVars(decomposeLet, decomposeDefns) where
+module E.FreeVars(decomposeLet, decomposeDefns, freeIds) where
hunk ./E/FreeVars.hs 13
+import Name.Id
+import Util.SetLike as S
hunk ./E/FreeVars.hs 26
-    freeVars as@(Alt l e) = IM.unions $ freeVars (getLitTyp l):(freeVars e IM.\\ IM.fromList [ (tvrNum t,t) | t <- litBinds l]):( map (freeVars . getTyp) $ litBinds l)
+    freeVars as@(Alt l e) = IM.unions $ freeVars (getLitTyp l):(freeVars e IM.\\ IM.fromList [ (tvrIdent t,t) | t <- litBinds l]):( map (freeVars . getTyp) $ litBinds l)
hunk ./E/FreeVars.hs 61
+instance FreeVars (Alt E) IdSet where
+    freeVars as@(Alt l e) = mconcat $ freeVars (getLitTyp l):(freeVars e S.\\ fromList [ tvrIdent t | t <- litBinds l]):(map (freeVars . getTyp) $ litBinds l)
+instance FreeVars E IdSet where
+    freeVars e = freeIds e
+
hunk ./E/FreeVars.hs 80
-    fv ECase { eCaseScrutinee = e, eCaseBind = b, eCaseAlts = as, eCaseDefault = d, eCaseType = ty } = IM.unions ( fv e:freeVars (getTyp  b):freeVars ty:(IM.delete (tvrNum b) $ IM.unions (freeVars d:map freeVars as)  ):[])
+    fv ECase { eCaseScrutinee = e, eCaseBind = b, eCaseAlts = as, eCaseDefault = d, eCaseType = ty } = IM.unions ( fv e:freeVars (getTyp  b):freeVars ty:(IM.delete (tvrIdent b) $ IM.unions (freeVars d:map freeVars as)  ):[])
hunk ./E/FreeVars.hs 121
-    fv ECase { eCaseScrutinee = e, eCaseBind = b, eCaseAlts = as, eCaseDefault = d, eCaseType = ty } = Map.unions ( fv e:freeVars' ty:freeVars' (getTyp  b):(Map.delete (tvrNum b) $ Map.unions (freeVars d:map freeVars as)  ):[])
+    fv ECase { eCaseScrutinee = e, eCaseBind = b, eCaseAlts = as, eCaseDefault = d, eCaseType = ty } = Map.unions ( fv e:freeVars' ty:freeVars' (getTyp  b):(Map.delete (tvrIdent b) $ Map.unions (freeVars d:map freeVars as)  ):[])
hunk ./E/FreeVars.hs 140
+-- we export this to get a concrete type for free id sets.
+freeIds ::  E -> IdSet
+freeIds =   fv where
+    (<>) = mappend
+    fv (EAp e1 e2) = fv e1 <> fv e2
+    fv (EVar tvr@TVr { tvrIdent = i, tvrType = t }) = insert i (fv t)
+    fv (ELam TVr { tvrIdent = i, tvrType = t} e) = delete i $ fv e <> fv t
+    fv (EPi  TVr { tvrIdent = i, tvrType = t} e) = delete i $ fv e <> fv t
+    fv (ELetRec dl e) =  ((tl <> bl <> fv e) S.\\ fromList ll)  where
+        (ll,tl,bl) = liftT3 (id,mconcat,mconcat) $ unzip3 $
+            map (\(tvr@(TVr { tvrIdent = j, tvrType =  t}),y) -> (j, fv t, fv y)) dl
+    fv (EError _ e) = fv e
+    fv (ELit l) = fvLit l
+    fv (EPrim _ es e) = mconcat $ fv e : map fv es
+    fv ECase { eCaseScrutinee = e, eCaseBind = b, eCaseAlts = as, eCaseDefault = d, eCaseType = ty } = mconcat ( fv e:freeVars (getTyp  b):freeVars ty:(delete (tvrIdent b) $ mconcat (freeVars d:map freeVars as)  ):[])
+    fv Unknown = mempty
+    fv ESort {} = mempty
+    fvLit (LitCons _ es e) = mconcat $ fv e:map fv es
+    fvLit l = fv (getLitTyp l)
+
+
hunk ./E/Inline.hs 34
+import Name.Id
hunk ./E/LambdaLift.hs 7
-import List
-import qualified Data.Set as Set
+import List hiding(insert)
hunk ./E/LambdaLift.hs 23
+import Util.SetLike
+import Name.Id
hunk ./E/LambdaLift.hs 39
-data S = S { funcName :: Name, topVars :: Set.Set Int, isStrict :: Bool, declEnv :: [(TVr,E)] }
+data S = S { funcName :: Name, topVars :: IdSet, isStrict :: Bool, declEnv :: [(TVr,E)] }
hunk ./E/LambdaLift.hs 47
-        f (ELam t (EAp x (EVar t'))) n | n `seq` True, t == t' && not (tvrNum t `Set.member` freeVars x) = f x (n + 1)
+        f (ELam t (EAp x (EVar t'))) n | n `seq` True, t == t' && not (tvrIdent t `member` (freeVars x :: IdSet)) = f x (n + 1)
hunk ./E/LambdaLift.hs 52
-    let wp =  Set.fromList [ tvrNum x | (x,_,_) <- cs ]
+    let wp =  fromList [ x | (x,_,_) <- cs ]
hunk ./E/LambdaLift.hs 91
-                fvs' = filter (not . (`Set.member` gs) . tvrNum) fvs
+                fvs' = filter (not . (`member` gs) . tvrIdent) fvs
hunk ./E/LambdaLift.hs 98
-                fvs'' = reverse $ topSort $ newGraph fvs' tvrNum freeVars
+                fvs'' = reverse $ topSort $ newGraph fvs' tvrIdent freeVars
hunk ./E/LambdaLift.hs 107
-            let fvs =  freeVars e
+            let fvs =  freeVars e :: [Id]
hunk ./E/LambdaLift.hs 109
-            let fvs' = filter (not . (`Set.member` gs) ) fvs
+            let fvs' = filter (not . (`member` gs) ) fvs
hunk ./E/LambdaLift.hs 117
-            let fvs' = filter (not . (`Set.member` (Set.fromList (map tvrIdent $ fsts rs) `Set.union` gs) ) . tvrIdent) fvs
-                fvs'' = reverse $ topSort $ newGraph fvs' tvrNum freeVars
+            let fvs' = filter (not . (`member` (fromList (map tvrIdent $ fsts rs) `mappend` gs) ) . tvrIdent) fvs
+                fvs'' = reverse $ topSort $ newGraph fvs' tvrIdent freeVars
hunk ./E/LambdaLift.hs 129
-        doLift t e r = local (topVars_u (Set.insert (tvrNum t)) ) $ do
+        doLift t e r = local (topVars_u (insert (tvrIdent t)) ) $ do
hunk ./E/LambdaLift.hs 137
-        doLiftR rs r = local (topVars_u (Set.union (Set.fromList (map (tvrNum . fst) rs)) )) $ do
+        doLiftR rs r = local (topVars_u (mappend (fromList (map (tvrIdent . fst) rs)) )) $ do
hunk ./E/LambdaLift.hs 209
---            let fvs' = filter (not . (`Set.member` gs) . tvrNum) fvs
---                fvs'' = reverse $ topSort $ newGraph fvs' tvrNum freeVars
+--            let fvs' = filter (not . (`Set.member` gs) . tvrIdent) fvs
+--                fvs'' = reverse $ topSort $ newGraph fvs' tvrIdent freeVars
hunk ./E/LambdaLift.hs 221
---                let fvs' = filter (not . (`Set.member` gs) . tvrNum) fvs
---                    fvs'' = reverse $ topSort $ newGraph fvs' tvrNum freeVars
+--                let fvs' = filter (not . (`Set.member` gs) . tvrIdent) fvs
+--                    fvs'' = reverse $ topSort $ newGraph fvs' tvrIdent freeVars
hunk ./E/LetFloat.hs 12
-import List
+import List  hiding(delete,insert)
hunk ./E/LetFloat.hs 14
-import qualified Data.Set as Set
hunk ./E/LetFloat.hs 22
-import Info.Info as Info
+import Info.Info as Info hiding(member,delete)
hunk ./E/LetFloat.hs 36
+import Util.SetLike
+import Name.Id
hunk ./E/LetFloat.hs 120
-            ELetRec ds' x' | not (null xs) -> do
+            ELetRec ds' x' | not (List.null xs) -> do
hunk ./E/LetFloat.hs 141
-fvBind (Right xs) = Set.unions (snds xs)
+fvBind (Right xs) = unions (snds xs)
hunk ./E/LetFloat.hs 152
-        (p',_:pe:pd:ps) = sepByDropPoint (mconcat [freeVars l | Alt l _ <- as ]:freeVars e: tvrNum b `Set.delete` freeVars d :[freeVars a | a <- as ]) xs
-    f (ELetRec ds e) xs = g (G.scc $  G.newGraph [ (d,bindingFreeVars x y) | d@(x,y) <- ds ] (tvrNum . fst . fst) (Set.toList . snd) ) xs where
+        (p',_:pe:pd:ps) = sepByDropPoint (mconcat [freeVars l | Alt l _ <- as ]:freeVars e: tvrIdent b `delete` freeVars d :[freeVars a | a <- as ]) xs
+    f (ELetRec ds e) xs = g (G.scc $  G.newGraph [ (d,bindingFreeVars x y) | d@(x,y) <- ds ] (tvrIdent . fst . fst) (idSetToList . snd) ) xs where
hunk ./E/LetFloat.hs 165
-        | (EVar v,as) <- fromAp e, v == v', not (tvrNum v' `Set.member` freeVars as)  = f (runIdentity $ app (ev,as) {- foldl EAp ev as -} ) xs
+        | (EVar v,as) <- fromAp e, v == v', not (tvrIdent v' `member` (freeVars as :: IdSet))  = f (runIdentity $ app (ev,as) {- foldl EAp ev as -} ) xs
hunk ./E/LetFloat.hs 168
-    letRec xs e = f (G.scc $ G.newGraph (concatMap G.fromScc xs) (tvrNum . fst . fst) (Set.toList . snd)) where
+    letRec xs e = f (G.scc $ G.newGraph (concatMap G.fromScc xs) (tvrIdent . fst . fst) (idSetToList . snd)) where
hunk ./E/LetFloat.hs 173
-type FVarSet = Set.Set Int
+type FVarSet = IdSet
hunk ./E/LetFloat.hs 178
-    g = G.reachable (G.newGraph (concatMap G.fromScc xs) (tvrNum . fst . fst) (Set.toList . snd)) (fvs `mappend` unsafe_ones)
-    uso = map (tvrNum . fst . fst) g
+    g = G.reachable (G.newGraph (concatMap G.fromScc xs) (tvrIdent . fst . fst) (idSetToList . snd)) (fvs `mappend` unsafe_ones)
+    uso = map (tvrIdent . fst . fst) g
hunk ./E/LetFloat.hs 181
-    ind x = any ( (`elem` uso) . tvrNum . fst . fst ) (G.fromScc x)
+    ind x = any ( (`elem` uso) . tvrIdent . fst . fst ) (G.fromScc x)
hunk ./E/LetFloat.hs 205
-        ds' = [ (d,any  (`Set.member` d) (fvDecls b)) | d <- ds ]
+        ds' = [ (d,any  (`member` d) (fvDecls b)) | d <- ds ]
hunk ./E/LetFloat.hs 207
-    fvDecls (Left ((t,_),_)) = [tvrNum t]
-    fvDecls (Right ts) = [tvrNum t | ((t,_),_) <- ts ]
+    fvDecls (Left ((t,_),_)) = [tvrIdent t]
+    fvDecls (Right ts) = [tvrIdent t | ((t,_),_) <- ts ]
hunk ./E/LetFloat.hs 258
-    let imap = Map.fromList $ map (\x -> (x,top_level)) ([ tvrIdent t| (t,_) <-  programDs prog ] ++ Set.toList (progExternalNames prog))
+    let imap = Map.fromList $ map (\x -> (x,top_level)) ([ tvrIdent t| (t,_) <-  programDs prog ] ++ idSetToList (progExternalNames prog))
hunk ./E/Program.hs 17
+import Name.Id
hunk ./E/Program.hs 21
-    progExternalNames :: Set.Set Id,
+    progExternalNames :: IdSet,
hunk ./E/Rules.hs 58
+import Name.Id
+import Util.SetLike as S
hunk ./E/Rules.hs 109
+ruleAllFreeVars :: Rules -> IdSet
hunk ./E/Rules.hs 112
-ruleFreeVars ::  Rules -> TVr -> Set.Set Int
+ruleFreeVars ::  Rules -> TVr -> IdSet
hunk ./E/Rules.hs 116
-    Just rs -> (freeVars (map ruleBody rs) Set.\\ freeVars (map ruleArgs rs))
+    Just rs -> (freeVars (map ruleBody rs) S.\\ freeVars (map ruleArgs rs))
hunk ./E/Rules.hs 118
-ruleFreeVars' ::  Rules -> Id -> Set.Set Int
+ruleFreeVars' ::  Rules -> Id -> IdSet
hunk ./E/Rules.hs 122
-    Just rs -> (freeVars (map ruleBody rs) Set.\\ freeVars (map ruleArgs rs))
+    Just rs -> (freeVars (map ruleBody rs) S.\\ freeVars (map ruleArgs rs))
hunk ./E/Rules.hs 134
+instance FreeVars Rule IdSet where
+    freeVars rule = freeVars (ruleBody rule) S.\\ fromList (map tvrIdent $ ruleBinds rule)
+
hunk ./E/Rules.hs 220
-        g e = substMap (Map.fromList [ (tvrNum t, EVar t) | t <- bs ]) e
+        g e = substMap (Map.fromList [ (tvrIdent t, EVar t) | t <- bs ]) e
hunk ./E/SSimplify.hs 8
-import List
+import List hiding(delete,union)
hunk ./E/SSimplify.hs 40
+import Name.Id
+import Util.SetLike as S
hunk ./E/SSimplify.hs 53
-newtype FreeVarSet = FreeVarSet (Set.Set Id)
-    deriving(Typeable,Show,Monoid)
-
hunk ./E/SSimplify.hs 69
-    f e@(EPi tvr@(TVr { tvrIdent = n, tvrType =  a}) b) = if n `Set.member` fvs || n `Map.member` ags then return (e,Set.delete n fvs ,Map.delete n ags) else return (EPi (tvr { tvrIdent =  0 } ) b,fvs,ags)  where
+    f e@(EPi tvr@(TVr { tvrIdent = n, tvrType =  a}) b) = if n `member` fvs || n `Map.member` ags then return (e,delete n fvs ,Map.delete n ags) else return (EPi (tvr { tvrIdent =  0 } ) b,fvs,ags)  where
hunk ./E/SSimplify.hs 78
-        return (foldr ELam b' as,foldr Set.delete  (freeVars (map tvrType as) `mappend` fvs) (map tvrNum as), Map.map inLam $ foldr Map.delete bs (map tvrNum as))
+        return (foldr ELam b' as,foldr delete  (freeVars (map tvrType as) `mappend` fvs) (map tvrIdent as), Map.map inLam $ foldr Map.delete bs (map tvrIdent as))
hunk ./E/SSimplify.hs 93
-        let gfv (_,fv,i) = fvs ++ Set.toList (mconcat (map (ruleFreeVars' rules) (fvs)))  where
-                fvs = Set.toList (Map.keysSet i `Set.union` fv)
-            gr = newGraph (zip (fsts ds) ds') (tvrNum . fst) (gfv . fst . snd )
+        let gfv (_,fv,i) = fvs ++ idSetToList (mconcat (map (ruleFreeVars' rules) (fvs)))  where
+                fvs = Set.toList (Map.keysSet i `union` fv)
+            gr = newGraph (zip (fsts ds) ds') (tvrIdent . fst) (gfv . fst . snd )
hunk ./E/SSimplify.hs 98
-        let gr' = newGraph nn (tvrNum . fst) (gfv . snd )
+        let gr' = newGraph nn (tvrIdent . fst) (gfv . snd )
hunk ./E/SSimplify.hs 100
-            cycNodes = Set.fromList $ [ v | (v,_) <- cyclicNodes gr']
+            cycNodes = (fromList $ [ v | (v,_) <- cyclicNodes gr'] :: IdSet)
hunk ./E/SSimplify.hs 102
-                | t `Set.member` cycNodes = setProperty prop_CYCLIC
+                | t `member` cycNodes = setProperty prop_CYCLIC
hunk ./E/SSimplify.hs 104
-        let dvars = map (tvrNum . fst) ds
-            fvs = foldr Set.delete (mconcat (fve:[ fv `mappend` freeVars t | (TVr { tvrType =  t},(_,fv,_)) <- ds'' ])) dvars
+        let dvars = map (tvrIdent . fst) ds
+            fvs = foldr delete (mconcat (fve:[ fv `mappend` freeVars t | (TVr { tvrType =  t},(_,fv,_)) <- ds'' ])) dvars
hunk ./E/SSimplify.hs 114
-    frules k _ | k `Set.member` rule_set = Many
+    frules k _ | k `member` rule_set = Many
hunk ./E/SSimplify.hs 118
-        return (Alt l e',foldr Set.delete (freeVars l `mappend` b) (map tvrNum $ litBinds l),foldr Map.delete c (map tvrNum $ litBinds l))
+        return (Alt l e',foldr delete (freeVars l `mappend` b) (map tvrIdent $ litBinds l),foldr Map.delete c (map tvrIdent $ litBinds l))
hunk ./E/SSimplify.hs 204
-    (dsOut,stat)  = runIdentity $ runStatT (runNameMT doit)
+    (dsOut,stat)  = runIdentity $ runStatT (runIdNameT doit)
hunk ./E/SSimplify.hs 214
-    go :: E -> Env -> NameMT Int (StatT Identity) E
+    go :: E -> Env -> IdNameT (StatT Identity) E
hunk ./E/SSimplify.hs 218
-    f :: E -> Subst -> Env -> NameMT Int (StatT Identity) E
+    f :: E -> Subst -> Env -> IdNameT (StatT Identity) E
hunk ./E/SSimplify.hs 221
-        case Map.lookup (tvrNum v) sub of
+        case Map.lookup (tvrIdent v) sub of
hunk ./E/SSimplify.hs 258
-        addNames (map tvrNum $ caseBinds ec)
+        addNames (map tvrIdent $ caseBinds ec)
hunk ./E/SSimplify.hs 262
-        addNames [tvrNum v]
+        addNames [tvrIdent v]
hunk ./E/SSimplify.hs 264
-        e' <- f e (Map.insert (tvrNum v) (Done $ EVar v') sub) (envInScope_u (Map.insert (tvrNum v') NotKnown) inb)
+        e' <- f e (Map.insert (tvrIdent v) (Done $ EVar v') sub) (envInScope_u (Map.insert (tvrIdent v') NotKnown) inb)
hunk ./E/SSimplify.hs 268
-        addNames $ map (tvrNum . fst) ds
+        addNames $ map (tvrIdent . fst) ds
hunk ./E/SSimplify.hs 272
-                return (tvrNum t,Many,t'',EError "<<loop>>" (getType t))
+                return (tvrIdent t,Many,t'',EError "<<loop>>" (getType t))
hunk ./E/SSimplify.hs 276
-                    _ | forceNoinline t -> return (tvrNum t,LoopBreaker,t',e)
-                    Just Once -> return (tvrNum t,Once,error $ "Once: " ++ show t,e)
-                    Just n -> return (tvrNum t,n,t',e)
+                    _ | forceNoinline t -> return (tvrIdent t,LoopBreaker,t',e)
+                    Just Once -> return (tvrIdent t,Once,error $ "Once: " ++ show t,e)
+                    Just n -> return (tvrIdent t,n,t',e)
hunk ./E/SSimplify.hs 280
-                    Nothing -> return (tvrNum t,LoopBreaker,t',e)
+                    Nothing -> return (tvrIdent t,LoopBreaker,t',e)
hunk ./E/SSimplify.hs 290
-                        w rs (Map.insert t (Done e') sub) (envInScope_u (Map.insert (tvrNum t') (isBoundTo n e')) inb) ((t',e'):ds)
+                        w rs (Map.insert t (Done e') sub) (envInScope_u (Map.insert (tvrIdent t') (isBoundTo n e')) inb) ((t',e'):ds)
hunk ./E/SSimplify.hs 292
-                    False -> w rs sub (if n /= LoopBreaker then (envInScope_u (Map.insert (tvrNum t') (isBoundTo n e')) inb) else inb) ((t',e'):ds)
+                    False -> w rs sub (if n /= LoopBreaker then (envInScope_u (Map.insert (tvrIdent t') (isBoundTo n e')) inb) else inb) ((t',e'):ds)
hunk ./E/SSimplify.hs 298
-        (ds',sub',inb') <- w s' sub'' (envInScope_u (Map.fromList [ (tvrNum t',NotKnown) | (_,n,t',_) <- s', n /= Once] `Map.union`) inb) []
+        (ds',sub',inb') <- w s' sub'' (envInScope_u (Map.fromList [ (tvrIdent t',NotKnown) | (_,n,t',_) <- s', n /= Once] `Map.union`) inb) []
hunk ./E/SSimplify.hs 352
-    doCase (EVar v) t b as d sub inb |  Just IsBoundTo { bindingE = ELit l } <- Map.lookup (tvrNum v) (envInScope inb)  = doConstCase l t  b as d sub inb
+    doCase (EVar v) t b as d sub inb |  Just IsBoundTo { bindingE = ELit l } <- Map.lookup (tvrIdent v) (envInScope inb)  = doConstCase l t  b as d sub inb
hunk ./E/SSimplify.hs 355
-    doCase (EVar v) t b as d sub inb | Just IsBoundTo { bindingE = e } <- Map.lookup (tvrNum v) (envInScope inb) , isBottom e = do
+    doCase (EVar v) t b as d sub inb | Just IsBoundTo { bindingE = e } <- Map.lookup (tvrIdent v) (envInScope inb) , isBottom e = do
hunk ./E/SSimplify.hs 366
-            g x = doCase x t b' as' d' sub (envInScope_u (Map.insert (tvrNum b) NotKnown) inb)
+            g x = doCase x t b' as' d' sub (envInScope_u (Map.insert (tvrIdent b) NotKnown) inb)
hunk ./E/SSimplify.hs 399
-        d' <- f d (Map.insert (tvrNum b) (Done (EVar b')) sub) (envInScope_u  (Map.insert (tvrNum b') (isBoundTo Many e)) inb)
+        d' <- f d (Map.insert (tvrIdent b) (Done (EVar b')) sub) (envInScope_u  (Map.insert (tvrIdent b') (isBoundTo Many e)) inb)
hunk ./E/SSimplify.hs 404
-        f d (Map.insert (tvrNum b) (Susp e sub) sub) inb
-    doCase (EVar v) _ b [] (Just d) sub inb | Just (NotAmong _) <-  Map.lookup (tvrNum v) (envInScope inb)  = do
+        f d (Map.insert (tvrIdent b) (Susp e sub) sub) inb
+    doCase (EVar v) _ b [] (Just d) sub inb | Just (NotAmong _) <-  Map.lookup (tvrIdent v) (envInScope inb)  = do
hunk ./E/SSimplify.hs 407
-        d' <- f d (Map.insert (tvrNum b) (Done (EVar v)) sub) inb
+        d' <- f d (Map.insert (tvrIdent b) (Done (EVar v)) sub) inb
hunk ./E/SSimplify.hs 409
-    doCase scrut _ v [] (Just sc@ECase { eCaseScrutinee = EVar v'} ) sub inb | v == v', not $ tvrNum v `Set.member` freeVars (caseBodies sc)  = do
+    doCase scrut _ v [] (Just sc@ECase { eCaseScrutinee = EVar v'} ) sub inb | v == v', not $ tvrIdent v `Set.member` freeVars (caseBodies sc)  = do
hunk ./E/SSimplify.hs 414
-        let dd e' = f e' (Map.insert (tvrNum b) (Done $ EVar b') sub) (envInScope_u (newinb `Map.union`) inb) where
+        let dd e' = f e' (Map.insert (tvrIdent b) (Done $ EVar b') sub) (envInScope_u (newinb `Map.union`) inb) where
hunk ./E/SSimplify.hs 430
-            mins (EVar v) e = envInScope_u (Map.insert (tvrNum v) (isBoundTo Many e))
+            mins (EVar v) e = envInScope_u (Map.insert (tvrIdent v) (isBoundTo Many e))
hunk ./E/SSimplify.hs 501
-            _ -> case Map.lookup (tvrNum v) (envInScope inb) of
+            _ -> case Map.lookup (tvrIdent v) (envInScope inb) of
hunk ./E/SSimplify.hs 518
-                -- Nothing | tvrNum v `Set.member` exports -> app (EVar v,xs')
+                -- Nothing | tvrIdent v `Set.member` exports -> app (EVar v,xs')
hunk ./E/Shadow.hs 69
-        vs = [ tvrNum x | x <- ts ]
+        vs = [ tvrIdent x | x <- ts ]
hunk ./E/Show.hs 5
-import qualified Data.Set as Set
hunk ./E/Show.hs 7
+import C.Prims
hunk ./E/Show.hs 13
-import C.Prims
hunk ./E/Show.hs 14
-import Support.FreeVars
+import Name.Id
hunk ./E/Show.hs 21
+import Support.FreeVars
hunk ./E/Show.hs 23
+import Util.SetLike
hunk ./E/Show.hs 148
-        f (EPi (TVr { tvrIdent = n, tvrType =  e1}) e2) | not $ dump FD.EVerbose, not $ n `Set.member` freeVars e2 = liftM2 arr (showE e1) (showE e2)
+        f (EPi (TVr { tvrIdent = n, tvrType =  e1}) e2) | not $ dump FD.EVerbose, not $ n `member` (freeVars e2 ::IdSet) = liftM2 arr (showE e1) (showE e2)
hunk ./E/Show.hs 201
-                    db <- showTVr (if dump FD.EVerbose || (tvrIdent ecb `Set.member` freeVars e) then ecb else ecb { tvrIdent = 0 })
+                    db <- showTVr (if dump FD.EVerbose || (tvrIdent ecb `member` (freeVars e :: IdSet)) then ecb else ecb { tvrIdent = 0 })
hunk ./E/Subst.hs 23
+import Name.Id
hunk ./E/Subst.hs 28
-eLetRec ds e = f (filter ((/= 0) . tvrNum . fst) ds) where
+eLetRec ds e = f (filter ((/= 0) . tvrIdent . fst) ds) where
hunk ./E/Subst.hs 127
-        vs = [ tvrNum x | x <- ts ]
+        vs = [ tvrIdent x | x <- ts ]
hunk ./E/Subst.hs 245
-        vs = [ tvrNum x | x <- ts ]
+        vs = [ tvrIdent x | x <- ts ]
hunk ./E/Traverse.hs 26
-import qualified Data.Set as Set
hunk ./E/Traverse.hs 39
+import Name.Id
+import Util.SetLike as S
hunk ./E/Traverse.hs 56
-runRename :: Set.Set Int -> E -> (E,Set.Set Int)
-runRename set e = runIdentity $ traverse travOptions { pruneUnreachable = Nothing } (\_ (x,xs) -> (return $ foldl EAp x xs)) mempty (Map.fromAscList [ (v,NotKnown) | v <- Set.toAscList set])  e
+runRename :: IdSet -> E -> (E,IdSet)
+runRename set e = runIdentity $ traverse travOptions { pruneUnreachable = Nothing } (\_ (x,xs) -> (return $ foldl EAp x xs)) mempty (Map.fromDistinctAscList [ (v,NotKnown) | v <- idSetToList set])  e
hunk ./E/Traverse.hs 92
-newtype TravM m a = TravM (ReaderT (Map.Map Int Binding) (NameMT Int m) a)
+newtype TravM m a = TravM (ReaderT (Map.Map Int Binding) (IdNameT m) a)
hunk ./E/Traverse.hs 132
-traverse :: (MonadFix m,Monad m) => TravOptions m -> (Int -> (E,[E]) -> TravM m E) -> Subst -> (Map.Map Int Binding) -> E -> m (E,Set.Set Int)
-traverse (tOpt :: TravOptions m) func subst smap e = runNameMT' $ initNames >> runReaderT (f e) (smap,subst,0::Int)  where
+traverse :: (MonadFix m,Monad m) => TravOptions m -> (Int -> (E,[E]) -> TravM m E) -> Subst -> (Map.Map Int Binding) -> E -> m (E,IdSet)
+traverse (tOpt :: TravOptions m) func subst smap e = runIdNameT' $ initNames >> runReaderT (f e) (smap,subst,0::Int)  where
hunk ./E/Traverse.hs 138
-    f :: E -> ReaderT (Map.Map Int Binding, Subst, Int) (NameMT Int m) E
+    f :: E -> ReaderT (Map.Map Int Binding, Subst, Int) (IdNameT m) E
hunk ./E/Traverse.hs 141
-        --(y,z,n) <- get
-        --put (y,z,n + 1)
-        --put (y,z,n)
-        --return x
hunk ./E/Traverse.hs 146
-        --put (m,p,lvl)
hunk ./E/Traverse.hs 150
-            Just n'@(EVar t) | tvrNum t == n -> return $ n'
+            Just n'@(EVar t) | tvrIdent t == n -> return $ n'
hunk ./E/Traverse.hs 174
-            d' <- localVars [ (tvrNum v,NotAmong [ n | Alt (LitCons n _ _) _ <- as]) | EVar v <- [e',EVar b'] ] $ fmapM f d
+            d' <- localVars [ (tvrIdent v,NotAmong [ n | Alt (LitCons n _ _) _ <- as]) | EVar v <- [e',EVar b'] ] $ fmapM f d
hunk ./E/Traverse.hs 182
-        z (Left (tvr,x):rs) e | worthStricting x, Just (S _) <- Map.lookup (tvrNum tvr) (trav_strictness tOpt)  = do
+        z (Left (tvr,x):rs) e | worthStricting x, Just (S _) <- Map.lookup (tvrIdent tvr) (trav_strictness tOpt)  = do
hunk ./E/Traverse.hs 191
-            nr <- localVars [(tvrNum tvrn, IsBoundTo x')] $ localSubst [(n,EVar tvrn)]   (z rs e)
+            nr <- localVars [(tvrIdent tvrn, IsBoundTo x')] $ localSubst [(n,EVar tvrn)]   (z rs e)
hunk ./E/Traverse.hs 195
-            --let ds'' = inlineDecompose (pruneUnreachable tOpt) e ds
-            --lift $ lift $  pruneRecord tOpt (length ds - length ds'')
hunk ./E/Traverse.hs 220
-        localVars [ (tvrNum v, IsBoundTo (ELit $ LitCons n (map (EVar . snd) xs') t')) |  v <- vs ] $ do
+        localVars [ (tvrIdent v, IsBoundTo (ELit $ LitCons n (map (EVar . snd) xs') t')) |  v <- vs ] $ do
hunk ./E/Traverse.hs 226
-        localVars [ (tvrNum v, IsBoundTo (patToLitEE p')) |  v <- vs ] $ do
+        localVars [ (tvrIdent v, IsBoundTo (patToLitEE p')) |  v <- vs ] $ do
hunk ./E/Traverse.hs 263
-        localVars [(tvrNum nt, IsBoundTo x')] $ h dds e ((nt,x'):ds)
+        localVars [(tvrIdent nt, IsBoundTo x')] $ h dds e ((nt,x'):ds)
hunk ./E/Traverse.hs 266
-                --modify (\ (a,b,c) -> (Map.insert (tvrNum nt) (IsBoundTo x') a,b,c))
-        --        localVars [(tvrNum nt, IsBoundTo x')] $ h dds e ((nt,x'):ds)
+                --modify (\ (a,b,c) -> (Map.insert (tvrIdent nt) (IsBoundTo x') a,b,c))
+        --        localVars [(tvrIdent nt, IsBoundTo x')] $ h dds e ((nt,x'):ds)
hunk ./E/Traverse.hs 275
-        modify (\ (a,b,c) -> (Map.insert (tvrNum nt) (Just x') a,b,c))
+        modify (\ (a,b,c) -> (Map.insert (tvrIdent nt) (Just x') a,b,c))
hunk ./E/Traverse.hs 286
-        localVars [ (tvrNum v, IsBoundTo (ELit $ patToLitEE p)) |  v <- vs ] $ do
+        localVars [ (tvrIdent v, IsBoundTo (ELit $ patToLitEE p)) |  v <- vs ] $ do
hunk ./E/Traverse.hs 293
-        localVars [ (tvrNum v, IsBoundTo (ELit $ patToLitEE p)) |  v <- vs ] $ do
+        localVars [ (tvrIdent v, IsBoundTo (ELit $ patToLitEE p)) |  v <- vs ] $ do
hunk ./E/Traverse.hs 363
-    zs = [ ((t,e), tvrNum t, bindingFreeVars t e ) |  (t,e) <- ds ]
+    zs = [ ((t,e), tvrIdent t, bindingFreeVars t e ) |  (t,e) <- ds ]
hunk ./E/TypeAnalysis.hs 38
+import Name.Id
hunk ./E/TypeAnalysis.hs 274
-    sub = substMap''  $ Map.fromList [ (tvrNum t,v) | (t,Just v) <- sts ]
+    sub = substMap''  $ Map.fromList [ (tvrIdent t,v) | (t,Just v) <- sts ]
hunk ./E/TypeCheck.hs 4
-import qualified Data.Set as Set
hunk ./E/TypeCheck.hs 19
+import Util.SetLike
+import Name.Id
hunk ./E/TypeCheck.hs 100
-    fc (EPi (TVr { tvrIdent = n, tvrType =  at}) b) = valid at >> rfc' [ d | d@(v,_) <- ds, tvrNum v /= n ] b
-    --fc (ELam tvr@(TVr n at) b) = valid at >> rfc' [ d | d@(v,_) <- ds, tvrNum v /= n ] b >>= \b' -> (strong' $ EPi tvr b')
+    fc (EPi (TVr { tvrIdent = n, tvrType =  at}) b) = valid at >> rfc' [ d | d@(v,_) <- ds, tvrIdent v /= n ] b
+    --fc (ELam tvr@(TVr n at) b) = valid at >> rfc' [ d | d@(v,_) <- ds, tvrIdent v /= n ] b >>= \b' -> (strong' $ EPi tvr b')
hunk ./E/TypeCheck.hs 104
-        b' <- rfc' [ d | d@(v,_) <- ds, tvrNum v /= n ] b
+        b' <- rfc' [ d | d@(v,_) <- ds, tvrIdent v /= n ] b
hunk ./E/TypeCheck.hs 129
-        when (hasRepeatUnder (tvrNum . fst) vs) $ fail "Repeat Variable in ELetRec"
+        when (hasRepeatUnder (tvrIdent . fst) vs) $ fail "Repeat Variable in ELetRec"
hunk ./E/TypeCheck.hs 173
-    verifyPats' LitCons { litArgs = xs } = when (hasRepeatUnder id (filter (/= 0) $ map tvrNum xs)) $ fail "Case pattern is non-linear"
+    verifyPats' LitCons { litArgs = xs } = when (hasRepeatUnder id (filter (/= 0) $ map tvrIdent xs)) $ fail "Case pattern is non-linear"
hunk ./E/TypeCheck.hs 257
-    fc (EPi TVr { tvrIdent = n, tvrType = at} b) =  rfc' [ d | d@(v,_) <- ds, tvrNum v /= n ] b
+    fc (EPi TVr { tvrIdent = n, tvrType = at} b) =  rfc' [ d | d@(v,_) <- ds, tvrIdent v /= n ] b
hunk ./E/TypeCheck.hs 260
-        b' <- rfc' [ d | d@(v,_) <- ds, tvrNum v /= n ] b
+        b' <- rfc' [ d | d@(v,_) <- ds, tvrIdent v /= n ] b
hunk ./E/TypeCheck.hs 291
-    bvs = Set.fromList (map tvrIdent vs)
+    bvs :: IdSet
+    bvs = fromList (map tvrIdent vs)
hunk ./E/TypeCheck.hs 312
-        | i `Set.member` bvs = tell (Seq.single (tvr,b))
+        | i `member` bvs = tell (Seq.single (tvr,b))
hunk ./E/Values.hs 129
-    (as,nas) = partition (isAtomic . snd) (filter ((/= 0) . tvrNum . fst) ds)
+    (as,nas) = partition (isAtomic . snd) (filter ((/= 0) . tvrIdent . fst) ds)
hunk ./E/Values.hs 137
-    nas = filter ((/= 0) . tvrNum . fst) ds
+    nas = filter ((/= 0) . tvrIdent . fst) ds
hunk ./Grin/FromE.hs 111
-    | Just nm <- intToAtom (tvrNum n)  = f (toAtom ('f':show (fromAtom nm :: Name)))
-    | otherwise = f (toAtom ('f':show (tvrNum n))) where
+    | Just nm <- intToAtom (tvrIdent n)  = f (toAtom ('f':show (fromAtom nm :: Name)))
+    | otherwise = f (toAtom ('f':show (tvrIdent n))) where
hunk ./Grin/FromE.hs 145
-            ccafMap = Map.fromList $ [(tvrNum v,e) |(v,_,e) <- cc ]  ++ [ (tvrNum v,Var vv (TyPtr TyNode)) | (v,vv,_) <- rcafs]
+            ccafMap = Map.fromList $ [(tvrIdent v,e) |(v,_,e) <- cc ]  ++ [ (tvrIdent v,Var vv (TyPtr TyNode)) | (v,vv,_) <- rcafs]
hunk ./Grin/FromE.hs 162
-    -- let (main,as,rtype) = runIdentity $ Map.lookup (tvrNum mt) scMap
+    -- let (main,as,rtype) = runIdentity $ Map.lookup (tvrIdent mt) scMap
hunk ./Grin/FromE.hs 181
-    scMap = Map.fromList [ (tvrNum t,toEntry x) |  x@(t,_,_) <- map stripTheWorld $ progCombinators prog]
+    scMap = Map.fromList [ (tvrIdent t,toEntry x) |  x@(t,_,_) <- map stripTheWorld $ progCombinators prog]
hunk ./Grin/FromE.hs 231
-    (lbs',cafs) = G.findLoopBreakers (const 0) (const True) $ G.newGraph (filter (canidate . snd) ecafs) (tvrNum . fst) (freeVars . snd)
+    (lbs',cafs) = G.findLoopBreakers (const 0) (const True) $ G.newGraph (filter (canidate . snd) ecafs) (tvrIdent . fst) (freeVars . snd)
hunk ./Grin/FromE.hs 270
-    toVal tvr = Var  (V (tvrNum tvr)) (TyPtr TyNode) -- (toTy $ tvrType tvr)
+    toVal tvr = Var  (V (tvrIdent tvr)) (TyPtr TyNode) -- (toTy $ tvrType tvr)
hunk ./Grin/FromE.hs 299
-    funcName = maybe (show $ tvrNum tvr) show (fmap fromAtom ( intToAtom $ tvrNum tvr) :: Maybe Name)
+    funcName = maybe (show $ tvrIdent tvr) show (fmap fromAtom ( intToAtom $ tvrIdent tvr) :: Maybe Name)
hunk ./Grin/FromE.hs 301
-    (nn,_,_) = runIdentity $ Map.lookup (tvrNum tvr) (scMap cenv)
+    (nn,_,_) = runIdentity $ Map.lookup (tvrIdent tvr) (scMap cenv)
hunk ./Grin/FromE.hs 315
-        case Map.lookup (tvrNum tvr) (ccafMap cenv) of
+        case Map.lookup (tvrIdent tvr) (ccafMap cenv) of
hunk ./Grin/FromE.hs 318
-            Nothing -> case Map.lookup (tvrNum tvr) (scMap cenv) of
+            Nothing -> case Map.lookup (tvrIdent tvr) (scMap cenv) of
hunk ./Grin/FromE.hs 480
-        case Map.lookup (tvrNum v) (scMap cenv) of
+        case Map.lookup (tvrIdent v) (scMap cenv) of
hunk ./Grin/FromE.hs 550
-    constant (EVar tvr) | Just c <- Map.lookup (tvrNum tvr) (ccafMap cenv) = return c
-                        | Just (v,as,_) <- Map.lookup (tvrNum tvr) (scMap cenv)
+    constant (EVar tvr) | Just c <- Map.lookup (tvrIdent tvr) (ccafMap cenv) = return c
+                        | Just (v,as,_) <- Map.lookup (tvrIdent tvr) (scMap cenv)
hunk ./Grin/FromE.hs 579
-    scInfo tvr | Just n <- Map.lookup (tvrNum tvr) (scMap cenv) = return n
+    scInfo tvr | Just n <- Map.lookup (tvrIdent tvr) (scMap cenv) = return n
hunk ./Ho/Type.hs 8
-import E.E(TVr,Id,E)
+import E.E(TVr,E)
hunk ./Ho/Type.hs 20
+import Name.Id
hunk ./Main.hs 8
-import List hiding(group)
+import List hiding(group,union)
hunk ./Main.hs 63
+import Name.Id
+import Util.SetLike as S hiding(null)
hunk ./Main.hs 211
-            progExternalNames = Set.fromList [ tvrIdent n | (n,_) <- Map.elems $ hoEs ho ],
+            progExternalNames = fromList [ tvrIdent n | (n,_) <- Map.elems $ hoEs ho ],
hunk ./Main.hs 232
-        mangle = mangle' (Just $ Set.fromList $ inscope) fullDataTable
-        namesInscope = Set.fromList inscope
+        mangle = mangle' (Just $ fromList inscope) fullDataTable
+        namesInscope = fromList inscope
hunk ./Main.hs 279
-        let mprog = programSetDs ns prog { progStats = mempty, progEntryPoints = fsts ns, progExternalNames = progExternalNames prog `mappend` (Set.fromList $ map tvrIdent $ fsts (programDs prog)) }
+        let mprog = programSetDs ns prog { progStats = mempty, progEntryPoints = fsts ns, progExternalNames = progExternalNames prog `mappend` (fromList $ map tvrIdent $ fsts (programDs prog)) }
hunk ./Main.hs 340
-        let namesInscope' = Set.fromAscList (Map.keys smap) `Set.union` namesInscope
+        let namesInscope' = fromDistinctAscList (Map.keys smap) `union` namesInscope
hunk ./Main.hs 350
-        let mangle = mangle' (Just $ namesInscope' `Set.union` Set.fromList (map (tvrIdent . fst) cds)) fullDataTable
+        let mangle = mangle' (Just $ namesInscope' `union` fromList (map (tvrIdent . fst) cds)) fullDataTable
hunk ./Main.hs 387
-        let mangle = mangle' (Just $ namesInscope' `Set.union` Set.fromList (map (tvrIdent . fst) cds')) fullDataTable
+        let mangle = mangle' (Just $ namesInscope' `union` fromList (map (tvrIdent . fst) cds')) fullDataTable
hunk ./Main.hs 398
-        (cds,usedids) <- foldM dd ([],hoUsedIds ho) cds
+        (cds,usedids) <- foldM dd ([],fromDistinctAscList $ Set.toList $ hoUsedIds ho) cds
hunk ./Main.hs 407
-        let uidMap = Map.fromAscList [  (id,Nothing :: Maybe E) | id <- Set.toAscList usedids ]
+        let uidMap = Map.fromAscList [  (id,Nothing :: Maybe E) | id <- idSetToList usedids ]
hunk ./Main.hs 763
-    -> Maybe (Set.Set Id)    -- ^ acceptable free variables
+    -> Maybe IdSet           -- ^ acceptable free variables
hunk ./Main.hs 801
-    Maybe (Set.Set Id)  -- ^ Acceptable free variables
+    Maybe IdSet  -- ^ Acceptable free variables
hunk ./Main.hs 813
-        let ufreevars e | Just as <- fv = filter ( not . (`Set.member` as) . tvrIdent) (freeVars e)
+        let ufreevars e | Just as <- fv = filter ( not . (`member` as) . tvrIdent) (freeVars e)
hunk ./Main.hs 884
-    let ids = progExternalNames prog `mappend` Set.fromList (map tvrIdent $ fsts (programDs prog))
+    let ids = progExternalNames prog `mappend` fromList (map tvrIdent $ fsts (programDs prog))
hunk ./Main.hs 886
-        unaccounted = Set.filter (not . (`Set.member` ids) . tvrIdent) fvs
+        unaccounted = Set.filter (not . (`member` ids) . tvrIdent) fvs