Simplify bindLHsTyVarBndrs and bindHsQTyVars
Both bindLHsTyVarBndrs
and bindHsQTyVars
take two separate
Maybe
arguments, which I find terribly confusing. Thankfully, it's
possible to remove one Maybe
argument from each of these functions,
which this patch accomplishes:
-
bindHsQTyVars
takes aMaybe SDoc
argument, which isJust
if GHC should warn about any of the quantified type variables going unused. However, every call site usesNothing
in practice. This makes sense, since it doesn't really make sense to warn about unused type variables bound by anLHsQTyVars
. For instance, you wouldn't warn about thea
indata Proxy a = Proxy
going unused.As a result, I simply remove this
Maybe SDoc
argument altogether. -
bindLHsTyVarBndrs
also takes aMaybe SDoc
argument for the same reasons thatbindHsQTyVars
took one. To make things more confusing, however,bindLHsTyVarBndrs
also takes a separateHsDocContext
argument, which is pretty-printed (to anSDoc
) in warnings and error messages.In practice, the
Maybe SDoc
and theHsDocContext
often contain the same text. See the call sites forbindLHsTyVarBndrs
inrnFamInstEqn
andrnConDecl
, for instance. There are only a handful of call sites where the text differs between theMaybe SDoc
andHsDocContext
arguments:- In
rnHsRuleDecl
, where theMaybe SDoc
says "In the rule
" and theHsDocContext
says "In the transformation rule
". - In
rnHsTyKi
/rn_ty
, where theMaybe SDoc
says "In the type
" but theHsDocContext
is inhereted from the surrounding context (e.g., ifrnHsTyKi
were called on a top-level type signature, theHsDocContext
would be "In the type signature
" instead)
In both cases, warnings/error messages arguably improve by unifying making the
Maybe SDoc
's text match that of theHsDocContext
. As a result, I decided to remove theMaybe SDoc
argument tobindLHsTyVarBndrs
entirely and simply reuse the text from theHsDocContext
.The
Maybe SDoc
argument has one other purpose: signaling when to emit "Unused quantified type variable
" warnings. To recover this functionality, I replaced theMaybe SDoc
argument with a boolean-likeWarnUnusedForalls
argument. The onlybindLHsTyVarBndrs
call site that chooses not to emit these warnings inbindHsQTyVars
. - In