2 % (c) The AQUA Project, Glasgow University, 1994-1996
4 \section[CoreUnfold]{Core-syntax unfoldings}
6 Unfoldings (which can travel across module boundaries) are in Core
7 syntax (namely @CoreExpr@s).
9 The type @UnfoldingDetails@ sits ``above'' simply-Core-expressions
10 unfoldings, capturing ``higher-level'' things we know about a binding,
11 usually things that the simplifier found out (e.g., ``it's a
12 literal''). In the corner of a @GenForm@ unfolding, you will
13 find, unsurprisingly, a Core expression.
16 #include "HsVersions.h"
19 UnfoldingDetails(..), UnfoldingGuidance(..), -- types
25 modifyUnfoldingDetails,
26 calcUnfoldingGuidance,
31 import IdLoop -- for paranoia checking;
32 -- and also to get mkMagicUnfoldingFun
33 import PrelLoop -- for paranoia checking
35 import Bag ( emptyBag, unitBag, unionBags, Bag )
36 import BinderInfo ( oneTextualOcc, oneSafeOcc )
37 import CgCompInfo ( uNFOLDING_CHEAP_OP_COST,
38 uNFOLDING_DEAR_OP_COST,
39 uNFOLDING_NOREP_LIT_COST
42 import CoreUtils ( coreExprType, manifestlyWHNF )
43 import CostCentre ( ccMentionsId )
44 import Id ( IdSet(..), GenId{-instances-} )
45 import IdInfo ( bottomIsGuaranteed )
46 import Literal ( isNoRepLit, isLitLitLit )
48 import PrimOp ( primOpCanTriggerGC, PrimOp(..) )
49 import TyCon ( tyConFamilySize )
50 import Type ( getAppDataTyCon )
51 import UniqSet ( emptyUniqSet, unitUniqSet, mkUniqSet,
52 addOneToUniqSet, unionUniqSets
54 import Usage ( UVar(..) )
55 import Util ( isIn, panic )
57 whatsMentionedInId = panic "whatsMentionedInId (CoreUnfold)"
58 getMentionedTyConsAndClassesFromType = panic "getMentionedTyConsAndClassesFromType (CoreUnfold)"
61 %************************************************************************
63 \subsection{@UnfoldingDetails@ and @UnfoldingGuidance@ types}
65 %************************************************************************
67 (And @FormSummary@, too.)
77 [Literal] -- It is a literal, but definitely not one of these
81 [CoreArg] -- Value arguments; NB OutArgs, already cloned
84 [Id] -- It definitely isn't one of these constructors
85 -- This captures the situation in the default branch of
90 -- Then in default-rhs we know that v isn't c1 or c2.
92 -- NB. In the degenerate: case x of {v -> default-rhs}
95 -- which captures the idea that x is eval'd but we don't
96 -- know which constructor.
100 Bool -- True <=> At most one textual occurrence of the
101 -- binder in its scope, *or*
102 -- if we are happy to duplicate this
104 FormSummary -- Tells whether the template is a WHNF or bottom
105 TemplateOutExpr -- The template
106 UnfoldingGuidance -- Tells about the *size* of the template.
109 Unique -- of the Id whose magic unfolding this is
112 type TemplateOutExpr = GenCoreExpr (Id, BinderInfo) Id TyVar UVar
113 -- An OutExpr with occurrence info attached. This is used as
114 -- a template in GeneralForms.
116 mkMagicUnfolding :: Unique -> UnfoldingDetails
117 mkMagicUnfolding tag = MagicForm tag (mkMagicUnfoldingFun tag)
120 = WhnfForm -- Expression is WHNF
121 | BottomForm -- Expression is guaranteed to be bottom. We're more gung
122 -- ho about inlining such things, because it can't waste work
123 | OtherForm -- Anything else
125 instance Outputable FormSummary where
126 ppr sty WhnfForm = ppStr "WHNF"
127 ppr sty BottomForm = ppStr "Bot"
128 ppr sty OtherForm = ppStr "Other"
130 --???mkFormSummary :: StrictnessInfo -> GenCoreExpr bndr Id -> FormSummary
131 mkFormSummary si expr
132 | manifestlyWHNF expr = WhnfForm
133 | bottomIsGuaranteed si = BottomForm
135 -- Chances are that the Id will be decorated with strictness info
136 -- telling that the RHS is definitely bottom. This *might* not be the
137 -- case, if it's been a while since strictness analysis, but leaving out
138 -- the test for manifestlyBottom makes things a little more efficient.
139 -- We can always put it back...
140 -- | manifestlyBottom expr = BottomForm
142 | otherwise = OtherForm
146 data UnfoldingGuidance
147 = UnfoldNever -- Don't do it!
149 | UnfoldAlways -- There is no "original" definition,
150 -- so you'd better unfold. Or: something
151 -- so cheap to unfold (e.g., 1#) that
152 -- you should do it absolutely always.
154 | EssentialUnfolding -- Like UnfoldAlways, but you *must* do
155 -- it absolutely always.
156 -- This is what we use for data constructors
157 -- and PrimOps, because we don't feel like
158 -- generating curried versions "just in case".
160 | UnfoldIfGoodArgs Int -- if "m" type args and "n" value args; and
161 Int -- those val args are manifestly data constructors
162 [Bool] -- the val-arg positions marked True
163 -- (i.e., a simplification will definitely
165 Int -- The "size" of the unfolding; to be elaborated
168 | BadUnfolding -- This is used by TcPragmas if the *lazy*
169 -- lintUnfolding test fails
170 -- It will never escape from the IdInfo as
171 -- it is caught by getInfo_UF and converted
172 -- to NoUnfoldingDetails
176 instance Outputable UnfoldingGuidance where
177 ppr sty UnfoldNever = ppStr "_N_"
178 ppr sty UnfoldAlways = ppStr "_ALWAYS_"
179 ppr sty EssentialUnfolding = ppStr "_ESSENTIAL_" -- shouldn't appear in an iface
180 ppr sty (UnfoldIfGoodArgs t v cs size)
181 = ppCat [ppStr "_IF_ARGS_", ppInt t, ppInt v,
182 if null cs -- always print *something*
184 else ppBesides (map pp_c cs),
187 pp_c False = ppChar 'X'
188 pp_c True = ppChar 'C'
192 %************************************************************************
194 \subsection{@mkGenForm@ and @modifyUnfoldingDetails@}
196 %************************************************************************
199 mkGenForm :: Bool -- Ok to Dup code down different case branches,
200 -- because of either a flag saying so,
201 -- or alternatively the object is *SMALL*
204 -> TemplateOutExpr -- Template
205 -> UnfoldingGuidance -- Tells about the *size* of the template.
208 mkGenForm safe_to_dup occ_info WhnfForm template guidance
209 = GenForm (oneTextualOcc safe_to_dup occ_info) WhnfForm template guidance
211 mkGenForm safe_to_dup occ_info form_summary template guidance
212 | oneSafeOcc safe_to_dup occ_info -- Non-WHNF with only safe occurrences
213 = GenForm True form_summary template guidance
215 | otherwise -- Not a WHNF, many occurrences
220 modifyUnfoldingDetails
222 -> BinderInfo -- New occurrence info for the thing
226 modifyUnfoldingDetails ok_to_dup occ_info
227 (GenForm only_one form_summary template guidance)
228 | only_one = mkGenForm ok_to_dup occ_info form_summary template guidance
230 modifyUnfoldingDetails ok_to_dup occ_info other = other
234 %************************************************************************
236 \subsection[calcUnfoldingGuidance]{Calculate ``unfolding guidance'' for an expression}
238 %************************************************************************
241 calcUnfoldingGuidance
242 :: Bool -- True <=> OK if _scc_s appear in expr
243 -> Int -- bomb out if size gets bigger than this
244 -> CoreExpr -- expression to look at
247 calcUnfoldingGuidance scc_s_OK bOMB_OUT_SIZE expr
249 (use_binders, ty_binders, val_binders, body) = collectBinders expr
251 case (sizeExpr scc_s_OK bOMB_OUT_SIZE val_binders body) of
253 Nothing -> UnfoldNever
255 Just (size, cased_args)
257 uf = UnfoldIfGoodArgs
260 [ b `is_elem` cased_args | b <- val_binders ]
263 -- pprTrace "calcUnfold:" (ppAbove (ppr PprDebug uf) (ppr PprDebug expr))
266 is_elem = isIn "calcUnfoldingGuidance"
270 sizeExpr :: Bool -- True <=> _scc_s OK
271 -> Int -- Bomb out if it gets bigger than this
272 -> [Id] -- Arguments; we're interested in which of these
275 -> Maybe (Int, -- Size
276 [Id] -- Subset of args which are cased
279 sizeExpr scc_s_OK bOMB_OUT_SIZE args expr
282 size_up (Var v) = sizeOne
283 size_up (App fun arg) = size_up fun `addSize` size_up_arg arg
284 size_up (Lit lit) = if isNoRepLit lit
285 then sizeN uNFOLDING_NOREP_LIT_COST
288 size_up (SCC _ (Con _ _)) = Nothing -- **** HACK *****
289 size_up (SCC lbl body)
290 = if scc_s_OK then size_up body else Nothing
292 size_up (Con con args) = -- 1 + # of val args
293 sizeN (1 + numValArgs args)
294 size_up (Prim op args) = sizeN op_cost -- NB: no charge for PrimOp args
296 op_cost = if primOpCanTriggerGC op
297 then uNFOLDING_DEAR_OP_COST
298 -- these *tend* to be more expensive;
299 -- number chosen to avoid unfolding (HACK)
300 else uNFOLDING_CHEAP_OP_COST
302 size_up expr@(Lam _ _)
304 (uvars, tyvars, args, body) = collectBinders expr
306 size_up body `addSizeN` length args
308 size_up (Let (NonRec binder rhs) body)
315 size_up (Let (Rec pairs) body)
316 = foldr addSize sizeZero [size_up rhs | (_,rhs) <- pairs]
322 size_up (Case scrut alts)
323 = size_up_scrut scrut
325 size_up_alts (coreExprType scrut) alts
326 -- We charge for the "case" itself in "size_up_alts"
329 size_up_arg arg = if isValArg arg then sizeOne else sizeZero{-it's free-}
332 size_up_alts scrut_ty (AlgAlts alts deflt)
333 = foldr (addSize . size_alg_alt) (size_up_deflt deflt) alts
334 `addSizeN` (tyConFamilySize tycon)
335 -- NB: we charge N for an alg. "case", where N is
336 -- the number of constructors in the thing being eval'd.
337 -- (You'll eventually get a "discount" of N if you
338 -- think the "case" is likely to go away.)
340 size_alg_alt (con,args,rhs) = size_up rhs
341 -- Don't charge for args, so that wrappers look cheap
343 (tycon, _, _) = getAppDataTyCon scrut_ty
345 size_up_alts _ (PrimAlts alts deflt)
346 = foldr (addSize . size_prim_alt) (size_up_deflt deflt) alts
347 -- *no charge* for a primitive "case"!
349 size_prim_alt (lit,rhs) = size_up rhs
352 size_up_deflt NoDefault = sizeZero
353 size_up_deflt (BindDefault binder rhs) = size_up rhs
356 -- Scrutinees. There are two things going on here.
357 -- First, we want to record if we're case'ing an argument
358 -- Second, we want to charge nothing for the srutinee if it's just
359 -- a variable. That way wrapper-like things look cheap.
360 size_up_scrut (Var v) | v `is_elem` args = Just (0, [v])
361 | otherwise = Just (0, [])
362 size_up_scrut other = size_up other
364 is_elem :: Id -> [Id] -> Bool
365 is_elem = isIn "size_up_scrut"
368 sizeZero = Just (0, [])
369 sizeOne = Just (1, [])
370 sizeN n = Just (n, [])
371 sizeVar v = Just (0, [v])
373 addSizeN Nothing _ = Nothing
374 addSizeN (Just (n, xs)) m
375 | tot < bOMB_OUT_SIZE = Just (tot, xs)
376 | otherwise = Nothing
380 addSize Nothing _ = Nothing
381 addSize _ Nothing = Nothing
382 addSize (Just (n, xs)) (Just (m, ys))
383 | tot < bOMB_OUT_SIZE = Just (tot, xys)
384 | otherwise = Nothing
390 %************************************************************************
392 \subsection[unfoldings-for-ifaces]{Processing unfoldings for interfaces}
394 %************************************************************************
396 Of course, the main thing we do to unfoldings-for-interfaces is {\em
397 print} them. But, while we're at it, we collect info about
398 ``mentioned'' Ids, etc., etc.---we're going to need this stuff anyway.
400 %************************************************************************
402 \subsubsection{Monad stuff for the unfolding-generation game}
404 %************************************************************************
407 type UnfoldM bndr thing
408 = IdSet -- in-scope Ids (passed downwards only)
409 -> (bndr -> Id) -- to extract an Id from a binder (down only)
411 -> (Bag Id, -- mentioned global vars (ditto)
412 Bag TyCon, -- ditto, tycons
413 Bag Class, -- ditto, classes
414 Bool) -- True <=> mentions something litlit-ish
416 -> (thing, (Bag Id, Bag TyCon, Bag Class, Bool)) -- accumulated...
419 A little stuff for in-scopery:
421 no_in_scopes :: IdSet
422 add1 :: IdSet -> Id -> IdSet
423 add_some :: IdSet -> [Id] -> IdSet
425 no_in_scopes = emptyUniqSet
426 in_scopes `add1` x = addOneToUniqSet in_scopes x
427 in_scopes `add_some` xs = in_scopes `unionUniqSets` mkUniqSet xs
430 The can-see-inside-monad functions are the usual sorts of things.
433 thenUf :: UnfoldM bndr a -> (a -> UnfoldM bndr b) -> UnfoldM bndr b
434 thenUf m k in_scopes get_id mentioneds
435 = case m in_scopes get_id mentioneds of { (v, mentioneds1) ->
436 k v in_scopes get_id mentioneds1 }
438 thenUf_ :: UnfoldM bndr a -> UnfoldM bndr b -> UnfoldM bndr b
439 thenUf_ m k in_scopes get_id mentioneds
440 = case m in_scopes get_id mentioneds of { (_, mentioneds1) ->
441 k in_scopes get_id mentioneds1 }
443 mapUf :: (a -> UnfoldM bndr b) -> [a] -> UnfoldM bndr [b]
444 mapUf f [] = returnUf []
446 = f x `thenUf` \ r ->
447 mapUf f xs `thenUf` \ rs ->
450 returnUf :: a -> UnfoldM bndr a
451 returnUf v in_scopes get_id mentioneds = (v, mentioneds)
453 addInScopesUf :: [Id] -> UnfoldM bndr a -> UnfoldM bndr a
454 addInScopesUf more_in_scopes m in_scopes get_id mentioneds
455 = m (in_scopes `add_some` more_in_scopes) get_id mentioneds
457 getInScopesUf :: UnfoldM bndr IdSet
458 getInScopesUf in_scopes get_id mentioneds = (in_scopes, mentioneds)
460 extractIdsUf :: [bndr] -> UnfoldM bndr [Id]
461 extractIdsUf binders in_scopes get_id mentioneds
462 = (map get_id binders, mentioneds)
464 consider_Id :: Id -> UnfoldM bndr ()
465 consider_Id var in_scopes get_id (ids, tcs, clss, has_litlit)
467 (ids2, tcs2, clss2) = whatsMentionedInId in_scopes var
469 ((), (ids `unionBags` ids2,
470 tcs `unionBags` tcs2,
471 clss `unionBags`clss2,
476 addToMentionedIdsUf :: Id -> UnfoldM bndr ()
477 addToMentionedTyConsUf :: Bag TyCon -> UnfoldM bndr ()
478 addToMentionedClassesUf :: Bag Class -> UnfoldM bndr ()
479 litlit_oops :: UnfoldM bndr ()
481 addToMentionedIdsUf add_me in_scopes get_id (ids, tcs, clss, has_litlit)
482 = ((), (ids `unionBags` unitBag add_me, tcs, clss, has_litlit))
484 addToMentionedTyConsUf add_mes in_scopes get_id (ids, tcs, clss, has_litlit)
485 = ((), (ids, tcs `unionBags` add_mes, clss, has_litlit))
487 addToMentionedClassesUf add_mes in_scopes get_id (ids, tcs, clss, has_litlit)
488 = ((), (ids, tcs, clss `unionBags` add_mes, has_litlit))
490 litlit_oops in_scopes get_id (ids, tcs, clss, _)
491 = ((), (ids, tcs, clss, True))
495 %************************************************************************
497 \subsubsection{Gathering up info for an interface-unfolding}
499 %************************************************************************
504 :: (bndr -> Id) -- so we can get Ids out of binders
505 -> GenCoreExpr bndr Id -- input expression
506 -> (Bag Id, Bag TyCon, Bag Class,
507 -- what we found mentioned in the expr
508 Bool -- True <=> mentions a ``litlit''-ish thing
509 -- (the guy on the other side of an interface
510 -- may not be able to handle it)
514 mentionedInUnfolding get_id expr
515 = case (ment_expr expr no_in_scopes get_id (emptyBag, emptyBag, emptyBag, False)) of
516 (_, (ids_bag, tcs_bag, clss_bag, has_litlit)) ->
517 (ids_bag, tcs_bag, clss_bag, has_litlit)
521 --ment_expr :: GenCoreExpr bndr Id -> UnfoldM bndr ()
523 ment_expr (Var v) = consider_Id v
524 ment_expr (Lit l) = consider_lit l
526 ment_expr expr@(Lam _ _)
528 (uvars, tyvars, args, body) = collectBinders expr
530 extractIdsUf args `thenUf` \ bs_ids ->
531 addInScopesUf bs_ids (
532 -- this considering is just to extract any mentioned types/classes
533 mapUf consider_Id bs_ids `thenUf_`
537 ment_expr (App fun arg)
538 = ment_expr fun `thenUf_`
542 = consider_Id c `thenUf_`
543 mapUf ment_arg as `thenUf_`
546 ment_expr (Prim op as)
547 = ment_op op `thenUf_`
548 mapUf ment_arg as `thenUf_`
551 ment_op (CCallOp str is_asm may_gc arg_tys res_ty)
552 = mapUf ment_ty arg_tys `thenUf_`
554 ment_op other_op = returnUf ()
556 ment_expr (Case scrutinee alts)
557 = ment_expr scrutinee `thenUf_`
560 ment_expr (Let (NonRec bind rhs) body)
561 = ment_expr rhs `thenUf_`
562 extractIdsUf [bind] `thenUf` \ bi@[bind_id] ->
564 ment_expr body `thenUf_`
565 consider_Id bind_id )
567 ment_expr (Let (Rec pairs) body)
569 binders = map fst pairs
572 extractIdsUf binders `thenUf` \ binder_ids ->
573 addInScopesUf binder_ids (
574 mapUf ment_expr rhss `thenUf_`
575 mapUf consider_Id binder_ids `thenUf_`
578 ment_expr (SCC cc expr)
579 = (case (ccMentionsId cc) of
580 Just id -> consider_Id id
581 Nothing -> returnUf ()
583 `thenUf_` ment_expr expr
588 (tycons, clss) = getMentionedTyConsAndClassesFromType ty
590 addToMentionedTyConsUf tycons `thenUf_`
591 addToMentionedClassesUf clss
595 ment_alts alg_alts@(AlgAlts alts deflt)
596 = mapUf ment_alt alts `thenUf_`
599 ment_alt alt@(con, params, rhs)
600 = consider_Id con `thenUf_`
601 extractIdsUf params `thenUf` \ param_ids ->
602 addInScopesUf param_ids (
603 -- "consider" them so we can chk out their types...
604 mapUf consider_Id param_ids `thenUf_`
607 ment_alts (PrimAlts alts deflt)
608 = mapUf ment_alt alts `thenUf_`
611 ment_alt alt@(lit, rhs) = ment_expr rhs
617 ment_deflt d@(BindDefault b rhs)
618 = extractIdsUf [b] `thenUf` \ bi@[b_id] ->
620 consider_Id b_id `thenUf_`
624 ment_arg (VarArg v) = consider_Id v
625 ment_arg (LitArg l) = consider_lit l
626 ment_arg (TyArg ty) = ment_ty ty
627 ment_arg (UsageArg _) = returnUf ()
631 | isLitLitLit lit = litlit_oops `thenUf_` returnUf ()
632 | otherwise = returnUf ()
635 %************************************************************************
637 \subsubsection{Printing unfoldings in interfaces}
639 %************************************************************************
641 Printing Core-expression unfoldings is sufficiently delicate that we
642 give it its own function.
649 pprCoreUnfolding expr
651 (_, renamed) = instCoreExpr uniqSupply_u expr
652 -- We rename every unfolding with a "steady" unique supply,
653 -- so that the names won't constantly change.
654 -- One place we *MUST NOT* use a splittable UniqueSupply!
656 ppr_uf_Expr emptyUniqSet renamed
658 ppr_Unfolding = PprUnfolding (panic "CoreUnfold:ppr_Unfolding")
662 ppr_uf_Expr in_scopes (Var v) = pprIdInUnfolding in_scopes v
663 ppr_uf_Expr in_scopes (Lit l) = ppr ppr_Unfolding l
665 ppr_uf_Expr in_scopes (Con c as)
666 = ppBesides [ppPStr SLIT("_!_ "), pprIdInUnfolding no_in_scopes c, ppSP,
667 ppLbrack, ppIntersperse pp'SP{-'-} (map (pprParendUniType ppr_Unfolding) ts), ppRbrack,
668 ppSP, ppLbrack, ppIntersperse pp'SP{-'-} (map (ppr_uf_Atom in_scopes) as), ppRbrack]
669 ppr_uf_Expr in_scopes (Prim op as)
670 = ppBesides [ppPStr SLIT("_#_ "), ppr ppr_Unfolding op, ppSP,
671 ppLbrack, ppIntersperse pp'SP{-'-} (map (pprParendUniType ppr_Unfolding) ts), ppRbrack,
672 ppSP, ppLbrack, ppIntersperse pp'SP{-'-} (map (ppr_uf_Atom in_scopes) as), ppRbrack]
674 ppr_uf_Expr in_scopes (Lam binder body)
675 = ppCat [ppChar '\\', ppr_uf_Binder binder,
676 ppPStr SLIT("->"), ppr_uf_Expr (in_scopes `add1` binder) body]
678 ppr_uf_Expr in_scopes (CoTyLam tyvar expr)
679 = ppCat [ppPStr SLIT("_/\\_"), interppSP ppr_Unfolding (tyvar:tyvars), ppStr "->",
680 ppr_uf_Expr in_scopes body]
682 (tyvars, body) = collect_tyvars expr
684 collect_tyvars (CoTyLam tyv e) = ( tyv:tyvs, e_after )
685 where (tyvs, e_after) = collect_tyvars e
686 collect_tyvars other_e = ( [], other_e )
688 ppr_uf_Expr in_scopes expr@(App fun_expr atom)
690 (fun, args) = collect_args expr []
692 ppCat [ppPStr SLIT("_APP_ "), ppr_uf_Expr in_scopes fun, ppLbrack,
693 ppIntersperse pp'SP{-'-} (map (ppr_uf_Atom in_scopes) args), ppRbrack]
695 collect_args (App fun arg) args = collect_args fun (arg:args)
696 collect_args fun args = (fun, args)
698 ppr_uf_Expr in_scopes (CoTyApp expr ty)
699 = ppCat [ppPStr SLIT("_TYAPP_ "), ppr_uf_Expr in_scopes expr,
700 ppChar '{', pprParendUniType ppr_Unfolding ty, ppChar '}']
702 ppr_uf_Expr in_scopes (Case scrutinee alts)
703 = ppCat [ppPStr SLIT("case"), ppr_uf_Expr in_scopes scrutinee, ppStr "of {",
704 pp_alts alts, ppChar '}']
706 pp_alts (AlgAlts alts deflt)
707 = ppCat [ppPStr SLIT("_ALG_"), ppCat (map pp_alg alts), pp_deflt deflt]
708 pp_alts (PrimAlts alts deflt)
709 = ppCat [ppPStr SLIT("_PRIM_"), ppCat (map pp_prim alts), pp_deflt deflt]
711 pp_alg (con, params, rhs)
712 = ppBesides [pprIdInUnfolding no_in_scopes con, ppSP,
713 ppIntersperse ppSP (map ppr_uf_Binder params),
714 ppPStr SLIT(" -> "), ppr_uf_Expr (in_scopes `add_some` params) rhs, ppSemi]
717 = ppBesides [ppr ppr_Unfolding lit,
718 ppPStr SLIT(" -> "), ppr_uf_Expr in_scopes rhs, ppSemi]
720 pp_deflt NoDefault = ppPStr SLIT("_NO_DEFLT_")
721 pp_deflt (BindDefault binder rhs)
722 = ppBesides [ppr_uf_Binder binder, ppPStr SLIT(" -> "),
723 ppr_uf_Expr (in_scopes `add1` binder) rhs]
725 ppr_uf_Expr in_scopes (Let (NonRec binder rhs) body)
726 = ppBesides [ppStr "let {", ppr_uf_Binder binder, ppPStr SLIT(" = "), ppr_uf_Expr in_scopes rhs,
727 ppStr "} in ", ppr_uf_Expr (in_scopes `add1` binder) body]
729 ppr_uf_Expr in_scopes (Let (Rec pairs) body)
730 = ppBesides [ppStr "_LETREC_ {", ppIntersperse sep (map pp_pair pairs),
731 ppStr "} in ", ppr_uf_Expr new_in_scopes body]
733 sep = ppBeside ppSemi ppSP
734 new_in_scopes = in_scopes `add_some` map fst pairs
736 pp_pair (b, rhs) = ppCat [ppr_uf_Binder b, ppEquals, ppr_uf_Expr new_in_scopes rhs]
738 ppr_uf_Expr in_scopes (SCC cc body)
739 = ASSERT(not (noCostCentreAttached cc))
740 ASSERT(not (currentOrSubsumedCosts cc))
741 ppBesides [ppStr "_scc_ { ", ppStr (showCostCentre ppr_Unfolding False{-not as string-} cc), ppStr " } ", ppr_uf_Expr in_scopes body]
745 ppr_uf_Binder :: Id -> Pretty
747 = ppBesides [ppLparen, pprIdInUnfolding (unitUniqSet v) v, ppPStr SLIT(" :: "),
748 ppr ppr_Unfolding (idType v), ppRparen]
750 ppr_uf_Atom in_scopes (LitArg l) = ppr ppr_Unfolding l
751 ppr_uf_Atom in_scopes (VarArg v) = pprIdInUnfolding in_scopes v