Kill varSetElems
[ghc.git] / compiler / basicTypes / VarEnv.hs
1 {-
2 (c) The University of Glasgow 2006
3 (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 -}
5
6 module VarEnv (
7 -- * Var, Id and TyVar environments (maps)
8 VarEnv, IdEnv, TyVarEnv, CoVarEnv, TyCoVarEnv,
9
10 -- ** Manipulating these environments
11 emptyVarEnv, unitVarEnv, mkVarEnv, mkVarEnv_Directly,
12 elemVarEnv, varEnvElts,
13 extendVarEnv, extendVarEnv_C, extendVarEnv_Acc, extendVarEnv_Directly,
14 extendVarEnvList,
15 plusVarEnv, plusVarEnv_C, plusVarEnv_CD, alterVarEnv,
16 delVarEnvList, delVarEnv, delVarEnv_Directly,
17 minusVarEnv, intersectsVarEnv,
18 lookupVarEnv, lookupVarEnv_NF, lookupWithDefaultVarEnv,
19 mapVarEnv, zipVarEnv,
20 modifyVarEnv, modifyVarEnv_Directly,
21 isEmptyVarEnv,
22 elemVarEnvByKey, lookupVarEnv_Directly,
23 filterVarEnv, filterVarEnv_Directly, restrictVarEnv,
24 partitionVarEnv,
25
26 -- * Deterministic Var environments (maps)
27 DVarEnv, DIdEnv, DTyVarEnv,
28
29 -- ** Manipulating these environments
30 emptyDVarEnv,
31 dVarEnvElts,
32 extendDVarEnv, extendDVarEnv_C,
33 lookupDVarEnv,
34 isEmptyDVarEnv, foldDVarEnv,
35 mapDVarEnv,
36 modifyDVarEnv,
37 alterDVarEnv,
38 plusDVarEnv_C,
39 unitDVarEnv,
40 delDVarEnv,
41 delDVarEnvList,
42 partitionDVarEnv,
43 anyDVarEnv,
44
45 -- * The InScopeSet type
46 InScopeSet,
47
48 -- ** Operations on InScopeSets
49 emptyInScopeSet, mkInScopeSet, delInScopeSet,
50 extendInScopeSet, extendInScopeSetList, extendInScopeSetSet,
51 getInScopeVars, lookupInScope, lookupInScope_Directly,
52 unionInScope, elemInScopeSet, uniqAway,
53 varSetInScope,
54
55 -- * The RnEnv2 type
56 RnEnv2,
57
58 -- ** Operations on RnEnv2s
59 mkRnEnv2, rnBndr2, rnBndrs2, rnBndr2_var,
60 rnOccL, rnOccR, inRnEnvL, inRnEnvR, rnOccL_maybe, rnOccR_maybe,
61 rnBndrL, rnBndrR, nukeRnEnvL, nukeRnEnvR, rnSwap,
62 delBndrL, delBndrR, delBndrsL, delBndrsR,
63 addRnInScopeSet,
64 rnEtaL, rnEtaR,
65 rnInScope, rnInScopeSet, lookupRnInScope,
66 rnEnvL, rnEnvR,
67
68 -- * TidyEnv and its operation
69 TidyEnv,
70 emptyTidyEnv
71 ) where
72
73 import OccName
74 import Var
75 import VarSet
76 import UniqFM
77 import UniqDFM
78 import Unique
79 import Util
80 import Maybes
81 import Outputable
82 import StaticFlags
83
84 {-
85 ************************************************************************
86 * *
87 In-scope sets
88 * *
89 ************************************************************************
90 -}
91
92 -- | A set of variables that are in scope at some point
93 -- "Secrets of the Glasgow Haskell Compiler inliner" Section 3. provides
94 -- the motivation for this abstraction.
95 data InScopeSet = InScope (VarEnv Var) {-# UNPACK #-} !Int
96 -- The (VarEnv Var) is just a VarSet. But we write it like
97 -- this to remind ourselves that you can look up a Var in
98 -- the InScopeSet. Typically the InScopeSet contains the
99 -- canonical version of the variable (e.g. with an informative
100 -- unfolding), so this lookup is useful.
101 --
102 -- INVARIANT: the VarEnv maps (the Unique of) a variable to
103 -- a variable with the same Unique. (This was not
104 -- the case in the past, when we had a grevious hack
105 -- mapping var1 to var2.
106 --
107 -- The Int is a kind of hash-value used by uniqAway
108 -- For example, it might be the size of the set
109 -- INVARIANT: it's not zero; we use it as a multiplier in uniqAway
110
111 instance Outputable InScopeSet where
112 ppr (InScope s _) =
113 text "InScope" <+> braces (fsep (map (ppr . Var.varName) (nonDetEltsUFM s)))
114 -- It's OK to use nonDetEltsUFM here because it's
115 -- only for pretty printing
116 -- In-scope sets get big, and with -dppr-debug
117 -- the output is overwhelming
118
119 emptyInScopeSet :: InScopeSet
120 emptyInScopeSet = InScope emptyVarSet 1
121
122 getInScopeVars :: InScopeSet -> VarEnv Var
123 getInScopeVars (InScope vs _) = vs
124
125 mkInScopeSet :: VarEnv Var -> InScopeSet
126 mkInScopeSet in_scope = InScope in_scope 1
127
128 extendInScopeSet :: InScopeSet -> Var -> InScopeSet
129 extendInScopeSet (InScope in_scope n) v = InScope (extendVarEnv in_scope v v) (n + 1)
130
131 extendInScopeSetList :: InScopeSet -> [Var] -> InScopeSet
132 extendInScopeSetList (InScope in_scope n) vs
133 = InScope (foldl (\s v -> extendVarEnv s v v) in_scope vs)
134 (n + length vs)
135
136 extendInScopeSetSet :: InScopeSet -> VarEnv Var -> InScopeSet
137 extendInScopeSetSet (InScope in_scope n) vs
138 = InScope (in_scope `plusVarEnv` vs) (n + sizeUFM vs)
139
140 delInScopeSet :: InScopeSet -> Var -> InScopeSet
141 delInScopeSet (InScope in_scope n) v = InScope (in_scope `delVarEnv` v) n
142
143 elemInScopeSet :: Var -> InScopeSet -> Bool
144 elemInScopeSet v (InScope in_scope _) = v `elemVarEnv` in_scope
145
146 -- | Look up a variable the 'InScopeSet'. This lets you map from
147 -- the variable's identity (unique) to its full value.
148 lookupInScope :: InScopeSet -> Var -> Maybe Var
149 lookupInScope (InScope in_scope _) v = lookupVarEnv in_scope v
150
151 lookupInScope_Directly :: InScopeSet -> Unique -> Maybe Var
152 lookupInScope_Directly (InScope in_scope _) uniq
153 = lookupVarEnv_Directly in_scope uniq
154
155 unionInScope :: InScopeSet -> InScopeSet -> InScopeSet
156 unionInScope (InScope s1 _) (InScope s2 n2)
157 = InScope (s1 `plusVarEnv` s2) n2
158
159 varSetInScope :: VarSet -> InScopeSet -> Bool
160 varSetInScope vars (InScope s1 _) = vars `subVarSet` s1
161
162 -- | @uniqAway in_scope v@ finds a unique that is not used in the
163 -- in-scope set, and gives that to v.
164 uniqAway :: InScopeSet -> Var -> Var
165 -- It starts with v's current unique, of course, in the hope that it won't
166 -- have to change, and thereafter uses a combination of that and the hash-code
167 -- found in the in-scope set
168 uniqAway in_scope var
169 | var `elemInScopeSet` in_scope = uniqAway' in_scope var -- Make a new one
170 | otherwise = var -- Nothing to do
171
172 uniqAway' :: InScopeSet -> Var -> Var
173 -- This one *always* makes up a new variable
174 uniqAway' (InScope set n) var
175 = try 1
176 where
177 orig_unique = getUnique var
178 try k
179 | debugIsOn && (k > 1000)
180 = pprPanic "uniqAway loop:" (ppr k <+> text "tries" <+> ppr var <+> int n)
181 | uniq `elemVarSetByKey` set = try (k + 1)
182 | debugIsOn && opt_PprStyle_Debug && (k > 3)
183 = pprTrace "uniqAway:" (ppr k <+> text "tries" <+> ppr var <+> int n)
184 setVarUnique var uniq
185 | otherwise = setVarUnique var uniq
186 where
187 uniq = deriveUnique orig_unique (n * k)
188
189 {-
190 ************************************************************************
191 * *
192 Dual renaming
193 * *
194 ************************************************************************
195 -}
196
197 -- | When we are comparing (or matching) types or terms, we are faced with
198 -- \"going under\" corresponding binders. E.g. when comparing:
199 --
200 -- > \x. e1 ~ \y. e2
201 --
202 -- Basically we want to rename [@x@ -> @y@] or [@y@ -> @x@], but there are lots of
203 -- things we must be careful of. In particular, @x@ might be free in @e2@, or
204 -- y in @e1@. So the idea is that we come up with a fresh binder that is free
205 -- in neither, and rename @x@ and @y@ respectively. That means we must maintain:
206 --
207 -- 1. A renaming for the left-hand expression
208 --
209 -- 2. A renaming for the right-hand expressions
210 --
211 -- 3. An in-scope set
212 --
213 -- Furthermore, when matching, we want to be able to have an 'occurs check',
214 -- to prevent:
215 --
216 -- > \x. f ~ \y. y
217 --
218 -- matching with [@f@ -> @y@]. So for each expression we want to know that set of
219 -- locally-bound variables. That is precisely the domain of the mappings 1.
220 -- and 2., but we must ensure that we always extend the mappings as we go in.
221 --
222 -- All of this information is bundled up in the 'RnEnv2'
223 data RnEnv2
224 = RV2 { envL :: VarEnv Var -- Renaming for Left term
225 , envR :: VarEnv Var -- Renaming for Right term
226 , in_scope :: InScopeSet } -- In scope in left or right terms
227
228 -- The renamings envL and envR are *guaranteed* to contain a binding
229 -- for every variable bound as we go into the term, even if it is not
230 -- renamed. That way we can ask what variables are locally bound
231 -- (inRnEnvL, inRnEnvR)
232
233 mkRnEnv2 :: InScopeSet -> RnEnv2
234 mkRnEnv2 vars = RV2 { envL = emptyVarEnv
235 , envR = emptyVarEnv
236 , in_scope = vars }
237
238 addRnInScopeSet :: RnEnv2 -> VarEnv Var -> RnEnv2
239 addRnInScopeSet env vs
240 | isEmptyVarEnv vs = env
241 | otherwise = env { in_scope = extendInScopeSetSet (in_scope env) vs }
242
243 rnInScope :: Var -> RnEnv2 -> Bool
244 rnInScope x env = x `elemInScopeSet` in_scope env
245
246 rnInScopeSet :: RnEnv2 -> InScopeSet
247 rnInScopeSet = in_scope
248
249 -- | Retrieve the left mapping
250 rnEnvL :: RnEnv2 -> VarEnv Var
251 rnEnvL = envL
252
253 -- | Retrieve the right mapping
254 rnEnvR :: RnEnv2 -> VarEnv Var
255 rnEnvR = envR
256
257 rnBndrs2 :: RnEnv2 -> [Var] -> [Var] -> RnEnv2
258 -- ^ Applies 'rnBndr2' to several variables: the two variable lists must be of equal length
259 rnBndrs2 env bsL bsR = foldl2 rnBndr2 env bsL bsR
260
261 rnBndr2 :: RnEnv2 -> Var -> Var -> RnEnv2
262 -- ^ @rnBndr2 env bL bR@ goes under a binder @bL@ in the Left term,
263 -- and binder @bR@ in the Right term.
264 -- It finds a new binder, @new_b@,
265 -- and returns an environment mapping @bL -> new_b@ and @bR -> new_b@
266 rnBndr2 env bL bR = fst $ rnBndr2_var env bL bR
267
268 rnBndr2_var :: RnEnv2 -> Var -> Var -> (RnEnv2, Var)
269 -- ^ Similar to 'rnBndr2' but returns the new variable as well as the
270 -- new environment
271 rnBndr2_var (RV2 { envL = envL, envR = envR, in_scope = in_scope }) bL bR
272 = (RV2 { envL = extendVarEnv envL bL new_b -- See Note
273 , envR = extendVarEnv envR bR new_b -- [Rebinding]
274 , in_scope = extendInScopeSet in_scope new_b }, new_b)
275 where
276 -- Find a new binder not in scope in either term
277 new_b | not (bL `elemInScopeSet` in_scope) = bL
278 | not (bR `elemInScopeSet` in_scope) = bR
279 | otherwise = uniqAway' in_scope bL
280
281 -- Note [Rebinding]
282 -- If the new var is the same as the old one, note that
283 -- the extendVarEnv *deletes* any current renaming
284 -- E.g. (\x. \x. ...) ~ (\y. \z. ...)
285 --
286 -- Inside \x \y { [x->y], [y->y], {y} }
287 -- \x \z { [x->x], [y->y, z->x], {y,x} }
288
289 rnBndrL :: RnEnv2 -> Var -> (RnEnv2, Var)
290 -- ^ Similar to 'rnBndr2' but used when there's a binder on the left
291 -- side only.
292 rnBndrL (RV2 { envL = envL, envR = envR, in_scope = in_scope }) bL
293 = (RV2 { envL = extendVarEnv envL bL new_b
294 , envR = envR
295 , in_scope = extendInScopeSet in_scope new_b }, new_b)
296 where
297 new_b = uniqAway in_scope bL
298
299 rnBndrR :: RnEnv2 -> Var -> (RnEnv2, Var)
300 -- ^ Similar to 'rnBndr2' but used when there's a binder on the right
301 -- side only.
302 rnBndrR (RV2 { envL = envL, envR = envR, in_scope = in_scope }) bR
303 = (RV2 { envR = extendVarEnv envR bR new_b
304 , envL = envL
305 , in_scope = extendInScopeSet in_scope new_b }, new_b)
306 where
307 new_b = uniqAway in_scope bR
308
309 rnEtaL :: RnEnv2 -> Var -> (RnEnv2, Var)
310 -- ^ Similar to 'rnBndrL' but used for eta expansion
311 -- See Note [Eta expansion]
312 rnEtaL (RV2 { envL = envL, envR = envR, in_scope = in_scope }) bL
313 = (RV2 { envL = extendVarEnv envL bL new_b
314 , envR = extendVarEnv envR new_b new_b -- Note [Eta expansion]
315 , in_scope = extendInScopeSet in_scope new_b }, new_b)
316 where
317 new_b = uniqAway in_scope bL
318
319 rnEtaR :: RnEnv2 -> Var -> (RnEnv2, Var)
320 -- ^ Similar to 'rnBndr2' but used for eta expansion
321 -- See Note [Eta expansion]
322 rnEtaR (RV2 { envL = envL, envR = envR, in_scope = in_scope }) bR
323 = (RV2 { envL = extendVarEnv envL new_b new_b -- Note [Eta expansion]
324 , envR = extendVarEnv envR bR new_b
325 , in_scope = extendInScopeSet in_scope new_b }, new_b)
326 where
327 new_b = uniqAway in_scope bR
328
329 delBndrL, delBndrR :: RnEnv2 -> Var -> RnEnv2
330 delBndrL rn@(RV2 { envL = env, in_scope = in_scope }) v
331 = rn { envL = env `delVarEnv` v, in_scope = in_scope `extendInScopeSet` v }
332 delBndrR rn@(RV2 { envR = env, in_scope = in_scope }) v
333 = rn { envR = env `delVarEnv` v, in_scope = in_scope `extendInScopeSet` v }
334
335 delBndrsL, delBndrsR :: RnEnv2 -> [Var] -> RnEnv2
336 delBndrsL rn@(RV2 { envL = env, in_scope = in_scope }) v
337 = rn { envL = env `delVarEnvList` v, in_scope = in_scope `extendInScopeSetList` v }
338 delBndrsR rn@(RV2 { envR = env, in_scope = in_scope }) v
339 = rn { envR = env `delVarEnvList` v, in_scope = in_scope `extendInScopeSetList` v }
340
341 rnOccL, rnOccR :: RnEnv2 -> Var -> Var
342 -- ^ Look up the renaming of an occurrence in the left or right term
343 rnOccL (RV2 { envL = env }) v = lookupVarEnv env v `orElse` v
344 rnOccR (RV2 { envR = env }) v = lookupVarEnv env v `orElse` v
345
346 rnOccL_maybe, rnOccR_maybe :: RnEnv2 -> Var -> Maybe Var
347 -- ^ Look up the renaming of an occurrence in the left or right term
348 rnOccL_maybe (RV2 { envL = env }) v = lookupVarEnv env v
349 rnOccR_maybe (RV2 { envR = env }) v = lookupVarEnv env v
350
351 inRnEnvL, inRnEnvR :: RnEnv2 -> Var -> Bool
352 -- ^ Tells whether a variable is locally bound
353 inRnEnvL (RV2 { envL = env }) v = v `elemVarEnv` env
354 inRnEnvR (RV2 { envR = env }) v = v `elemVarEnv` env
355
356 lookupRnInScope :: RnEnv2 -> Var -> Var
357 lookupRnInScope env v = lookupInScope (in_scope env) v `orElse` v
358
359 nukeRnEnvL, nukeRnEnvR :: RnEnv2 -> RnEnv2
360 -- ^ Wipe the left or right side renaming
361 nukeRnEnvL env = env { envL = emptyVarEnv }
362 nukeRnEnvR env = env { envR = emptyVarEnv }
363
364 rnSwap :: RnEnv2 -> RnEnv2
365 -- ^ swap the meaning of left and right
366 rnSwap (RV2 { envL = envL, envR = envR, in_scope = in_scope })
367 = RV2 { envL = envR, envR = envL, in_scope = in_scope }
368
369 {-
370 Note [Eta expansion]
371 ~~~~~~~~~~~~~~~~~~~~
372 When matching
373 (\x.M) ~ N
374 we rename x to x' with, where x' is not in scope in
375 either term. Then we want to behave as if we'd seen
376 (\x'.M) ~ (\x'.N x')
377 Since x' isn't in scope in N, the form (\x'. N x') doesn't
378 capture any variables in N. But we must nevertheless extend
379 the envR with a binding [x' -> x'], to support the occurs check.
380 For example, if we don't do this, we can get silly matches like
381 forall a. (\y.a) ~ v
382 succeeding with [a -> v y], which is bogus of course.
383
384
385 ************************************************************************
386 * *
387 Tidying
388 * *
389 ************************************************************************
390 -}
391
392 -- | When tidying up print names, we keep a mapping of in-scope occ-names
393 -- (the 'TidyOccEnv') and a Var-to-Var of the current renamings
394 type TidyEnv = (TidyOccEnv, VarEnv Var)
395
396 emptyTidyEnv :: TidyEnv
397 emptyTidyEnv = (emptyTidyOccEnv, emptyVarEnv)
398
399 {-
400 ************************************************************************
401 * *
402 \subsection{@VarEnv@s}
403 * *
404 ************************************************************************
405 -}
406
407 type VarEnv elt = UniqFM elt
408 type IdEnv elt = VarEnv elt
409 type TyVarEnv elt = VarEnv elt
410 type TyCoVarEnv elt = VarEnv elt
411 type CoVarEnv elt = VarEnv elt
412
413 emptyVarEnv :: VarEnv a
414 mkVarEnv :: [(Var, a)] -> VarEnv a
415 mkVarEnv_Directly :: [(Unique, a)] -> VarEnv a
416 zipVarEnv :: [Var] -> [a] -> VarEnv a
417 unitVarEnv :: Var -> a -> VarEnv a
418 alterVarEnv :: (Maybe a -> Maybe a) -> VarEnv a -> Var -> VarEnv a
419 extendVarEnv :: VarEnv a -> Var -> a -> VarEnv a
420 extendVarEnv_C :: (a->a->a) -> VarEnv a -> Var -> a -> VarEnv a
421 extendVarEnv_Acc :: (a->b->b) -> (a->b) -> VarEnv b -> Var -> a -> VarEnv b
422 extendVarEnv_Directly :: VarEnv a -> Unique -> a -> VarEnv a
423 plusVarEnv :: VarEnv a -> VarEnv a -> VarEnv a
424 extendVarEnvList :: VarEnv a -> [(Var, a)] -> VarEnv a
425
426 lookupVarEnv_Directly :: VarEnv a -> Unique -> Maybe a
427 filterVarEnv_Directly :: (Unique -> a -> Bool) -> VarEnv a -> VarEnv a
428 delVarEnv_Directly :: VarEnv a -> Unique -> VarEnv a
429 partitionVarEnv :: (a -> Bool) -> VarEnv a -> (VarEnv a, VarEnv a)
430 restrictVarEnv :: VarEnv a -> VarSet -> VarEnv a
431 delVarEnvList :: VarEnv a -> [Var] -> VarEnv a
432 delVarEnv :: VarEnv a -> Var -> VarEnv a
433 minusVarEnv :: VarEnv a -> VarEnv b -> VarEnv a
434 intersectsVarEnv :: VarEnv a -> VarEnv a -> Bool
435 plusVarEnv_C :: (a -> a -> a) -> VarEnv a -> VarEnv a -> VarEnv a
436 plusVarEnv_CD :: (a -> a -> a) -> VarEnv a -> a -> VarEnv a -> a -> VarEnv a
437 mapVarEnv :: (a -> b) -> VarEnv a -> VarEnv b
438 modifyVarEnv :: (a -> a) -> VarEnv a -> Var -> VarEnv a
439 varEnvElts :: VarEnv a -> [a]
440
441 isEmptyVarEnv :: VarEnv a -> Bool
442 lookupVarEnv :: VarEnv a -> Var -> Maybe a
443 filterVarEnv :: (a -> Bool) -> VarEnv a -> VarEnv a
444 lookupVarEnv_NF :: VarEnv a -> Var -> a
445 lookupWithDefaultVarEnv :: VarEnv a -> a -> Var -> a
446 elemVarEnv :: Var -> VarEnv a -> Bool
447 elemVarEnvByKey :: Unique -> VarEnv a -> Bool
448
449 elemVarEnv = elemUFM
450 elemVarEnvByKey = elemUFM_Directly
451 alterVarEnv = alterUFM
452 extendVarEnv = addToUFM
453 extendVarEnv_C = addToUFM_C
454 extendVarEnv_Acc = addToUFM_Acc
455 extendVarEnv_Directly = addToUFM_Directly
456 extendVarEnvList = addListToUFM
457 plusVarEnv_C = plusUFM_C
458 plusVarEnv_CD = plusUFM_CD
459 delVarEnvList = delListFromUFM
460 delVarEnv = delFromUFM
461 minusVarEnv = minusUFM
462 intersectsVarEnv e1 e2 = not (isEmptyVarEnv (e1 `intersectUFM` e2))
463 plusVarEnv = plusUFM
464 lookupVarEnv = lookupUFM
465 filterVarEnv = filterUFM
466 lookupWithDefaultVarEnv = lookupWithDefaultUFM
467 mapVarEnv = mapUFM
468 mkVarEnv = listToUFM
469 mkVarEnv_Directly= listToUFM_Directly
470 emptyVarEnv = emptyUFM
471 varEnvElts = eltsUFM
472 unitVarEnv = unitUFM
473 isEmptyVarEnv = isNullUFM
474 lookupVarEnv_Directly = lookupUFM_Directly
475 filterVarEnv_Directly = filterUFM_Directly
476 delVarEnv_Directly = delFromUFM_Directly
477 partitionVarEnv = partitionUFM
478
479 restrictVarEnv env vs = filterVarEnv_Directly keep env
480 where
481 keep u _ = u `elemVarSetByKey` vs
482
483 zipVarEnv tyvars tys = mkVarEnv (zipEqual "zipVarEnv" tyvars tys)
484 lookupVarEnv_NF env id = case lookupVarEnv env id of
485 Just xx -> xx
486 Nothing -> panic "lookupVarEnv_NF: Nothing"
487
488 {-
489 @modifyVarEnv@: Look up a thing in the VarEnv,
490 then mash it with the modify function, and put it back.
491 -}
492
493 modifyVarEnv mangle_fn env key
494 = case (lookupVarEnv env key) of
495 Nothing -> env
496 Just xx -> extendVarEnv env key (mangle_fn xx)
497
498 modifyVarEnv_Directly :: (a -> a) -> UniqFM a -> Unique -> UniqFM a
499 modifyVarEnv_Directly mangle_fn env key
500 = case (lookupUFM_Directly env key) of
501 Nothing -> env
502 Just xx -> addToUFM_Directly env key (mangle_fn xx)
503
504 -- Deterministic VarEnv
505 -- See Note [Deterministic UniqFM] in UniqDFM for explanation why we need
506 -- DVarEnv.
507
508 type DVarEnv elt = UniqDFM elt
509 type DIdEnv elt = DVarEnv elt
510 type DTyVarEnv elt = DVarEnv elt
511
512 emptyDVarEnv :: DVarEnv a
513 emptyDVarEnv = emptyUDFM
514
515 dVarEnvElts :: DVarEnv a -> [a]
516 dVarEnvElts = eltsUDFM
517
518 extendDVarEnv :: DVarEnv a -> Var -> a -> DVarEnv a
519 extendDVarEnv = addToUDFM
520
521 lookupDVarEnv :: DVarEnv a -> Var -> Maybe a
522 lookupDVarEnv = lookupUDFM
523
524 foldDVarEnv :: (a -> b -> b) -> b -> DVarEnv a -> b
525 foldDVarEnv = foldUDFM
526
527 mapDVarEnv :: (a -> b) -> DVarEnv a -> DVarEnv b
528 mapDVarEnv = mapUDFM
529
530 alterDVarEnv :: (Maybe a -> Maybe a) -> DVarEnv a -> Var -> DVarEnv a
531 alterDVarEnv = alterUDFM
532
533 plusDVarEnv_C :: (a -> a -> a) -> DVarEnv a -> DVarEnv a -> DVarEnv a
534 plusDVarEnv_C = plusUDFM_C
535
536 unitDVarEnv :: Var -> a -> DVarEnv a
537 unitDVarEnv = unitUDFM
538
539 delDVarEnv :: DVarEnv a -> Var -> DVarEnv a
540 delDVarEnv = delFromUDFM
541
542 delDVarEnvList :: DVarEnv a -> [Var] -> DVarEnv a
543 delDVarEnvList = delListFromUDFM
544
545 isEmptyDVarEnv :: DVarEnv a -> Bool
546 isEmptyDVarEnv = isNullUDFM
547
548 extendDVarEnv_C :: (a -> a -> a) -> DVarEnv a -> Var -> a -> DVarEnv a
549 extendDVarEnv_C = addToUDFM_C
550
551 modifyDVarEnv :: (a -> a) -> DVarEnv a -> Var -> DVarEnv a
552 modifyDVarEnv mangle_fn env key
553 = case (lookupDVarEnv env key) of
554 Nothing -> env
555 Just xx -> extendDVarEnv env key (mangle_fn xx)
556
557 partitionDVarEnv :: (a -> Bool) -> DVarEnv a -> (DVarEnv a, DVarEnv a)
558 partitionDVarEnv = partitionUDFM
559
560 anyDVarEnv :: (a -> Bool) -> DVarEnv a -> Bool
561 anyDVarEnv = anyUDFM