-couldBeSmallEnoughToInline :: Int -> Int -- Constructor discount and size threshold
- -> UnfoldingGuidance
- -> Bool -- True => unfold it
-
-couldBeSmallEnoughToInline con_discount size_threshold guidance
- = smallEnoughToInline con_discount size_threshold (repeat True) guidance
-\end{code}
-
-%************************************************************************
-%* *
-\subsection[unfoldings-for-ifaces]{Processing unfoldings for interfaces}
-%* *
-%************************************************************************
-
-Of course, the main thing we do to unfoldings-for-interfaces is {\em
-print} them. But, while we're at it, we collect info about
-``mentioned'' Ids, etc., etc.---we're going to need this stuff anyway.
-
-%************************************************************************
-%* *
-\subsubsection{Monad stuff for the unfolding-generation game}
-%* *
-%************************************************************************
-
-\begin{code}
-type UnfoldM bndr thing
- = IdSet -- in-scope Ids (passed downwards only)
- -> (bndr -> Id) -- to extract an Id from a binder (down only)
-
- -> (Bag Id, -- mentioned global vars (ditto)
- Bag TyCon, -- ditto, tycons
- Bag Class, -- ditto, classes
- Bool) -- True <=> mentions something litlit-ish
-
- -> (thing, (Bag Id, Bag TyCon, Bag Class, Bool)) -- accumulated...
-\end{code}
-
-A little stuff for in-scopery:
-\begin{code}
-no_in_scopes :: IdSet
-add1 :: IdSet -> Id -> IdSet
-add_some :: IdSet -> [Id] -> IdSet
-
-no_in_scopes = emptyUniqSet
-in_scopes `add1` x = addOneToUniqSet in_scopes x
-in_scopes `add_some` xs = in_scopes `unionUniqSets` mkUniqSet xs
-\end{code}
-
-The can-see-inside-monad functions are the usual sorts of things.
-
-\begin{code}
-thenUf :: UnfoldM bndr a -> (a -> UnfoldM bndr b) -> UnfoldM bndr b
-thenUf m k in_scopes get_id mentioneds
- = case m in_scopes get_id mentioneds of { (v, mentioneds1) ->
- k v in_scopes get_id mentioneds1 }
-
-thenUf_ :: UnfoldM bndr a -> UnfoldM bndr b -> UnfoldM bndr b
-thenUf_ m k in_scopes get_id mentioneds
- = case m in_scopes get_id mentioneds of { (_, mentioneds1) ->
- k in_scopes get_id mentioneds1 }
-
-mapUf :: (a -> UnfoldM bndr b) -> [a] -> UnfoldM bndr [b]
-mapUf f [] = returnUf []
-mapUf f (x:xs)
- = f x `thenUf` \ r ->
- mapUf f xs `thenUf` \ rs ->
- returnUf (r:rs)
-
-returnUf :: a -> UnfoldM bndr a
-returnUf v in_scopes get_id mentioneds = (v, mentioneds)
-
-addInScopesUf :: [Id] -> UnfoldM bndr a -> UnfoldM bndr a
-addInScopesUf more_in_scopes m in_scopes get_id mentioneds
- = m (in_scopes `add_some` more_in_scopes) get_id mentioneds
-
-getInScopesUf :: UnfoldM bndr IdSet
-getInScopesUf in_scopes get_id mentioneds = (in_scopes, mentioneds)
-
-extractIdsUf :: [bndr] -> UnfoldM bndr [Id]
-extractIdsUf binders in_scopes get_id mentioneds
- = (map get_id binders, mentioneds)
-
-consider_Id :: Id -> UnfoldM bndr ()
-consider_Id var in_scopes get_id (ids, tcs, clss, has_litlit)
- = let
- (ids2, tcs2, clss2) = whatsMentionedInId in_scopes var
- in
- ((), (ids `unionBags` ids2,
- tcs `unionBags` tcs2,
- clss `unionBags`clss2,
- has_litlit))
-\end{code}
-
-\begin{code}
-addToMentionedIdsUf :: Id -> UnfoldM bndr ()
-addToMentionedTyConsUf :: Bag TyCon -> UnfoldM bndr ()
-addToMentionedClassesUf :: Bag Class -> UnfoldM bndr ()
-litlit_oops :: UnfoldM bndr ()
-
-addToMentionedIdsUf add_me in_scopes get_id (ids, tcs, clss, has_litlit)
- = ((), (ids `unionBags` unitBag add_me, tcs, clss, has_litlit))
-
-addToMentionedTyConsUf add_mes in_scopes get_id (ids, tcs, clss, has_litlit)
- = ((), (ids, tcs `unionBags` add_mes, clss, has_litlit))
-
-addToMentionedClassesUf add_mes in_scopes get_id (ids, tcs, clss, has_litlit)
- = ((), (ids, tcs, clss `unionBags` add_mes, has_litlit))
-
-litlit_oops in_scopes get_id (ids, tcs, clss, _)
- = ((), (ids, tcs, clss, True))