2 % (c) The University of Glasgow 2006
3 % (c) The GRASP/AQUA Project, Glasgow University, 1993-1998
5 \section[IdInfo]{@IdInfos@: Non-essential information about @Ids@}
7 (And a pretty good illustration of quite a few things wrong with
12 -- * The IdDetails type
13 IdDetails(..), pprIdDetails,
17 vanillaIdInfo, noCafIdInfo,
18 seqIdInfo, megaSeqIdInfo,
20 -- ** Zapping various forms of Info
21 zapLamInfo, zapDemandInfo, zapFragileInfo,
23 -- ** The ArityInfo type
26 arityInfo, setArityInfo, ppArityInfo,
28 -- ** Demand and strictness Info
29 newStrictnessInfo, setNewStrictnessInfo,
30 newDemandInfo, setNewDemandInfo, pprNewStrictness,
34 -- ** Old strictness Info
36 mkStrictnessInfo, noStrictnessInfo,
37 ppStrictnessInfo, isBottomingStrictness,
38 strictnessInfo, setStrictnessInfo,
40 oldStrictnessFromNew, newStrictnessFromOld,
43 demandInfo, setDemandInfo,
46 -- ** Old Constructed Product Result Info
48 cprInfo, setCprInfo, ppCprInfo, noCprInfo,
49 cprInfoFromNewStrictness,
52 -- ** The WorkerInfo type
54 workerExists, wrapperArity, workerId,
55 workerInfo, setWorkerInfo, ppWorkerInfo,
58 unfoldingInfo, setUnfoldingInfo, setUnfoldingInfoLazily,
60 -- ** The InlinePragInfo type
62 inlinePragInfo, setInlinePragInfo,
64 -- ** The OccInfo type
66 isFragileOcc, isDeadOcc, isLoopBreaker,
70 insideLam, notInsideLam, oneBranch, notOneBranch,
72 -- ** The SpecInfo type
74 isEmptySpecInfo, specInfoFreeVars,
75 specInfoRules, seqSpecInfo, setSpecInfoHead,
76 specInfo, setSpecInfo,
78 -- ** The CAFInfo type
80 ppCafInfo, mayHaveCafRefs,
83 -- ** The LBVarInfo type
85 noLBVarInfo, hasNoLBVarInfo,
86 lbvarInfo, setLBVarInfo,
89 TickBoxOp(..), TickBoxId,
92 import CoreSyn ( CoreRule, setRuleIdName, seqRules, Unfolding, noUnfolding )
110 #ifdef OLD_STRICTNESS
112 import qualified Demand
117 -- infixl so you can say (id `set` a `set` b)
118 infixl 1 `setSpecInfo`,
126 `setNewStrictnessInfo`,
127 `setAllStrictnessInfo`,
129 #ifdef OLD_STRICTNESS
132 , `setStrictnessInfo`
136 %************************************************************************
138 \subsection{New strictness info}
140 %************************************************************************
145 -- | Set old and new strictness information together
146 setAllStrictnessInfo :: IdInfo -> Maybe StrictSig -> IdInfo
147 setAllStrictnessInfo info Nothing
148 = info { newStrictnessInfo = Nothing
149 #ifdef OLD_STRICTNESS
150 , strictnessInfo = NoStrictnessInfo
151 , cprInfo = NoCPRInfo
155 setAllStrictnessInfo info (Just sig)
156 = info { newStrictnessInfo = Just sig
157 #ifdef OLD_STRICTNESS
158 , strictnessInfo = oldStrictnessFromNew sig
159 , cprInfo = cprInfoFromNewStrictness sig
163 seqNewStrictnessInfo :: Maybe StrictSig -> ()
164 seqNewStrictnessInfo Nothing = ()
165 seqNewStrictnessInfo (Just ty) = seqStrictSig ty
167 pprNewStrictness :: Maybe StrictSig -> SDoc
168 pprNewStrictness Nothing = empty
169 pprNewStrictness (Just sig) = ftext (fsLit "Str:") <+> ppr sig
171 #ifdef OLD_STRICTNESS
172 oldStrictnessFromNew :: StrictSig -> Demand.StrictnessInfo
173 oldStrictnessFromNew sig = mkStrictnessInfo (map oldDemand dmds, isBotRes res_info)
175 (dmds, res_info) = splitStrictSig sig
177 cprInfoFromNewStrictness :: StrictSig -> CprInfo
178 cprInfoFromNewStrictness sig = case strictSigResInfo sig of
182 newStrictnessFromOld :: Name -> Arity -> Demand.StrictnessInfo -> CprInfo -> StrictSig
183 newStrictnessFromOld name arity (Demand.StrictnessInfo ds res) cpr
184 | listLengthCmp ds arity /= GT -- length ds <= arity
185 -- Sometimes the old strictness analyser has more
186 -- demands than the arity justifies
187 = mk_strict_sig name arity $
188 mkTopDmdType (map newDemand ds) (newRes res cpr)
190 newStrictnessFromOld name arity other cpr
191 = -- Either no strictness info, or arity is too small
192 -- In either case we can't say anything useful
193 mk_strict_sig name arity $
194 mkTopDmdType (replicate arity lazyDmd) (newRes False cpr)
196 mk_strict_sig name arity dmd_ty
197 = WARN( arity /= dmdTypeDepth dmd_ty, ppr name <+> (ppr arity $$ ppr dmd_ty) )
200 newRes True _ = BotRes
201 newRes False ReturnsCPR = retCPR
202 newRes False NoCPRInfo = TopRes
204 newDemand :: Demand.Demand -> NewDemand.Demand
205 newDemand (WwLazy True) = Abs
206 newDemand (WwLazy False) = lazyDmd
207 newDemand WwStrict = evalDmd
208 newDemand (WwUnpack unpk ds) = Eval (Prod (map newDemand ds))
209 newDemand WwPrim = lazyDmd
210 newDemand WwEnum = evalDmd
212 oldDemand :: NewDemand.Demand -> Demand.Demand
213 oldDemand Abs = WwLazy True
214 oldDemand Top = WwLazy False
215 oldDemand Bot = WwStrict
216 oldDemand (Box Bot) = WwStrict
217 oldDemand (Box Abs) = WwLazy False
218 oldDemand (Box (Eval _)) = WwStrict -- Pass box only
219 oldDemand (Defer d) = WwLazy False
220 oldDemand (Eval (Prod ds)) = WwUnpack True (map oldDemand ds)
221 oldDemand (Eval (Poly _)) = WwStrict
222 oldDemand (Call _) = WwStrict
224 #endif /* OLD_STRICTNESS */
229 seqNewDemandInfo :: Maybe Demand -> ()
230 seqNewDemandInfo Nothing = ()
231 seqNewDemandInfo (Just dmd) = seqDemand dmd
235 %************************************************************************
239 %************************************************************************
242 -- | The 'IdDetails' of an 'Id' give stable, and necessary,
243 -- information about the Id.
247 -- | The 'Id' for a record selector
249 { sel_tycon :: TyCon -- ^ For a data type family, this is the /instance/ 'TyCon'
250 -- not the family 'TyCon'
251 , sel_naughty :: Bool -- True <=> a "naughty" selector which can't actually exist, for example @x@ in:
252 -- data T = forall a. MkT { x :: a }
253 } -- See Note [Naughty record selectors] in TcTyClsDecls
255 | DataConWorkId DataCon -- ^ The 'Id' is for a data constructor /worker/
256 | DataConWrapId DataCon -- ^ The 'Id' is for a data constructor /wrapper/
258 -- [the only reasons we need to know is so that
259 -- a) to support isImplicitId
260 -- b) when desugaring a RecordCon we can get
261 -- from the Id back to the data con]
263 | ClassOpId Class -- ^ The 'Id' is an operation of a class
265 | PrimOpId PrimOp -- ^ The 'Id' is for a primitive operator
266 | FCallId ForeignCall -- ^ The 'Id' is for a foreign call
268 | TickBoxOpId TickBoxOp -- ^ The 'Id' is for a HPC tick box (both traditional and binary)
270 | DFunId -- ^ A dictionary function. We don't use this in an essential way,
271 -- currently, but it's kind of nice that we can keep track of
272 -- which Ids are DFuns, across module boundaries too
275 instance Outputable IdDetails where
278 pprIdDetails :: IdDetails -> SDoc
279 pprIdDetails VanillaId = empty
280 pprIdDetails (DataConWorkId _) = ptext (sLit "[DataCon]")
281 pprIdDetails (DataConWrapId _) = ptext (sLit "[DataConWrapper]")
282 pprIdDetails (ClassOpId _) = ptext (sLit "[ClassOp]")
283 pprIdDetails (PrimOpId _) = ptext (sLit "[PrimOp]")
284 pprIdDetails (FCallId _) = ptext (sLit "[ForeignCall]")
285 pprIdDetails (TickBoxOpId _) = ptext (sLit "[TickBoxOp]")
286 pprIdDetails DFunId = ptext (sLit "[DFunId]")
287 pprIdDetails (RecSelId { sel_naughty = is_naughty })
288 = brackets $ ptext (sLit "RecSel") <> pp_naughty
290 pp_naughty | is_naughty = ptext (sLit "(naughty)")
295 %************************************************************************
297 \subsection{The main IdInfo type}
299 %************************************************************************
302 -- | An 'IdInfo' gives /optional/ information about an 'Id'. If
303 -- present it never lies, but it may not be present, in which case there
304 -- is always a conservative assumption which can be made.
306 -- Two 'Id's may have different info even though they have the same
307 -- 'Unique' (and are hence the same 'Id'); for example, one might lack
308 -- the properties attached to the other.
310 -- The 'IdInfo' gives information about the value, or definition, of the
311 -- 'Id'. It does not contain information about the 'Id''s usage,
312 -- except for 'demandInfo' and 'lbvarInfo'.
315 arityInfo :: !ArityInfo, -- ^ 'Id' arity
316 specInfo :: SpecInfo, -- ^ Specialisations of the 'Id's function which exist
317 #ifdef OLD_STRICTNESS
318 cprInfo :: CprInfo, -- ^ If the 'Id's function always constructs a product result
319 demandInfo :: Demand.Demand, -- ^ Whether or not the 'Id' is definitely demanded
320 strictnessInfo :: StrictnessInfo, -- ^ 'Id' strictness properties
322 workerInfo :: WorkerInfo, -- ^ Pointer to worker function.
323 -- Within one module this is irrelevant; the
324 -- inlining of a worker is handled via the 'Unfolding'.
325 -- However, when the module is imported by others, the
326 -- 'WorkerInfo' is used /only/ to indicate the form of
327 -- the RHS, so that interface files don't actually
328 -- need to contain the RHS; it can be derived from
329 -- the strictness info
331 unfoldingInfo :: Unfolding, -- ^ The 'Id's unfolding
332 cafInfo :: CafInfo, -- ^ 'Id' CAF info
333 lbvarInfo :: LBVarInfo, -- ^ Info about a lambda-bound variable, if the 'Id' is one
334 inlinePragInfo :: InlinePragma, -- ^ Any inline pragma atached to the 'Id'
335 occInfo :: OccInfo, -- ^ How the 'Id' occurs in the program
337 newStrictnessInfo :: Maybe StrictSig, -- ^ Id strictness information. Reason for Maybe:
338 -- the DmdAnal phase needs to know whether
339 -- this is the first visit, so it can assign botSig.
340 -- Other customers want topSig. So @Nothing@ is good.
342 newDemandInfo :: Maybe Demand -- ^ Id demand information. Similarly we want to know
343 -- if there's no known demand yet, for when we are looking
347 -- | Just evaluate the 'IdInfo' to WHNF
348 seqIdInfo :: IdInfo -> ()
349 seqIdInfo (IdInfo {}) = ()
351 -- | Evaluate all the fields of the 'IdInfo' that are generally demanded by the
353 megaSeqIdInfo :: IdInfo -> ()
355 = seqSpecInfo (specInfo info) `seq`
356 seqWorker (workerInfo info) `seq`
358 -- Omitting this improves runtimes a little, presumably because
359 -- some unfoldings are not calculated at all
360 -- seqUnfolding (unfoldingInfo info) `seq`
362 seqNewDemandInfo (newDemandInfo info) `seq`
363 seqNewStrictnessInfo (newStrictnessInfo info) `seq`
365 #ifdef OLD_STRICTNESS
366 Demand.seqDemand (demandInfo info) `seq`
367 seqStrictnessInfo (strictnessInfo info) `seq`
368 seqCpr (cprInfo info) `seq`
371 seqCaf (cafInfo info) `seq`
372 seqLBVar (lbvarInfo info) `seq`
373 seqOccInfo (occInfo info)
379 setWorkerInfo :: IdInfo -> WorkerInfo -> IdInfo
380 setWorkerInfo info wk = wk `seq` info { workerInfo = wk }
381 setSpecInfo :: IdInfo -> SpecInfo -> IdInfo
382 setSpecInfo info sp = sp `seq` info { specInfo = sp }
383 setInlinePragInfo :: IdInfo -> InlinePragma -> IdInfo
384 setInlinePragInfo info pr = pr `seq` info { inlinePragInfo = pr }
385 setOccInfo :: IdInfo -> OccInfo -> IdInfo
386 setOccInfo info oc = oc `seq` info { occInfo = oc }
387 #ifdef OLD_STRICTNESS
388 setStrictnessInfo info st = st `seq` info { strictnessInfo = st }
390 -- Try to avoid spack leaks by seq'ing
392 setUnfoldingInfoLazily :: IdInfo -> Unfolding -> IdInfo
393 setUnfoldingInfoLazily info uf -- Lazy variant to avoid looking at the
394 = -- unfolding of an imported Id unless necessary
395 info { unfoldingInfo = uf } -- (In this case the demand-zapping is redundant.)
397 setUnfoldingInfo :: IdInfo -> Unfolding -> IdInfo
398 setUnfoldingInfo info uf
399 -- We do *not* seq on the unfolding info, For some reason, doing so
400 -- actually increases residency significantly.
401 = info { unfoldingInfo = uf }
403 #ifdef OLD_STRICTNESS
404 setDemandInfo info dd = info { demandInfo = dd }
405 setCprInfo info cp = info { cprInfo = cp }
408 setArityInfo :: IdInfo -> ArityInfo -> IdInfo
409 setArityInfo info ar = info { arityInfo = ar }
410 setCafInfo :: IdInfo -> CafInfo -> IdInfo
411 setCafInfo info caf = info { cafInfo = caf }
413 setLBVarInfo :: IdInfo -> LBVarInfo -> IdInfo
414 setLBVarInfo info lb = {-lb `seq`-} info { lbvarInfo = lb }
416 setNewDemandInfo :: IdInfo -> Maybe Demand -> IdInfo
417 setNewDemandInfo info dd = dd `seq` info { newDemandInfo = dd }
418 setNewStrictnessInfo :: IdInfo -> Maybe StrictSig -> IdInfo
419 setNewStrictnessInfo info dd = dd `seq` info { newStrictnessInfo = dd }
424 -- | Basic 'IdInfo' that carries no useful information whatsoever
425 vanillaIdInfo :: IdInfo
428 cafInfo = vanillaCafInfo,
429 arityInfo = unknownArity,
430 #ifdef OLD_STRICTNESS
433 strictnessInfo = NoStrictnessInfo,
435 specInfo = emptySpecInfo,
436 workerInfo = NoWorker,
437 unfoldingInfo = noUnfolding,
438 lbvarInfo = NoLBVarInfo,
439 inlinePragInfo = defaultInlinePragma,
441 newDemandInfo = Nothing,
442 newStrictnessInfo = Nothing
445 -- | More informative 'IdInfo' we can use when we know the 'Id' has no CAF references
446 noCafIdInfo :: IdInfo
447 noCafIdInfo = vanillaIdInfo `setCafInfo` NoCafRefs
448 -- Used for built-in type Ids in MkId.
452 %************************************************************************
454 \subsection[arity-IdInfo]{Arity info about an @Id@}
456 %************************************************************************
458 For locally-defined Ids, the code generator maintains its own notion
459 of their arities; so it should not be asking... (but other things
460 besides the code-generator need arity info!)
463 -- | An 'ArityInfo' of @n@ tells us that partial application of this
464 -- 'Id' to up to @n-1@ value arguments does essentially no work.
466 -- That is not necessarily the same as saying that it has @n@ leading
467 -- lambdas, because coerces may get in the way.
469 -- The arity might increase later in the compilation process, if
470 -- an extra lambda floats up to the binding site.
471 type ArityInfo = Arity
473 -- | It is always safe to assume that an 'Id' has an arity of 0
474 unknownArity :: Arity
475 unknownArity = 0 :: Arity
477 ppArityInfo :: Int -> SDoc
478 ppArityInfo 0 = empty
479 ppArityInfo n = hsep [ptext (sLit "Arity"), int n]
482 %************************************************************************
484 \subsection{Inline-pragma information}
486 %************************************************************************
489 -- | Tells when the inlining is active.
490 -- When it is active the thing may be inlined, depending on how
493 -- If there was an @INLINE@ pragma, then as a separate matter, the
494 -- RHS will have been made to look small with a Core inline 'Note'
496 -- The default 'InlinePragInfo' is 'AlwaysActive', so the info serves
497 -- entirely as a way to inhibit inlining until we want it
498 type InlinePragInfo = InlinePragma
502 %************************************************************************
506 %************************************************************************
509 -- | Records the specializations of this 'Id' that we know about
510 -- in the form of rewrite 'CoreRule's that target them
514 VarSet -- Locally-defined free vars of *both* LHS and RHS
515 -- of rules. I don't think it needs to include the
517 -- Note [Rule dependency info] in OccurAnal
519 -- | Assume that no specilizations exist: always safe
520 emptySpecInfo :: SpecInfo
521 emptySpecInfo = SpecInfo [] emptyVarSet
523 isEmptySpecInfo :: SpecInfo -> Bool
524 isEmptySpecInfo (SpecInfo rs _) = null rs
526 -- | Retrieve the locally-defined free variables of both the left and
527 -- right hand sides of the specialization rules
528 specInfoFreeVars :: SpecInfo -> VarSet
529 specInfoFreeVars (SpecInfo _ fvs) = fvs
531 specInfoRules :: SpecInfo -> [CoreRule]
532 specInfoRules (SpecInfo rules _) = rules
534 -- | Change the name of the function the rule is keyed on on all of the 'CoreRule's
535 setSpecInfoHead :: Name -> SpecInfo -> SpecInfo
536 setSpecInfoHead fn (SpecInfo rules fvs)
537 = SpecInfo (map (setRuleIdName fn) rules) fvs
539 seqSpecInfo :: SpecInfo -> ()
540 seqSpecInfo (SpecInfo rules fvs) = seqRules rules `seq` seqVarSet fvs
543 %************************************************************************
545 \subsection[worker-IdInfo]{Worker info about an @Id@}
547 %************************************************************************
549 There might not be a worker, even for a strict function, because:
550 (a) the function might be small enough to inline, so no need
552 (b) the strictness info might be "SSS" or something, so no w/w split.
554 Sometimes the arity of a wrapper changes from the original arity from
555 which it was generated, so we always emit the "original" arity into
556 the interface file, as part of the worker info.
558 How can this happen? Sometimes we get
559 f = coerce t (\x y -> $wf x y)
560 at the moment of w/w split; but the eta reducer turns it into
562 which is perfectly fine except that the exposed arity so far as
563 the code generator is concerned (zero) differs from the arity
564 when we did the split (2).
566 All this arises because we use 'arity' to mean "exactly how many
567 top level lambdas are there" in interface files; but during the
568 compilation of this module it means "how many things can I apply
573 -- | If this Id has a worker then we store a reference to it. Worker
574 -- functions are generated by the worker\/wrapper pass, using information
575 -- information from strictness analysis.
576 data WorkerInfo = NoWorker -- ^ No known worker function
577 | HasWorker Id Arity -- ^ The 'Arity' is the arity of the /wrapper/ at the moment of the
578 -- worker\/wrapper split, which may be different from the current 'Id' 'Aritiy'
580 seqWorker :: WorkerInfo -> ()
581 seqWorker (HasWorker id a) = id `seq` a `seq` ()
582 seqWorker NoWorker = ()
584 ppWorkerInfo :: WorkerInfo -> SDoc
585 ppWorkerInfo NoWorker = empty
586 ppWorkerInfo (HasWorker wk_id _) = ptext (sLit "Worker") <+> ppr wk_id
588 workerExists :: WorkerInfo -> Bool
589 workerExists NoWorker = False
590 workerExists (HasWorker _ _) = True
592 -- | The 'Id' of the worker function if it exists, or a panic otherwise
593 workerId :: WorkerInfo -> Id
594 workerId (HasWorker id _) = id
595 workerId NoWorker = panic "workerId: NoWorker"
597 -- | The 'Arity' of the worker function at the time of the split if it exists, or a panic otherwise
598 wrapperArity :: WorkerInfo -> Arity
599 wrapperArity (HasWorker _ a) = a
600 wrapperArity NoWorker = panic "wrapperArity: NoWorker"
604 %************************************************************************
606 \subsection[CG-IdInfo]{Code generator-related information}
608 %************************************************************************
611 -- CafInfo is used to build Static Reference Tables (see simplStg/SRT.lhs).
613 -- | Records whether an 'Id' makes Constant Applicative Form references
615 = MayHaveCafRefs -- ^ Indicates that the 'Id' is for either:
617 -- 1. A function or static constructor
618 -- that refers to one or more CAFs, or
620 -- 2. A real live CAF
622 | NoCafRefs -- ^ A function or static constructor
623 -- that refers to no CAFs.
626 -- | Assumes that the 'Id' has CAF references: definitely safe
627 vanillaCafInfo :: CafInfo
628 vanillaCafInfo = MayHaveCafRefs
630 mayHaveCafRefs :: CafInfo -> Bool
631 mayHaveCafRefs MayHaveCafRefs = True
632 mayHaveCafRefs _ = False
634 seqCaf :: CafInfo -> ()
635 seqCaf c = c `seq` ()
637 ppCafInfo :: CafInfo -> SDoc
638 ppCafInfo NoCafRefs = ptext (sLit "NoCafRefs")
639 ppCafInfo MayHaveCafRefs = empty
642 %************************************************************************
644 \subsection[cpr-IdInfo]{Constructed Product Result info about an @Id@}
646 %************************************************************************
649 #ifdef OLD_STRICTNESS
650 -- | If the @Id@ is a function then it may have Constructed Product Result
651 -- (CPR) info. A CPR analysis phase detects whether:
653 -- 1. The function's return value has a product type, i.e. an algebraic type
654 -- with a single constructor. Examples of such types are tuples and boxed
657 -- 2. The function always 'constructs' the value that it is returning. It
658 -- must do this on every path through, and it's OK if it calls another
659 -- function which constructs the result.
661 -- If this is the case then we store a template which tells us the
662 -- function has the CPR property and which components of the result are
665 = NoCPRInfo -- ^ No, this function does not return a constructed product
666 | ReturnsCPR -- ^ Yes, this function returns a constructed product
668 -- Implicitly, this means "after the function has been applied
669 -- to all its arguments", so the worker\/wrapper builder in
670 -- WwLib.mkWWcpr checks that that it is indeed saturated before
671 -- making use of the CPR info
673 -- We used to keep nested info about sub-components, but
674 -- we never used it so I threw it away
676 -- | It's always safe to assume that an 'Id' does not have the CPR property
678 noCprInfo = NoCPRInfo
680 seqCpr :: CprInfo -> ()
681 seqCpr ReturnsCPR = ()
682 seqCpr NoCPRInfo = ()
684 ppCprInfo NoCPRInfo = empty
685 ppCprInfo ReturnsCPR = ptext (sLit "__M")
687 instance Outputable CprInfo where
690 instance Show CprInfo where
691 showsPrec p c = showsPrecSDoc p (ppr c)
695 %************************************************************************
697 \subsection[lbvar-IdInfo]{Lambda-bound var info about an @Id@}
699 %************************************************************************
702 -- | If the 'Id' is a lambda-bound variable then it may have lambda-bound
703 -- variable info. Sometimes we know whether the lambda binding this variable
704 -- is a \"one-shot\" lambda; that is, whether it is applied at most once.
706 -- This information may be useful in optimisation, as computations may
707 -- safely be floated inside such a lambda without risk of duplicating
709 data LBVarInfo = NoLBVarInfo -- ^ No information
710 | IsOneShotLambda -- ^ The lambda is applied at most once).
712 -- | It is always safe to assume that an 'Id' has no lambda-bound variable information
713 noLBVarInfo :: LBVarInfo
714 noLBVarInfo = NoLBVarInfo
716 hasNoLBVarInfo :: LBVarInfo -> Bool
717 hasNoLBVarInfo NoLBVarInfo = True
718 hasNoLBVarInfo IsOneShotLambda = False
720 seqLBVar :: LBVarInfo -> ()
721 seqLBVar l = l `seq` ()
723 pprLBVarInfo :: LBVarInfo -> SDoc
724 pprLBVarInfo NoLBVarInfo = empty
725 pprLBVarInfo IsOneShotLambda = ptext (sLit "OneShot")
727 instance Outputable LBVarInfo where
730 instance Show LBVarInfo where
731 showsPrec p c = showsPrecSDoc p (ppr c)
735 %************************************************************************
737 \subsection{Bulk operations on IdInfo}
739 %************************************************************************
742 -- | This is used to remove information on lambda binders that we have
743 -- setup as part of a lambda group, assuming they will be applied all at once,
744 -- but turn out to be part of an unsaturated lambda as in e.g:
746 -- > (\x1. \x2. e) arg1
747 zapLamInfo :: IdInfo -> Maybe IdInfo
748 zapLamInfo info@(IdInfo {occInfo = occ, newDemandInfo = demand})
749 | is_safe_occ occ && is_safe_dmd demand
752 = Just (info {occInfo = safe_occ, newDemandInfo = Nothing})
754 -- The "unsafe" occ info is the ones that say I'm not in a lambda
755 -- because that might not be true for an unsaturated lambda
756 is_safe_occ (OneOcc in_lam _ _) = in_lam
757 is_safe_occ _other = True
759 safe_occ = case occ of
760 OneOcc _ once int_cxt -> OneOcc insideLam once int_cxt
763 is_safe_dmd Nothing = True
764 is_safe_dmd (Just dmd) = not (isStrictDmd dmd)
768 -- | Remove demand info on the 'IdInfo' if it is present, otherwise return @Nothing@
769 zapDemandInfo :: IdInfo -> Maybe IdInfo
770 zapDemandInfo info@(IdInfo {newDemandInfo = dmd})
771 | isJust dmd = Just (info {newDemandInfo = Nothing})
772 | otherwise = Nothing
776 zapFragileInfo :: IdInfo -> Maybe IdInfo
777 -- ^ Zap info that depends on free variables
779 = Just (info `setSpecInfo` emptySpecInfo
780 `setWorkerInfo` NoWorker
781 `setUnfoldingInfo` noUnfolding
782 `setOccInfo` if isFragileOcc occ then NoOccInfo else occ)
787 %************************************************************************
789 \subsection{TickBoxOp}
791 %************************************************************************
796 -- | Tick box for Hpc-style coverage
798 = TickBox Module {-# UNPACK #-} !TickBoxId
800 instance Outputable TickBoxOp where
801 ppr (TickBox mod n) = ptext (sLit "tick") <+> ppr (mod,n)