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 FiniteMap, -- abstract type
24 emptyFM, unitFM, listToFM,
42 sizeFM, isEmptyFM, elemFM, lookupFM, lookupWithDefaultFM,
44 fmToList, keysFM, eltsFM,
49 #if defined(DEBUG_FINITEMAPS)/* NB NB NB */
50 #define OUTPUTABLE_key , Outputable key
52 #define OUTPUTABLE_key {--}
56 import Bag ( Bag, foldrBag )
61 -- was this import only needed for I#, or does it have something
62 -- to do with the (not-presently-used) IF_NCG also?
68 #if ! OMIT_NATIVE_CODEGEN
71 # define IF_NCG(a) {--}
77 %************************************************************************
79 \subsection{The signature of the module}
81 %************************************************************************
85 emptyFM :: FiniteMap key elt
86 unitFM :: key -> elt -> FiniteMap key elt
87 -- In the case of duplicates, the last is taken:
88 listToFM :: (Ord key OUTPUTABLE_key) => [(key,elt)] -> FiniteMap key elt
89 -- In the case of duplicates, who knows which is taken:
90 bagToFM :: (Ord key OUTPUTABLE_key) => Bag (key,elt) -> FiniteMap key elt
92 -- ADDING AND DELETING
93 -- Throws away any previous binding
94 -- In the list case, the items are added starting with the
95 -- first one in the list
96 addToFM :: (Ord key OUTPUTABLE_key)
97 => FiniteMap key elt -> key -> elt -> FiniteMap key elt
98 addListToFM :: (Ord key OUTPUTABLE_key)
99 => FiniteMap key elt -> [(key,elt)] -> FiniteMap key elt
101 -- Combines with previous binding
102 -- The combining fn goes (old -> new -> new)
103 addToFM_C :: (Ord key OUTPUTABLE_key) => (elt -> elt -> elt)
104 -> FiniteMap key elt -> key -> elt
106 addListToFM_C :: (Ord key OUTPUTABLE_key) => (elt -> elt -> elt)
107 -> FiniteMap key elt -> [(key,elt)]
110 -- Deletion doesn't complain if you try to delete something which isn't there
111 delFromFM :: (Ord key OUTPUTABLE_key)
112 => FiniteMap key elt -> key -> FiniteMap key elt
113 delListFromFM :: (Ord key OUTPUTABLE_key)
114 => FiniteMap key elt -> [key] -> FiniteMap key elt
117 -- Bindings in right argument shadow those in the left
118 plusFM :: (Ord key OUTPUTABLE_key)
119 => FiniteMap key elt -> FiniteMap key elt -> FiniteMap key elt
121 -- Combines bindings for the same thing with the given function
122 plusFM_C :: (Ord key OUTPUTABLE_key)
123 => (elt -> elt -> elt)
124 -> FiniteMap key elt -> FiniteMap key elt -> FiniteMap key elt
126 -- (minusFM a1 a2) deletes from a1 any bindings which are bound in a2
127 minusFM :: (Ord key OUTPUTABLE_key)
128 => FiniteMap key elt -> FiniteMap key elt -> FiniteMap key elt
130 intersectFM :: (Ord key OUTPUTABLE_key)
131 => FiniteMap key elt -> FiniteMap key elt -> FiniteMap key elt
132 intersectFM_C :: (Ord key OUTPUTABLE_key)
133 => (elt1 -> elt2 -> elt3)
134 -> FiniteMap key elt1 -> FiniteMap key elt2
135 -> FiniteMap key elt3
137 -- MAPPING, FOLDING, FILTERING
138 foldFM :: (key -> elt -> a -> a) -> a -> FiniteMap key elt -> a
139 mapFM :: (key -> elt1 -> elt2)
140 -> FiniteMap key elt1 -> FiniteMap key elt2
141 filterFM :: (Ord key OUTPUTABLE_key)
142 => (key -> elt -> Bool)
143 -> FiniteMap key elt -> FiniteMap key elt
146 sizeFM :: FiniteMap key elt -> Int
147 isEmptyFM :: FiniteMap key elt -> Bool
149 elemFM :: (Ord key OUTPUTABLE_key)
150 => key -> FiniteMap key elt -> Bool
151 lookupFM :: (Ord key OUTPUTABLE_key)
152 => FiniteMap key elt -> key -> Maybe elt
153 -- lookupWithDefaultFM supplies a "default" elt
154 -- to return for an unmapped key
155 lookupWithDefaultFM :: (Ord key OUTPUTABLE_key)
156 => FiniteMap key elt -> elt -> key -> elt
159 fmToList :: FiniteMap key elt -> [(key,elt)]
160 keysFM :: FiniteMap key elt -> [key]
161 eltsFM :: FiniteMap key elt -> [elt]
164 %************************************************************************
166 \subsection{The @FiniteMap@ data type, and building of same}
168 %************************************************************************
170 Invariants about @FiniteMap@:
173 all keys in a FiniteMap are distinct
175 all keys in left subtree are $<$ key in Branch and
176 all keys in right subtree are $>$ key in Branch
178 size field of a Branch gives number of Branch nodes in the tree
180 size of left subtree is differs from size of right subtree by a
181 factor of at most \tr{sIZE_RATIO}
185 data FiniteMap key elt
187 | Branch key elt -- Key and elt stored here
188 {-# UNPACK #-} !Int -- Size >= 1
189 (FiniteMap key elt) -- Children
197 = Branch bottom bottom 0 bottom bottom
199 bottom = panic "emptyFM"
202 -- #define EmptyFM (Branch _ _ 0 _ _)
204 unitFM key elt = Branch key elt 1 emptyFM emptyFM
206 listToFM = addListToFM emptyFM
208 bagToFM = foldrBag (\(k,v) fm -> addToFM fm k v) emptyFM
211 %************************************************************************
213 \subsection{Adding to and deleting from @FiniteMaps@}
215 %************************************************************************
218 addToFM fm key elt = addToFM_C (\ _old new -> new) fm key elt
220 addToFM_C _ EmptyFM key elt = unitFM key elt
221 addToFM_C combiner (Branch key elt size fm_l fm_r) new_key new_elt
222 = case compare new_key key of
223 LT -> mkBalBranch key elt (addToFM_C combiner fm_l new_key new_elt) fm_r
224 GT -> mkBalBranch key elt fm_l (addToFM_C combiner fm_r new_key new_elt)
225 EQ -> Branch new_key (combiner elt new_elt) size fm_l fm_r
227 addListToFM fm key_elt_pairs
228 = addListToFM_C (\ _old new -> new) fm key_elt_pairs
230 addListToFM_C combiner fm key_elt_pairs
231 = foldl' add fm key_elt_pairs -- foldl adds from the left
233 add fmap (key,elt) = addToFM_C combiner fmap key elt
237 delFromFM EmptyFM _ = emptyFM
238 delFromFM (Branch key elt _ fm_l fm_r) del_key
239 = case compare del_key key of
240 GT -> mkBalBranch key elt fm_l (delFromFM fm_r del_key)
241 LT -> mkBalBranch key elt (delFromFM fm_l del_key) fm_r
242 EQ -> glueBal fm_l fm_r
244 delListFromFM fm keys = foldl' delFromFM fm keys
247 %************************************************************************
249 \subsection{Combining @FiniteMaps@}
251 %************************************************************************
254 plusFM_C _ EmptyFM fm2 = fm2
255 plusFM_C _ fm1 EmptyFM = fm1
256 plusFM_C combiner fm1 (Branch split_key elt2 _ left right)
257 = mkVBalBranch split_key new_elt
258 (plusFM_C combiner lts left)
259 (plusFM_C combiner gts right)
261 lts = splitLT fm1 split_key
262 gts = splitGT fm1 split_key
263 new_elt = case lookupFM fm1 split_key of
265 Just elt1 -> combiner elt1 elt2
267 -- It's worth doing plusFM specially, because we don't need
268 -- to do the lookup in fm1.
269 -- FM2 over-rides FM1.
271 plusFM EmptyFM fm2 = fm2
272 plusFM fm1 EmptyFM = fm1
273 plusFM fm1 (Branch split_key elt1 _ left right)
274 = mkVBalBranch split_key elt1 (plusFM lts left) (plusFM gts right)
276 lts = splitLT fm1 split_key
277 gts = splitGT fm1 split_key
279 minusFM EmptyFM _ = emptyFM
280 minusFM fm1 EmptyFM = fm1
281 minusFM fm1 (Branch split_key _ _ left right)
282 = glueVBal (minusFM lts left) (minusFM gts right)
283 -- The two can be way different, so we need glueVBal
285 lts = splitLT fm1 split_key -- NB gt and lt, so the equal ones
286 gts = splitGT fm1 split_key -- are not in either.
288 intersectFM fm1 fm2 = intersectFM_C (\ _ right -> right) fm1 fm2
290 intersectFM_C _ _ EmptyFM = emptyFM
291 intersectFM_C _ EmptyFM _ = emptyFM
292 intersectFM_C combiner fm1 (Branch split_key elt2 _ left right)
294 | maybeToBool maybe_elt1 -- split_elt *is* in intersection
295 = mkVBalBranch split_key (combiner elt1 elt2)
296 (intersectFM_C combiner lts left)
297 (intersectFM_C combiner gts right)
299 | otherwise -- split_elt is *not* in intersection
300 = glueVBal (intersectFM_C combiner lts left)
301 (intersectFM_C combiner gts right)
304 lts = splitLT fm1 split_key -- NB gt and lt, so the equal ones
305 gts = splitGT fm1 split_key -- are not in either.
307 maybe_elt1 = lookupFM fm1 split_key
308 Just elt1 = maybe_elt1
311 %************************************************************************
313 \subsection{Mapping, folding, and filtering with @FiniteMaps@}
315 %************************************************************************
318 foldFM _ z EmptyFM = z
319 foldFM k z (Branch key elt _ fm_l fm_r)
320 = foldFM k (k key elt (foldFM k z fm_r)) fm_l
322 mapFM _ EmptyFM = emptyFM
323 mapFM f (Branch key elt size fm_l fm_r)
324 = Branch key (f key elt) size (mapFM f fm_l) (mapFM f fm_r)
326 filterFM _ EmptyFM = emptyFM
327 filterFM p (Branch key elt _ fm_l fm_r)
328 | p key elt -- Keep the item
329 = mkVBalBranch key elt (filterFM p fm_l) (filterFM p fm_r)
331 | otherwise -- Drop the item
332 = glueVBal (filterFM p fm_l) (filterFM p fm_r)
335 %************************************************************************
337 \subsection{Interrogating @FiniteMaps@}
339 %************************************************************************
342 --{-# INLINE sizeFM #-}
344 sizeFM (Branch _ _ size _ _) = size
346 isEmptyFM fm = sizeFM fm == 0
348 lookupFM EmptyFM _ = Nothing
349 lookupFM (Branch key elt _ fm_l fm_r) key_to_find
350 = case compare key_to_find key of
351 LT -> lookupFM fm_l key_to_find
352 GT -> lookupFM fm_r key_to_find
355 key `elemFM` fm = isJust (lookupFM fm key)
357 lookupWithDefaultFM fm deflt key
358 = case (lookupFM fm key) of { Nothing -> deflt; Just elt -> elt }
361 %************************************************************************
363 \subsection{Listifying @FiniteMaps@}
365 %************************************************************************
368 fmToList fm = foldFM (\ key elt rest -> (key, elt) : rest) [] fm
369 keysFM fm = foldFM (\ key _elt rest -> key : rest) [] fm
370 eltsFM fm = foldFM (\ _key elt rest -> elt : rest) [] fm
374 %************************************************************************
376 \subsection{The implementation of balancing}
378 %************************************************************************
380 %************************************************************************
382 \subsubsection{Basic construction of a @FiniteMap@}
384 %************************************************************************
386 @mkBranch@ simply gets the size component right. This is the ONLY
387 (non-trivial) place the Branch object is built, so the ASSERTion
388 recursively checks consistency. (The trivial use of Branch is in
395 mkBranch :: (Ord key OUTPUTABLE_key) -- Used for the assertion checking only
398 -> FiniteMap key elt -> FiniteMap key elt
401 mkBranch _which key elt fm_l fm_r
402 = --ASSERT( left_ok && right_ok && balance_ok )
403 #if defined(DEBUG_FINITEMAPS)
404 if not ( left_ok && right_ok && balance_ok ) then
405 pprPanic ("mkBranch:"++show _which)
406 (vcat [ppr [left_ok, right_ok, balance_ok],
413 result = Branch key elt (1 + left_size + right_size) fm_l fm_r
415 -- if sizeFM result <= 8 then
418 -- pprTrace ("mkBranch:"++(show which)) (ppr result) (
422 #if defined(DEBUG_FINITEMAPS)
423 left_ok = case fm_l of
425 Branch _ _ _ _ _ -> let
426 biggest_left_key = fst (findMax fm_l)
428 biggest_left_key < key
429 right_ok = case fm_r of
431 Branch _ _ _ _ _ -> let
432 smallest_right_key = fst (findMin fm_r)
434 key < smallest_right_key
435 balance_ok = True -- sigh
439 = -- Both subtrees have one or no elements...
440 (left_size + right_size <= 1)
441 -- NO || left_size == 0 -- ???
442 -- NO || right_size == 0 -- ???
443 -- ... or the number of elements in a subtree does not exceed
444 -- sIZE_RATIO times the number of elements in the other subtree
445 || (left_size * sIZE_RATIO >= right_size &&
446 right_size * sIZE_RATIO >= left_size)
449 left_size = sizeFM fm_l
450 right_size = sizeFM fm_r
453 %************************************************************************
455 \subsubsection{{\em Balanced} construction of a @FiniteMap@}
457 %************************************************************************
459 @mkBalBranch@ rebalances, assuming that the subtrees aren't too far
463 mkBalBranch :: (Ord key OUTPUTABLE_key)
465 -> FiniteMap key elt -> FiniteMap key elt
468 mkBalBranch key elt fm_L fm_R
470 | size_l + size_r < 2
471 = mkBranch 1{-which-} key elt fm_L fm_R
473 | size_r > sIZE_RATIO * size_l -- Right tree too big
475 Branch _ _ _ fm_rl fm_rr
476 | sizeFM fm_rl < 2 * sizeFM fm_rr -> single_L fm_L fm_R
477 | otherwise -> double_L fm_L fm_R
478 _ -> panic "mkBalBranch: impossible case 1"
480 | size_l > sIZE_RATIO * size_r -- Left tree too big
482 Branch _ _ _ fm_ll fm_lr
483 | sizeFM fm_lr < 2 * sizeFM fm_ll -> single_R fm_L fm_R
484 | otherwise -> double_R fm_L fm_R
485 _ -> panic "mkBalBranch: impossible case 2"
486 | otherwise -- No imbalance
487 = mkBranch 2{-which-} key elt fm_L fm_R
493 single_L fm_l (Branch key_r elt_r _ fm_rl fm_rr)
494 = mkBranch 3{-which-} key_r elt_r (mkBranch 4{-which-} key elt fm_l fm_rl) fm_rr
495 single_L _ _ = panic "mkBalBranch: impossible case 3"
497 double_L fm_l (Branch key_r elt_r _ (Branch key_rl elt_rl _ fm_rll fm_rlr) fm_rr)
498 = mkBranch 5{-which-} key_rl elt_rl
499 (mkBranch 6{-which-} key elt fm_l fm_rll)
500 (mkBranch 7{-which-} key_r elt_r fm_rlr fm_rr)
501 double_L _ _ = panic "mkBalBranch: impossible case 4"
503 single_R (Branch key_l elt_l _ fm_ll fm_lr) fm_r
504 = mkBranch 8{-which-} key_l elt_l fm_ll
505 (mkBranch 9{-which-} key elt fm_lr fm_r)
506 single_R _ _ = panic "mkBalBranch: impossible case 5"
508 double_R (Branch key_l elt_l _ fm_ll (Branch key_lr elt_lr _ fm_lrl fm_lrr)) fm_r
509 = mkBranch 10{-which-} key_lr elt_lr
510 (mkBranch 11{-which-} key_l elt_l fm_ll fm_lrl)
511 (mkBranch 12{-which-} key elt fm_lrr fm_r)
512 double_R _ _ = panic "mkBalBranch: impossible case 6"
517 mkVBalBranch :: (Ord key OUTPUTABLE_key)
519 -> FiniteMap key elt -> FiniteMap key elt
522 -- Assert: in any call to (mkVBalBranch_C comb key elt l r),
523 -- (a) all keys in l are < all keys in r
524 -- (b) all keys in l are < key
525 -- (c) all keys in r are > key
527 mkVBalBranch key elt EmptyFM fm_r = addToFM fm_r key elt
528 mkVBalBranch key elt fm_l EmptyFM = addToFM fm_l key elt
530 mkVBalBranch key elt fm_l@(Branch key_l elt_l _ fm_ll fm_lr)
531 fm_r@(Branch key_r elt_r _ fm_rl fm_rr)
532 | sIZE_RATIO * size_l < size_r
533 = mkBalBranch key_r elt_r (mkVBalBranch key elt fm_l fm_rl) fm_rr
535 | sIZE_RATIO * size_r < size_l
536 = mkBalBranch key_l elt_l fm_ll (mkVBalBranch key elt fm_lr fm_r)
539 = mkBranch 13{-which-} key elt fm_l fm_r
546 %************************************************************************
548 \subsubsection{Gluing two trees together}
550 %************************************************************************
552 @glueBal@ assumes its two arguments aren't too far out of whack, just
553 like @mkBalBranch@. But: all keys in first arg are $<$ all keys in
557 glueBal :: (Ord key OUTPUTABLE_key)
558 => FiniteMap key elt -> FiniteMap key elt
561 glueBal EmptyFM fm2 = fm2
562 glueBal fm1 EmptyFM = fm1
564 -- The case analysis here (absent in Adams' program) is really to deal
565 -- with the case where fm2 is a singleton. Then deleting the minimum means
566 -- we pass an empty tree to mkBalBranch, which breaks its invariant.
567 | sizeFM fm2 > sizeFM fm1
568 = mkBalBranch mid_key2 mid_elt2 fm1 (deleteMin fm2)
571 = mkBalBranch mid_key1 mid_elt1 (deleteMax fm1) fm2
573 (mid_key1, mid_elt1) = findMax fm1
574 (mid_key2, mid_elt2) = findMin fm2
577 @glueVBal@ copes with arguments which can be of any size.
578 But: all keys in first arg are $<$ all keys in second.
581 glueVBal :: (Ord key OUTPUTABLE_key)
582 => FiniteMap key elt -> FiniteMap key elt
585 glueVBal EmptyFM fm2 = fm2
586 glueVBal fm1 EmptyFM = fm1
587 glueVBal fm_l@(Branch key_l elt_l _ fm_ll fm_lr)
588 fm_r@(Branch key_r elt_r _ fm_rl fm_rr)
589 | sIZE_RATIO * size_l < size_r
590 = mkBalBranch key_r elt_r (glueVBal fm_l fm_rl) fm_rr
592 | sIZE_RATIO * size_r < size_l
593 = mkBalBranch key_l elt_l fm_ll (glueVBal fm_lr fm_r)
595 | otherwise -- We now need the same two cases as in glueBal above.
602 %************************************************************************
604 \subsection{Local utilities}
606 %************************************************************************
609 splitLT, splitGT :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> key -> FiniteMap key elt
611 -- splitLT fm split_key = fm restricted to keys < split_key
612 -- splitGT fm split_key = fm restricted to keys > split_key
614 splitLT EmptyFM _ = emptyFM
615 splitLT (Branch key elt _ fm_l fm_r) split_key
616 = case compare split_key key of
617 LT -> splitLT fm_l split_key
618 GT -> mkVBalBranch key elt fm_l (splitLT fm_r split_key)
621 splitGT EmptyFM _ = emptyFM
622 splitGT (Branch key elt _ fm_l fm_r) split_key
623 = case compare split_key key of
624 GT -> splitGT fm_r split_key
625 LT -> mkVBalBranch key elt (splitGT fm_l split_key) fm_r
628 findMin :: FiniteMap key elt -> (key,elt)
629 findMin (Branch key elt _ EmptyFM _) = (key, elt)
630 findMin (Branch _ _ _ fm_l _) = findMin fm_l
631 findMin EmptyFM = panic "findMin: Empty"
633 deleteMin :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> FiniteMap key elt
634 deleteMin (Branch _ _ _ EmptyFM fm_r) = fm_r
635 deleteMin (Branch key elt _ fm_l fm_r)
636 = mkBalBranch key elt (deleteMin fm_l) fm_r
637 deleteMin EmptyFM = panic "deleteMin: Empty"
639 findMax :: FiniteMap key elt -> (key, elt)
640 findMax (Branch key elt _ _ EmptyFM) = (key, elt)
641 findMax (Branch _ _ _ _ fm_r) = findMax fm_r
642 findMax EmptyFM = panic "findMax: Empty"
644 deleteMax :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> FiniteMap key elt
645 deleteMax (Branch _ _ _ fm_l EmptyFM) = fm_l
646 deleteMax (Branch key elt _ fm_l fm_r) = mkBalBranch key elt fm_l (deleteMax fm_r)
647 deleteMax EmptyFM = panic "deleteMax: Empty"
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 */