Note [Cannot trivialise]
Consider: f :: Int -> Addr# foo :: Bar foo = Bar (f 3) Then we can't ANF-ise foo, even though we'd like to, because we can't make a top-level binding for the Addr# (f 3). And if so we don't want to turn it into foo = let x = f 3 in Bar x because we'll just end up inlining x back, and that makes the simplifier loop. Better not to ANF-ise it at all. Literal strings are an exception. foo = Ptr "blob"# We want to turn this into: foo1 = "blob"# foo = Ptr foo1 See Note [Core top-level string literals] in GHC.Core. ************************************************************************ * * Completing a lazy binding * * ************************************************************************ completeBind * deals only with Ids, not TyVars * takes an already-simplified binder and RHS * is used for both recursive and non-recursive bindings * is used for both top-level and non-top-level bindings It does the following: - tries discarding a dead binding - tries PostInlineUnconditionally - add unfolding [this is the only place we add an unfolding] - add arity - extend the InScopeSet of the SimplEnv It does *not* attempt to do let-to-case. Why? Because it is used for - top-level bindings (when let-to-case is impossible) - many situations where the "rhs" is known to be a WHNF (so let-to-case is inappropriate). Nor does it do the atomic-argument thing
References 1
- Core top-level string literals GHC.Core
Referenced by 1
- GHC.Core.Opt.Simplify.Iteration call site