-- | The 'IdDetails' of an 'Id' give stable, and necessary, -- information about the Id. dataIdDetails=VanillaId-- | The 'Id' for a record selector|RecSelId{sel_tycon::TyCon-- ^ For a data type family, this is the /instance/ 'TyCon'-- not the family 'TyCon',sel_naughty::Bool-- True <=> a "naughty" selector which can't actually exist, for example @x@ in:-- data T = forall a. MkT { x :: a }}-- See Note [Naughty record selectors] in TcTyClsDecls|DataConWorkIdDataCon-- ^ The 'Id' is for a data constructor /worker/|DataConWrapIdDataCon-- ^ The 'Id' is for a data constructor /wrapper/-- [the only reasons we need to know is so that-- a) to support isImplicitId-- b) when desugaring a RecordCon we can get -- from the Id back to the data con]|ClassOpIdClass-- ^ The 'Id' is an superclass selector or class operation of a class|PrimOpIdPrimOp-- ^ The 'Id' is for a primitive operator|FCallIdForeignCall-- ^ The 'Id' is for a foreign call|TickBoxOpIdTickBoxOp-- ^ The 'Id' is for a HPC tick box (both traditional and binary)|DFunIdIntBool-- ^ A dictionary function.-- Int = the number of "silent" arguments to the dfun-- e.g. class D a => C a where ...-- instance C a => C [a]-- has is_silent = 1, because the dfun-- has type dfun :: (D a, C a) => C [a]-- See the DFun Superclass Invariant in TcInstDcls---- Bool = True <=> the class has only one method, so may be-- implemented with a newtype, so it might be bad-- to be strict on this dictionarycoVarDetails::IdDetailscoVarDetails=VanillaIdinstanceOutputableIdDetailswhereppr=pprIdDetailspprIdDetails::IdDetails->SDocpprIdDetailsVanillaId=emptypprIdDetailsother=brackets(ppother)whereppVanillaId=panic"pprIdDetails"pp(DataConWorkId_)=ptext(sLit"DataCon")pp(DataConWrapId_)=ptext(sLit"DataConWrapper")pp(ClassOpId{})=ptext(sLit"ClassOp")pp(PrimOpId_)=ptext(sLit"PrimOp")pp(FCallId_)=ptext(sLit"ForeignCall")pp(TickBoxOpId_)=ptext(sLit"TickBoxOp")pp(DFunIdnsnt)=ptext(sLit"DFunId")<>ppWhen(ns/=0)(brackets(intns))<>ppWhennt(ptext(sLit"(nt)"))pp(RecSelId{sel_naughty=is_naughty})=brackets$ptext(sLit"RecSel")<>ppWhenis_naughty(ptext(sLit"(naughty)"))

-- | An 'IdInfo' gives /optional/ information about an 'Id'. If-- present it never lies, but it may not be present, in which case there-- is always a conservative assumption which can be made.-- -- Two 'Id's may have different info even though they have the same-- 'Unique' (and are hence the same 'Id'); for example, one might lack-- the properties attached to the other.-- -- The 'IdInfo' gives information about the value, or definition, of the-- 'Id'. It does not contain information about the 'Id''s usage,-- except for 'demandInfo' and 'lbvarInfo'.dataIdInfo=IdInfo{arityInfo::!ArityInfo,-- ^ 'Id' arityspecInfo::SpecInfo,-- ^ Specialisations of the 'Id's function which exist-- See Note [Specialisations and RULES in IdInfo]unfoldingInfo::Unfolding,-- ^ The 'Id's unfoldingcafInfo::CafInfo,-- ^ 'Id' CAF infolbvarInfo::LBVarInfo,-- ^ Info about a lambda-bound variable, if the 'Id' is oneinlinePragInfo::InlinePragma,-- ^ Any inline pragma atached to the 'Id'occInfo::OccInfo,-- ^ How the 'Id' occurs in the programstrictnessInfo::MaybeStrictSig,-- ^ Id strictness information. Reason for Maybe: -- the DmdAnal phase needs to know whether-- this is the first visit, so it can assign botSig.-- Other customers want topSig. So @Nothing@ is good.demandInfo::MaybeDemand-- ^ Id demand information. Similarly we want to know -- if there's no known demand yet, for when we are looking-- for CPR info}-- | Just evaluate the 'IdInfo' to WHNFseqIdInfo::IdInfo->()seqIdInfo(IdInfo{})=()-- | Evaluate all the fields of the 'IdInfo' that are generally demanded by the-- compilermegaSeqIdInfo::IdInfo->()megaSeqIdInfoinfo=seqSpecInfo(specInfoinfo)`seq`-- Omitting this improves runtimes a little, presumably because-- some unfoldings are not calculated at all-- seqUnfolding (unfoldingInfo info) `seq`seqDemandInfo(demandInfoinfo)`seq`seqStrictnessInfo(strictnessInfoinfo)`seq`seqCaf(cafInfoinfo)`seq`seqLBVar(lbvarInfoinfo)`seq`seqOccInfo(occInfoinfo)seqStrictnessInfo::MaybeStrictSig->()seqStrictnessInfoNothing=()seqStrictnessInfo(Justty)=seqStrictSigtyseqDemandInfo::MaybeDemand->()seqDemandInfoNothing=()seqDemandInfo(Justdmd)=seqDemanddmd

