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 -- * Mappings keyed from arbitrary types
23 FiniteMap, -- abstract type
25 -- ** Manipulating those mappings
26 emptyFM, unitFM, listToFM,
44 sizeFM, isEmptyFM, elemFM, lookupFM, lookupWithDefaultFM,
46 fmToList, keysFM, eltsFM,
51 #if defined(DEBUG_FINITEMAPS)/* NB NB NB */
52 #define OUTPUTABLE_key , Outputable key
54 #define OUTPUTABLE_key {--}
58 import Bag ( Bag, foldrBag )
63 -- was this import only needed for I#, or does it have something
64 -- to do with the (not-presently-used) IF_NCG also?
70 #if ! OMIT_NATIVE_CODEGEN
73 # define IF_NCG(a) {--}
79 %************************************************************************
81 \subsection{The signature of the module}
83 %************************************************************************
87 emptyFM :: FiniteMap key elt
88 unitFM :: key -> elt -> FiniteMap key elt
89 -- | In the case of duplicates keys, the last item is taken
90 listToFM :: (Ord key OUTPUTABLE_key) => [(key,elt)] -> FiniteMap key elt
91 -- | In the case of duplicate keys, who knows which item is taken
92 bagToFM :: (Ord key OUTPUTABLE_key) => Bag (key,elt) -> FiniteMap key elt
94 -- ADDING AND DELETING
96 -- | Throws away any previous binding
97 addToFM :: (Ord key OUTPUTABLE_key)
98 => FiniteMap key elt -> key -> elt -> FiniteMap key elt
99 -- | Throws away any previous binding, items are added left-to-right
100 addListToFM :: (Ord key OUTPUTABLE_key)
101 => FiniteMap key elt -> [(key,elt)] -> FiniteMap key elt
103 -- | Combines added item with previous item, if any
104 addToFM_C :: (Ord key OUTPUTABLE_key) => (elt -> elt -> elt)
105 -> FiniteMap key elt -> key -> elt
107 -- | Combines added item with previous item, if any, items are added left-to-right
108 addListToFM_C :: (Ord key OUTPUTABLE_key) => (elt -> elt -> elt)
109 -> FiniteMap key elt -> [(key,elt)]
112 -- | Deletion doesn't complain if you try to delete something which isn't there
113 delFromFM :: (Ord key OUTPUTABLE_key)
114 => FiniteMap key elt -> key -> FiniteMap key elt
115 -- | Deletion doesn't complain if you try to delete something which isn't there
116 delListFromFM :: (Ord key OUTPUTABLE_key)
117 => FiniteMap key elt -> [key] -> FiniteMap key elt
121 -- | Bindings in right argument shadow those in the left
122 plusFM :: (Ord key OUTPUTABLE_key)
123 => FiniteMap key elt -> FiniteMap key elt -> FiniteMap key elt
125 -- | Combines bindings for the same thing with the given function,
126 -- bindings in right argument shadow those in the left
127 plusFM_C :: (Ord key OUTPUTABLE_key)
128 => (elt -> elt -> elt)
129 -> FiniteMap key elt -> FiniteMap key elt -> FiniteMap key elt
131 -- | Deletes from the left argument any bindings in the right argument
132 minusFM :: (Ord key OUTPUTABLE_key)
133 => FiniteMap key elt -> FiniteMap key elt -> FiniteMap key elt
135 intersectFM :: (Ord key OUTPUTABLE_key)
136 => FiniteMap key elt -> FiniteMap key elt -> FiniteMap key elt
137 -- | Combines bindings for the same thing in the two maps with the given function
138 intersectFM_C :: (Ord key OUTPUTABLE_key)
139 => (elt1 -> elt2 -> elt3)
140 -> FiniteMap key elt1 -> FiniteMap key elt2
141 -> FiniteMap key elt3
143 -- MAPPING, FOLDING, FILTERING
144 foldFM :: (key -> elt -> a -> a) -> a -> FiniteMap key elt -> a
145 mapFM :: (key -> elt1 -> elt2)
146 -> FiniteMap key elt1 -> FiniteMap key elt2
147 filterFM :: (Ord key OUTPUTABLE_key)
148 => (key -> elt -> Bool)
149 -> FiniteMap key elt -> FiniteMap key elt
152 sizeFM :: FiniteMap key elt -> Int
153 isEmptyFM :: FiniteMap key elt -> Bool
155 elemFM :: (Ord key OUTPUTABLE_key)
156 => key -> FiniteMap key elt -> Bool
157 lookupFM :: (Ord key OUTPUTABLE_key)
158 => FiniteMap key elt -> key -> Maybe elt
159 -- | Supplies a "default" element in return for an unmapped key
160 lookupWithDefaultFM :: (Ord key OUTPUTABLE_key)
161 => FiniteMap key elt -> elt -> key -> elt
164 fmToList :: FiniteMap key elt -> [(key,elt)]
165 keysFM :: FiniteMap key elt -> [key]
166 eltsFM :: FiniteMap key elt -> [elt]
169 %************************************************************************
171 \subsection{The @FiniteMap@ data type, and building of same}
173 %************************************************************************
175 Invariants about @FiniteMap@:
178 all keys in a FiniteMap are distinct
180 all keys in left subtree are $<$ key in Branch and
181 all keys in right subtree are $>$ key in Branch
183 size field of a Branch gives number of Branch nodes in the tree
185 size of left subtree is differs from size of right subtree by a
186 factor of at most \tr{sIZE_RATIO}
190 -- | A finite mapping from (orderable) key types to elements
191 data FiniteMap key elt
193 | Branch key elt -- Key and elt stored here
194 {-# UNPACK #-} !Int -- Size >= 1
195 (FiniteMap key elt) -- Children
203 = Branch bottom bottom 0 bottom bottom
205 bottom = panic "emptyFM"
208 -- #define EmptyFM (Branch _ _ 0 _ _)
210 unitFM key elt = Branch key elt 1 emptyFM emptyFM
212 listToFM = addListToFM emptyFM
214 bagToFM = foldrBag (\(k,v) fm -> addToFM fm k v) emptyFM
217 %************************************************************************
219 \subsection{Adding to and deleting from @FiniteMaps@}
221 %************************************************************************
224 addToFM fm key elt = addToFM_C (\ _old new -> new) fm key elt
226 addToFM_C _ EmptyFM key elt = unitFM key elt
227 addToFM_C combiner (Branch key elt size fm_l fm_r) new_key new_elt
228 = case compare new_key key of
229 LT -> mkBalBranch key elt (addToFM_C combiner fm_l new_key new_elt) fm_r
230 GT -> mkBalBranch key elt fm_l (addToFM_C combiner fm_r new_key new_elt)
231 EQ -> Branch new_key (combiner elt new_elt) size fm_l fm_r
233 addListToFM fm key_elt_pairs
234 = addListToFM_C (\ _old new -> new) fm key_elt_pairs
236 addListToFM_C combiner fm key_elt_pairs
237 = foldl' add fm key_elt_pairs -- foldl adds from the left
239 add fmap (key,elt) = addToFM_C combiner fmap key elt
243 delFromFM EmptyFM _ = emptyFM
244 delFromFM (Branch key elt _ fm_l fm_r) del_key
245 = case compare del_key key of
246 GT -> mkBalBranch key elt fm_l (delFromFM fm_r del_key)
247 LT -> mkBalBranch key elt (delFromFM fm_l del_key) fm_r
248 EQ -> glueBal fm_l fm_r
250 delListFromFM fm keys = foldl' delFromFM fm keys
253 %************************************************************************
255 \subsection{Combining @FiniteMaps@}
257 %************************************************************************
260 plusFM_C _ EmptyFM fm2 = fm2
261 plusFM_C _ fm1 EmptyFM = fm1
262 plusFM_C combiner fm1 (Branch split_key elt2 _ left right)
263 = mkVBalBranch split_key new_elt
264 (plusFM_C combiner lts left)
265 (plusFM_C combiner gts right)
267 lts = splitLT fm1 split_key
268 gts = splitGT fm1 split_key
269 new_elt = case lookupFM fm1 split_key of
271 Just elt1 -> combiner elt1 elt2
273 -- It's worth doing plusFM specially, because we don't need
274 -- to do the lookup in fm1.
275 -- FM2 over-rides FM1.
277 plusFM EmptyFM fm2 = fm2
278 plusFM fm1 EmptyFM = fm1
279 plusFM fm1 (Branch split_key elt1 _ left right)
280 = mkVBalBranch split_key elt1 (plusFM lts left) (plusFM gts right)
282 lts = splitLT fm1 split_key
283 gts = splitGT fm1 split_key
285 minusFM EmptyFM _ = emptyFM
286 minusFM fm1 EmptyFM = fm1
287 minusFM fm1 (Branch split_key _ _ left right)
288 = glueVBal (minusFM lts left) (minusFM gts right)
289 -- The two can be way different, so we need glueVBal
291 lts = splitLT fm1 split_key -- NB gt and lt, so the equal ones
292 gts = splitGT fm1 split_key -- are not in either.
294 intersectFM fm1 fm2 = intersectFM_C (\ _ right -> right) fm1 fm2
296 intersectFM_C _ _ EmptyFM = emptyFM
297 intersectFM_C _ EmptyFM _ = emptyFM
298 intersectFM_C combiner fm1 (Branch split_key elt2 _ left right)
300 | maybeToBool maybe_elt1 -- split_elt *is* in intersection
301 = mkVBalBranch split_key (combiner elt1 elt2)
302 (intersectFM_C combiner lts left)
303 (intersectFM_C combiner gts right)
305 | otherwise -- split_elt is *not* in intersection
306 = glueVBal (intersectFM_C combiner lts left)
307 (intersectFM_C combiner gts right)
310 lts = splitLT fm1 split_key -- NB gt and lt, so the equal ones
311 gts = splitGT fm1 split_key -- are not in either.
313 maybe_elt1 = lookupFM fm1 split_key
314 Just elt1 = maybe_elt1
317 %************************************************************************
319 \subsection{Mapping, folding, and filtering with @FiniteMaps@}
321 %************************************************************************
324 foldFM _ z EmptyFM = z
325 foldFM k z (Branch key elt _ fm_l fm_r)
326 = foldFM k (k key elt (foldFM k z fm_r)) fm_l
328 mapFM _ EmptyFM = emptyFM
329 mapFM f (Branch key elt size fm_l fm_r)
330 = Branch key (f key elt) size (mapFM f fm_l) (mapFM f fm_r)
332 filterFM _ EmptyFM = emptyFM
333 filterFM p (Branch key elt _ fm_l fm_r)
334 | p key elt -- Keep the item
335 = mkVBalBranch key elt (filterFM p fm_l) (filterFM p fm_r)
337 | otherwise -- Drop the item
338 = glueVBal (filterFM p fm_l) (filterFM p fm_r)
341 %************************************************************************
343 \subsection{Interrogating @FiniteMaps@}
345 %************************************************************************
348 --{-# INLINE sizeFM #-}
350 sizeFM (Branch _ _ size _ _) = size
352 isEmptyFM fm = sizeFM fm == 0
354 lookupFM EmptyFM _ = Nothing
355 lookupFM (Branch key elt _ fm_l fm_r) key_to_find
356 = case compare key_to_find key of
357 LT -> lookupFM fm_l key_to_find
358 GT -> lookupFM fm_r key_to_find
361 key `elemFM` fm = isJust (lookupFM fm key)
363 lookupWithDefaultFM fm deflt key
364 = case (lookupFM fm key) of { Nothing -> deflt; Just elt -> elt }
367 %************************************************************************
369 \subsection{Listifying @FiniteMaps@}
371 %************************************************************************
374 fmToList fm = foldFM (\ key elt rest -> (key, elt) : rest) [] fm
375 keysFM fm = foldFM (\ key _elt rest -> key : rest) [] fm
376 eltsFM fm = foldFM (\ _key elt rest -> elt : rest) [] fm
380 %************************************************************************
382 \subsection{The implementation of balancing}
384 %************************************************************************
386 %************************************************************************
388 \subsubsection{Basic construction of a @FiniteMap@}
390 %************************************************************************
392 @mkBranch@ simply gets the size component right. This is the ONLY
393 (non-trivial) place the Branch object is built, so the ASSERTion
394 recursively checks consistency. (The trivial use of Branch is in
401 mkBranch :: (Ord key OUTPUTABLE_key) -- Used for the assertion checking only
404 -> FiniteMap key elt -> FiniteMap key elt
407 mkBranch _which key elt fm_l fm_r
408 = --ASSERT( left_ok && right_ok && balance_ok )
409 #if defined(DEBUG_FINITEMAPS)
410 if not ( left_ok && right_ok && balance_ok ) then
411 pprPanic ("mkBranch:"++show _which)
412 (vcat [ppr [left_ok, right_ok, balance_ok],
419 result = Branch key elt (1 + left_size + right_size) fm_l fm_r
421 -- if sizeFM result <= 8 then
424 -- pprTrace ("mkBranch:"++(show which)) (ppr result) (
428 #if defined(DEBUG_FINITEMAPS)
429 left_ok = case fm_l of
431 Branch _ _ _ _ _ -> let
432 biggest_left_key = fst (findMax fm_l)
434 biggest_left_key < key
435 right_ok = case fm_r of
437 Branch _ _ _ _ _ -> let
438 smallest_right_key = fst (findMin fm_r)
440 key < smallest_right_key
441 balance_ok = True -- sigh
445 = -- Both subtrees have one or no elements...
446 (left_size + right_size <= 1)
447 -- NO || left_size == 0 -- ???
448 -- NO || right_size == 0 -- ???
449 -- ... or the number of elements in a subtree does not exceed
450 -- sIZE_RATIO times the number of elements in the other subtree
451 || (left_size * sIZE_RATIO >= right_size &&
452 right_size * sIZE_RATIO >= left_size)
455 left_size = sizeFM fm_l
456 right_size = sizeFM fm_r
459 %************************************************************************
461 \subsubsection{{\em Balanced} construction of a @FiniteMap@}
463 %************************************************************************
465 @mkBalBranch@ rebalances, assuming that the subtrees aren't too far
469 mkBalBranch :: (Ord key OUTPUTABLE_key)
471 -> FiniteMap key elt -> FiniteMap key elt
474 mkBalBranch key elt fm_L fm_R
476 | size_l + size_r < 2
477 = mkBranch 1{-which-} key elt fm_L fm_R
479 | size_r > sIZE_RATIO * size_l -- Right tree too big
481 Branch _ _ _ fm_rl fm_rr
482 | sizeFM fm_rl < 2 * sizeFM fm_rr -> single_L fm_L fm_R
483 | otherwise -> double_L fm_L fm_R
484 _ -> panic "mkBalBranch: impossible case 1"
486 | size_l > sIZE_RATIO * size_r -- Left tree too big
488 Branch _ _ _ fm_ll fm_lr
489 | sizeFM fm_lr < 2 * sizeFM fm_ll -> single_R fm_L fm_R
490 | otherwise -> double_R fm_L fm_R
491 _ -> panic "mkBalBranch: impossible case 2"
492 | otherwise -- No imbalance
493 = mkBranch 2{-which-} key elt fm_L fm_R
499 single_L fm_l (Branch key_r elt_r _ fm_rl fm_rr)
500 = mkBranch 3{-which-} key_r elt_r (mkBranch 4{-which-} key elt fm_l fm_rl) fm_rr
501 single_L _ _ = panic "mkBalBranch: impossible case 3"
503 double_L fm_l (Branch key_r elt_r _ (Branch key_rl elt_rl _ fm_rll fm_rlr) fm_rr)
504 = mkBranch 5{-which-} key_rl elt_rl
505 (mkBranch 6{-which-} key elt fm_l fm_rll)
506 (mkBranch 7{-which-} key_r elt_r fm_rlr fm_rr)
507 double_L _ _ = panic "mkBalBranch: impossible case 4"
509 single_R (Branch key_l elt_l _ fm_ll fm_lr) fm_r
510 = mkBranch 8{-which-} key_l elt_l fm_ll
511 (mkBranch 9{-which-} key elt fm_lr fm_r)
512 single_R _ _ = panic "mkBalBranch: impossible case 5"
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)
518 double_R _ _ = panic "mkBalBranch: impossible case 6"
523 mkVBalBranch :: (Ord key OUTPUTABLE_key)
525 -> FiniteMap key elt -> FiniteMap key elt
528 -- Assert: in any call to (mkVBalBranch_C comb key elt l r),
529 -- (a) all keys in l are < all keys in r
530 -- (b) all keys in l are < key
531 -- (c) all keys in r are > key
533 mkVBalBranch key elt EmptyFM fm_r = addToFM fm_r key elt
534 mkVBalBranch key elt fm_l EmptyFM = addToFM fm_l key elt
536 mkVBalBranch key elt fm_l@(Branch key_l elt_l _ fm_ll fm_lr)
537 fm_r@(Branch key_r elt_r _ fm_rl fm_rr)
538 | sIZE_RATIO * size_l < size_r
539 = mkBalBranch key_r elt_r (mkVBalBranch key elt fm_l fm_rl) fm_rr
541 | sIZE_RATIO * size_r < size_l
542 = mkBalBranch key_l elt_l fm_ll (mkVBalBranch key elt fm_lr fm_r)
545 = mkBranch 13{-which-} key elt fm_l fm_r
552 %************************************************************************
554 \subsubsection{Gluing two trees together}
556 %************************************************************************
558 @glueBal@ assumes its two arguments aren't too far out of whack, just
559 like @mkBalBranch@. But: all keys in first arg are $<$ all keys in
563 glueBal :: (Ord key OUTPUTABLE_key)
564 => FiniteMap key elt -> FiniteMap key elt
567 glueBal EmptyFM fm2 = fm2
568 glueBal fm1 EmptyFM = fm1
570 -- The case analysis here (absent in Adams' program) is really to deal
571 -- with the case where fm2 is a singleton. Then deleting the minimum means
572 -- we pass an empty tree to mkBalBranch, which breaks its invariant.
573 | sizeFM fm2 > sizeFM fm1
574 = mkBalBranch mid_key2 mid_elt2 fm1 (deleteMin fm2)
577 = mkBalBranch mid_key1 mid_elt1 (deleteMax fm1) fm2
579 (mid_key1, mid_elt1) = findMax fm1
580 (mid_key2, mid_elt2) = findMin fm2
583 @glueVBal@ copes with arguments which can be of any size.
584 But: all keys in first arg are $<$ all keys in second.
587 glueVBal :: (Ord key OUTPUTABLE_key)
588 => FiniteMap key elt -> FiniteMap key elt
591 glueVBal EmptyFM fm2 = fm2
592 glueVBal fm1 EmptyFM = fm1
593 glueVBal fm_l@(Branch key_l elt_l _ fm_ll fm_lr)
594 fm_r@(Branch key_r elt_r _ fm_rl fm_rr)
595 | sIZE_RATIO * size_l < size_r
596 = mkBalBranch key_r elt_r (glueVBal fm_l fm_rl) fm_rr
598 | sIZE_RATIO * size_r < size_l
599 = mkBalBranch key_l elt_l fm_ll (glueVBal fm_lr fm_r)
601 | otherwise -- We now need the same two cases as in glueBal above.
608 %************************************************************************
610 \subsection{Local utilities}
612 %************************************************************************
615 splitLT, splitGT :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> key -> FiniteMap key elt
617 -- splitLT fm split_key = fm restricted to keys < split_key
618 -- splitGT fm split_key = fm restricted to keys > split_key
620 splitLT EmptyFM _ = emptyFM
621 splitLT (Branch key elt _ fm_l fm_r) split_key
622 = case compare split_key key of
623 LT -> splitLT fm_l split_key
624 GT -> mkVBalBranch key elt fm_l (splitLT fm_r split_key)
627 splitGT EmptyFM _ = emptyFM
628 splitGT (Branch key elt _ fm_l fm_r) split_key
629 = case compare split_key key of
630 GT -> splitGT fm_r split_key
631 LT -> mkVBalBranch key elt (splitGT fm_l split_key) fm_r
634 findMin :: FiniteMap key elt -> (key,elt)
635 findMin (Branch key elt _ EmptyFM _) = (key, elt)
636 findMin (Branch _ _ _ fm_l _) = findMin fm_l
637 findMin EmptyFM = panic "findMin: Empty"
639 deleteMin :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> FiniteMap key elt
640 deleteMin (Branch _ _ _ EmptyFM fm_r) = fm_r
641 deleteMin (Branch key elt _ fm_l fm_r)
642 = mkBalBranch key elt (deleteMin fm_l) fm_r
643 deleteMin EmptyFM = panic "deleteMin: Empty"
645 findMax :: FiniteMap key elt -> (key, elt)
646 findMax (Branch key elt _ _ EmptyFM) = (key, elt)
647 findMax (Branch _ _ _ _ fm_r) = findMax fm_r
648 findMax EmptyFM = panic "findMax: Empty"
650 deleteMax :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> FiniteMap key elt
651 deleteMax (Branch _ _ _ fm_l EmptyFM) = fm_l
652 deleteMax (Branch key elt _ fm_l fm_r) = mkBalBranch key elt fm_l (deleteMax fm_r)
653 deleteMax EmptyFM = panic "deleteMax: Empty"
656 %************************************************************************
658 \subsection{Output-ery}
660 %************************************************************************
663 #if defined(DEBUG_FINITEMAPS)
665 instance (Outputable key) => Outputable (FiniteMap key elt) where
668 pprX EmptyFM = char '!'
669 pprX (Branch key elt sz fm_l fm_r)
670 = parens (hcat [pprX fm_l, space,
671 ppr key, space, int sz, space,
674 -- and when not debugging the package itself...
675 instance (Outputable key, Outputable elt) => Outputable (FiniteMap key elt) where
676 ppr fm = ppr (fmToList fm)
680 instance (Eq key, Eq elt) => Eq (FiniteMap key elt) where
681 fm_1 == fm_2 = (sizeFM fm_1 == sizeFM fm_2) && -- quick test
682 (fmToList fm_1 == fmToList fm_2)
684 {- NO: not clear what The Right Thing to do is:
685 instance (Ord key, Ord elt) => Ord (FiniteMap key elt) where
686 fm_1 <= fm_2 = (sizeFM fm_1 <= sizeFM fm_2) && -- quick test
687 (fmToList fm_1 <= fmToList fm_2)
692 %************************************************************************
694 \subsection{Efficiency pragmas for GHC}
696 %************************************************************************
698 When the FiniteMap module is used in GHC, we specialise it for
699 \tr{Uniques}, for dastardly efficiency reasons.
704 #ifdef __GLASGOW_HASKELL__
706 {-# SPECIALIZE addListToFM
707 :: FiniteMap (FastString, FAST_STRING) elt -> [((FAST_STRING, FAST_STRING),elt)] -> FiniteMap (FAST_STRING, FAST_STRING) elt
708 , FiniteMap RdrName elt -> [(RdrName,elt)] -> FiniteMap RdrName elt
709 IF_NCG(COMMA FiniteMap Reg elt -> [(Reg COMMA elt)] -> FiniteMap Reg elt)
711 {-# SPECIALIZE addListToFM_C
712 :: (elt -> elt -> elt) -> FiniteMap TyCon elt -> [(TyCon,elt)] -> FiniteMap TyCon elt
713 , (elt -> elt -> elt) -> FiniteMap FastString elt -> [(FAST_STRING,elt)] -> FiniteMap FAST_STRING elt
714 IF_NCG(COMMA (elt -> elt -> elt) -> FiniteMap Reg elt -> [(Reg COMMA elt)] -> FiniteMap Reg elt)
716 {-# SPECIALIZE addToFM
717 :: FiniteMap CLabel elt -> CLabel -> elt -> FiniteMap CLabel elt
718 , FiniteMap FastString elt -> FAST_STRING -> elt -> FiniteMap FAST_STRING elt
719 , FiniteMap (FastString, FAST_STRING) elt -> (FAST_STRING, FAST_STRING) -> elt -> FiniteMap (FAST_STRING, FAST_STRING) elt
720 , FiniteMap RdrName elt -> RdrName -> elt -> FiniteMap RdrName elt
721 IF_NCG(COMMA FiniteMap Reg elt -> Reg -> elt -> FiniteMap Reg elt)
723 {-# SPECIALIZE addToFM_C
724 :: (elt -> elt -> elt) -> FiniteMap (RdrName, RdrName) elt -> (RdrName, RdrName) -> elt -> FiniteMap (RdrName, RdrName) elt
725 , (elt -> elt -> elt) -> FiniteMap FastString elt -> FAST_STRING -> elt -> FiniteMap FAST_STRING elt
726 IF_NCG(COMMA (elt -> elt -> elt) -> FiniteMap Reg elt -> Reg -> elt -> FiniteMap Reg elt)
728 {-# SPECIALIZE bagToFM
729 :: Bag (FastString,elt) -> FiniteMap FAST_STRING elt
731 {-# SPECIALIZE delListFromFM
732 :: FiniteMap RdrName elt -> [RdrName] -> FiniteMap RdrName elt
733 , FiniteMap FastString elt -> [FAST_STRING] -> FiniteMap FAST_STRING elt
734 IF_NCG(COMMA FiniteMap Reg elt -> [Reg] -> FiniteMap Reg elt)
736 {-# SPECIALIZE listToFM
737 :: [([Char],elt)] -> FiniteMap [Char] elt
738 , [(FastString,elt)] -> FiniteMap FAST_STRING elt
739 , [((FastString,FAST_STRING),elt)] -> FiniteMap (FAST_STRING, FAST_STRING) elt
740 IF_NCG(COMMA [(Reg COMMA elt)] -> FiniteMap Reg elt)
742 {-# SPECIALIZE lookupFM
743 :: FiniteMap CLabel elt -> CLabel -> Maybe elt
744 , FiniteMap [Char] elt -> [Char] -> Maybe elt
745 , FiniteMap FastString elt -> FAST_STRING -> Maybe elt
746 , FiniteMap (FastString,FAST_STRING) elt -> (FAST_STRING,FAST_STRING) -> Maybe elt
747 , FiniteMap RdrName elt -> RdrName -> Maybe elt
748 , FiniteMap (RdrName,RdrName) elt -> (RdrName,RdrName) -> Maybe elt
749 IF_NCG(COMMA FiniteMap Reg elt -> Reg -> Maybe elt)
751 {-# SPECIALIZE lookupWithDefaultFM
752 :: FiniteMap FastString elt -> elt -> FAST_STRING -> elt
753 IF_NCG(COMMA FiniteMap Reg elt -> elt -> Reg -> elt)
755 {-# SPECIALIZE plusFM
756 :: FiniteMap RdrName elt -> FiniteMap RdrName elt -> FiniteMap RdrName elt
757 , FiniteMap FastString elt -> FiniteMap FAST_STRING elt -> FiniteMap FAST_STRING elt
758 IF_NCG(COMMA FiniteMap Reg elt -> FiniteMap Reg elt -> FiniteMap Reg elt)
760 {-# SPECIALIZE plusFM_C
761 :: (elt -> elt -> elt) -> FiniteMap FastString elt -> FiniteMap FAST_STRING elt -> FiniteMap FAST_STRING elt
762 IF_NCG(COMMA (elt -> elt -> elt) -> FiniteMap Reg elt -> FiniteMap Reg elt -> FiniteMap Reg elt)
765 #endif /* compiling with ghc and have specialiser */