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)
23 FiniteMap, -- abstract type
25 emptyFM, unitFM, listToFM,
43 sizeFM, isEmptyFM, elemFM, lookupFM, lookupWithDefaultFM,
45 fmToList, keysFM, eltsFM
51 #include "HsVersions.h"
52 #define IF_NOT_GHC(a) {--}
54 #if defined(DEBUG_FINITEMAPS)/* NB NB NB */
55 #define OUTPUTABLE_key , Outputable key
57 #define OUTPUTABLE_key {--}
61 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 -- The combining fn goes (old -> new -> new)
109 addToFM_C :: (Ord key OUTPUTABLE_key) => (elt -> elt -> elt)
110 -> FiniteMap key elt -> key -> elt
112 addListToFM_C :: (Ord key OUTPUTABLE_key) => (elt -> elt -> elt)
113 -> FiniteMap key elt -> [(key,elt)]
116 -- Deletion doesn't complain if you try to delete something
118 delFromFM :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> key -> FiniteMap key elt
119 delListFromFM :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> [key] -> FiniteMap key elt
122 -- Bindings in right argument shadow those in the left
123 plusFM :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> FiniteMap key elt
126 -- Combines bindings for the same thing with the given function
127 plusFM_C :: (Ord key OUTPUTABLE_key) => (elt -> elt -> elt)
128 -> FiniteMap key elt -> FiniteMap key elt -> FiniteMap key elt
130 minusFM :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> FiniteMap key elt -> FiniteMap key elt
131 -- (minusFM a1 a2) deletes from a1 any bindings which are bound in a2
133 intersectFM :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> FiniteMap key elt -> FiniteMap key elt
134 intersectFM_C :: (Ord key OUTPUTABLE_key) => (elt1 -> elt2 -> elt3)
135 -> FiniteMap key elt1 -> FiniteMap key elt2 -> FiniteMap key elt3
137 -- MAPPING, FOLDING, FILTERING
138 foldFM :: (key -> elt -> a -> a) -> a -> FiniteMap key elt -> a
139 mapFM :: (key -> elt1 -> elt2) -> FiniteMap key elt1 -> FiniteMap key elt2
140 filterFM :: (Ord key OUTPUTABLE_key) => (key -> elt -> Bool)
141 -> FiniteMap key elt -> FiniteMap key elt
145 sizeFM :: FiniteMap key elt -> Int
146 isEmptyFM :: FiniteMap key elt -> Bool
148 elemFM :: (Ord key OUTPUTABLE_key) => key -> FiniteMap key elt -> Bool
149 lookupFM :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> key -> Maybe elt
151 :: (Ord key OUTPUTABLE_key) => FiniteMap key elt -> elt -> key -> elt
152 -- lookupWithDefaultFM supplies a "default" elt
153 -- to return for an unmapped key
156 fmToList :: FiniteMap key elt -> [(key,elt)]
157 keysFM :: FiniteMap key elt -> [key]
158 eltsFM :: FiniteMap key elt -> [elt]
161 %************************************************************************
163 \subsection{The @FiniteMap@ data type, and building of same}
165 %************************************************************************
167 Invariants about @FiniteMap@:
170 all keys in a FiniteMap are distinct
172 all keys in left subtree are $<$ key in Branch and
173 all keys in right subtree are $>$ key in Branch
175 size field of a Branch gives number of Branch nodes in the tree
177 size of left subtree is differs from size of right subtree by a
178 factor of at most \tr{sIZE_RATIO}
182 data FiniteMap key elt
184 | Branch key elt -- Key and elt stored here
185 IF_GHC(Int#,Int{-STRICT-}) -- Size >= 1
186 (FiniteMap key elt) -- Children
194 = Branch bottom bottom IF_GHC(0#,0) bottom bottom
196 bottom = panic "emptyFM"
199 -- #define EmptyFM (Branch _ _ IF_GHC(0#,0) _ _)
201 unitFM key elt = Branch key elt IF_GHC(1#,1) emptyFM emptyFM
203 listToFM = addListToFM emptyFM
205 bagToFM = foldrBag (\(k,v) fm -> addToFM fm k v) emptyFM
208 %************************************************************************
210 \subsection{Adding to and deleting from @FiniteMaps@}
212 %************************************************************************
215 addToFM fm key elt = addToFM_C (\ old new -> new) fm key elt
217 addToFM_C combiner EmptyFM key elt = unitFM key elt
218 addToFM_C combiner (Branch key elt size fm_l fm_r) new_key new_elt
219 = case compare new_key key of
220 LT -> mkBalBranch key elt (addToFM_C combiner fm_l new_key new_elt) fm_r
221 GT -> mkBalBranch key elt fm_l (addToFM_C combiner fm_r new_key new_elt)
222 EQ -> Branch new_key (combiner elt new_elt) size fm_l fm_r
224 addListToFM fm key_elt_pairs = addListToFM_C (\ old new -> new) fm key_elt_pairs
226 addListToFM_C combiner fm key_elt_pairs
227 = foldl' add fm key_elt_pairs -- foldl adds from the left
229 add fmap (key,elt) = addToFM_C combiner fmap key elt
233 delFromFM EmptyFM del_key = emptyFM
234 delFromFM (Branch key elt size fm_l fm_r) del_key
235 = case compare del_key key of
236 GT -> mkBalBranch key elt fm_l (delFromFM fm_r del_key)
237 LT -> mkBalBranch key elt (delFromFM fm_l del_key) fm_r
238 EQ -> glueBal fm_l fm_r
240 delListFromFM fm keys = foldl' delFromFM fm keys
243 %************************************************************************
245 \subsection{Combining @FiniteMaps@}
247 %************************************************************************
250 plusFM_C combiner EmptyFM fm2 = fm2
251 plusFM_C combiner fm1 EmptyFM = fm1
252 plusFM_C combiner fm1 (Branch split_key elt2 _ left right)
253 = mkVBalBranch split_key new_elt
254 (plusFM_C combiner lts left)
255 (plusFM_C combiner gts right)
257 lts = splitLT fm1 split_key
258 gts = splitGT fm1 split_key
259 new_elt = case lookupFM fm1 split_key of
261 Just elt1 -> combiner elt1 elt2
263 -- It's worth doing plusFM specially, because we don't need
264 -- to do the lookup in fm1.
265 -- FM2 over-rides FM1.
267 plusFM EmptyFM fm2 = fm2
268 plusFM fm1 EmptyFM = fm1
269 plusFM fm1 (Branch split_key elt1 _ left right)
270 = mkVBalBranch split_key elt1 (plusFM lts left) (plusFM gts right)
272 lts = splitLT fm1 split_key
273 gts = splitGT fm1 split_key
275 minusFM EmptyFM fm2 = emptyFM
276 minusFM fm1 EmptyFM = fm1
277 minusFM fm1 (Branch split_key elt _ left right)
278 = glueVBal (minusFM lts left) (minusFM gts right)
279 -- The two can be way different, so we need glueVBal
281 lts = splitLT fm1 split_key -- NB gt and lt, so the equal ones
282 gts = splitGT fm1 split_key -- are not in either.
284 intersectFM fm1 fm2 = intersectFM_C (\ left right -> right) fm1 fm2
286 intersectFM_C combiner fm1 EmptyFM = emptyFM
287 intersectFM_C combiner EmptyFM fm2 = emptyFM
288 intersectFM_C combiner fm1 (Branch split_key elt2 _ left right)
290 | maybeToBool maybe_elt1 -- split_elt *is* in intersection
291 = mkVBalBranch split_key (combiner elt1 elt2) (intersectFM_C combiner lts left)
292 (intersectFM_C combiner gts right)
294 | otherwise -- split_elt is *not* in intersection
295 = glueVBal (intersectFM_C combiner lts left) (intersectFM_C combiner gts right)
298 lts = splitLT fm1 split_key -- NB gt and lt, so the equal ones
299 gts = splitGT fm1 split_key -- are not in either.
301 maybe_elt1 = lookupFM fm1 split_key
302 Just elt1 = maybe_elt1
305 %************************************************************************
307 \subsection{Mapping, folding, and filtering with @FiniteMaps@}
309 %************************************************************************
312 foldFM k z EmptyFM = z
313 foldFM k z (Branch key elt _ fm_l fm_r)
314 = foldFM k (k key elt (foldFM k z fm_r)) fm_l
316 mapFM f EmptyFM = emptyFM
317 mapFM f (Branch key elt size fm_l fm_r)
318 = Branch key (f key elt) size (mapFM f fm_l) (mapFM f fm_r)
320 filterFM p EmptyFM = emptyFM
321 filterFM p (Branch key elt _ fm_l fm_r)
322 | p key elt -- Keep the item
323 = mkVBalBranch key elt (filterFM p fm_l) (filterFM p fm_r)
325 | otherwise -- Drop the item
326 = glueVBal (filterFM p fm_l) (filterFM p fm_r)
329 %************************************************************************
331 \subsection{Interrogating @FiniteMaps@}
333 %************************************************************************
336 --{-# INLINE sizeFM #-}
338 sizeFM (Branch _ _ size _ _) = IF_GHC(I# size, size)
340 isEmptyFM fm = sizeFM fm == 0
342 lookupFM EmptyFM key = Nothing
343 lookupFM (Branch key elt _ fm_l fm_r) key_to_find
344 = case compare key_to_find key of
345 LT -> lookupFM fm_l key_to_find
346 GT -> lookupFM fm_r key_to_find
350 = case (lookupFM fm key) of { Nothing -> False; Just elt -> True }
352 lookupWithDefaultFM fm deflt key
353 = case (lookupFM fm key) of { Nothing -> deflt; Just elt -> elt }
356 %************************************************************************
358 \subsection{Listifying @FiniteMaps@}
360 %************************************************************************
363 fmToList fm = foldFM (\ key elt rest -> (key,elt) : rest) [] fm
364 keysFM fm = foldFM (\ key elt rest -> key : rest) [] fm
365 eltsFM fm = foldFM (\ key elt rest -> elt : rest) [] fm
369 %************************************************************************
371 \subsection{The implementation of balancing}
373 %************************************************************************
375 %************************************************************************
377 \subsubsection{Basic construction of a @FiniteMap@}
379 %************************************************************************
381 @mkBranch@ simply gets the size component right. This is the ONLY
382 (non-trivial) place the Branch object is built, so the ASSERTion
383 recursively checks consistency. (The trivial use of Branch is in
390 mkBranch :: (Ord key OUTPUTABLE_key) -- Used for the assertion checking only
393 -> FiniteMap key elt -> FiniteMap key elt
396 mkBranch which key elt fm_l fm_r
397 = --ASSERT( left_ok && right_ok && balance_ok )
398 #if defined(DEBUG_FINITEMAPS)
399 if not ( left_ok && right_ok && balance_ok ) then
400 pprPanic ("mkBranch:"++show which) (vcat [ppr [left_ok, right_ok, balance_ok],
407 result = Branch key elt (unbox (1 + left_size + right_size)) fm_l fm_r
409 -- if sizeFM result <= 8 then
412 -- pprTrace ("mkBranch:"++(show which)) (ppr result) (
416 left_ok = case fm_l of
418 Branch left_key _ _ _ _ -> let
419 biggest_left_key = fst (findMax fm_l)
421 biggest_left_key < key
422 right_ok = case fm_r of
424 Branch right_key _ _ _ _ -> let
425 smallest_right_key = fst (findMin fm_r)
427 key < smallest_right_key
428 balance_ok = True -- sigh
431 = -- Both subtrees have one or no elements...
432 (left_size + right_size <= 1)
433 -- NO || left_size == 0 -- ???
434 -- NO || right_size == 0 -- ???
435 -- ... or the number of elements in a subtree does not exceed
436 -- sIZE_RATIO times the number of elements in the other subtree
437 || (left_size * sIZE_RATIO >= right_size &&
438 right_size * sIZE_RATIO >= left_size)
441 left_size = sizeFM fm_l
442 right_size = sizeFM fm_r
444 #ifdef __GLASGOW_HASKELL__
446 unbox (I# size) = size
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 -- Other case impossible
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 -- Other case impossible
487 | otherwise -- No imbalance
488 = mkBranch 2{-which-} key elt fm_L fm_R
494 single_L fm_l (Branch key_r elt_r _ fm_rl fm_rr)
495 = mkBranch 3{-which-} key_r elt_r (mkBranch 4{-which-} key elt fm_l fm_rl) fm_rr
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 (mkBranch 6{-which-} key elt fm_l fm_rll)
499 (mkBranch 7{-which-} key_r elt_r fm_rlr fm_rr)
501 single_R (Branch key_l elt_l _ fm_ll fm_lr) fm_r
502 = mkBranch 8{-which-} key_l elt_l fm_ll (mkBranch 9{-which-} key elt fm_lr fm_r)
504 double_R (Branch key_l elt_l _ fm_ll (Branch key_lr elt_lr _ fm_lrl fm_lrr)) fm_r
505 = mkBranch 10{-which-} key_lr elt_lr (mkBranch 11{-which-} key_l elt_l fm_ll fm_lrl)
506 (mkBranch 12{-which-} key elt fm_lrr fm_r)
511 mkVBalBranch :: (Ord key OUTPUTABLE_key)
513 -> FiniteMap key elt -> FiniteMap key elt
516 -- Assert: in any call to (mkVBalBranch_C comb key elt l r),
517 -- (a) all keys in l are < all keys in r
518 -- (b) all keys in l are < key
519 -- (c) all keys in r are > key
521 mkVBalBranch key elt EmptyFM fm_r = addToFM fm_r key elt
522 mkVBalBranch key elt fm_l EmptyFM = addToFM fm_l key elt
524 mkVBalBranch key elt fm_l@(Branch key_l elt_l _ fm_ll fm_lr)
525 fm_r@(Branch key_r elt_r _ fm_rl fm_rr)
526 | sIZE_RATIO * size_l < size_r
527 = mkBalBranch key_r elt_r (mkVBalBranch key elt fm_l fm_rl) fm_rr
529 | sIZE_RATIO * size_r < size_l
530 = mkBalBranch key_l elt_l fm_ll (mkVBalBranch key elt fm_lr fm_r)
533 = mkBranch 13{-which-} key elt fm_l fm_r
540 %************************************************************************
542 \subsubsection{Gluing two trees together}
544 %************************************************************************
546 @glueBal@ assumes its two arguments aren't too far out of whack, just
547 like @mkBalBranch@. But: all keys in first arg are $<$ all keys in
551 glueBal :: (Ord key OUTPUTABLE_key)
552 => FiniteMap key elt -> FiniteMap key elt
555 glueBal EmptyFM fm2 = fm2
556 glueBal fm1 EmptyFM = fm1
558 -- The case analysis here (absent in Adams' program) is really to deal
559 -- with the case where fm2 is a singleton. Then deleting the minimum means
560 -- we pass an empty tree to mkBalBranch, which breaks its invariant.
561 | sizeFM fm2 > sizeFM fm1
562 = mkBalBranch mid_key2 mid_elt2 fm1 (deleteMin fm2)
565 = mkBalBranch mid_key1 mid_elt1 (deleteMax fm1) fm2
567 (mid_key1, mid_elt1) = findMax fm1
568 (mid_key2, mid_elt2) = findMin fm2
571 @glueVBal@ copes with arguments which can be of any size.
572 But: all keys in first arg are $<$ all keys in second.
575 glueVBal :: (Ord key OUTPUTABLE_key)
576 => FiniteMap key elt -> FiniteMap key elt
579 glueVBal EmptyFM fm2 = fm2
580 glueVBal fm1 EmptyFM = fm1
581 glueVBal fm_l@(Branch key_l elt_l _ fm_ll fm_lr)
582 fm_r@(Branch key_r elt_r _ fm_rl fm_rr)
583 | sIZE_RATIO * size_l < size_r
584 = mkBalBranch key_r elt_r (glueVBal fm_l fm_rl) fm_rr
586 | sIZE_RATIO * size_r < size_l
587 = mkBalBranch key_l elt_l fm_ll (glueVBal fm_lr fm_r)
589 | otherwise -- We now need the same two cases as in glueBal above.
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,
657 -- and when not debugging the package itself...
658 instance (Outputable key, Outputable elt) => Outputable (FiniteMap key elt) where
659 ppr fm = ppr (fmToList fm)
663 instance (Eq key, Eq elt) => Eq (FiniteMap key elt) where
664 fm_1 == fm_2 = (sizeFM fm_1 == sizeFM fm_2) && -- quick test
665 (fmToList fm_1 == fmToList fm_2)
667 {- NO: not clear what The Right Thing to do is:
668 instance (Ord key, Ord elt) => Ord (FiniteMap key elt) where
669 fm_1 <= fm_2 = (sizeFM fm_1 <= sizeFM fm_2) && -- quick test
670 (fmToList fm_1 <= fmToList fm_2)
675 %************************************************************************
677 \subsection{Efficiency pragmas for GHC}
679 %************************************************************************
681 When the FiniteMap module is used in GHC, we specialise it for
682 \tr{Uniques}, for dastardly efficiency reasons.
687 #if __GLASGOW_HASKELL__
689 {-# SPECIALIZE addListToFM
690 :: FiniteMap (FastString, FAST_STRING) elt -> [((FAST_STRING, FAST_STRING),elt)] -> FiniteMap (FAST_STRING, FAST_STRING) elt
691 , FiniteMap RdrName elt -> [(RdrName,elt)] -> FiniteMap RdrName elt
692 IF_NCG(COMMA FiniteMap Reg elt -> [(Reg COMMA elt)] -> FiniteMap Reg elt)
694 {-# SPECIALIZE addListToFM_C
695 :: (elt -> elt -> elt) -> FiniteMap TyCon elt -> [(TyCon,elt)] -> FiniteMap TyCon elt
696 , (elt -> elt -> elt) -> FiniteMap FastString elt -> [(FAST_STRING,elt)] -> FiniteMap FAST_STRING elt
697 IF_NCG(COMMA (elt -> elt -> elt) -> FiniteMap Reg elt -> [(Reg COMMA elt)] -> FiniteMap Reg elt)
699 {-# SPECIALIZE addToFM
700 :: FiniteMap CLabel elt -> CLabel -> elt -> FiniteMap CLabel elt
701 , FiniteMap FastString elt -> FAST_STRING -> elt -> FiniteMap FAST_STRING elt
702 , FiniteMap (FastString, FAST_STRING) elt -> (FAST_STRING, FAST_STRING) -> elt -> FiniteMap (FAST_STRING, FAST_STRING) elt
703 , FiniteMap RdrName elt -> RdrName -> elt -> FiniteMap RdrName elt
704 IF_NCG(COMMA FiniteMap Reg elt -> Reg -> elt -> FiniteMap Reg elt)
706 {-# SPECIALIZE addToFM_C
707 :: (elt -> elt -> elt) -> FiniteMap (RdrName, RdrName) elt -> (RdrName, RdrName) -> elt -> FiniteMap (RdrName, RdrName) elt
708 , (elt -> elt -> elt) -> FiniteMap FastString elt -> FAST_STRING -> elt -> FiniteMap FAST_STRING elt
709 IF_NCG(COMMA (elt -> elt -> elt) -> FiniteMap Reg elt -> Reg -> elt -> FiniteMap Reg elt)
711 {-# SPECIALIZE bagToFM
712 :: Bag (FastString,elt) -> FiniteMap FAST_STRING elt
714 {-# SPECIALIZE delListFromFM
715 :: FiniteMap RdrName elt -> [RdrName] -> FiniteMap RdrName elt
716 , FiniteMap FastString elt -> [FAST_STRING] -> FiniteMap FAST_STRING elt
717 IF_NCG(COMMA FiniteMap Reg elt -> [Reg] -> FiniteMap Reg elt)
719 {-# SPECIALIZE listToFM
720 :: [([Char],elt)] -> FiniteMap [Char] elt
721 , [(FastString,elt)] -> FiniteMap FAST_STRING elt
722 , [((FastString,FAST_STRING),elt)] -> FiniteMap (FAST_STRING, FAST_STRING) elt
723 IF_NCG(COMMA [(Reg COMMA elt)] -> FiniteMap Reg elt)
725 {-# SPECIALIZE lookupFM
726 :: FiniteMap CLabel elt -> CLabel -> Maybe elt
727 , FiniteMap [Char] elt -> [Char] -> Maybe elt
728 , FiniteMap FastString elt -> FAST_STRING -> Maybe elt
729 , FiniteMap (FastString,FAST_STRING) elt -> (FAST_STRING,FAST_STRING) -> Maybe elt
730 , FiniteMap RdrName elt -> RdrName -> Maybe elt
731 , FiniteMap (RdrName,RdrName) elt -> (RdrName,RdrName) -> Maybe elt
732 IF_NCG(COMMA FiniteMap Reg elt -> Reg -> Maybe elt)
734 {-# SPECIALIZE lookupWithDefaultFM
735 :: FiniteMap FastString elt -> elt -> FAST_STRING -> elt
736 IF_NCG(COMMA FiniteMap Reg elt -> elt -> Reg -> elt)
738 {-# SPECIALIZE plusFM
739 :: FiniteMap RdrName elt -> FiniteMap RdrName elt -> FiniteMap RdrName elt
740 , FiniteMap FastString elt -> FiniteMap FAST_STRING elt -> FiniteMap FAST_STRING elt
741 IF_NCG(COMMA FiniteMap Reg elt -> FiniteMap Reg elt -> FiniteMap Reg elt)
743 {-# SPECIALIZE plusFM_C
744 :: (elt -> elt -> elt) -> FiniteMap FastString elt -> FiniteMap FAST_STRING elt -> FiniteMap FAST_STRING elt
745 IF_NCG(COMMA (elt -> elt -> elt) -> FiniteMap Reg elt -> FiniteMap Reg elt -> FiniteMap Reg elt)
748 #endif /* compiling with ghc and have specialiser */