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 GlobalIdDetails type
13 GlobalIdDetails(..), notGlobalId, -- Not abstract
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 %************************************************************************
237 \subsection{GlobalIdDetails}
239 %************************************************************************
241 This type is here (rather than in Id.lhs) mainly because there's
242 an IdInfo.hi-boot, but no Id.hi-boot, and GlobalIdDetails is imported
243 (recursively) by Var.lhs.
246 -- | Information pertaining to global 'Id's. See "Var#globalvslocal" for the distinction
247 -- between global and local in this context
249 = VanillaGlobal -- ^ The 'Id' is imported from elsewhere or is a default method 'Id'
251 -- | The 'Id' for a record selector
253 { sel_tycon :: TyCon -- ^ For a data type family, this is the /instance/ 'TyCon'
254 -- not the family 'TyCon'
255 , sel_label :: FieldLabel
256 , sel_naughty :: Bool -- True <=> a "naughty" selector which can't actually exist, for example @x@ in:
258 -- > data T = forall a. MkT { x :: a }
260 -- See Note [Naughty record selectors]
261 -- with MkId.mkRecordSelectorId
263 | DataConWorkId DataCon -- ^ The 'Id' is for a data constructor /worker/
264 | DataConWrapId DataCon -- ^ The 'Id' is for a data constructor /wrapper/
266 -- [the only reasons we need to know is so that
267 -- a) to support isImplicitId
268 -- b) when desugaring a RecordCon we can get
269 -- from the Id back to the data con]
271 | ClassOpId Class -- ^ The 'Id' is an operation of a class
273 | PrimOpId PrimOp -- ^ The 'Id' is for a primitive operator
274 | FCallId ForeignCall -- ^ The 'Id' is for a foreign call
276 | TickBoxOpId TickBoxOp -- ^ The 'Id' is for a HPC tick box (both traditional and binary)
278 | NotGlobalId -- ^ Used as a convenient extra return value from 'globalIdDetails'
280 -- | An entirely unhelpful 'GlobalIdDetails'
281 notGlobalId :: GlobalIdDetails
282 notGlobalId = NotGlobalId
284 instance Outputable GlobalIdDetails where
285 ppr NotGlobalId = ptext (sLit "[***NotGlobalId***]")
286 ppr VanillaGlobal = ptext (sLit "[GlobalId]")
287 ppr (DataConWorkId _) = ptext (sLit "[DataCon]")
288 ppr (DataConWrapId _) = ptext (sLit "[DataConWrapper]")
289 ppr (ClassOpId _) = ptext (sLit "[ClassOp]")
290 ppr (PrimOpId _) = ptext (sLit "[PrimOp]")
291 ppr (FCallId _) = ptext (sLit "[ForeignCall]")
292 ppr (TickBoxOpId _) = ptext (sLit "[TickBoxOp]")
293 ppr (RecordSelId {}) = ptext (sLit "[RecSel]")
297 %************************************************************************
299 \subsection{The main IdInfo type}
301 %************************************************************************
304 -- | An 'IdInfo' gives /optional/ information about an 'Id'. If
305 -- present it never lies, but it may not be present, in which case there
306 -- is always a conservative assumption which can be made.
308 -- Two 'Id's may have different info even though they have the same
309 -- 'Unique' (and are hence the same 'Id'); for example, one might lack
310 -- the properties attached to the other.
312 -- The 'IdInfo' gives information about the value, or definition, of the
313 -- 'Id'. It does not contain information about the 'Id''s usage,
314 -- except for 'demandInfo' and 'lbvarInfo'.
317 arityInfo :: !ArityInfo, -- ^ 'Id' arity
318 specInfo :: SpecInfo, -- ^ Specialisations of the 'Id's function which exist
319 #ifdef OLD_STRICTNESS
320 cprInfo :: CprInfo, -- ^ If the 'Id's function always constructs a product result
321 demandInfo :: Demand.Demand, -- ^ Whether or not the 'Id' is definitely demanded
322 strictnessInfo :: StrictnessInfo, -- ^ 'Id' strictness properties
324 workerInfo :: WorkerInfo, -- ^ Pointer to worker function.
325 -- Within one module this is irrelevant; the
326 -- inlining of a worker is handled via the 'Unfolding'.
327 -- However, when the module is imported by others, the
328 -- 'WorkerInfo' is used /only/ to indicate the form of
329 -- the RHS, so that interface files don't actually
330 -- need to contain the RHS; it can be derived from
331 -- the strictness info
333 unfoldingInfo :: Unfolding, -- ^ The 'Id's unfolding
334 cafInfo :: CafInfo, -- ^ 'Id' CAF info
335 lbvarInfo :: LBVarInfo, -- ^ Info about a lambda-bound variable, if the 'Id' is one
336 inlinePragInfo :: InlinePragInfo, -- ^ Any inline pragma atached to the 'Id'
337 occInfo :: OccInfo, -- ^ How the 'Id' occurs in the program
339 newStrictnessInfo :: Maybe StrictSig, -- ^ Id strictness information. Reason for Maybe:
340 -- the DmdAnal phase needs to know whether
341 -- this is the first visit, so it can assign botSig.
342 -- Other customers want topSig. So @Nothing@ is good.
344 newDemandInfo :: Maybe Demand -- ^ Id demand information. Similarly we want to know
345 -- if there's no known demand yet, for when we are looking
349 -- | Just evaluate the 'IdInfo' to WHNF
350 seqIdInfo :: IdInfo -> ()
351 seqIdInfo (IdInfo {}) = ()
353 -- | Evaluate all the fields of the 'IdInfo' that are generally demanded by the
355 megaSeqIdInfo :: IdInfo -> ()
357 = seqSpecInfo (specInfo info) `seq`
358 seqWorker (workerInfo info) `seq`
360 -- Omitting this improves runtimes a little, presumably because
361 -- some unfoldings are not calculated at all
362 -- seqUnfolding (unfoldingInfo info) `seq`
364 seqNewDemandInfo (newDemandInfo info) `seq`
365 seqNewStrictnessInfo (newStrictnessInfo info) `seq`
367 #ifdef OLD_STRICTNESS
368 Demand.seqDemand (demandInfo info) `seq`
369 seqStrictnessInfo (strictnessInfo info) `seq`
370 seqCpr (cprInfo info) `seq`
373 seqCaf (cafInfo info) `seq`
374 seqLBVar (lbvarInfo info) `seq`
375 seqOccInfo (occInfo info)
381 setWorkerInfo :: IdInfo -> WorkerInfo -> IdInfo
382 setWorkerInfo info wk = wk `seq` info { workerInfo = wk }
383 setSpecInfo :: IdInfo -> SpecInfo -> IdInfo
384 setSpecInfo info sp = sp `seq` info { specInfo = sp }
385 setInlinePragInfo :: IdInfo -> InlinePragInfo -> IdInfo
386 setInlinePragInfo info pr = pr `seq` info { inlinePragInfo = pr }
387 setOccInfo :: IdInfo -> OccInfo -> IdInfo
388 setOccInfo info oc = oc `seq` info { occInfo = oc }
389 #ifdef OLD_STRICTNESS
390 setStrictnessInfo info st = st `seq` info { strictnessInfo = st }
392 -- Try to avoid spack leaks by seq'ing
394 setUnfoldingInfoLazily :: IdInfo -> Unfolding -> IdInfo
395 setUnfoldingInfoLazily info uf -- Lazy variant to avoid looking at the
396 = -- unfolding of an imported Id unless necessary
397 info { unfoldingInfo = uf } -- (In this case the demand-zapping is redundant.)
399 setUnfoldingInfo :: IdInfo -> Unfolding -> IdInfo
400 setUnfoldingInfo info uf
401 -- We do *not* seq on the unfolding info, For some reason, doing so
402 -- actually increases residency significantly.
403 = info { unfoldingInfo = uf }
405 #ifdef OLD_STRICTNESS
406 setDemandInfo info dd = info { demandInfo = dd }
407 setCprInfo info cp = info { cprInfo = cp }
410 setArityInfo :: IdInfo -> ArityInfo -> IdInfo
411 setArityInfo info ar = info { arityInfo = ar }
412 setCafInfo :: IdInfo -> CafInfo -> IdInfo
413 setCafInfo info caf = info { cafInfo = caf }
415 setLBVarInfo :: IdInfo -> LBVarInfo -> IdInfo
416 setLBVarInfo info lb = {-lb `seq`-} info { lbvarInfo = lb }
418 setNewDemandInfo :: IdInfo -> Maybe Demand -> IdInfo
419 setNewDemandInfo info dd = dd `seq` info { newDemandInfo = dd }
420 setNewStrictnessInfo :: IdInfo -> Maybe StrictSig -> IdInfo
421 setNewStrictnessInfo info dd = dd `seq` info { newStrictnessInfo = dd }
426 -- | Basic 'IdInfo' that carries no useful information whatsoever
427 vanillaIdInfo :: IdInfo
430 cafInfo = vanillaCafInfo,
431 arityInfo = unknownArity,
432 #ifdef OLD_STRICTNESS
435 strictnessInfo = NoStrictnessInfo,
437 specInfo = emptySpecInfo,
438 workerInfo = NoWorker,
439 unfoldingInfo = noUnfolding,
440 lbvarInfo = NoLBVarInfo,
441 inlinePragInfo = AlwaysActive,
443 newDemandInfo = Nothing,
444 newStrictnessInfo = Nothing
447 -- | More informative 'IdInfo' we can use when we know the 'Id' has no CAF references
448 noCafIdInfo :: IdInfo
449 noCafIdInfo = vanillaIdInfo `setCafInfo` NoCafRefs
450 -- Used for built-in type Ids in MkId.
454 %************************************************************************
456 \subsection[arity-IdInfo]{Arity info about an @Id@}
458 %************************************************************************
460 For locally-defined Ids, the code generator maintains its own notion
461 of their arities; so it should not be asking... (but other things
462 besides the code-generator need arity info!)
465 -- | An 'ArityInfo' of @n@ tells us that partial application of this
466 -- 'Id' to up to @n-1@ value arguments does essentially no work.
468 -- That is not necessarily the same as saying that it has @n@ leading
469 -- lambdas, because coerces may get in the way.
471 -- The arity might increase later in the compilation process, if
472 -- an extra lambda floats up to the binding site.
473 type ArityInfo = Arity
475 -- | It is always safe to assume that an 'Id' has an arity of 0
476 unknownArity :: Arity
477 unknownArity = 0 :: Arity
479 ppArityInfo :: Int -> SDoc
480 ppArityInfo 0 = empty
481 ppArityInfo n = hsep [ptext (sLit "Arity"), int n]
484 %************************************************************************
486 \subsection{Inline-pragma information}
488 %************************************************************************
491 -- | Tells when the inlining is active.
492 -- When it is active the thing may be inlined, depending on how
495 -- If there was an @INLINE@ pragma, then as a separate matter, the
496 -- RHS will have been made to look small with a Core inline 'Note'
498 -- The default 'InlinePragInfo' is 'AlwaysActive', so the info serves
499 -- entirely as a way to inhibit inlining until we want it
500 type InlinePragInfo = Activation
504 %************************************************************************
508 %************************************************************************
511 -- | Records the specializations of this 'Id' that we know about
512 -- in the form of rewrite 'CoreRule's that target them
516 VarSet -- Locally-defined free vars of *both* LHS and RHS
517 -- of rules. I don't think it needs to include the
519 -- Note [Rule dependency info] in OccurAnal
521 -- | Assume that no specilizations exist: always safe
522 emptySpecInfo :: SpecInfo
523 emptySpecInfo = SpecInfo [] emptyVarSet
525 isEmptySpecInfo :: SpecInfo -> Bool
526 isEmptySpecInfo (SpecInfo rs _) = null rs
528 -- | Retrieve the locally-defined free variables of both the left and
529 -- right hand sides of the specialization rules
530 specInfoFreeVars :: SpecInfo -> VarSet
531 specInfoFreeVars (SpecInfo _ fvs) = fvs
533 specInfoRules :: SpecInfo -> [CoreRule]
534 specInfoRules (SpecInfo rules _) = rules
536 -- | Change the name of the function the rule is keyed on on all of the 'CoreRule's
537 setSpecInfoHead :: Name -> SpecInfo -> SpecInfo
538 setSpecInfoHead fn (SpecInfo rules fvs)
539 = SpecInfo (map (setRuleIdName fn) rules) fvs
541 seqSpecInfo :: SpecInfo -> ()
542 seqSpecInfo (SpecInfo rules fvs) = seqRules rules `seq` seqVarSet fvs
545 %************************************************************************
547 \subsection[worker-IdInfo]{Worker info about an @Id@}
549 %************************************************************************
551 There might not be a worker, even for a strict function, because:
552 (a) the function might be small enough to inline, so no need
554 (b) the strictness info might be "SSS" or something, so no w/w split.
556 Sometimes the arity of a wrapper changes from the original arity from
557 which it was generated, so we always emit the "original" arity into
558 the interface file, as part of the worker info.
560 How can this happen? Sometimes we get
561 f = coerce t (\x y -> $wf x y)
562 at the moment of w/w split; but the eta reducer turns it into
564 which is perfectly fine except that the exposed arity so far as
565 the code generator is concerned (zero) differs from the arity
566 when we did the split (2).
568 All this arises because we use 'arity' to mean "exactly how many
569 top level lambdas are there" in interface files; but during the
570 compilation of this module it means "how many things can I apply
575 -- | If this Id has a worker then we store a reference to it. Worker
576 -- functions are generated by the worker\/wrapper pass, using information
577 -- information from strictness analysis.
578 data WorkerInfo = NoWorker -- ^ No known worker function
579 | HasWorker Id Arity -- ^ The 'Arity' is the arity of the /wrapper/ at the moment of the
580 -- worker\/wrapper split, which may be different from the current 'Id' 'Aritiy'
582 seqWorker :: WorkerInfo -> ()
583 seqWorker (HasWorker id a) = id `seq` a `seq` ()
584 seqWorker NoWorker = ()
586 ppWorkerInfo :: WorkerInfo -> SDoc
587 ppWorkerInfo NoWorker = empty
588 ppWorkerInfo (HasWorker wk_id _) = ptext (sLit "Worker") <+> ppr wk_id
590 workerExists :: WorkerInfo -> Bool
591 workerExists NoWorker = False
592 workerExists (HasWorker _ _) = True
594 -- | The 'Id' of the worker function if it exists, or a panic otherwise
595 workerId :: WorkerInfo -> Id
596 workerId (HasWorker id _) = id
597 workerId NoWorker = panic "workerId: NoWorker"
599 -- | The 'Arity' of the worker function at the time of the split if it exists, or a panic otherwise
600 wrapperArity :: WorkerInfo -> Arity
601 wrapperArity (HasWorker _ a) = a
602 wrapperArity NoWorker = panic "wrapperArity: NoWorker"
606 %************************************************************************
608 \subsection[CG-IdInfo]{Code generator-related information}
610 %************************************************************************
613 -- CafInfo is used to build Static Reference Tables (see simplStg/SRT.lhs).
615 -- | Records whether an 'Id' makes Constant Applicative Form references
617 = MayHaveCafRefs -- ^ Indicates that the 'Id' is for either:
619 -- 1. A function or static constructor
620 -- that refers to one or more CAFs, or
622 -- 2. A real live CAF
624 | NoCafRefs -- ^ A function or static constructor
625 -- that refers to no CAFs.
627 -- | Assumes that the 'Id' has CAF references: definitely safe
628 vanillaCafInfo :: CafInfo
629 vanillaCafInfo = MayHaveCafRefs
631 mayHaveCafRefs :: CafInfo -> Bool
632 mayHaveCafRefs MayHaveCafRefs = True
633 mayHaveCafRefs _ = False
635 seqCaf :: CafInfo -> ()
636 seqCaf c = c `seq` ()
638 ppCafInfo :: CafInfo -> SDoc
639 ppCafInfo NoCafRefs = ptext (sLit "NoCafRefs")
640 ppCafInfo MayHaveCafRefs = empty
643 %************************************************************************
645 \subsection[cpr-IdInfo]{Constructed Product Result info about an @Id@}
647 %************************************************************************
650 #ifdef OLD_STRICTNESS
651 -- | If the @Id@ is a function then it may have Constructed Product Result
652 -- (CPR) info. A CPR analysis phase detects whether:
654 -- 1. The function's return value has a product type, i.e. an algebraic type
655 -- with a single constructor. Examples of such types are tuples and boxed
658 -- 2. The function always 'constructs' the value that it is returning. It
659 -- must do this on every path through, and it's OK if it calls another
660 -- function which constructs the result.
662 -- If this is the case then we store a template which tells us the
663 -- function has the CPR property and which components of the result are
666 = NoCPRInfo -- ^ No, this function does not return a constructed product
667 | ReturnsCPR -- ^ Yes, this function returns a constructed product
669 -- Implicitly, this means "after the function has been applied
670 -- to all its arguments", so the worker\/wrapper builder in
671 -- WwLib.mkWWcpr checks that that it is indeed saturated before
672 -- making use of the CPR info
674 -- We used to keep nested info about sub-components, but
675 -- we never used it so I threw it away
677 -- | It's always safe to assume that an 'Id' does not have the CPR property
679 noCprInfo = NoCPRInfo
681 seqCpr :: CprInfo -> ()
682 seqCpr ReturnsCPR = ()
683 seqCpr NoCPRInfo = ()
685 ppCprInfo NoCPRInfo = empty
686 ppCprInfo ReturnsCPR = ptext (sLit "__M")
688 instance Outputable CprInfo where
691 instance Show CprInfo where
692 showsPrec p c = showsPrecSDoc p (ppr c)
696 %************************************************************************
698 \subsection[lbvar-IdInfo]{Lambda-bound var info about an @Id@}
700 %************************************************************************
703 -- | If the 'Id' is a lambda-bound variable then it may have lambda-bound
704 -- variable info. Sometimes we know whether the lambda binding this variable
705 -- is a \"one-shot\" lambda; that is, whether it is applied at most once.
707 -- This information may be useful in optimisation, as computations may
708 -- safely be floated inside such a lambda without risk of duplicating
710 data LBVarInfo = NoLBVarInfo -- ^ No information
711 | IsOneShotLambda -- ^ The lambda is applied at most once).
713 -- | It is always safe to assume that an 'Id' has no lambda-bound variable information
714 noLBVarInfo :: LBVarInfo
715 noLBVarInfo = NoLBVarInfo
717 hasNoLBVarInfo :: LBVarInfo -> Bool
718 hasNoLBVarInfo NoLBVarInfo = True
719 hasNoLBVarInfo IsOneShotLambda = False
721 seqLBVar :: LBVarInfo -> ()
722 seqLBVar l = l `seq` ()
724 pprLBVarInfo :: LBVarInfo -> SDoc
725 pprLBVarInfo NoLBVarInfo = empty
726 pprLBVarInfo IsOneShotLambda = ptext (sLit "OneShot")
728 instance Outputable LBVarInfo where
731 instance Show LBVarInfo where
732 showsPrec p c = showsPrecSDoc p (ppr c)
736 %************************************************************************
738 \subsection{Bulk operations on IdInfo}
740 %************************************************************************
743 -- | This is used to remove information on lambda binders that we have
744 -- setup as part of a lambda group, assuming they will be applied all at once,
745 -- but turn out to be part of an unsaturated lambda as in e.g:
747 -- > (\x1. \x2. e) arg1
748 zapLamInfo :: IdInfo -> Maybe IdInfo
749 zapLamInfo info@(IdInfo {occInfo = occ, newDemandInfo = demand})
750 | is_safe_occ occ && is_safe_dmd demand
753 = Just (info {occInfo = safe_occ, newDemandInfo = Nothing})
755 -- The "unsafe" occ info is the ones that say I'm not in a lambda
756 -- because that might not be true for an unsaturated lambda
757 is_safe_occ (OneOcc in_lam _ _) = in_lam
758 is_safe_occ _other = True
760 safe_occ = case occ of
761 OneOcc _ once int_cxt -> OneOcc insideLam once int_cxt
764 is_safe_dmd Nothing = True
765 is_safe_dmd (Just dmd) = not (isStrictDmd dmd)
769 -- | Remove demand info on the 'IdInfo' if it is present, otherwise return @Nothing@
770 zapDemandInfo :: IdInfo -> Maybe IdInfo
771 zapDemandInfo info@(IdInfo {newDemandInfo = dmd})
772 | isJust dmd = Just (info {newDemandInfo = Nothing})
773 | otherwise = Nothing
777 zapFragileInfo :: IdInfo -> Maybe IdInfo
778 -- ^ Zap info that depends on free variables
780 = Just (info `setSpecInfo` emptySpecInfo
781 `setWorkerInfo` NoWorker
782 `setUnfoldingInfo` noUnfolding
783 `setOccInfo` if isFragileOcc occ then NoOccInfo else occ)
788 %************************************************************************
790 \subsection{TickBoxOp}
792 %************************************************************************
797 -- | Tick box for Hpc-style coverage
799 = TickBox Module {-# UNPACK #-} !TickBoxId
801 instance Outputable TickBoxOp where
802 ppr (TickBox mod n) = ptext (sLit "tick") <+> ppr (mod,n)