+
+
+%************************************************************************
+%* *
+\subsection{Bulk operations on IdInfo}
+%* *
+%************************************************************************
+
+zapFragileInfo is used when cloning binders, mainly in the
+simplifier. We must forget about used-once information because that
+isn't necessarily correct in the transformed program.
+Also forget specialisations and unfoldings because they would need
+substitution to be correct. (They get pinned back on separately.)
+
+\begin{code}
+zapFragileInfo :: IdInfo -> Maybe IdInfo
+zapFragileInfo info@(IdInfo {occInfo = occ,
+ workerInfo = wrkr,
+ specInfo = rules,
+ unfoldingInfo = unfolding})
+ | not (isFragileOccInfo occ)
+ -- We must forget about whether it was marked safe-to-inline,
+ -- because that isn't necessarily true in the simplified expression.
+ -- This is important because expressions may be re-simplified
+ -- We don't zap deadness or loop-breaker-ness.
+ -- The latter is important because it tells MkIface not to
+ -- spit out an inlining for the thing. The former doesn't
+ -- seem so important, but there's no harm.
+
+ && isEmptyCoreRules rules
+ -- Specialisations would need substituting. They get pinned
+ -- back on separately.
+
+ && not (workerExists wrkr)
+
+ && not (hasUnfolding unfolding)
+ -- This is very important; occasionally a let-bound binder is used
+ -- as a binder in some lambda, in which case its unfolding is utterly
+ -- bogus. Also the unfolding uses old binders so if we left it we'd
+ -- have to substitute it. Much better simply to give the Id a new
+ -- unfolding each time, which is what the simplifier does.
+ = Nothing
+
+ | otherwise
+ = Just (info {occInfo = robust_occ_info,
+ workerInfo = noWorkerInfo,
+ specInfo = emptyCoreRules,
+ unfoldingInfo = noUnfolding})
+ where
+ -- It's important to keep the loop-breaker info,
+ -- because the substitution doesn't remember it.
+ robust_occ_info = case occ of
+ OneOcc _ _ -> NoOccInfo
+ other -> occ
+\end{code}
+
+@zapLamInfo@ is used for lambda binders that turn out to to be
+part of an unsaturated lambda
+
+\begin{code}
+zapLamInfo :: IdInfo -> Maybe IdInfo
+zapLamInfo info@(IdInfo {occInfo = occ, demandInfo = demand})
+ | is_safe_occ && not (isStrict demand)
+ = Nothing
+ | otherwise
+ = Just (info {occInfo = safe_occ,
+ demandInfo = wwLazy})
+ 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 lambda
+ is_safe_occ = case occ of
+ OneOcc in_lam once -> in_lam
+ other -> True
+
+ safe_occ = case occ of
+ OneOcc _ once -> OneOcc insideLam once
+ other -> occ
+\end{code}
+
+
+copyIdInfo is used when shorting out a top-level binding
+ f_local = BIG
+ f = f_local
+where f is exported. We are going to swizzle it around to
+ f = BIG
+ f_local = f
+but we must be careful to combine their IdInfos right.
+The fact that things can go wrong here is a bad sign, but I can't see
+how to make it 'patently right', so copyIdInfo is derived (pretty much) by trial and error
+
+Here 'from' is f_local, 'to' is f, and the result is attached to f
+
+\begin{code}
+copyIdInfo :: IdInfo -- From
+ -> IdInfo -- To
+ -> IdInfo -- To, updated with stuff from From; except flavour unchanged
+copyIdInfo from to = from { flavourInfo = flavourInfo to,
+ specInfo = specInfo to,
+ inlinePragInfo = inlinePragInfo to
+ }
+ -- It's important to preserve the inline pragma on 'f'; e.g. consider
+ -- {-# NOINLINE f #-}
+ -- f = local
+ --
+ -- similarly, transformation rules may be attached to f
+ -- and we want to preserve them.
+ --
+ -- On the other hand, we want the strictness info from f_local.
+\end{code}