Note [Injecting implicit bindings]

GHC/CoreToStg/AddImplicitBinds.hs:36 compiler 1 ticket

`addImplicitBinds` injects the so-called "implicit bindings" generated by
the TyCons of the module. Specifically:

 * Data constructor wrappers
 * Data constructor workers: see Note [Data constructor workers]
 * Class op selectors: we want curriedn versions of these too

Note that /record selector/ are injected much earlier, at the beginning
of the pipeline -- see Note [Record selectors] in GHC.Tc.TyCl.Utils.

At one time I tried injecting the implicit bindings *early*, at the
beginning of SimplCore.  But that gave rise to real difficulty,
because GlobalIds are supposed to have *fixed* IdInfo, but the
simplifier and other core-to-core passes mess with IdInfo all the
time.  The straw that broke the camels back was when a class selector
got the wrong arity -- ie the simplifier gave it arity 2, whereas
importing modules were expecting it to have arity 1 (#2844).
It's much safer just to inject them right at the end, after tidying.

Oh: two other reasons for injecting them late:

  - If implicit Ids are already in the bindings when we start tidying,
    we'd have to be careful not to treat them as external Ids (in
    the sense of chooseExternalIds); else the Ids mentioned in *their*
    RHSs will be treated as external and you get an interface file
    saying      a18 = <blah>
    but nothing referring to a18 (because the implicit Id is the
    one that does, and implicit Ids don't appear in interface files).

  - More seriously, the tidied type-envt will include the implicit
    Id replete with a18 in its unfolding; but we won't take account
    of a18 when computing a fingerprint for the class; result chaos.

References 2

Referenced by 2