Note [Cloning in CorePrep]

GHC/CoreToStg/Prep.hs:157 compiler 1 ticket

In CorePrep we
* Always clone non-CoVar Ids, so each has a unique Unique
* Sometimes clone CoVars and TyVars

We always clone non-CoVarIds, for three reasons

1. Things associated with labels in the final code must be truly unique in
   order to avoid labels being shadowed in the final output.

2. Even binders without info tables like function arguments or alternative
   bound binders must be unique at least in their type/unique combination.
   We only emit a single declaration for each binder when compiling to C
   so if binders are not unique we would either get duplicate declarations
   or misstyped variables. The later happend in #22402.

3. We heavily use unique-keyed maps in the backend which can go wrong when
   ids with the same unique are meant to represent the same variable.

Generally speaking we don't clone TyVars or CoVars. The code gen doesn't need
that (they are erased), and doing so would be tiresome because then we'd need
to substitute in types and coercions.  But sometimes need to: see
Note [Cloning CoVars and TyVars]

References 1

Referenced by 3