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