summaryrefslogtreecommitdiff
path: root/compiler/typecheck/TcHsType.hs
diff options
context:
space:
mode:
authorVladislav Zavialov <vlad.z.4096@gmail.com>2019-02-13 17:15:49 +0300
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-02-27 09:53:52 -0500
commit5bc195b1fe788e9a900a15fbe473967850517c3e (patch)
tree83844589096791edb049f719a990004756e02114 /compiler/typecheck/TcHsType.hs
parent4dbacba5d2831bc80c48f3986e59b1a1c91cc620 (diff)
downloadhaskell-5bc195b1fe788e9a900a15fbe473967850517c3e.tar.gz
Treat kind/type variables identically, demolish FKTV
Implements GHC Proposal #24: .../ghc-proposals/blob/master/proposals/0024-no-kind-vars.rst Fixes Trac #16334, Trac #16315 With this patch, scoping rules for type and kind variables have been unified: kind variables no longer receieve special treatment. This simplifies both the language and the implementation. User-facing changes ------------------- * Kind variables are no longer implicitly quantified when an explicit forall is used: p :: Proxy (a :: k) -- still accepted p :: forall k a. Proxy (a :: k) -- still accepted p :: forall a. Proxy (a :: k) -- no longer accepted In other words, now we adhere to the "forall-or-nothing" rule more strictly. Related function: RnTypes.rnImplicitBndrs * The -Wimplicit-kind-vars warning has been deprecated. * Kind variables are no longer implicitly quantified in constructor declarations: data T a = T1 (S (a :: k) | forall (b::k). T2 (S b) -- no longer accepted data T (a :: k) = T1 (S (a :: k) | forall (b::k). T2 (S b) -- still accepted Related function: RnTypes.extractRdrKindSigVars * Implicitly quantified kind variables are no longer put in front of other variables: f :: Proxy (a :: k) -> Proxy (b :: j) f :: forall k j (a :: k) (b :: j). Proxy a -> Proxy b -- old order f :: forall k (a :: k) j (b :: j). Proxy a -> Proxy b -- new order This is a breaking change for users of TypeApplications. Note that we still respect the dpendency order: 'k' before 'a', 'j' before 'b'. See "Ordering of specified variables" in the User's Guide. Related function: RnTypes.rnImplicitBndrs * In type synonyms and type family equations, free variables on the RHS are no longer implicitly quantified unless used in an outermost kind annotation: type T = Just (Nothing :: Maybe a) -- no longer accepted type T = Just Nothing :: Maybe (Maybe a) -- still accepted The latter form is a workaround due to temporary lack of an explicit quantification method. Ideally, we would write something along these lines: type T @a = Just (Nothing :: Maybe a) Related function: RnTypes.extractHsTyRdrTyVarsKindVars * Named wildcards in kinds are fixed (Trac #16334): x :: (Int :: _t) -- this compiles, infers (_t ~ Type) Related function: RnTypes.partition_nwcs Implementation notes -------------------- * One of the key changes is the removal of FKTV in RnTypes: - data FreeKiTyVars = FKTV { fktv_kis :: [Located RdrName] - , fktv_tys :: [Located RdrName] } + type FreeKiTyVars = [Located RdrName] We used to keep track of type and kind variables separately, but now that they are on equal footing when it comes to scoping, we can put them in the same list. * extract_lty and family are no longer parametrized by TypeOrKind, as we now do not distinguish kind variables from type variables. * PatSynExPE and the related Note [Pattern synonym existentials do not scope] have been removed (Trac #16315). With no implicit kind quantification, we can no longer trigger the error. * reportFloatingKvs and the related Note [Free-floating kind vars] have been removed. With no implicit kind quantification, we can no longer trigger the error.
Diffstat (limited to 'compiler/typecheck/TcHsType.hs')
-rw-r--r--compiler/typecheck/TcHsType.hs116
1 files changed, 0 insertions, 116 deletions
diff --git a/compiler/typecheck/TcHsType.hs b/compiler/typecheck/TcHsType.hs
index 467c60465a..ef038e119b 100644
--- a/compiler/typecheck/TcHsType.hs
+++ b/compiler/typecheck/TcHsType.hs
@@ -47,7 +47,6 @@ module TcHsType (
typeLevelMode, kindLevelMode,
kindGeneralize, checkExpectedKind_pp,
- reportFloatingKvs,
-- Sort-checking kinds
tcLHsKindSig, badKindSig,
@@ -1871,13 +1870,6 @@ kcLHsQTyVars_Cusk name flav
-- doesn't work, we catch it here, before an error cascade
; checkValidTelescope tycon
- -- If any of the specified tyvars aren't actually mentioned in a binder's
- -- kind (or the return kind), then we're in the CUSK case from
- -- Note [Free-floating kind vars]
- ; let unmentioned_kvs = filterOut (`elemVarSet` mentioned_kv_set) specified
- ; reportFloatingKvs name flav (map binderVar final_tc_binders) unmentioned_kvs
-
-
; traceTc "kcLHsQTyVars: cusk" $
vcat [ text "name" <+> ppr name
, text "kv_ns" <+> ppr kv_ns
@@ -2889,8 +2881,6 @@ promotionErr name err
NoDataKindsTC -> text "perhaps you intended to use DataKinds"
NoDataKindsDC -> text "perhaps you intended to use DataKinds"
PatSynPE -> text "pattern synonyms cannot be promoted"
- PatSynExPE -> sep [ text "the existential variables of a pattern synonym"
- , text "signature do not scope over the pattern" ]
_ -> text "it is defined and used in the same recursive group"
{-
@@ -2919,112 +2909,6 @@ badPatTyVarTvs sig_ty bad_tvs
-}
-{- Note [Free-floating kind vars]
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Consider
-
- data S a = MkS (Proxy (a :: k))
-
-According to the rules around implicitly-bound kind variables,
-that k scopes over the whole declaration. The renamer grabs
-it and adds it to the hsq_implicits field of the HsQTyVars of the
-tycon. So we get
- S :: forall {k}. k -> Type
-
-That's fine. But consider this variant:
- data T = MkT (forall (a :: k). Proxy a)
- -- from test ghci/scripts/T7873
-
-This is not an existential datatype, but a higher-rank one (the forall
-to the right of MkT). Again, 'k' scopes over the whole declaration,
-but we do not want to get
- T :: forall {k}. Type
-Why not? Because the kind variable isn't fixed by anything. For
-a variable like k to be implicit, it needs to be mentioned in the kind
-of a tycon tyvar. But it isn't.
-
-Rejecting T depends on whether or not the datatype has a CUSK.
-
-Non-CUSK (handled in TcTyClsDecls.kcTyClGroup (generalise)):
- When generalising the TyCon we check that every Specified 'k'
- appears free in the kind of the TyCon; that is, in the kind of
- one of its Required arguments, or the result kind.
-
-CUSK (handled in TcHsType.kcLHsQTyVars, the CUSK case):
- When we determine the tycon's final, never-to-be-changed kind
- in kcLHsQTyVars, we check to make sure all implicitly-bound kind
- vars are indeed mentioned in a kind somewhere. If not, error.
-
-We also perform free-floating kind var analysis for type family instances
-(see #13985). Here is an interesting example:
-
- type family T :: k
- type instance T = (Nothing :: Maybe a)
-
-Upon a cursory glance, it may appear that the kind variable `a` is
-free-floating above, since there are no (visible) LHS patterns in `T`. However,
-there is an *invisible* pattern due to the return kind, so inside of GHC, the
-instance looks closer to this:
-
- type family T @k :: k
- type instance T @(Maybe a) = (Nothing :: Maybe a)
-
-Here, we can see that `a` really is bound by a LHS type pattern, so `a` is in
-fact not free-floating. Contrast that with this example:
-
- type instance T = Proxy (Nothing :: Maybe a)
-
-This would looks like this inside of GHC:
-
- type instance T @(*) = Proxy (Nothing :: Maybe a)
-
-So this time, `a` is neither bound by a visible nor invisible type pattern on
-the LHS, so it would be reported as free-floating.
-
-Finally, here's one more brain-teaser (from #9574). In the example below:
-
- class Funct f where
- type Codomain f :: *
- instance Funct ('KProxy :: KProxy o) where
- type Codomain 'KProxy = NatTr (Proxy :: o -> *)
-
-As it turns out, `o` is not free-floating in this example. That is because `o`
-bound by the kind signature of the LHS type pattern 'KProxy. To make this more
-obvious, one can also write the instance like so:
-
- instance Funct ('KProxy :: KProxy o) where
- type Codomain ('KProxy :: KProxy o) = NatTr (Proxy :: o -> *)
--}
-
--- See Note [Free-floating kind vars]
-reportFloatingKvs :: Name -- of the tycon
- -> TyConFlavour -- What sort of TyCon it is
- -> [TcTyVar] -- all tyvars, not necessarily zonked
- -> [TcTyVar] -- floating tyvars
- -> TcM ()
-reportFloatingKvs tycon_name flav all_tvs bad_tvs
- = unless (null bad_tvs) $ -- don't bother zonking if there's no error
- do { all_tvs <- mapM zonkTcTyVarToTyVar all_tvs
- ; bad_tvs <- mapM zonkTcTyVarToTyVar bad_tvs
- ; let (tidy_env, tidy_all_tvs) = tidyOpenTyCoVars emptyTidyEnv all_tvs
- tidy_bad_tvs = map (tidyTyCoVarOcc tidy_env) bad_tvs
- ; mapM_ (report tidy_all_tvs) tidy_bad_tvs }
- where
- report tidy_all_tvs tidy_bad_tv
- = addErr $
- vcat [ text "Kind variable" <+> quotes (ppr tidy_bad_tv) <+>
- text "is implicitly bound in" <+> ppr flav
- , quotes (ppr tycon_name) <> comma <+>
- text "but does not appear as the kind of any"
- , text "of its type variables. Perhaps you meant"
- , text "to bind it explicitly somewhere?"
- , ppWhen (not (null tidy_all_tvs)) $
- hang (text "Type variables with inferred kinds:")
- 2 (ppr_tv_bndrs tidy_all_tvs) ]
-
- ppr_tv_bndrs tvs = sep (map pp_tv tvs)
- pp_tv tv = parens (ppr tv <+> dcolon <+> ppr (tyVarKind tv))
-
-- | If the inner action emits constraints, report them as errors and fail;
-- otherwise, propagates the return value. Useful as a wrapper around
-- 'tcImplicitTKBndrs', which uses solveLocalEqualities, when there won't be