2 % (c) The AQUA Project, Glasgow University, 1994-1996
4 \section[FiniteMap]{An implementation of finite maps}
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)
23 FiniteMap, -- abstract type
25 emptyFM, unitFM, listToFM,
43 sizeFM, isEmptyFM, elemFM, lookupFM, lookupWithDefaultFM,
45 fmToList, keysFM, eltsFM
48 , FiniteSet, emptySet, mkSet, isEmptySet
49 , elementOf, setToList, union, minusSet
53 #include "HsVersions.h"
54 #define IF_NOT_GHC(a) {--}
56 #if defined(DEBUG_FINITEMAPS)/* NB NB NB */
57 #define OUTPUTABLE_key , Outputable key
59 #define OUTPUTABLE_key {--}
62 import {-# SOURCE #-} Name
66 import Bag ( Bag, foldrBag )
69 #if ! OMIT_NATIVE_CODEGEN
72 # define IF_NCG(a) {--}
76 -- SIGH: but we use unboxed "sizes"...
77 #if __GLASGOW_HASKELL__
85 %************************************************************************
87 \subsection{The signature of the module}
89 %************************************************************************
93 emptyFM :: FiniteMap key elt
94 unitFM :: key -> elt -> FiniteMap key elt
95 listToFM :: (Ord key OUTPUTABLE_key) => [(key,elt)] -> FiniteMap key elt
96 -- In the case of duplicates, the last is taken
97 bagToFM :: (Ord key OUTPUTABLE_key) => Bag (key,elt) -> FiniteMap key elt
98 -- In the case of duplicates, who knows which is taken
100 -- ADDING AND DELETING
101 -- Throws away any previous binding
102 -- In the list case, the items are added starting with the
103 -- first one in the list
104 addToFM :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> key -> elt -> FiniteMap key elt
105 addListToFM :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> [(key,elt)] -> FiniteMap key elt
107 -- Combines with previous binding
108 addToFM_C :: (Ord key OUTPUTABLE_key) => (elt -> elt -> elt)
109 -> FiniteMap key elt -> key -> elt
111 addListToFM_C :: (Ord key OUTPUTABLE_key) => (elt -> elt -> elt)
112 -> FiniteMap key elt -> [(key,elt)]
115 -- Deletion doesn't complain if you try to delete something
117 delFromFM :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> key -> FiniteMap key elt
118 delListFromFM :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> [key] -> FiniteMap key elt
121 -- Bindings in right argument shadow those in the left
122 plusFM :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> FiniteMap key elt
125 -- Combines bindings for the same thing with the given function
126 plusFM_C :: (Ord key OUTPUTABLE_key) => (elt -> elt -> elt)
127 -> FiniteMap key elt -> FiniteMap key elt -> FiniteMap key elt
129 minusFM :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> FiniteMap key elt -> FiniteMap key elt
130 -- (minusFM a1 a2) deletes from a1 any bindings which are bound in a2
132 intersectFM :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> FiniteMap key elt -> FiniteMap key elt
133 intersectFM_C :: (Ord key OUTPUTABLE_key) => (elt -> elt -> elt2)
134 -> FiniteMap key elt -> FiniteMap key elt -> FiniteMap key elt2
136 -- MAPPING, FOLDING, FILTERING
137 foldFM :: (key -> elt -> a -> a) -> a -> FiniteMap key elt -> a
138 mapFM :: (key -> elt1 -> elt2) -> FiniteMap key elt1 -> FiniteMap key elt2
139 filterFM :: (Ord key OUTPUTABLE_key) => (key -> elt -> Bool)
140 -> FiniteMap key elt -> FiniteMap key elt
143 sizeFM :: FiniteMap key elt -> Int
144 isEmptyFM :: FiniteMap key elt -> Bool
146 elemFM :: (Ord key OUTPUTABLE_key) => key -> FiniteMap key elt -> Bool
147 lookupFM :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> key -> Maybe elt
149 :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> elt -> key -> elt
150 -- lookupWithDefaultFM supplies a "default" elt
151 -- to return for an unmapped key
154 fmToList :: FiniteMap key elt -> [(key,elt)]
155 keysFM :: FiniteMap key elt -> [key]
156 eltsFM :: FiniteMap key elt -> [elt]
159 %************************************************************************
161 \subsection{The @FiniteMap@ data type, and building of same}
163 %************************************************************************
165 Invariants about @FiniteMap@:
168 all keys in a FiniteMap are distinct
170 all keys in left subtree are $<$ key in Branch and
171 all keys in right subtree are $>$ key in Branch
173 size field of a Branch gives number of Branch nodes in the tree
175 size of left subtree is differs from size of right subtree by a
176 factor of at most \tr{sIZE_RATIO}
180 data FiniteMap key elt
182 | Branch key elt -- Key and elt stored here
183 IF_GHC(Int#,Int{-STRICT-}) -- Size >= 1
184 (FiniteMap key elt) -- Children
192 = Branch bottom bottom IF_GHC(0#,0) bottom bottom
194 bottom = panic "emptyFM"
197 -- #define EmptyFM (Branch _ _ IF_GHC(0#,0) _ _)
199 unitFM key elt = Branch key elt IF_GHC(1#,1) emptyFM emptyFM
201 listToFM = addListToFM emptyFM
203 bagToFM = foldrBag (\(k,v) fm -> addToFM fm k v) emptyFM
206 %************************************************************************
208 \subsection{Adding to and deleting from @FiniteMaps@}
210 %************************************************************************
213 addToFM fm key elt = addToFM_C (\ old new -> new) fm key elt
215 addToFM_C combiner EmptyFM key elt = unitFM key elt
216 addToFM_C combiner (Branch key elt size fm_l fm_r) new_key new_elt
217 = case compare new_key key of
218 LT -> mkBalBranch key elt (addToFM_C combiner fm_l new_key new_elt) fm_r
219 GT -> mkBalBranch key elt fm_l (addToFM_C combiner fm_r new_key new_elt)
220 EQ -> Branch new_key (combiner elt new_elt) size fm_l fm_r
222 addListToFM fm key_elt_pairs = addListToFM_C (\ old new -> new) fm key_elt_pairs
224 addListToFM_C combiner fm key_elt_pairs
225 = foldl add fm key_elt_pairs -- foldl adds from the left
227 add fmap (key,elt) = addToFM_C combiner fmap key elt
231 delFromFM EmptyFM del_key = emptyFM
232 delFromFM (Branch key elt size fm_l fm_r) del_key
233 = case compare del_key key of
234 GT -> mkBalBranch key elt fm_l (delFromFM fm_r del_key)
235 LT -> mkBalBranch key elt (delFromFM fm_l del_key) fm_r
236 EQ -> glueBal fm_l fm_r
238 delListFromFM fm keys = foldl delFromFM fm keys
241 %************************************************************************
243 \subsection{Combining @FiniteMaps@}
245 %************************************************************************
248 plusFM_C combiner EmptyFM fm2 = fm2
249 plusFM_C combiner fm1 EmptyFM = fm1
250 plusFM_C combiner fm1 (Branch split_key elt2 _ left right)
251 = mkVBalBranch split_key new_elt
252 (plusFM_C combiner lts left)
253 (plusFM_C combiner gts right)
255 lts = splitLT fm1 split_key
256 gts = splitGT fm1 split_key
257 new_elt = case lookupFM fm1 split_key of
259 Just elt1 -> combiner elt1 elt2
261 -- It's worth doing plusFM specially, because we don't need
262 -- to do the lookup in fm1.
263 -- FM2 over-rides FM1.
265 plusFM EmptyFM fm2 = fm2
266 plusFM fm1 EmptyFM = fm1
267 plusFM fm1 (Branch split_key elt1 _ left right)
268 = mkVBalBranch split_key elt1 (plusFM lts left) (plusFM gts right)
270 lts = splitLT fm1 split_key
271 gts = splitGT fm1 split_key
273 minusFM EmptyFM fm2 = emptyFM
274 minusFM fm1 EmptyFM = fm1
275 minusFM fm1 (Branch split_key elt _ left right)
276 = glueVBal (minusFM lts left) (minusFM gts right)
277 -- The two can be way different, so we need glueVBal
279 lts = splitLT fm1 split_key -- NB gt and lt, so the equal ones
280 gts = splitGT fm1 split_key -- are not in either.
282 intersectFM fm1 fm2 = intersectFM_C (\ left right -> right) fm1 fm2
284 intersectFM_C combiner fm1 EmptyFM = emptyFM
285 intersectFM_C combiner EmptyFM fm2 = emptyFM
286 intersectFM_C combiner fm1 (Branch split_key elt2 _ left right)
288 | maybeToBool maybe_elt1 -- split_elt *is* in intersection
289 = mkVBalBranch split_key (combiner elt1 elt2) (intersectFM_C combiner lts left)
290 (intersectFM_C combiner gts right)
292 | otherwise -- split_elt is *not* in intersection
293 = glueVBal (intersectFM_C combiner lts left) (intersectFM_C combiner gts right)
296 lts = splitLT fm1 split_key -- NB gt and lt, so the equal ones
297 gts = splitGT fm1 split_key -- are not in either.
299 maybe_elt1 = lookupFM fm1 split_key
300 Just elt1 = maybe_elt1
303 %************************************************************************
305 \subsection{Mapping, folding, and filtering with @FiniteMaps@}
307 %************************************************************************
310 foldFM k z EmptyFM = z
311 foldFM k z (Branch key elt _ fm_l fm_r)
312 = foldFM k (k key elt (foldFM k z fm_r)) fm_l
314 mapFM f EmptyFM = emptyFM
315 mapFM f (Branch key elt size fm_l fm_r)
316 = Branch key (f key elt) size (mapFM f fm_l) (mapFM f fm_r)
318 filterFM p EmptyFM = emptyFM
319 filterFM p (Branch key elt _ fm_l fm_r)
320 | p key elt -- Keep the item
321 = mkVBalBranch key elt (filterFM p fm_l) (filterFM p fm_r)
323 | otherwise -- Drop the item
324 = glueVBal (filterFM p fm_l) (filterFM p fm_r)
327 %************************************************************************
329 \subsection{Interrogating @FiniteMaps@}
331 %************************************************************************
334 --{-# INLINE sizeFM #-}
336 sizeFM (Branch _ _ size _ _) = IF_GHC(I# size, size)
338 isEmptyFM fm = sizeFM fm == 0
340 lookupFM EmptyFM key = Nothing
341 lookupFM (Branch key elt _ fm_l fm_r) key_to_find
342 = case compare key_to_find key of
343 LT -> lookupFM fm_l key_to_find
344 GT -> lookupFM fm_r key_to_find
348 = case (lookupFM fm key) of { Nothing -> False; Just elt -> True }
350 lookupWithDefaultFM fm deflt key
351 = case (lookupFM fm key) of { Nothing -> deflt; Just elt -> elt }
354 %************************************************************************
356 \subsection{Listifying @FiniteMaps@}
358 %************************************************************************
361 fmToList fm = foldFM (\ key elt rest -> (key,elt) : rest) [] fm
362 keysFM fm = foldFM (\ key elt rest -> key : rest) [] fm
363 eltsFM fm = foldFM (\ key elt rest -> elt : rest) [] fm
367 %************************************************************************
369 \subsection{The implementation of balancing}
371 %************************************************************************
373 %************************************************************************
375 \subsubsection{Basic construction of a @FiniteMap@}
377 %************************************************************************
379 @mkBranch@ simply gets the size component right. This is the ONLY
380 (non-trivial) place the Branch object is built, so the ASSERTion
381 recursively checks consistency. (The trivial use of Branch is in
388 mkBranch :: (Ord key OUTPUTABLE_key) -- Used for the assertion checking only
391 -> FiniteMap key elt -> FiniteMap key elt
394 mkBranch which key elt fm_l fm_r
395 = --ASSERT( left_ok && right_ok && balance_ok )
396 #if defined(DEBUG_FINITEMAPS)
397 if not ( left_ok && right_ok && balance_ok ) then
398 pprPanic ("mkBranch:"++show which) (vcat [ppr [left_ok, right_ok, balance_ok],
405 result = Branch key elt (unbox (1 + left_size + right_size)) fm_l fm_r
407 -- if sizeFM result <= 8 then
410 -- pprTrace ("mkBranch:"++(show which)) (ppr result) (
414 left_ok = case fm_l of
416 Branch left_key _ _ _ _ -> let
417 biggest_left_key = fst (findMax fm_l)
419 biggest_left_key < key
420 right_ok = case fm_r of
422 Branch right_key _ _ _ _ -> let
423 smallest_right_key = fst (findMin fm_r)
425 key < smallest_right_key
426 balance_ok = True -- sigh
429 = -- Both subtrees have one or no elements...
430 (left_size + right_size <= 1)
431 -- NO || left_size == 0 -- ???
432 -- NO || right_size == 0 -- ???
433 -- ... or the number of elements in a subtree does not exceed
434 -- sIZE_RATIO times the number of elements in the other subtree
435 || (left_size * sIZE_RATIO >= right_size &&
436 right_size * sIZE_RATIO >= left_size)
439 left_size = sizeFM fm_l
440 right_size = sizeFM fm_r
442 #ifdef __GLASGOW_HASKELL__
444 unbox (I# size) = size
451 %************************************************************************
453 \subsubsection{{\em Balanced} construction of a @FiniteMap@}
455 %************************************************************************
457 @mkBalBranch@ rebalances, assuming that the subtrees aren't too far
461 mkBalBranch :: (Ord key OUTPUTABLE_key)
463 -> FiniteMap key elt -> FiniteMap key elt
466 mkBalBranch key elt fm_L fm_R
468 | size_l + size_r < 2
469 = mkBranch 1{-which-} key elt fm_L fm_R
471 | size_r > sIZE_RATIO * size_l -- Right tree too big
473 Branch _ _ _ fm_rl fm_rr
474 | sizeFM fm_rl < 2 * sizeFM fm_rr -> single_L fm_L fm_R
475 | otherwise -> double_L fm_L fm_R
476 -- Other case impossible
478 | size_l > sIZE_RATIO * size_r -- Left tree too big
480 Branch _ _ _ fm_ll fm_lr
481 | sizeFM fm_lr < 2 * sizeFM fm_ll -> single_R fm_L fm_R
482 | otherwise -> double_R fm_L fm_R
483 -- Other case impossible
485 | otherwise -- No imbalance
486 = mkBranch 2{-which-} key elt fm_L fm_R
492 single_L fm_l (Branch key_r elt_r _ fm_rl fm_rr)
493 = mkBranch 3{-which-} key_r elt_r (mkBranch 4{-which-} key elt fm_l fm_rl) fm_rr
495 double_L fm_l (Branch key_r elt_r _ (Branch key_rl elt_rl _ fm_rll fm_rlr) fm_rr)
496 = mkBranch 5{-which-} key_rl elt_rl (mkBranch 6{-which-} key elt fm_l fm_rll)
497 (mkBranch 7{-which-} key_r elt_r fm_rlr fm_rr)
499 single_R (Branch key_l elt_l _ fm_ll fm_lr) fm_r
500 = mkBranch 8{-which-} key_l elt_l fm_ll (mkBranch 9{-which-} key elt fm_lr fm_r)
502 double_R (Branch key_l elt_l _ fm_ll (Branch key_lr elt_lr _ fm_lrl fm_lrr)) fm_r
503 = mkBranch 10{-which-} key_lr elt_lr (mkBranch 11{-which-} key_l elt_l fm_ll fm_lrl)
504 (mkBranch 12{-which-} key elt fm_lrr fm_r)
509 mkVBalBranch :: (Ord key OUTPUTABLE_key)
511 -> FiniteMap key elt -> FiniteMap key elt
514 -- Assert: in any call to (mkVBalBranch_C comb key elt l r),
515 -- (a) all keys in l are < all keys in r
516 -- (b) all keys in l are < key
517 -- (c) all keys in r are > key
519 mkVBalBranch key elt EmptyFM fm_r = addToFM fm_r key elt
520 mkVBalBranch key elt fm_l EmptyFM = addToFM fm_l key elt
522 mkVBalBranch key elt fm_l@(Branch key_l elt_l _ fm_ll fm_lr)
523 fm_r@(Branch key_r elt_r _ fm_rl fm_rr)
524 | sIZE_RATIO * size_l < size_r
525 = mkBalBranch key_r elt_r (mkVBalBranch key elt fm_l fm_rl) fm_rr
527 | sIZE_RATIO * size_r < size_l
528 = mkBalBranch key_l elt_l fm_ll (mkVBalBranch key elt fm_lr fm_r)
531 = mkBranch 13{-which-} key elt fm_l fm_r
538 %************************************************************************
540 \subsubsection{Gluing two trees together}
542 %************************************************************************
544 @glueBal@ assumes its two arguments aren't too far out of whack, just
545 like @mkBalBranch@. But: all keys in first arg are $<$ all keys in
549 glueBal :: (Ord key OUTPUTABLE_key)
550 => FiniteMap key elt -> FiniteMap key elt
553 glueBal EmptyFM fm2 = fm2
554 glueBal fm1 EmptyFM = fm1
556 -- The case analysis here (absent in Adams' program) is really to deal
557 -- with the case where fm2 is a singleton. Then deleting the minimum means
558 -- we pass an empty tree to mkBalBranch, which breaks its invariant.
559 | sizeFM fm2 > sizeFM fm1
560 = mkBalBranch mid_key2 mid_elt2 fm1 (deleteMin fm2)
563 = mkBalBranch mid_key1 mid_elt1 (deleteMax fm1) fm2
565 (mid_key1, mid_elt1) = findMax fm1
566 (mid_key2, mid_elt2) = findMin fm2
569 @glueVBal@ copes with arguments which can be of any size.
570 But: all keys in first arg are $<$ all keys in second.
573 glueVBal :: (Ord key OUTPUTABLE_key)
574 => FiniteMap key elt -> FiniteMap key elt
577 glueVBal EmptyFM fm2 = fm2
578 glueVBal fm1 EmptyFM = fm1
579 glueVBal fm_l@(Branch key_l elt_l _ fm_ll fm_lr)
580 fm_r@(Branch key_r elt_r _ fm_rl fm_rr)
581 | sIZE_RATIO * size_l < size_r
582 = mkBalBranch key_r elt_r (glueVBal fm_l fm_rl) fm_rr
584 | sIZE_RATIO * size_r < size_l
585 = mkBalBranch key_l elt_l fm_ll (glueVBal fm_lr fm_r)
587 | otherwise -- We now need the same two cases as in glueBal above.
590 (mid_key_l,mid_elt_l) = findMax fm_l
591 (mid_key_r,mid_elt_r) = findMin fm_r
596 %************************************************************************
598 \subsection{Local utilities}
600 %************************************************************************
603 splitLT, splitGT :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> key -> FiniteMap key elt
605 -- splitLT fm split_key = fm restricted to keys < split_key
606 -- splitGT fm split_key = fm restricted to keys > split_key
608 splitLT EmptyFM split_key = emptyFM
609 splitLT (Branch key elt _ fm_l fm_r) split_key
610 = case compare split_key key of
611 LT -> splitLT fm_l split_key
612 GT -> mkVBalBranch key elt fm_l (splitLT fm_r split_key)
615 splitGT EmptyFM split_key = emptyFM
616 splitGT (Branch key elt _ fm_l fm_r) split_key
617 = case compare split_key key of
618 GT -> splitGT fm_r split_key
619 LT -> mkVBalBranch key elt (splitGT fm_l split_key) fm_r
622 findMin :: FiniteMap key elt -> (key,elt)
623 findMin (Branch key elt _ EmptyFM _) = (key,elt)
624 findMin (Branch key elt _ fm_l _) = findMin fm_l
626 deleteMin :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> FiniteMap key elt
627 deleteMin (Branch key elt _ EmptyFM fm_r) = fm_r
628 deleteMin (Branch key elt _ fm_l fm_r) = mkBalBranch key elt (deleteMin fm_l) fm_r
630 findMax :: FiniteMap key elt -> (key,elt)
631 findMax (Branch key elt _ _ EmptyFM) = (key,elt)
632 findMax (Branch key elt _ _ fm_r) = findMax fm_r
634 deleteMax :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> FiniteMap key elt
635 deleteMax (Branch key elt _ fm_l EmptyFM) = fm_l
636 deleteMax (Branch key elt _ fm_l fm_r) = mkBalBranch key elt fm_l (deleteMax fm_r)
639 %************************************************************************
641 \subsection{Output-ery}
643 %************************************************************************
646 #if defined(DEBUG_FINITEMAPS)
648 instance (Outputable key) => Outputable (FiniteMap key elt) where
651 pprX EmptyFM = char '!'
652 pprX (Branch key elt sz fm_l fm_r)
653 = parens (hcat [pprX fm_l, space,
654 ppr key, space, int (IF_GHC(I# sz, sz)), space,
659 instance (Eq key, Eq elt) => Eq (FiniteMap key elt) where
660 fm_1 == fm_2 = (sizeFM fm_1 == sizeFM fm_2) && -- quick test
661 (fmToList fm_1 == fmToList fm_2)
663 {- NO: not clear what The Right Thing to do is:
664 instance (Ord key, Ord elt) => Ord (FiniteMap key elt) where
665 fm_1 <= fm_2 = (sizeFM fm_1 <= sizeFM fm_2) && -- quick test
666 (fmToList fm_1 <= fmToList fm_2)
671 %************************************************************************
673 \subsection{FiniteSets---a thin veneer}
675 %************************************************************************
678 type FiniteSet key = FiniteMap key ()
679 emptySet :: FiniteSet key
680 mkSet :: (Ord key OUTPUTABLE_key) => [key] -> FiniteSet key
681 isEmptySet :: FiniteSet key -> Bool
682 elementOf :: (Ord key OUTPUTABLE_key) => key -> FiniteSet key -> Bool
683 minusSet :: (Ord key OUTPUTABLE_key) => FiniteSet key -> FiniteSet key -> FiniteSet key
684 setToList :: FiniteSet key -> [key]
685 union :: (Ord key OUTPUTABLE_key) => FiniteSet key -> FiniteSet key -> FiniteSet key
688 mkSet xs = listToFM [ (x, ()) | x <- xs]
689 isEmptySet = isEmptyFM
697 %************************************************************************
699 \subsection{Efficiency pragmas for GHC}
701 %************************************************************************
703 When the FiniteMap module is used in GHC, we specialise it for
704 \tr{Uniques}, for dastardly efficiency reasons.
707 #if __GLASGOW_HASKELL__ && !defined(REALLY_HASKELL_1_3)
709 {-# SPECIALIZE addListToFM
710 :: FiniteMap (FAST_STRING, FAST_STRING) elt -> [((FAST_STRING, FAST_STRING),elt)] -> FiniteMap (FAST_STRING, FAST_STRING) elt
711 , FiniteMap RdrName elt -> [(RdrName,elt)] -> FiniteMap RdrName elt
712 IF_NCG(COMMA FiniteMap Reg elt -> [(Reg COMMA elt)] -> FiniteMap Reg elt)
714 {-# SPECIALIZE addListToFM_C
715 :: (elt -> elt -> elt) -> FiniteMap TyCon elt -> [(TyCon,elt)] -> FiniteMap TyCon elt
716 , (elt -> elt -> elt) -> FiniteMap FAST_STRING elt -> [(FAST_STRING,elt)] -> FiniteMap FAST_STRING elt
717 IF_NCG(COMMA (elt -> elt -> elt) -> FiniteMap Reg elt -> [(Reg COMMA elt)] -> FiniteMap Reg elt)
719 {-# SPECIALIZE addToFM
720 :: FiniteMap CLabel elt -> CLabel -> elt -> FiniteMap CLabel elt
721 , FiniteMap FAST_STRING elt -> FAST_STRING -> elt -> FiniteMap FAST_STRING elt
722 , FiniteMap (FAST_STRING, FAST_STRING) elt -> (FAST_STRING, FAST_STRING) -> elt -> FiniteMap (FAST_STRING, FAST_STRING) elt
723 , FiniteMap RdrName elt -> RdrName -> elt -> FiniteMap RdrName elt
724 IF_NCG(COMMA FiniteMap Reg elt -> Reg -> elt -> FiniteMap Reg elt)
726 {-# SPECIALIZE addToFM_C
727 :: (elt -> elt -> elt) -> FiniteMap (RdrName, RdrName) elt -> (RdrName, RdrName) -> elt -> FiniteMap (RdrName, RdrName) elt
728 , (elt -> elt -> elt) -> FiniteMap FAST_STRING elt -> FAST_STRING -> elt -> FiniteMap FAST_STRING elt
729 IF_NCG(COMMA (elt -> elt -> elt) -> FiniteMap Reg elt -> Reg -> elt -> FiniteMap Reg elt)
731 {-# SPECIALIZE bagToFM
732 :: Bag (FAST_STRING,elt) -> FiniteMap FAST_STRING elt
734 {-# SPECIALIZE delListFromFM
735 :: FiniteMap RdrName elt -> [RdrName] -> FiniteMap RdrName elt
736 , FiniteMap FAST_STRING elt -> [FAST_STRING] -> FiniteMap FAST_STRING elt
737 IF_NCG(COMMA FiniteMap Reg elt -> [Reg] -> FiniteMap Reg elt)
739 {-# SPECIALIZE listToFM
740 :: [([Char],elt)] -> FiniteMap [Char] elt
741 , [(FAST_STRING,elt)] -> FiniteMap FAST_STRING elt
742 , [((FAST_STRING,FAST_STRING),elt)] -> FiniteMap (FAST_STRING, FAST_STRING) elt
743 IF_NCG(COMMA [(Reg COMMA elt)] -> FiniteMap Reg elt)
745 {-# SPECIALIZE lookupFM
746 :: FiniteMap CLabel elt -> CLabel -> Maybe elt
747 , FiniteMap [Char] elt -> [Char] -> Maybe elt
748 , FiniteMap FAST_STRING elt -> FAST_STRING -> Maybe elt
749 , FiniteMap (FAST_STRING,FAST_STRING) elt -> (FAST_STRING,FAST_STRING) -> Maybe elt
750 , FiniteMap RdrName elt -> RdrName -> Maybe elt
751 , FiniteMap (RdrName,RdrName) elt -> (RdrName,RdrName) -> Maybe elt
752 IF_NCG(COMMA FiniteMap Reg elt -> Reg -> Maybe elt)
754 {-# SPECIALIZE lookupWithDefaultFM
755 :: FiniteMap FAST_STRING elt -> elt -> FAST_STRING -> elt
756 IF_NCG(COMMA FiniteMap Reg elt -> elt -> Reg -> elt)
758 {-# SPECIALIZE plusFM
759 :: FiniteMap RdrName elt -> FiniteMap RdrName elt -> FiniteMap RdrName elt
760 , FiniteMap FAST_STRING elt -> FiniteMap FAST_STRING elt -> FiniteMap FAST_STRING elt
761 IF_NCG(COMMA FiniteMap Reg elt -> FiniteMap Reg elt -> FiniteMap Reg elt)
763 {-# SPECIALIZE plusFM_C
764 :: (elt -> elt -> elt) -> FiniteMap FAST_STRING elt -> FiniteMap FAST_STRING elt -> FiniteMap FAST_STRING elt
765 IF_NCG(COMMA (elt -> elt -> elt) -> FiniteMap Reg elt -> FiniteMap Reg elt -> FiniteMap Reg elt)
768 #endif {- compiling with ghc and have specialiser -}