\end{code}
Setters
\begin{code}

setSpecInfo::IdInfo->SpecInfo->IdInfosetSpecInfoinfosp=sp`seq`info{specInfo=sp}setInlinePragInfo::IdInfo->InlinePragma->IdInfosetInlinePragInfoinfopr=pr`seq`info{inlinePragInfo=pr}setOccInfo::IdInfo->OccInfo->IdInfosetOccInfoinfooc=oc`seq`info{occInfo=oc}-- Try to avoid spack leaks by seq'ingsetUnfoldingInfoLazily::IdInfo->Unfolding->IdInfosetUnfoldingInfoLazilyinfouf-- Lazy variant to avoid looking at the=-- unfolding of an imported Id unless necessaryinfo{unfoldingInfo=uf}-- (In this case the demand-zapping is redundant.)setUnfoldingInfo::IdInfo->Unfolding->IdInfosetUnfoldingInfoinfouf=-- We don't seq the unfolding, as we generate intermediate-- unfoldings which are just thrown away, so evaluating them is a-- waste of time.-- seqUnfolding uf `seq`info{unfoldingInfo=uf}setArityInfo::IdInfo->ArityInfo->IdInfosetArityInfoinfoar=info{arityInfo=ar}setCafInfo::IdInfo->CafInfo->IdInfosetCafInfoinfocaf=info{cafInfo=caf}setLBVarInfo::IdInfo->LBVarInfo->IdInfosetLBVarInfoinfolb={-lb `seq`-}info{lbvarInfo=lb}setDemandInfo::IdInfo->MaybeDemand->IdInfosetDemandInfoinfodd=dd`seq`info{demandInfo=dd}setStrictnessInfo::IdInfo->MaybeStrictSig->IdInfosetStrictnessInfoinfodd=dd`seq`info{strictnessInfo=dd}

\end{code}
\begin{code}

-- | Basic 'IdInfo' that carries no useful information whatsoevervanillaIdInfo::IdInfovanillaIdInfo=IdInfo{cafInfo=vanillaCafInfo,arityInfo=unknownArity,specInfo=emptySpecInfo,unfoldingInfo=noUnfolding,lbvarInfo=NoLBVarInfo,inlinePragInfo=defaultInlinePragma,occInfo=NoOccInfo,demandInfo=Nothing,strictnessInfo=Nothing}-- | More informative 'IdInfo' we can use when we know the 'Id' has no CAF referencesnoCafIdInfo::IdInfonoCafIdInfo=vanillaIdInfo`setCafInfo`NoCafRefs-- Used for built-in type Ids in MkId.

\end{code}
%************************************************************************
%* *
\subsection[arity-IdInfo]{Arity info about an @Id@}
%* *
%************************************************************************
For locally-defined Ids, the code generator maintains its own notion
of their arities; so it should not be asking... (but other things
besides the code-generator need arity info!)
\begin{code}

-- | An 'ArityInfo' of @n@ tells us that partial application of this -- 'Id' to up to @n-1@ value arguments does essentially no work.---- That is not necessarily the same as saying that it has @n@ leading -- lambdas, because coerces may get in the way.---- The arity might increase later in the compilation process, if-- an extra lambda floats up to the binding site.typeArityInfo=Arity-- | It is always safe to assume that an 'Id' has an arity of 0unknownArity::ArityunknownArity=0::ArityppArityInfo::Int->SDocppArityInfo0=emptyppArityInfon=hsep[ptext(sLit"Arity"),intn]

-- | Tells when the inlining is active.-- When it is active the thing may be inlined, depending on how-- big it is.---- If there was an @INLINE@ pragma, then as a separate matter, the-- RHS will have been made to look small with a Core inline 'Note'---- The default 'InlinePragInfo' is 'AlwaysActive', so the info serves-- entirely as a way to inhibit inlining until we want ittypeInlinePragInfo=InlinePragma

\end{code}
%************************************************************************
%* *
SpecInfo
%* *
%************************************************************************
Note [Specialisations and RULES in IdInfo]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Generally speaking, a GlobalIdshas an *empty* SpecInfo. All their
RULES are contained in the globally-built rule-base. In principle,
one could attach the to M.f the RULES for M.f that are defined in M.
But we don't do that for instance declarations and so we just treat
them all uniformly.
The EXCEPTION is PrimOpIds, which do have rules in their IdInfo. That is
jsut for convenience really.
However, LocalIds may have non-empty SpecInfo. We treat them
differently because:
a) they might be nested, in which case a global table won't work
b) the RULE might mention free variables, which we use to keep things alive
In TidyPgm, when the LocalId becomes a GlobalId, its RULES are stripped off
and put in the global list.
\begin{code}

