Skip to content

Refactor: FreshOrReuse instead of addTyClTyVarBinds

Vladislav Zavialov requested to merge wip/int-index/fresh-or-reuse into master

This is a refactoring that should have no effect on observable behavior.

Prior to this change, GHC.HsToCore.Quote contained a few closely related functions to process type variable bindings: addSimpleTyVarBinds, addHsTyVarBinds, addQTyVarBinds, and addTyClTyVarBinds.

We can classify them by their input type and name generation strategy:

                              Fresh names only    Reuse bound names
                          +---------------------+-------------------+
                   [Name] | addSimpleTyVarBinds |                   |
[LHsTyVarBndr flag GhcRn] |     addHsTyVarBinds |                   |
        LHsQTyVars GhcRn  |      addQTyVarBinds | addTyClTyVarBinds |
                          +---------------------+-------------------+

Note how two functions are missing. Because of this omission, there were two places where a LHsQTyVars value was constructed just to be able to pass it to addTyClTyVarBinds:

  1. mk_qtvs in addHsOuterFamEqnTyVarBinds
  2. mkHsQTvs in repFamilyDecl

This prevented me from making other changes to LHsQTyVars, so the main goal of this refactoring is to get rid of those workarounds.

The most direct solution would be to define the missing functions. But that would lead to a certain amount of code duplication. To avoid code duplication, I factored out the name generation strategy into a function parameter:

data FreshOrReuse
  = FreshNamesOnly
  | ReuseBoundNames

addSimpleTyVarBinds :: FreshOrReuse -> ...
addHsTyVarBinds     :: FreshOrReuse -> ...
addQTyVarBinds      :: FreshOrReuse -> ...
Edited by Vladislav Zavialov

Merge request reports