Skip to content

Is Note [Kind-checking tyvar binders for associated types] obsolete?

While browsing Notes recently, I came across this peculiar Note:

Note [Kind-checking tyvar binders for associated types]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When kind-checking the type-variable binders for associated
   data/newtype decls
   family decls
we behave specially for type variables that are already in scope;
that is, bound by the enclosing class decl.  This is done in
kcLHsQTyVarBndrs:
  * The use of tcImplicitQTKBndrs
  * The tcLookupLocal_maybe code in kc_hs_tv

See Note [Associated type tyvar names] in GHC.Core.Class and
    Note [TyVar binders for associated decls] in GHC.Hs.Decls

We must do the same for family instance decls, where the in-scope
variables may be bound by the enclosing class instance decl.
Hence the use of tcImplicitQTKBndrs in tcFamTyPatsAndGen.

This Note dates back to 9fc40c73, and since then, I believe that this Note has become obsolete:

  • There are no references to Note [Kind-checking tyvar binders for associated types] whatsoever in the rest of the codebase.

  • Four of the functions that this Note mentions (kcLHsQTyVarBndrs, tcImplicitQTKBndrs, tcLookupLocal_maybe, and kc_hs_tv) exist anymore.

  • One of the functions that this Note mentions, tcFamTyPatsAndGen, does not exist save for a brief mention in the comments of another function:

    checkFamPatBinders :: TyCon
                       -> [TcTyVar]   -- Bound on LHS of family instance
                       -> [TcType]    -- LHS patterns
                       -> Type        -- RHS
                       -> TcM ()
    -- We do these binder checks now, in tcFamTyPatsAndGen, rather
    -- than later, in checkValidFamEqn, for two reasons:
    --   - We have the implicitly and explicitly
    --     bound type variables conveniently to hand
    --   - If implicit variables are out of scope it may
    --     cause a crash; notably in tcConDecl in tcDataFamInstDecl

    But these comments are themselves outdated!

In light of this, does Note [Kind-checking tyvar binders for associated types] serve a useful purpose anymore? Or should we just rip it out?

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information