-- | Records the specializations of this 'Id' that we know about-- in the form of rewrite 'CoreRule's that target themdataSpecInfo=SpecInfo[CoreRule]VarSet-- Locally-defined free vars of *both* LHS and RHS -- of rules. I don't think it needs to include the-- ru_fn though.-- Note [Rule dependency info] in OccurAnal-- | Assume that no specilizations exist: always safeemptySpecInfo::SpecInfoemptySpecInfo=SpecInfo[]emptyVarSetisEmptySpecInfo::SpecInfo->BoolisEmptySpecInfo(SpecInfors_)=nullrs-- | Retrieve the locally-defined free variables of both the left and-- right hand sides of the specialization rulesspecInfoFreeVars::SpecInfo->VarSetspecInfoFreeVars(SpecInfo_fvs)=fvsspecInfoRules::SpecInfo->[CoreRule]specInfoRules(SpecInforules_)=rules-- | Change the name of the function the rule is keyed on on all of the 'CoreRule'ssetSpecInfoHead::Name->SpecInfo->SpecInfosetSpecInfoHeadfn(SpecInforulesfvs)=SpecInfo(map(setRuleIdNamefn)rules)fvsseqSpecInfo::SpecInfo->()seqSpecInfo(SpecInforulesfvs)=seqRulesrules`seq`seqVarSetfvs

-- CafInfo is used to build Static Reference Tables (see simplStg/SRT.lhs).-- | Records whether an 'Id' makes Constant Applicative Form referencesdataCafInfo=MayHaveCafRefs-- ^ Indicates that the 'Id' is for either:---- 1. A function or static constructor-- that refers to one or more CAFs, or---- 2. A real live CAF|NoCafRefs-- ^ A function or static constructor-- that refers to no CAFs.deriving(Eq,Ord)-- | Assumes that the 'Id' has CAF references: definitely safevanillaCafInfo::CafInfovanillaCafInfo=MayHaveCafRefsmayHaveCafRefs::CafInfo->BoolmayHaveCafRefsMayHaveCafRefs=TruemayHaveCafRefs_=FalseseqCaf::CafInfo->()seqCafc=c`seq`()instanceOutputableCafInfowhereppr=ppCafInfoppCafInfo::CafInfo->SDocppCafInfoNoCafRefs=ptext(sLit"NoCafRefs")ppCafInfoMayHaveCafRefs=empty

-- | If the 'Id' is a lambda-bound variable then it may have lambda-bound-- variable info. Sometimes we know whether the lambda binding this variable-- is a \"one-shot\" lambda; that is, whether it is applied at most once.---- This information may be useful in optimisation, as computations may-- safely be floated inside such a lambda without risk of duplicating-- work.dataLBVarInfo=NoLBVarInfo-- ^ No information|IsOneShotLambda-- ^ The lambda is applied at most once).-- | It is always safe to assume that an 'Id' has no lambda-bound variable informationnoLBVarInfo::LBVarInfonoLBVarInfo=NoLBVarInfohasNoLBVarInfo::LBVarInfo->BoolhasNoLBVarInfoNoLBVarInfo=TruehasNoLBVarInfoIsOneShotLambda=FalseseqLBVar::LBVarInfo->()seqLBVarl=l`seq`()pprLBVarInfo::LBVarInfo->SDocpprLBVarInfoNoLBVarInfo=emptypprLBVarInfoIsOneShotLambda=ptext(sLit"OneShot")instanceOutputableLBVarInfowhereppr=pprLBVarInfo

-- | This is used to remove information on lambda binders that we have-- setup as part of a lambda group, assuming they will be applied all at once,-- but turn out to be part of an unsaturated lambda as in e.g:---- > (\x1. \x2. e) arg1zapLamInfo::IdInfo->MaybeIdInfozapLamInfoinfo@(IdInfo{occInfo=occ,demandInfo=demand})|is_safe_occocc&&is_safe_dmddemand=Nothing|otherwise=Just(info{occInfo=safe_occ,demandInfo=Nothing})where-- The "unsafe" occ info is the ones that say I'm not in a lambda-- because that might not be true for an unsaturated lambdais_safe_occ(OneOccin_lam__)=in_lamis_safe_occ_other=Truesafe_occ=caseoccofOneOcc_onceint_cxt->OneOccinsideLamonceint_cxt_other->occis_safe_dmdNothing=Trueis_safe_dmd(Justdmd)=not(isStrictDmddmd)

\end{code}
\begin{code}

-- | Remove demand info on the 'IdInfo' if it is present, otherwise return @Nothing@zapDemandInfo::IdInfo->MaybeIdInfozapDemandInfoinfo@(IdInfo{demandInfo=dmd})|isJustdmd=Just(info{demandInfo=Nothing})|otherwise=Nothing