2 % (c) The AQUA Project, Glasgow University, 1993-1996
4 \section[SimplEnv]{Environment stuff for the simplifier}
9 getEnvs, setTyEnv, setIdEnv, notInScope, setSubstEnvs, zapSubstEnvs,
10 emptySubstEnvs, getSubstEnvs,
12 bindTyVar, bindTyVars, simplTy,
14 lookupIdSubst, lookupOutIdEnv,
16 bindIdToAtom, bindIdToExpr,
19 lookupUnfolding, isEvaluated,
20 extendEnvGivenBinding, extendEnvGivenNewRhs,
21 extendEnvGivenUnfolding,
25 getSwitchChecker, switchIsSet, getSimplIntSwitch,
26 switchOffInlining, setCaseScrutinee,
28 setEnclosingCC, getEnclosingCC,
36 InId, InBinder, InBinding, InType,
37 OutId, OutBinder, OutBinding, OutType,
39 InExpr, InAlts, InDefault, InArg,
40 OutExpr, OutAlts, OutDefault, OutArg
43 #include "HsVersions.h"
45 import BinderInfo ( orBinderInfo, andBinderInfo, noBinderInfo, isOneOcc,
49 import CmdLineOpts ( switchIsOn, intSwitchSet, opt_UnfoldingCreationThreshold,
50 SimplifierSwitch(..), SwitchResult(..)
53 import CoreUnfold ( mkFormSummary, couldBeSmallEnoughToInline, whnfOrBottom,
55 Unfolding(..), FormSummary(..),
56 calcUnfoldingGuidance )
57 import CoreUtils ( coreExprCc )
58 import CostCentre ( CostCentre, isCurrentCostCentre, useCurrentCostCentre,
59 costsAreSubsumed, noCostCentreAttached, subsumedCosts,
60 currentOrSubsumedCosts
62 import FiniteMap -- lots of things
63 import Id ( IdEnv, IdSet, Id,
65 nullIdEnv, growIdEnvList, lookupIdEnv, delOneFromIdEnv,
66 addOneToIdEnv, modifyIdEnv, modifyIdEnv_Directly,
69 import Literal ( Literal )
70 import Maybes ( expectJust )
71 import OccurAnal ( occurAnalyseExpr )
72 import PprCore -- various instances
73 import Type ( instantiateTy, Type )
74 import TyVar ( TyVarEnv, emptyTyVarEnv, plusTyVarEnv, addToTyVarEnv, growTyVarEnvList,
75 TyVarSet, emptyTyVarSet,
78 import Unique ( Unique{-instance Outputable-}, Uniquable(..) )
79 import UniqFM ( addToUFM, addToUFM_C, ufmToList, mapUFM )
80 import Util ( Eager, returnEager, zipEqual, thenCmp, cmpList )
84 %************************************************************************
86 \subsection[Simplify-types]{Type declarations}
88 %************************************************************************
91 type InId = Id -- Not yet cloned
92 type InBinder = (InId, BinderInfo)
93 type InType = Type -- Ditto
94 type InBinding = SimplifiableCoreBinding
95 type InExpr = SimplifiableCoreExpr
96 type InAlts = SimplifiableCoreCaseAlts
97 type InDefault = SimplifiableCoreCaseDefault
98 type InArg = SimplifiableCoreArg
100 type OutId = Id -- Cloned
102 type OutType = Type -- Cloned
103 type OutBinding = CoreBinding
104 type OutExpr = CoreExpr
105 type OutAlts = CoreCaseAlts
106 type OutDefault = CoreCaseDefault
107 type OutArg = CoreArg
109 type SwitchChecker = SimplifierSwitch -> SwitchResult
112 %************************************************************************
114 \subsubsection{The @SimplEnv@ type}
116 %************************************************************************
119 INVARIANT: we assume {\em no shadowing}. (ToDo: How can we ASSERT
120 this? WDP 94/06) This allows us to neglect keeping everything paired
121 with its static environment.
123 The environment contains bindings for all
125 {\em locally-defined}
128 For such things, any unfolding is found in the environment, not in the
129 Id. Unfoldings in the Id itself are used only for imported things
130 (otherwise we get trouble because we have to simplify the unfoldings
131 inside the Ids, etc.).
137 CostCentre -- The enclosing cost-centre (when profiling)
138 SimplTypeEnv -- Maps old type variables to new clones
139 SimplValEnv -- Maps locally-bound Ids to new clones
140 ConAppMap -- Maps constructor applications back to OutIds
142 type SimplTypeEnv = (TyVarSet, -- In-scope tyvars (in result)
143 TyVarEnv Type) -- Type substitution
144 -- If t is in the in-scope set, it certainly won't be
145 -- in the domain of the substitution, and vice versa
147 type SimplValEnv = (IdEnv StuffAboutId, -- Domain includes *all* in-scope
148 -- Ids (in result), range gives info about them
149 IdEnv SubstInfo) -- Id substitution
150 -- The first envt tells what Ids are in scope; it
151 -- corresponds to the TyVarSet in SimplTypeEnv
153 -- The substitution usually maps an Id to its clone,
154 -- but if the orig defn is a let-binding, and
155 -- the RHS of the let simplifies to an atom,
156 -- we just add the binding to the substitution and elide the let.
158 -- Ids in the domain of the substitution are *not* in scope;
159 -- they *must* be substituted for the given OutArg
161 type SubstEnvs = (TyVarEnv Type, IdEnv SubstInfo)
164 = SubstVar OutId -- The Id maps to an already-substituted atom
165 | SubstLit Literal -- ...ditto literal
166 | SubstExpr -- Id maps to an as-yet-unsimplified expression
167 (TyVarEnv Type) -- ...hence we need to capture the substitution
168 (IdEnv SubstInfo) -- environments too
171 type StuffAboutId = (OutId, -- Always has the same unique as the
172 -- Id that maps to it; but may have better
173 -- IdInfo, and a correctly-substituted type,
174 -- than the occurrences of the Id. So use
175 -- this to replace occurrences
177 BinderInfo, -- How it occurs
178 -- We keep this info so we can modify it when
179 -- something changes.
181 Unfolding) -- Info about what it is bound to
186 nullSimplEnv :: SwitchChecker -> SimplEnv
189 = SimplEnv sw_chkr subsumedCosts
190 (emptyTyVarSet, emptyTyVarEnv)
191 (nullIdEnv, nullIdEnv)
194 -- The top level "enclosing CC" is "SUBSUMED". But the enclosing CC
195 -- for the rhs of top level defs is "OST_CENTRE". Consider
197 -- g = \y -> let v = f y in scc "x" (v ...)
198 -- Here we want to inline "f", since its CC is SUBSUMED, but we don't
199 -- want to inline "v" since its CC is dynamically determined.
202 getEnvs :: SimplEnv -> (SimplTypeEnv, SimplValEnv)
203 getEnvs (SimplEnv _ _ ty_env id_env _) = (ty_env, id_env)
205 setTyEnv :: SimplEnv -> SimplTypeEnv -> SimplEnv
206 setTyEnv (SimplEnv chkr encl_cc _ in_id_env con_apps) ty_env
207 = SimplEnv chkr encl_cc ty_env in_id_env con_apps
209 setIdEnv :: SimplEnv -> SimplValEnv -> SimplEnv
210 setIdEnv (SimplEnv chkr encl_cc ty_env _ con_apps) id_env
211 = SimplEnv chkr encl_cc ty_env id_env con_apps
213 getSubstEnvs :: SimplEnv -> SubstEnvs
214 getSubstEnvs (SimplEnv _ _ (_, ty_subst) (_, id_subst) _) = (ty_subst, id_subst)
216 emptySubstEnvs :: SubstEnvs
217 emptySubstEnvs = (emptyTyVarEnv, nullIdEnv)
219 setSubstEnvs :: SimplEnv -> SubstEnvs -> SimplEnv
220 setSubstEnvs (SimplEnv chkr encl_cc (in_scope_tyvars, _) (in_scope_ids, _) con_apps)
222 = SimplEnv chkr encl_cc (in_scope_tyvars, ty_subst) (in_scope_ids, id_subst) con_apps
224 combineEnvs :: SimplEnv -- Get substitution from here
225 -> SimplEnv -- Get in-scope info from here
227 combineEnvs (SimplEnv _ _ (_, ty_subst) (_, id_subst) _)
228 (SimplEnv chkr encl_cc (in_scope_tyvars, _) (in_scope_ids, _) con_apps)
229 = SimplEnv chkr encl_cc (in_scope_tyvars, ty_subst) (in_scope_ids, id_subst) con_apps
231 zapSubstEnvs :: SimplEnv -> SimplEnv
232 zapSubstEnvs (SimplEnv chkr encl_cc (in_scope_tyvars, _) (in_scope_ids, _) con_apps)
233 = SimplEnv chkr encl_cc (in_scope_tyvars, emptyTyVarEnv) (in_scope_ids, nullIdEnv) con_apps
237 %************************************************************************
239 \subsubsection{Command-line switches}
241 %************************************************************************
244 getSwitchChecker :: SimplEnv -> SwitchChecker
245 getSwitchChecker (SimplEnv chkr _ _ _ _) = chkr
247 switchIsSet :: SimplEnv -> SimplifierSwitch -> Bool
248 switchIsSet (SimplEnv chkr _ _ _ _) switch
249 = switchIsOn chkr switch
251 getSimplIntSwitch :: SwitchChecker -> (Int-> SimplifierSwitch) -> Int
252 getSimplIntSwitch chkr switch
253 = expectJust "getSimplIntSwitch" (intSwitchSet chkr switch)
256 setCaseScrutinee :: SimplEnv -> SimplEnv
257 setCaseScrutinee (SimplEnv chkr encl_cc ty_env id_env con_apps)
258 = SimplEnv chkr' encl_cc ty_env id_env con_apps
260 chkr' SimplCaseScrutinee = SwBool True
261 chkr' other = chkr other
264 @switchOffInlining@ is used to prepare the environment for simplifying
265 the RHS of an Id that's marked with an INLINE pragma. It is going to
266 be inlined wherever they are used, and then all the inlining will take
267 effect. Meanwhile, there isn't much point in doing anything to the
268 as-yet-un-INLINEd rhs. Furthermore, it's very important to switch off
270 (a) not doing so will inline a worker straight back into its wrapper!
272 and (b) Consider the following example
277 in ...g...g...g...g...g...
279 Now, if that's the ONLY occurrence of f, it will be inlined inside g,
280 and thence copied multiple times when g is inlined.
282 Andy disagrees! Example:
283 all xs = foldr (&&) True xs
284 any p = all . map p {-# INLINE any #-}
286 Problem: any won't get deforested, and so if it's exported and
287 the importer doesn't use the inlining, (eg passes it as an arg)
288 then we won't get deforestation at all.
289 We havn't solved this problem yet!
291 We prepare the envt by simply modifying the id_env, which has
292 all the unfolding info. At one point we did it by modifying the chkr so
293 that it said "EssentialUnfoldingsOnly", but that prevented legitmate, and important,
294 simplifications happening in the body of the RHS.
298 We don't prevent inlining from happening for identifiers
299 that are marked as must-be-inlined. An example of where
300 doing this is crucial is:
302 class Bar a => Foo a where
308 If `f' needs to peer inside Foo's superclass, Bar, it refers
309 to the appropriate super class selector, which is marked as
310 must-inlineable. We don't generate any code for a superclass
311 selector, so failing to inline it in the RHS of `f' will
312 leave a reference to a non-existent id, with bad consequences.
315 switchOffInlining :: SimplEnv -> SimplEnv
316 switchOffInlining (SimplEnv chkr encl_cc ty_env (in_scope_ids, id_subst) con_apps)
317 = SimplEnv chkr encl_cc ty_env (mapUFM forget in_scope_ids, id_subst) nullConApps
319 forget (id, binder_info, rhs_info)
320 | idMustBeINLINEd id = (id, binder_info, rhs_info)
321 | otherwise = (id, noBinderInfo, NoUnfolding)
325 %************************************************************************
327 \subsubsection{The ``enclosing cost-centre''}
329 %************************************************************************
332 setEnclosingCC :: SimplEnv -> CostCentre -> SimplEnv
334 setEnclosingCC env@(SimplEnv chkr _ ty_env id_env con_apps) encl_cc
335 = SimplEnv chkr encl_cc ty_env id_env con_apps
337 getEnclosingCC :: SimplEnv -> CostCentre
338 getEnclosingCC (SimplEnv chkr encl_cc ty_env id_env con_apps) = encl_cc
341 %************************************************************************
343 \subsubsection{The @TypeEnv@ part}
345 %************************************************************************
347 These two "bind" functions extend the tyvar substitution.
348 They don't affect what tyvars are in scope.
351 bindTyVar :: SimplEnv -> TyVar -> Type -> SimplEnv
352 bindTyVar (SimplEnv chkr encl_cc (tyvars, ty_subst) id_env con_apps) tyvar ty
353 = SimplEnv chkr encl_cc (tyvars, new_ty_subst) id_env con_apps
355 new_ty_subst = addToTyVarEnv ty_subst tyvar ty
357 bindTyVars :: SimplEnv -> TyVarEnv Type -> SimplEnv
358 bindTyVars (SimplEnv chkr encl_cc (tyvars, ty_subst) id_env con_apps) extra_subst
359 = SimplEnv chkr encl_cc (tyvars, new_ty_subst) id_env con_apps
361 new_ty_subst = ty_subst `plusTyVarEnv` extra_subst
365 simplTy (SimplEnv _ _ (_, ty_subst) _ _) ty = returnEager (instantiateTy ty_subst ty)
368 %************************************************************************
370 \subsubsection{The ``Id env'' part}
372 %************************************************************************
374 notInScope forgets that the specified binder is in scope.
375 It is used when we decide to bind a let(rec) bound thing to
376 an atom, *after* the Id has been added to the in-scope mapping by simplBinder.
379 notInScope :: SimplEnv -> OutBinder -> SimplEnv
380 notInScope (SimplEnv chkr encl_cc ty_env (in_scope_ids, id_subst) con_apps) id
381 = SimplEnv chkr encl_cc ty_env (new_in_scope_ids, id_subst) con_apps
383 new_in_scope_ids = delOneFromIdEnv in_scope_ids id
386 These "bind" functions extend the Id substitution.
389 bindIdToAtom :: SimplEnv
391 -> OutArg -- Val args only, please
394 bindIdToAtom (SimplEnv chkr encl_cc ty_env (in_scope_ids, id_subst) con_apps)
395 (in_id,occ_info) atom
396 = SimplEnv chkr encl_cc ty_env id_env' con_apps
398 id_env' = case atom of
399 LitArg lit -> (in_scope_ids, addOneToIdEnv id_subst in_id (SubstLit lit))
400 VarArg id -> (modifyOccInfo in_scope_ids (uniqueOf id) occ_info,
401 addOneToIdEnv id_subst in_id (SubstVar id))
403 bindIdToExpr :: SimplEnv
405 -> SimplifiableCoreExpr
408 bindIdToExpr (SimplEnv chkr encl_cc ty_env@(_, ty_subst) (in_scope_ids, id_subst) con_apps)
409 (in_id,occ_info) expr
410 = ASSERT( isOneFunOcc occ_info ) -- Binder occurs just once, safely, so no
411 -- need to adjust occurrence info for RHS,
412 -- unlike bindIdToAtom
413 SimplEnv chkr encl_cc ty_env (in_scope_ids, id_subst') con_apps
415 id_subst' = addOneToIdEnv id_subst in_id (SubstExpr ty_subst id_subst expr)
419 %************************************************************************
421 \subsubsection{The @OutIdEnv@}
423 %************************************************************************
426 lookupIdSubst :: SimplEnv -> InId -> Maybe SubstInfo
427 lookupIdSubst (SimplEnv _ _ _ (_, id_subst) _) id = lookupIdEnv id_subst id
429 lookupOutIdEnv :: SimplEnv -> OutId -> Maybe (OutId, BinderInfo, Unfolding)
430 lookupOutIdEnv (SimplEnv _ _ _ (in_scope_ids, _) _) id = lookupIdEnv in_scope_ids id
432 lookupUnfolding :: SimplEnv -> OutId -> Unfolding
433 lookupUnfolding env id
434 = case lookupOutIdEnv env id of
435 Just (_,_,info) -> info
436 Nothing -> NoUnfolding
438 modifyOutEnvItem :: (OutId, BinderInfo, Unfolding) -- Existing
439 -> (OutId, BinderInfo, Unfolding) -- New
440 -> (OutId, BinderInfo, Unfolding)
441 modifyOutEnvItem (_, _, info1) (id, occ, info2)
442 = (id, occ, case (info1, info2) of
443 (OtherLit ls1, OtherLit ls2) -> OtherLit (ls1++ls2)
444 (OtherCon cs1, OtherCon cs2) -> OtherCon (cs1++cs2)
445 (_, NoUnfolding) -> info1
451 isEvaluated :: Unfolding -> Bool
452 isEvaluated (OtherLit _) = True
453 isEvaluated (OtherCon _) = True
454 isEvaluated (CoreUnfolding ValueForm _ expr) = True
455 isEvaluated other = False
461 extendEnvGivenUnfolding :: SimplEnv -> OutId -> BinderInfo -> Unfolding -> SimplEnv
462 extendEnvGivenUnfolding env@(SimplEnv chkr encl_cc ty_env (in_scope_ids, id_subst) con_apps)
463 out_id occ_info rhs_info
464 = SimplEnv chkr encl_cc ty_env (new_in_scope_ids, id_subst) con_apps
466 new_in_scope_ids = addToUFM in_scope_ids out_id (out_id, occ_info, rhs_info)
471 modifyOccInfo in_scope_ids uniq new_occ
472 = modifyIdEnv_Directly modify_fn in_scope_ids uniq
474 modify_fn (id,occ,rhs) = (id, orBinderInfo occ new_occ, rhs)
476 markDangerousOccs (SimplEnv chkr encl_cc ty_env (in_scope_ids, id_subst) con_apps) atoms
477 = SimplEnv chkr encl_cc ty_env (new_in_scope_ids, id_subst) con_apps
479 new_in_scope_ids = foldl (modifyIdEnv modify_fn) in_scope_ids [v | VarArg v <- atoms]
480 modify_fn (id,occ,rhs) = (id, noBinderInfo, rhs)
484 %************************************************************************
486 \subsubsection{The @ConAppMap@ type}
488 %************************************************************************
490 The @ConAppMap@ maps applications of constructors (to value atoms)
491 back to an association list that says "if the constructor was applied
492 to one of these lists-of-Types, then this OutId is your man (in a
493 non-gender-specific sense)". I.e., this is a reversed mapping for
494 (part of) the main OutIdEnv
497 type ConAppMap = FiniteMap UnfoldConApp [([Type], OutId)]
500 = UCA OutId -- data constructor
501 [OutArg] -- *value* arguments; see use below
505 nullConApps = emptyFM
507 extendConApps con_apps id (Con con args)
508 = addToFM_C (\old new -> new++old) con_apps (UCA con val_args) [(ty_args,id)]
510 val_args = filter isValArg args -- Literals and Ids
511 ty_args = [ty | TyArg ty <- args] -- Just types
513 extendConApps con_apps id other_rhs = con_apps
517 lookForConstructor env@(SimplEnv _ _ _ _ con_apps) (Con con args)
518 | switchIsSet env SimplReuseCon
519 = case lookupFM con_apps (UCA con val_args) of
522 Just assocs -> case [id | (tys, id) <- assocs,
523 and (zipWith (==) tys ty_args)]
528 val_args = filter isValArg args -- Literals and Ids
529 ty_args = [ty | TyArg ty <- args] -- Just types
531 lookForConstructor env other = Nothing
534 NB: In @lookForConstructor@ we used (before Apr 94) to have a special case
535 for nullary constructors, but now we only do constructor re-use in
536 let-bindings the special case isn't necessary any more.
539 = -- Don't re-use nullary constructors; it's a waste. Consider
547 -- Here the False in the second case will get replace by "a", hardly
553 The main thing about @UnfoldConApp@ is that it has @Ord@ defined on
554 it, so we can use it for a @FiniteMap@ key.
557 instance Eq UnfoldConApp where
558 a == b = case (a `compare` b) of { EQ -> True; _ -> False }
559 a /= b = case (a `compare` b) of { EQ -> False; _ -> True }
561 instance Ord UnfoldConApp where
562 a <= b = case (a `compare` b) of { LT -> True; EQ -> True; GT -> False }
563 a < b = case (a `compare` b) of { LT -> True; EQ -> False; GT -> False }
564 a >= b = case (a `compare` b) of { LT -> False; EQ -> True; GT -> True }
565 a > b = case (a `compare` b) of { LT -> False; EQ -> False; GT -> True }
566 compare a b = cmp_app a b
568 cmp_app (UCA c1 as1) (UCA c2 as2)
569 = compare c1 c2 `thenCmp` cmpList cmp_arg as1 as2
571 -- ToDo: make an "instance Ord CoreArg"???
573 cmp_arg (VarArg x) (VarArg y) = x `compare` y
574 cmp_arg (LitArg x) (LitArg y) = x `compare` y
575 cmp_arg (TyArg x) (TyArg y) = panic "SimplEnv.cmp_app:TyArgs"
577 | tag x _LT_ tag y = LT
580 tag (VarArg _) = ILIT(1)
581 tag (LitArg _) = ILIT(2)
582 tag (TyArg _) = panic# "SimplEnv.cmp_app:TyArg"
586 @extendUnfoldEnvGivenRhs@ records in the UnfoldEnv info about the RHS
587 of a new binding. There is a horrid case we have to take care about,
588 due to Andr\'e Santos:
590 type Array_type b = Array Int b;
591 type Descr_type = (Int,Int);
593 tabulate :: (Int -> x) -> Descr_type -> Array_type x;
594 tabulate f (l,u) = listArray (l,u) [f i | i <- [l..u]];
598 f_aareorder::(Array_type Int) -> (Array_type t1) -> Array_type t1;
599 f_aareorder a_index a_ar=
601 f_aareorder' a_i= a_ar ! (a_index ! a_i)
602 } in tabulate f_aareorder' (bounds a_ar);
603 r_index=tabulate ((+) 1) (1,1);
604 arr = listArray (1,1) a_xs;
605 arg = f_aareorder r_index arr
608 Now, when the RHS of arg gets simplified, we inline f_aareorder to get
610 arg = let f_aareorder' a_i = arr ! (r_index ! a_i)
611 in tabulate f_aareorder' (bounds arr)
613 Note that r_index is not inlined, because it was bound to a_index which
614 occurs inside a lambda.
616 Alas, if elems is inlined, so that (elems arg) becomes (case arg of ...),
617 then arg is inlined. IF WE USE THE NEW VERSION OF arg, and re-occurrence
618 analyse it, we won't spot the inside-lambda property of r_index, so r_index
619 will get inlined inside the lambda. AARGH.
621 Solution: when we occurrence-analyse the new RHS we have to go back
622 and modify the info recorded in the UnfoldEnv for the free vars
623 of the RHS. In the example we'd go back and record that r_index is now used
627 extendEnvGivenNewRhs :: SimplEnv -> OutId -> OutExpr -> SimplEnv
628 extendEnvGivenNewRhs env out_id rhs
629 = extendEnvGivenBinding env noBinderInfo out_id rhs
631 extendEnvGivenBinding :: SimplEnv -> BinderInfo -> OutId -> OutExpr -> SimplEnv
632 extendEnvGivenBinding env@(SimplEnv chkr encl_cc ty_env (in_scope_ids, id_subst) con_apps)
634 = SimplEnv chkr encl_cc ty_env (new_in_scope_ids, id_subst) new_con_apps
636 new_in_scope_ids | okToInline out_id
638 (couldBeSmallEnoughToInline out_id guidance)
643 -- Don't bother to munge the OutIdEnv unless there is some possibility
644 -- that the thing might be inlined. We check this by calling okToInline suitably.
646 new_con_apps = _scc_ "eegnr.conapps"
647 extendConApps con_apps out_id rhs
649 -- Modify the occ info for rhs's interesting free variables.
650 -- That's to take account of:
651 -- let a = \x -> BIG in
653 -- in ...b...b...b...
654 -- Here "a" occurs exactly once. "b" simplifies to a small value.
655 -- So "b" will be inlined at each call site, and there's a good chance
656 -- that "a" will too. So we'd better modify "a"s occurrence info to
657 -- record the fact that it can now occur many times by virtue that "b" can.
658 env_with_unfolding = _scc_ "eegnr.modify_occ"
659 foldl zap env1 (ufmToList fv_occ_info)
660 zap env (uniq,_) = modifyOccInfo env uniq occ_info
663 -- Add an unfolding and rhs_info for the new Id.
664 -- If the out_id is already in the OutIdEnv (which should be the
665 -- case because it was put there by simplBinder)
666 -- then just replace the unfolding, leaving occurrence info alone.
667 env1 = _scc_ "eegnr.modify_out"
668 addToUFM_C modifyOutEnvItem in_scope_ids out_id
669 (out_id, occ_info, rhs_info)
671 -- Occurrence-analyse the RHS
672 -- The "interesting" free variables we want occurrence info for are those
673 -- in the OutIdEnv that have only a single occurrence right now.
674 (fv_occ_info, template) = _scc_ "eegnr.occ-anal"
675 occurAnalyseExpr is_interesting rhs_w_cc
677 is_interesting v = _scc_ "eegnr.mkidset"
678 case lookupIdEnv in_scope_ids v of
679 Just (_, occ, _) -> isOneOcc occ
682 -- Compute unfolding details
683 rhs_info = CoreUnfolding form guidance template
684 form = _scc_ "eegnr.form_sum"
686 guidance = _scc_ "eegnr.guidance"
687 calcUnfoldingGuidance opt_UnfoldingCreationThreshold rhs
689 -- Attach a cost centre to the RHS if necessary
690 rhs_w_cc | currentOrSubsumedCosts encl_cc
691 || not (noCostCentreAttached (coreExprCc rhs))
694 = Note (SCC encl_cc) rhs