2 % (c) The University of Glasgow 2006
3 % (c) The AQUA Project, Glasgow University, 1994-1998
6 ``Finite maps'' are the heart of the compiler's
7 lookup-tables/environments and its implementation of sets. Important
10 This code is derived from that in the paper:
13 "Efficient sets: a balancing act"
14 Journal of functional programming 3(4) Oct 1993, pp553-562
17 The code is SPECIALIZEd to various highly-desirable types (e.g., Id)
22 -- The above warning supression flag is a temporary kludge.
23 -- While working on this module you are encouraged to remove it and fix
24 -- any warnings in the module. See
25 -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
29 FiniteMap, -- abstract type
31 emptyFM, unitFM, listToFM,
49 sizeFM, isEmptyFM, elemFM, lookupFM, lookupWithDefaultFM,
51 fmToList, keysFM, eltsFM,
56 #include "HsVersions.h"
58 #if defined(DEBUG_FINITEMAPS)/* NB NB NB */
59 #define OUTPUTABLE_key , Outputable key
61 #define OUTPUTABLE_key {--}
65 import Bag ( Bag, foldrBag )
71 -- was this import only needed for I#, or does it have something
72 -- to do with the (not-presently-used) IF_NCG also?
78 #if ! OMIT_NATIVE_CODEGEN
81 # define IF_NCG(a) {--}
87 %************************************************************************
89 \subsection{The signature of the module}
91 %************************************************************************
95 emptyFM :: FiniteMap key elt
96 unitFM :: key -> elt -> FiniteMap key elt
97 -- In the case of duplicates, the last is taken:
98 listToFM :: (Ord key OUTPUTABLE_key) => [(key,elt)] -> FiniteMap key elt
99 -- In the case of duplicates, who knows which is taken:
100 bagToFM :: (Ord key OUTPUTABLE_key) => Bag (key,elt) -> FiniteMap key elt
102 -- ADDING AND DELETING
103 -- Throws away any previous binding
104 -- In the list case, the items are added starting with the
105 -- first one in the list
106 addToFM :: (Ord key OUTPUTABLE_key)
107 => FiniteMap key elt -> key -> elt -> FiniteMap key elt
108 addListToFM :: (Ord key OUTPUTABLE_key)
109 => FiniteMap key elt -> [(key,elt)] -> FiniteMap key elt
111 -- Combines with previous binding
112 -- The combining fn goes (old -> new -> new)
113 addToFM_C :: (Ord key OUTPUTABLE_key) => (elt -> elt -> elt)
114 -> FiniteMap key elt -> key -> elt
116 addListToFM_C :: (Ord key OUTPUTABLE_key) => (elt -> elt -> elt)
117 -> FiniteMap key elt -> [(key,elt)]
120 -- Deletion doesn't complain if you try to delete something which isn't there
121 delFromFM :: (Ord key OUTPUTABLE_key)
122 => FiniteMap key elt -> key -> FiniteMap key elt
123 delListFromFM :: (Ord key OUTPUTABLE_key)
124 => FiniteMap key elt -> [key] -> FiniteMap key elt
127 -- Bindings in right argument shadow those in the left
128 plusFM :: (Ord key OUTPUTABLE_key)
129 => FiniteMap key elt -> FiniteMap key elt -> FiniteMap key elt
131 -- Combines bindings for the same thing with the given function
132 plusFM_C :: (Ord key OUTPUTABLE_key)
133 => (elt -> elt -> elt)
134 -> FiniteMap key elt -> FiniteMap key elt -> FiniteMap key elt
136 -- (minusFM a1 a2) deletes from a1 any bindings which are bound in a2
137 minusFM :: (Ord key OUTPUTABLE_key)
138 => FiniteMap key elt -> FiniteMap key elt -> FiniteMap key elt
140 intersectFM :: (Ord key OUTPUTABLE_key)
141 => FiniteMap key elt -> FiniteMap key elt -> FiniteMap key elt
142 intersectFM_C :: (Ord key OUTPUTABLE_key)
143 => (elt1 -> elt2 -> elt3)
144 -> FiniteMap key elt1 -> FiniteMap key elt2
145 -> FiniteMap key elt3
147 -- MAPPING, FOLDING, FILTERING
148 foldFM :: (key -> elt -> a -> a) -> a -> FiniteMap key elt -> a
149 mapFM :: (key -> elt1 -> elt2)
150 -> FiniteMap key elt1 -> FiniteMap key elt2
151 filterFM :: (Ord key OUTPUTABLE_key)
152 => (key -> elt -> Bool)
153 -> FiniteMap key elt -> FiniteMap key elt
156 sizeFM :: FiniteMap key elt -> Int
157 isEmptyFM :: FiniteMap key elt -> Bool
159 elemFM :: (Ord key OUTPUTABLE_key)
160 => key -> FiniteMap key elt -> Bool
161 lookupFM :: (Ord key OUTPUTABLE_key)
162 => FiniteMap key elt -> key -> Maybe elt
163 -- lookupWithDefaultFM supplies a "default" elt
164 -- to return for an unmapped key
165 lookupWithDefaultFM :: (Ord key OUTPUTABLE_key)
166 => FiniteMap key elt -> elt -> key -> elt
169 fmToList :: FiniteMap key elt -> [(key,elt)]
170 keysFM :: FiniteMap key elt -> [key]
171 eltsFM :: FiniteMap key elt -> [elt]
174 %************************************************************************
176 \subsection{The @FiniteMap@ data type, and building of same}
178 %************************************************************************
180 Invariants about @FiniteMap@:
183 all keys in a FiniteMap are distinct
185 all keys in left subtree are $<$ key in Branch and
186 all keys in right subtree are $>$ key in Branch
188 size field of a Branch gives number of Branch nodes in the tree
190 size of left subtree is differs from size of right subtree by a
191 factor of at most \tr{sIZE_RATIO}
195 data FiniteMap key elt
197 | Branch key elt -- Key and elt stored here
198 {-# UNPACK #-} !Int -- Size >= 1
199 (FiniteMap key elt) -- Children
207 = Branch bottom bottom 0 bottom bottom
209 bottom = panic "emptyFM"
212 -- #define EmptyFM (Branch _ _ 0 _ _)
214 unitFM key elt = Branch key elt 1 emptyFM emptyFM
216 listToFM = addListToFM emptyFM
218 bagToFM = foldrBag (\(k,v) fm -> addToFM fm k v) emptyFM
221 %************************************************************************
223 \subsection{Adding to and deleting from @FiniteMaps@}
225 %************************************************************************
228 addToFM fm key elt = addToFM_C (\ old new -> new) fm key elt
230 addToFM_C combiner EmptyFM key elt = unitFM key elt
231 addToFM_C combiner (Branch key elt size fm_l fm_r) new_key new_elt
232 = case compare new_key key of
233 LT -> mkBalBranch key elt (addToFM_C combiner fm_l new_key new_elt) fm_r
234 GT -> mkBalBranch key elt fm_l (addToFM_C combiner fm_r new_key new_elt)
235 EQ -> Branch new_key (combiner elt new_elt) size fm_l fm_r
237 addListToFM fm key_elt_pairs = addListToFM_C (\ old new -> new) fm key_elt_pairs
239 addListToFM_C combiner fm key_elt_pairs
240 = foldl' add fm key_elt_pairs -- foldl adds from the left
242 add fmap (key,elt) = addToFM_C combiner fmap key elt
246 delFromFM EmptyFM del_key = emptyFM
247 delFromFM (Branch key elt size fm_l fm_r) del_key
248 = case compare del_key key of
249 GT -> mkBalBranch key elt fm_l (delFromFM fm_r del_key)
250 LT -> mkBalBranch key elt (delFromFM fm_l del_key) fm_r
251 EQ -> glueBal fm_l fm_r
253 delListFromFM fm keys = foldl' delFromFM fm keys
256 %************************************************************************
258 \subsection{Combining @FiniteMaps@}
260 %************************************************************************
263 plusFM_C combiner EmptyFM fm2 = fm2
264 plusFM_C combiner fm1 EmptyFM = fm1
265 plusFM_C combiner fm1 (Branch split_key elt2 _ left right)
266 = mkVBalBranch split_key new_elt
267 (plusFM_C combiner lts left)
268 (plusFM_C combiner gts right)
270 lts = splitLT fm1 split_key
271 gts = splitGT fm1 split_key
272 new_elt = case lookupFM fm1 split_key of
274 Just elt1 -> combiner elt1 elt2
276 -- It's worth doing plusFM specially, because we don't need
277 -- to do the lookup in fm1.
278 -- FM2 over-rides FM1.
280 plusFM EmptyFM fm2 = fm2
281 plusFM fm1 EmptyFM = fm1
282 plusFM fm1 (Branch split_key elt1 _ left right)
283 = mkVBalBranch split_key elt1 (plusFM lts left) (plusFM gts right)
285 lts = splitLT fm1 split_key
286 gts = splitGT fm1 split_key
288 minusFM EmptyFM fm2 = emptyFM
289 minusFM fm1 EmptyFM = fm1
290 minusFM fm1 (Branch split_key elt _ left right)
291 = glueVBal (minusFM lts left) (minusFM gts right)
292 -- The two can be way different, so we need glueVBal
294 lts = splitLT fm1 split_key -- NB gt and lt, so the equal ones
295 gts = splitGT fm1 split_key -- are not in either.
297 intersectFM fm1 fm2 = intersectFM_C (\ left right -> right) fm1 fm2
299 intersectFM_C combiner fm1 EmptyFM = emptyFM
300 intersectFM_C combiner EmptyFM fm2 = emptyFM
301 intersectFM_C combiner fm1 (Branch split_key elt2 _ left right)
303 | maybeToBool maybe_elt1 -- split_elt *is* in intersection
304 = mkVBalBranch split_key (combiner elt1 elt2)
305 (intersectFM_C combiner lts left)
306 (intersectFM_C combiner gts right)
308 | otherwise -- split_elt is *not* in intersection
309 = glueVBal (intersectFM_C combiner lts left)
310 (intersectFM_C combiner gts right)
313 lts = splitLT fm1 split_key -- NB gt and lt, so the equal ones
314 gts = splitGT fm1 split_key -- are not in either.
316 maybe_elt1 = lookupFM fm1 split_key
317 Just elt1 = maybe_elt1
320 %************************************************************************
322 \subsection{Mapping, folding, and filtering with @FiniteMaps@}
324 %************************************************************************
327 foldFM k z EmptyFM = z
328 foldFM k z (Branch key elt _ fm_l fm_r)
329 = foldFM k (k key elt (foldFM k z fm_r)) fm_l
331 mapFM f EmptyFM = emptyFM
332 mapFM f (Branch key elt size fm_l fm_r)
333 = Branch key (f key elt) size (mapFM f fm_l) (mapFM f fm_r)
335 filterFM p EmptyFM = emptyFM
336 filterFM p (Branch key elt _ fm_l fm_r)
337 | p key elt -- Keep the item
338 = mkVBalBranch key elt (filterFM p fm_l) (filterFM p fm_r)
340 | otherwise -- Drop the item
341 = glueVBal (filterFM p fm_l) (filterFM p fm_r)
344 %************************************************************************
346 \subsection{Interrogating @FiniteMaps@}
348 %************************************************************************
351 --{-# INLINE sizeFM #-}
353 sizeFM (Branch _ _ size _ _) = size
355 isEmptyFM fm = sizeFM fm == 0
357 lookupFM EmptyFM key = Nothing
358 lookupFM (Branch key elt _ fm_l fm_r) key_to_find
359 = case compare key_to_find key of
360 LT -> lookupFM fm_l key_to_find
361 GT -> lookupFM fm_r key_to_find
365 = case (lookupFM fm key) of { Nothing -> False; Just elt -> True }
367 lookupWithDefaultFM fm deflt key
368 = case (lookupFM fm key) of { Nothing -> deflt; Just elt -> elt }
371 %************************************************************************
373 \subsection{Listifying @FiniteMaps@}
375 %************************************************************************
378 fmToList fm = foldFM (\ key elt rest -> (key,elt) : rest) [] fm
379 keysFM fm = foldFM (\ key elt rest -> key : rest) [] fm
380 eltsFM fm = foldFM (\ key elt rest -> elt : rest) [] fm
384 %************************************************************************
386 \subsection{The implementation of balancing}
388 %************************************************************************
390 %************************************************************************
392 \subsubsection{Basic construction of a @FiniteMap@}
394 %************************************************************************
396 @mkBranch@ simply gets the size component right. This is the ONLY
397 (non-trivial) place the Branch object is built, so the ASSERTion
398 recursively checks consistency. (The trivial use of Branch is in
405 mkBranch :: (Ord key OUTPUTABLE_key) -- Used for the assertion checking only
408 -> FiniteMap key elt -> FiniteMap key elt
411 mkBranch which key elt fm_l fm_r
412 = --ASSERT( left_ok && right_ok && balance_ok )
413 #if defined(DEBUG_FINITEMAPS)
414 if not ( left_ok && right_ok && balance_ok ) then
415 pprPanic ("mkBranch:"++show which)
416 (vcat [ppr [left_ok, right_ok, balance_ok],
423 result = Branch key elt (1 + left_size + right_size) fm_l fm_r
425 -- if sizeFM result <= 8 then
428 -- pprTrace ("mkBranch:"++(show which)) (ppr result) (
432 left_ok = case fm_l of
434 Branch left_key _ _ _ _ -> let
435 biggest_left_key = fst (findMax fm_l)
437 biggest_left_key < key
438 right_ok = case fm_r of
440 Branch right_key _ _ _ _ -> let
441 smallest_right_key = fst (findMin fm_r)
443 key < smallest_right_key
444 balance_ok = True -- sigh
447 = -- Both subtrees have one or no elements...
448 (left_size + right_size <= 1)
449 -- NO || left_size == 0 -- ???
450 -- NO || right_size == 0 -- ???
451 -- ... or the number of elements in a subtree does not exceed
452 -- sIZE_RATIO times the number of elements in the other subtree
453 || (left_size * sIZE_RATIO >= right_size &&
454 right_size * sIZE_RATIO >= left_size)
457 left_size = sizeFM fm_l
458 right_size = sizeFM fm_r
461 %************************************************************************
463 \subsubsection{{\em Balanced} construction of a @FiniteMap@}
465 %************************************************************************
467 @mkBalBranch@ rebalances, assuming that the subtrees aren't too far
471 mkBalBranch :: (Ord key OUTPUTABLE_key)
473 -> FiniteMap key elt -> FiniteMap key elt
476 mkBalBranch key elt fm_L fm_R
478 | size_l + size_r < 2
479 = mkBranch 1{-which-} key elt fm_L fm_R
481 | size_r > sIZE_RATIO * size_l -- Right tree too big
483 Branch _ _ _ fm_rl fm_rr
484 | sizeFM fm_rl < 2 * sizeFM fm_rr -> single_L fm_L fm_R
485 | otherwise -> double_L fm_L fm_R
486 -- Other case impossible
488 | size_l > sIZE_RATIO * size_r -- Left tree too big
490 Branch _ _ _ fm_ll fm_lr
491 | sizeFM fm_lr < 2 * sizeFM fm_ll -> single_R fm_L fm_R
492 | otherwise -> double_R fm_L fm_R
493 -- Other case impossible
495 | otherwise -- No imbalance
496 = mkBranch 2{-which-} key elt fm_L fm_R
502 single_L fm_l (Branch key_r elt_r _ fm_rl fm_rr)
503 = mkBranch 3{-which-} key_r elt_r (mkBranch 4{-which-} key elt fm_l fm_rl) fm_rr
505 double_L fm_l (Branch key_r elt_r _ (Branch key_rl elt_rl _ fm_rll fm_rlr) fm_rr)
506 = mkBranch 5{-which-} key_rl elt_rl
507 (mkBranch 6{-which-} key elt fm_l fm_rll)
508 (mkBranch 7{-which-} key_r elt_r fm_rlr fm_rr)
510 single_R (Branch key_l elt_l _ fm_ll fm_lr) fm_r
511 = mkBranch 8{-which-} key_l elt_l fm_ll
512 (mkBranch 9{-which-} key elt fm_lr fm_r)
514 double_R (Branch key_l elt_l _ fm_ll (Branch key_lr elt_lr _ fm_lrl fm_lrr)) fm_r
515 = mkBranch 10{-which-} key_lr elt_lr
516 (mkBranch 11{-which-} key_l elt_l fm_ll fm_lrl)
517 (mkBranch 12{-which-} key elt fm_lrr fm_r)
522 mkVBalBranch :: (Ord key OUTPUTABLE_key)
524 -> FiniteMap key elt -> FiniteMap key elt
527 -- Assert: in any call to (mkVBalBranch_C comb key elt l r),
528 -- (a) all keys in l are < all keys in r
529 -- (b) all keys in l are < key
530 -- (c) all keys in r are > key
532 mkVBalBranch key elt EmptyFM fm_r = addToFM fm_r key elt
533 mkVBalBranch key elt fm_l EmptyFM = addToFM fm_l key elt
535 mkVBalBranch key elt fm_l@(Branch key_l elt_l _ fm_ll fm_lr)
536 fm_r@(Branch key_r elt_r _ fm_rl fm_rr)
537 | sIZE_RATIO * size_l < size_r
538 = mkBalBranch key_r elt_r (mkVBalBranch key elt fm_l fm_rl) fm_rr
540 | sIZE_RATIO * size_r < size_l
541 = mkBalBranch key_l elt_l fm_ll (mkVBalBranch key elt fm_lr fm_r)
544 = mkBranch 13{-which-} key elt fm_l fm_r
551 %************************************************************************
553 \subsubsection{Gluing two trees together}
555 %************************************************************************
557 @glueBal@ assumes its two arguments aren't too far out of whack, just
558 like @mkBalBranch@. But: all keys in first arg are $<$ all keys in
562 glueBal :: (Ord key OUTPUTABLE_key)
563 => FiniteMap key elt -> FiniteMap key elt
566 glueBal EmptyFM fm2 = fm2
567 glueBal fm1 EmptyFM = fm1
569 -- The case analysis here (absent in Adams' program) is really to deal
570 -- with the case where fm2 is a singleton. Then deleting the minimum means
571 -- we pass an empty tree to mkBalBranch, which breaks its invariant.
572 | sizeFM fm2 > sizeFM fm1
573 = mkBalBranch mid_key2 mid_elt2 fm1 (deleteMin fm2)
576 = mkBalBranch mid_key1 mid_elt1 (deleteMax fm1) fm2
578 (mid_key1, mid_elt1) = findMax fm1
579 (mid_key2, mid_elt2) = findMin fm2
582 @glueVBal@ copes with arguments which can be of any size.
583 But: all keys in first arg are $<$ all keys in second.
586 glueVBal :: (Ord key OUTPUTABLE_key)
587 => FiniteMap key elt -> FiniteMap key elt
590 glueVBal EmptyFM fm2 = fm2
591 glueVBal fm1 EmptyFM = fm1
592 glueVBal fm_l@(Branch key_l elt_l _ fm_ll fm_lr)
593 fm_r@(Branch key_r elt_r _ fm_rl fm_rr)
594 | sIZE_RATIO * size_l < size_r
595 = mkBalBranch key_r elt_r (glueVBal fm_l fm_rl) fm_rr
597 | sIZE_RATIO * size_r < size_l
598 = mkBalBranch key_l elt_l fm_ll (glueVBal fm_lr fm_r)
600 | otherwise -- We now need the same two cases as in glueBal above.
607 %************************************************************************
609 \subsection{Local utilities}
611 %************************************************************************
614 splitLT, splitGT :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> key -> FiniteMap key elt
616 -- splitLT fm split_key = fm restricted to keys < split_key
617 -- splitGT fm split_key = fm restricted to keys > split_key
619 splitLT EmptyFM split_key = emptyFM
620 splitLT (Branch key elt _ fm_l fm_r) split_key
621 = case compare split_key key of
622 LT -> splitLT fm_l split_key
623 GT -> mkVBalBranch key elt fm_l (splitLT fm_r split_key)
626 splitGT EmptyFM split_key = emptyFM
627 splitGT (Branch key elt _ fm_l fm_r) split_key
628 = case compare split_key key of
629 GT -> splitGT fm_r split_key
630 LT -> mkVBalBranch key elt (splitGT fm_l split_key) fm_r
633 findMin :: FiniteMap key elt -> (key,elt)
634 findMin (Branch key elt _ EmptyFM _) = (key,elt)
635 findMin (Branch key elt _ fm_l _) = findMin fm_l
637 deleteMin :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> FiniteMap key elt
638 deleteMin (Branch key elt _ EmptyFM fm_r) = fm_r
639 deleteMin (Branch key elt _ fm_l fm_r) = mkBalBranch key elt (deleteMin fm_l) fm_r
641 findMax :: FiniteMap key elt -> (key,elt)
642 findMax (Branch key elt _ _ EmptyFM) = (key,elt)
643 findMax (Branch key elt _ _ fm_r) = findMax fm_r
645 deleteMax :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> FiniteMap key elt
646 deleteMax (Branch key elt _ fm_l EmptyFM) = fm_l
647 deleteMax (Branch key elt _ fm_l fm_r) = mkBalBranch key elt fm_l (deleteMax fm_r)
650 %************************************************************************
652 \subsection{Output-ery}
654 %************************************************************************
657 #if defined(DEBUG_FINITEMAPS)
659 instance (Outputable key) => Outputable (FiniteMap key elt) where
662 pprX EmptyFM = char '!'
663 pprX (Branch key elt sz fm_l fm_r)
664 = parens (hcat [pprX fm_l, space,
665 ppr key, space, int sz, space,
668 -- and when not debugging the package itself...
669 instance (Outputable key, Outputable elt) => Outputable (FiniteMap key elt) where
670 ppr fm = ppr (fmToList fm)
674 instance (Eq key, Eq elt) => Eq (FiniteMap key elt) where
675 fm_1 == fm_2 = (sizeFM fm_1 == sizeFM fm_2) && -- quick test
676 (fmToList fm_1 == fmToList fm_2)
678 {- NO: not clear what The Right Thing to do is:
679 instance (Ord key, Ord elt) => Ord (FiniteMap key elt) where
680 fm_1 <= fm_2 = (sizeFM fm_1 <= sizeFM fm_2) && -- quick test
681 (fmToList fm_1 <= fmToList fm_2)
686 %************************************************************************
688 \subsection{Efficiency pragmas for GHC}
690 %************************************************************************
692 When the FiniteMap module is used in GHC, we specialise it for
693 \tr{Uniques}, for dastardly efficiency reasons.
698 #ifdef __GLASGOW_HASKELL__
700 {-# SPECIALIZE addListToFM
701 :: FiniteMap (FastString, FAST_STRING) elt -> [((FAST_STRING, FAST_STRING),elt)] -> FiniteMap (FAST_STRING, FAST_STRING) elt
702 , FiniteMap RdrName elt -> [(RdrName,elt)] -> FiniteMap RdrName elt
703 IF_NCG(COMMA FiniteMap Reg elt -> [(Reg COMMA elt)] -> FiniteMap Reg elt)
705 {-# SPECIALIZE addListToFM_C
706 :: (elt -> elt -> elt) -> FiniteMap TyCon elt -> [(TyCon,elt)] -> FiniteMap TyCon elt
707 , (elt -> elt -> elt) -> FiniteMap FastString elt -> [(FAST_STRING,elt)] -> FiniteMap FAST_STRING elt
708 IF_NCG(COMMA (elt -> elt -> elt) -> FiniteMap Reg elt -> [(Reg COMMA elt)] -> FiniteMap Reg elt)
710 {-# SPECIALIZE addToFM
711 :: FiniteMap CLabel elt -> CLabel -> elt -> FiniteMap CLabel elt
712 , FiniteMap FastString elt -> FAST_STRING -> elt -> FiniteMap FAST_STRING elt
713 , FiniteMap (FastString, FAST_STRING) elt -> (FAST_STRING, FAST_STRING) -> elt -> FiniteMap (FAST_STRING, FAST_STRING) elt
714 , FiniteMap RdrName elt -> RdrName -> elt -> FiniteMap RdrName elt
715 IF_NCG(COMMA FiniteMap Reg elt -> Reg -> elt -> FiniteMap Reg elt)
717 {-# SPECIALIZE addToFM_C
718 :: (elt -> elt -> elt) -> FiniteMap (RdrName, RdrName) elt -> (RdrName, RdrName) -> elt -> FiniteMap (RdrName, RdrName) elt
719 , (elt -> elt -> elt) -> FiniteMap FastString elt -> FAST_STRING -> elt -> FiniteMap FAST_STRING elt
720 IF_NCG(COMMA (elt -> elt -> elt) -> FiniteMap Reg elt -> Reg -> elt -> FiniteMap Reg elt)
722 {-# SPECIALIZE bagToFM
723 :: Bag (FastString,elt) -> FiniteMap FAST_STRING elt
725 {-# SPECIALIZE delListFromFM
726 :: FiniteMap RdrName elt -> [RdrName] -> FiniteMap RdrName elt
727 , FiniteMap FastString elt -> [FAST_STRING] -> FiniteMap FAST_STRING elt
728 IF_NCG(COMMA FiniteMap Reg elt -> [Reg] -> FiniteMap Reg elt)
730 {-# SPECIALIZE listToFM
731 :: [([Char],elt)] -> FiniteMap [Char] elt
732 , [(FastString,elt)] -> FiniteMap FAST_STRING elt
733 , [((FastString,FAST_STRING),elt)] -> FiniteMap (FAST_STRING, FAST_STRING) elt
734 IF_NCG(COMMA [(Reg COMMA elt)] -> FiniteMap Reg elt)
736 {-# SPECIALIZE lookupFM
737 :: FiniteMap CLabel elt -> CLabel -> Maybe elt
738 , FiniteMap [Char] elt -> [Char] -> Maybe elt
739 , FiniteMap FastString elt -> FAST_STRING -> Maybe elt
740 , FiniteMap (FastString,FAST_STRING) elt -> (FAST_STRING,FAST_STRING) -> Maybe elt
741 , FiniteMap RdrName elt -> RdrName -> Maybe elt
742 , FiniteMap (RdrName,RdrName) elt -> (RdrName,RdrName) -> Maybe elt
743 IF_NCG(COMMA FiniteMap Reg elt -> Reg -> Maybe elt)
745 {-# SPECIALIZE lookupWithDefaultFM
746 :: FiniteMap FastString elt -> elt -> FAST_STRING -> elt
747 IF_NCG(COMMA FiniteMap Reg elt -> elt -> Reg -> elt)
749 {-# SPECIALIZE plusFM
750 :: FiniteMap RdrName elt -> FiniteMap RdrName elt -> FiniteMap RdrName elt
751 , FiniteMap FastString elt -> FiniteMap FAST_STRING elt -> FiniteMap FAST_STRING elt
752 IF_NCG(COMMA FiniteMap Reg elt -> FiniteMap Reg elt -> FiniteMap Reg elt)
754 {-# SPECIALIZE plusFM_C
755 :: (elt -> elt -> elt) -> FiniteMap FastString elt -> FiniteMap FAST_STRING elt -> FiniteMap FAST_STRING elt
756 IF_NCG(COMMA (elt -> elt -> elt) -> FiniteMap Reg elt -> FiniteMap Reg elt -> FiniteMap Reg elt)
759 #endif /* compiling with ghc and have specialiser */