Note [CorePrep Overview]
The goal of this pass is to prepare for code generation.
1. Saturate constructor and primop applications.
2. Convert to A-normal form; that is, function arguments
are always variables.
* Use case for strict arguments:
f E ==> case E of x -> f x
(where f is strict)
* Use let for non-trivial lazy arguments
f E ==> let x = E in f x
(were f is lazy and x is non-trivial)
3. Similarly, convert any unboxed lets into cases.
[I'm experimenting with leaving 'ok-for-speculation'
rhss in let-form right up to this point.]
4. Ensure that *value* lambdas only occur as the RHS of a binding
(The code generator can't deal with anything else.)
Type lambdas are ok, however, because the code gen discards them.
5. ANF-isation results in additional bindings that can obscure values.
We float these out; see Note [Floating in CorePrep].
6. Clone all local Ids. See Note [Cloning in CorePrep]
7. Give each dynamic CCall occurrence a fresh unique; this is
rather like the cloning step above.
8. Convert bignum literals into their core representation.
9. Uphold tick consistency while doing this: We move ticks out of
(non-type) applications where we can, and make sure that we
annotate according to scoping rules when floating.
10. Collect cost centres (including cost centres in unfoldings) if we're in
profiling mode. We have to do this here because we won't have unfoldings
after this pass (see `trimUnfolding` and Note [Drop unfoldings and rules].
11. Eliminate some magic Ids, specifically
runRW# (\s. e) ==> e[readWorldId/s]
lazy e ==> e (see Note [lazyId magic] in GHC.Types.Id.Make)
noinline e ==> e
nospec e ==> e
ToDo: keepAlive# ...
This is done in cpeApp
This is all done modulo type applications and abstractions, so that
when type erasure is done for conversion to STG, we don't end up with
any trivial or useless bindings. References 4
- Cloning in CorePrep GHC.CoreToStg.Prep
- Drop unfoldings and rules GHC.CoreToStg.Prep
- Floating in CorePrep GHC.CoreToStg.Prep
- lazyId magic GHC.Types.Id.Make
Referenced by 3
- GHC.Stg.Subst call site
- GHC.Stg.Syntax call site
- Casting slot arguments GHC.Stg.Unarise