Skip to content
  • Ryan Scott's avatar
    Always use rnImplicitBndrs to bring implicit tyvars into scope · a47e6442
    Ryan Scott authored and Marge Bot's avatar Marge Bot committed
    This implements a first step towards #16762 by changing the renamer
    to always use `rnImplicitBndrs` to bring implicitly bound type
    variables into scope. The main change is in `rnFamInstEqn` and
    `bindHsQTyVars`, which previously used _ad hoc_ methods of binding
    their implicit tyvars.
    
    There are a number of knock-on consequences:
    
    * One of the reasons that `rnFamInstEqn` used an _ad hoc_ binding
      mechanism was to give more precise source locations in
      `-Wunused-type-patterns` warnings. (See
      ghc/ghc#16762 (comment 273343) for an
      example of this.) However, these warnings are actually a little
      _too_ precise, since implicitly bound type variables don't have
      exact binding sites like explicitly bound type variables do.
      A similar problem existed for
      "`Different names for the same type variable`" errors involving
      implicit tyvars bound by `bindHsQTyVars`.
      Therefore, we simply accept the less precise (but more accurate)
      source locations from `rnImplicitBndrs` in `rnFamInstEqn` and
      `bindHsQTyVars`. See
      `Note [Source locations for implicitly bound type variables]` in
      `GHC.Rename.HsType` for the full story.
    * In order for `rnImplicitBndrs` to work in `rnFamInstEqn`, it needs
      to be able to look up names from the parent class (in the event
      that we are renaming an associated type family instance). As a
      result, `rnImplicitBndrs` now takes an argument of type
      `Maybe assoc`, which is `Just` in the event that a type family
      instance is associated with a class.
    * Previously, GHC kept track of three type synonyms for free type
      variables in the renamer: `FreeKiTyVars`, `FreeKiTyVarsDups`
      (which are allowed to contain duplicates), and
      `FreeKiTyVarsNoDups` (which contain no duplicates). However, making
      is a distinction between `-Dups` and `-NoDups` is now pointless, as
      all code that returns `FreeKiTyVars{,Dups,NoDups}` will eventually
      end up being passed to `rnImplicitBndrs`, which removes duplicates.
      As a result, I decided to just get rid of `FreeKiTyVarsDups` and
      `FreeKiTyVarsNoDups`, leaving only `FreeKiTyVars`.
    * The `bindLRdrNames` and `deleteBys` functions are now dead code, so
      I took the liberty of removing them.
    a47e6442