Revamp the treatment of auxiliary bindings for derived instances
This started as a simple fix for #18321 (closed) that organically grew into a
much more sweeping refactor of how auxiliary bindings for derived
instances are handled. I have rewritten Note [Auxiliary binders]
in GHC.Tc.Deriv.Generate
to explain all of the moving parts, but
the highlights are:
- Previously, the OccName of each auxiliary binding would be given
a suffix containing a hash of its package name, module name, and
parent data type to avoid name clashes. This was needlessly
complicated, so we take the more direct approach of generating
Exact
RdrName
s for each auxiliary binding with the sameOccName
, but using an underlyingSystem
Name
with a freshUnique
for each binding. Unlike hashes, allocating newUnique
s does not require any cleverness and avoid name clashes all the same... - ...speaking of which, in order to convince the renamer that multiple
auxiliary bindings with the same
OccName
(but differentUnique
s) are kosher, we now usernLocalValBindsLHS
instead ofrnTopBindsLHS
to rename auxiliary bindings. Again, seeNote [Auxiliary binders]
for the full story. - I have removed the
DerivHsBind
constructor forDerivStuff
—which was only used forData.Data
-related auxiliary bindings—and refactoredgen_Data_binds
to useDerivAuxBind
instead. This brings the treatment ofData.Data
-related auxiliary bindings in line with every other form of auxiliary binding.
Fixes #18321 (closed).