diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2020-11-13 10:15:32 -0500 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-11-15 03:36:21 -0500 |
commit | d61adb3dace8f52e21f302989182145a0efa103f (patch) | |
tree | a2770a8a8b47c715354758ed6ed8c58c8f2f9dde /compiler/GHC/Tc/Gen/App.hs | |
parent | a2539650cc9c6606c6b50dd5dd96caa0209b408c (diff) | |
download | haskell-d61adb3dace8f52e21f302989182145a0efa103f.tar.gz |
Name (tc)SplitForAll- functions more consistently
There is a zoo of `splitForAll-` functions in `GHC.Core.Type` (as well as
`tcSplitForAll-` functions in `GHC.Tc.Utils.TcType`) that all do very similar
things, but vary in the particular form of type variable that they return. To
make things worse, the names of these functions are often quite misleading.
Some particularly egregious examples:
* `splitForAllTys` returns `TyCoVar`s, but `splitSomeForAllTys` returns
`VarBndr`s.
* `splitSomeForAllTys` returns `VarBndr`s, but `tcSplitSomeForAllTys` returns
`TyVar`s.
* `splitForAllTys` returns `TyCoVar`s, but `splitForAllTysInvis` returns
`InvisTVBinder`s. (This in particular arose in the context of #18939, and
this finally motivated me to bite the bullet and improve the status quo
vis-à-vis how we name these functions.)
In an attempt to bring some sanity to how these functions are named, I have
opted to rename most of these functions en masse to use consistent suffixes
that describe the particular form of type variable that each function returns.
In concrete terms, this amounts to:
* Functions that return a `TyVar` now use the suffix `-TyVar`.
This caused the following functions to be renamed:
* `splitTyVarForAllTys` -> `splitForAllTyVars`
* `splitForAllTy_ty_maybe` -> `splitForAllTyVar_maybe`
* `tcSplitForAllTys` -> `tcSplitForAllTyVars`
* `tcSplitSomeForAllTys` -> `tcSplitSomeForAllTyVars`
* Functions that return a `CoVar` now use the suffix `-CoVar`.
This caused the following functions to be renamed:
* `splitForAllTy_co_maybe` -> `splitForAllCoVar_maybe`
* Functions that return a `TyCoVar` now use the suffix `-TyCoVar`.
This caused the following functions to be renamed:
* `splitForAllTy` -> `splitForAllTyCoVar`
* `splitForAllTys` -> `splitForAllTyCoVars`
* `splitForAllTys'` -> `splitForAllTyCoVars'`
* `splitForAllTy_maybe` -> `splitForAllTyCoVar_maybe`
* Functions that return a `VarBndr` now use the suffix corresponding to the
most relevant type synonym. This caused the following functions to be renamed:
* `splitForAllVarBndrs` -> `splitForAllTyCoVarBinders`
* `splitForAllTysInvis` -> `splitForAllInvisTVBinders`
* `splitForAllTysReq` -> `splitForAllReqTVBinders`
* `splitSomeForAllTys` -> `splitSomeForAllTyCoVarBndrs`
* `tcSplitForAllVarBndrs` -> `tcSplitForAllTyVarBinders`
* `tcSplitForAllTysInvis` -> `tcSplitForAllInvisTVBinders`
* `tcSplitForAllTysReq` -> `tcSplitForAllReqTVBinders`
* `tcSplitForAllTy_maybe` -> `tcSplitForAllTyVarBinder_maybe`
Note that I left the following functions alone:
* Functions that split apart things besides `ForAllTy`s, such as `splitFunTys`
or `splitPiTys`. Thankfully, there are far fewer of these functions than
there are functions that split apart `ForAllTy`s, so there isn't much of a
pressing need to apply the new naming convention elsewhere.
* Functions that split apart `ForAllCo`s in `Coercion`s, such as
`GHC.Core.Coercion.splitForAllCo_maybe`. We could theoretically apply the new
naming convention here, but then we'd have to figure out how to disambiguate
`Type`-splitting functions from `Coercion`-splitting functions. Ultimately,
the `Coercion`-splitting functions aren't used nearly as much as the
`Type`-splitting functions, so I decided to leave the former alone.
This is purely refactoring and should cause no change in behavior.
Diffstat (limited to 'compiler/GHC/Tc/Gen/App.hs')
-rw-r--r-- | compiler/GHC/Tc/Gen/App.hs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/compiler/GHC/Tc/Gen/App.hs b/compiler/GHC/Tc/Gen/App.hs index ab8c3c7247..eb5540c539 100644 --- a/compiler/GHC/Tc/Gen/App.hs +++ b/compiler/GHC/Tc/Gen/App.hs @@ -450,7 +450,7 @@ tcInstFun do_ql inst_final rn_fun fun_sigma rn_args -- Rule IALL from Fig 4 of the QL paper go1 delta acc so_far fun_ty args - | (tvs, body1) <- tcSplitSomeForAllTys (inst_fun args) fun_ty + | (tvs, body1) <- tcSplitSomeForAllTyVars (inst_fun args) fun_ty , (theta, body2) <- tcSplitPhiTy body1 , not (null tvs && null theta) = do { (inst_tvs, wrap, fun_rho) <- setSrcSpanFromArgs rn_args $ @@ -556,7 +556,7 @@ tcVTA :: TcType -- Function type -- Deal with a visible type application -- The function type has already had its Inferred binders instantiated tcVTA fun_ty hs_ty - | Just (tvb, inner_ty) <- tcSplitForAllTy_maybe fun_ty + | Just (tvb, inner_ty) <- tcSplitForAllTyVarBinder_maybe fun_ty , binderArgFlag tvb == Specified -- It really can't be Inferred, because we've just -- instantiated those. But, oddly, it might just be Required. @@ -969,11 +969,11 @@ findNoQuantVars fun_ty args go bvs fun_ty (EPrag {} : args) = go bvs fun_ty args go bvs fun_ty args@(ETypeArg {} : rest_args) - | (tvs, body1) <- tcSplitSomeForAllTys (== Inferred) fun_ty + | (tvs, body1) <- tcSplitSomeForAllTyVars (== Inferred) fun_ty , (theta, body2) <- tcSplitPhiTy body1 , not (null tvs && null theta) = go (bvs `extendVarSetList` tvs) body2 args - | Just (_tv, res_ty) <- tcSplitForAllTy_maybe fun_ty + | Just (_tv, res_ty) <- tcSplitForAllTyVarBinder_maybe fun_ty = go bvs res_ty rest_args | otherwise = False -- E.g. head ids @Int |