Skip to content

Generate unique names for derived auxiliary bindings, don't deduplicate them

Ryan Scott requested to merge wip/T18321 into master

Previously, GHC attempted to deduplicate auxiliary bindings for derived instances to avoid name clashes. See Note [Auxiliary binders] in GHC.Tc.Deriv.Generate. However, this approach was not bulletproof, as #18321 (closed) shows that this approach can fall over in the presence of Template Haskell splices.

Rather than attempting to repair the previous approach, this patch adopts the different approach of simply generating multiple copies of each form of auxiliary binding, each with its own unique name taken from a global counter. This can lead to code bloat, but GHC's CSE pass in the optimizer is usually quite good about catching these, since the definitions of auxiliary bindings are small. See the revamped Note [Auxiliary binders] for the full story.

Fix #18321 (closed).

Merge request reports