summaryrefslogtreecommitdiff
path: root/compiler/GHC/Tc
diff options
context:
space:
mode:
authorAlan Zimmerman <alan.zimm@gmail.com>2021-02-21 21:16:24 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-03-01 17:32:12 -0500
commitce85cffc7c3afa55755ae8d1aa027761bf54bed4 (patch)
tree81986b7475f28a20bb80301107f9360a90b1e976 /compiler/GHC/Tc
parent6429943b0a377e076bcfd26c79ceb27cf2f4a9ab (diff)
downloadhaskell-ce85cffc7c3afa55755ae8d1aa027761bf54bed4.tar.gz
Wrap LHsContext in Maybe in the GHC AST
If the context is missing it is captured as Nothing, rather than putting a noLoc in the ParsedSource. Updates haddock submodule
Diffstat (limited to 'compiler/GHC/Tc')
-rw-r--r--compiler/GHC/Tc/Deriv.hs2
-rw-r--r--compiler/GHC/Tc/Gen/Bind.hs4
-rw-r--r--compiler/GHC/Tc/Gen/HsType.hs21
-rw-r--r--compiler/GHC/Tc/Gen/Sig.hs4
-rw-r--r--compiler/GHC/Tc/TyCl.hs19
-rw-r--r--compiler/GHC/Tc/TyCl/Instance.hs2
6 files changed, 26 insertions, 26 deletions
diff --git a/compiler/GHC/Tc/Deriv.hs b/compiler/GHC/Tc/Deriv.hs
index 4d072fff5f..7a536fcaf7 100644
--- a/compiler/GHC/Tc/Deriv.hs
+++ b/compiler/GHC/Tc/Deriv.hs
@@ -723,7 +723,7 @@ tcStandaloneDerivInstType ctxt
(HsWC { hswc_body = deriv_ty@(L loc (HsSig { sig_bndrs = outer_bndrs
, sig_body = deriv_ty_body }))})
| (theta, rho) <- splitLHsQualTy deriv_ty_body
- , L _ [wc_pred] <- theta
+ , [wc_pred] <- fromMaybeContext theta
, L wc_span (HsWildCardTy _) <- ignoreParens wc_pred
= do dfun_ty <- tcHsClsInstType ctxt $ L loc $
HsSig { sig_ext = noExtField
diff --git a/compiler/GHC/Tc/Gen/Bind.hs b/compiler/GHC/Tc/Gen/Bind.hs
index c63cbabdc1..caaa8b4894 100644
--- a/compiler/GHC/Tc/Gen/Bind.hs
+++ b/compiler/GHC/Tc/Gen/Bind.hs
@@ -1670,10 +1670,10 @@ decideGeneralisationPlan dflags lbinds closed sig_fn
-- so we should apply the MR
-- See Note [Partial type signatures and generalisation]
partial_sig_mrs
- = [ null theta
+ = [ null $ fromMaybeContext mtheta
| TcIdSig (PartialSig { psig_hs_ty = hs_ty })
<- mapMaybe sig_fn (collectHsBindListBinders CollNoDictBinders lbinds)
- , let (L _ theta, _) = splitLHsQualTy (hsSigWcType hs_ty) ]
+ , let (mtheta, _) = splitLHsQualTy (hsSigWcType hs_ty) ]
has_partial_sigs = not (null partial_sig_mrs)
diff --git a/compiler/GHC/Tc/Gen/HsType.hs b/compiler/GHC/Tc/Gen/HsType.hs
index 87da41b890..cc82f30dbc 100644
--- a/compiler/GHC/Tc/Gen/HsType.hs
+++ b/compiler/GHC/Tc/Gen/HsType.hs
@@ -53,7 +53,7 @@ module GHC.Tc.Gen.HsType (
tcHsLiftedTypeNC, tcHsOpenTypeNC,
tcInferLHsTypeKind, tcInferLHsType, tcInferLHsTypeUnsaturated,
tcCheckLHsType,
- tcHsMbContext, tcHsContext, tcLHsPredType,
+ tcHsContext, tcLHsPredType,
kindGeneralizeAll, kindGeneralizeSome, kindGeneralizeNone,
@@ -1112,7 +1112,7 @@ tc_hs_type mode (HsForAllTy { hst_tele = tele, hst_body = ty }) exp_kind
; return (mkForAllTys tv_bndrs ty') }
tc_hs_type mode (HsQualTy { hst_ctxt = ctxt, hst_body = rn_ty }) exp_kind
- | null (unLoc ctxt)
+ | null (fromMaybeContext ctxt)
= tc_lhs_type mode rn_ty exp_kind
-- See Note [Body kind of a HsQualTy]
@@ -1860,18 +1860,16 @@ checkExpectedKind hs_ty ty act_kind exp_kind
n_to_inst = n_act_invis_bndrs - n_exp_invis_bndrs
---------------------------
-tcHsMbContext :: Maybe (LHsContext GhcRn) -> TcM [PredType]
-tcHsMbContext Nothing = return []
-tcHsMbContext (Just cxt) = tcHsContext cxt
-tcHsContext :: LHsContext GhcRn -> TcM [PredType]
+tcHsContext :: Maybe (LHsContext GhcRn) -> TcM [PredType]
tcHsContext cxt = tc_hs_context typeLevelMode cxt
tcLHsPredType :: LHsType GhcRn -> TcM PredType
tcLHsPredType pred = tc_lhs_pred typeLevelMode pred
-tc_hs_context :: TcTyMode -> LHsContext GhcRn -> TcM [PredType]
-tc_hs_context mode ctxt = mapM (tc_lhs_pred mode) (unLoc ctxt)
+tc_hs_context :: TcTyMode -> Maybe (LHsContext GhcRn) -> TcM [PredType]
+tc_hs_context _ Nothing = return []
+tc_hs_context mode (Just ctxt) = mapM (tc_lhs_pred mode) (unLoc ctxt)
tc_lhs_pred :: TcTyMode -> LHsType GhcRn -> TcM PredType
tc_lhs_pred mode pred = tc_lhs_type mode pred constraintKind
@@ -3775,7 +3773,7 @@ tcHsPartialSigType
tcHsPartialSigType ctxt sig_ty
| HsWC { hswc_ext = sig_wcs, hswc_body = sig_ty } <- sig_ty
, L _ (HsSig{sig_bndrs = hs_outer_bndrs, sig_body = body_ty}) <- sig_ty
- , (L _ hs_ctxt, hs_tau) <- splitLHsQualTy body_ty
+ , (hs_ctxt, hs_tau) <- splitLHsQualTy body_ty
= addSigCtxt ctxt sig_ty $
do { mode <- mkHoleMode TypeLevel HM_Sig
; (outer_bndrs, (wcs, wcx, theta, tau))
@@ -3829,8 +3827,9 @@ tcHsPartialSigType ctxt sig_ty
; traceTc "tcHsPartialSigType" (ppr tv_prs)
; return (wcs, wcx, tv_prs, theta, tau) }
-tcPartialContext :: TcTyMode -> HsContext GhcRn -> TcM (TcThetaType, Maybe TcType)
-tcPartialContext mode hs_theta
+tcPartialContext :: TcTyMode -> Maybe (LHsContext GhcRn) -> TcM (TcThetaType, Maybe TcType)
+tcPartialContext _ Nothing = return ([], Nothing)
+tcPartialContext mode (Just (L _ hs_theta))
| Just (hs_theta1, hs_ctxt_last) <- snocView hs_theta
, L wc_loc ty@(HsWildCardTy _) <- ignoreParens hs_ctxt_last
= do { wc_tv_ty <- setSrcSpan wc_loc $
diff --git a/compiler/GHC/Tc/Gen/Sig.hs b/compiler/GHC/Tc/Gen/Sig.hs
index 6d6a74c65d..45dbc96d8f 100644
--- a/compiler/GHC/Tc/Gen/Sig.hs
+++ b/compiler/GHC/Tc/Gen/Sig.hs
@@ -286,8 +286,8 @@ no_anon_wc_ty lty = go lty
HsForAllTy { hst_tele = tele
, hst_body = ty } -> no_anon_wc_tele tele
&& go ty
- HsQualTy { hst_ctxt = L _ ctxt
- , hst_body = ty } -> gos ctxt && go ty
+ HsQualTy { hst_ctxt = ctxt
+ , hst_body = ty } -> gos (fromMaybeContext ctxt) && go ty
HsSpliceTy _ (HsSpliced _ _ (HsSplicedTy ty)) -> go $ L noSrcSpan ty
HsSpliceTy{} -> True
HsTyLit{} -> True
diff --git a/compiler/GHC/Tc/TyCl.hs b/compiler/GHC/Tc/TyCl.hs
index 45d38fd87d..e1da82d3bb 100644
--- a/compiler/GHC/Tc/TyCl.hs
+++ b/compiler/GHC/Tc/TyCl.hs
@@ -1622,7 +1622,7 @@ kcConDecl new_or_data tc_res_kind (ConDeclH98
= addErrCtxt (dataConCtxt [name]) $
discardResult $
bindExplicitTKBndrs_Tv ex_tvs $
- do { _ <- tcHsMbContext ex_ctxt
+ do { _ <- tcHsContext ex_ctxt
; kcConH98Args new_or_data tc_res_kind args
-- We don't need to check the telescope here,
-- because that's done in tcConDecl
@@ -1638,7 +1638,7 @@ kcConDecl new_or_data
discardResult $
bindOuterSigTKBndrs_Tv outer_bndrs $
-- Why "_Tv"? See Note [Using TyVarTvs for kind-checking GADTs]
- do { _ <- tcHsMbContext cxt
+ do { _ <- tcHsContext cxt
; traceTc "kcConDecl:GADT {" (ppr names $$ ppr res_ty)
; con_res_kind <- newOpenTypeKind
; _ <- tcCheckLHsType res_ty (TheKind con_res_kind)
@@ -2325,7 +2325,7 @@ tcTyClDecl1 _parent roles_info
* *
********************************************************************* -}
-tcClassDecl1 :: RolesInfo -> Name -> LHsContext GhcRn
+tcClassDecl1 :: RolesInfo -> Name -> Maybe (LHsContext GhcRn)
-> LHsBinds GhcRn -> [LHsFunDep GhcRn] -> [LSig GhcRn]
-> [LFamilyDecl GhcRn] -> [LTyFamDefltDecl GhcRn]
-> TcM Class
@@ -3210,11 +3210,12 @@ that 'a' must have that kind, and to bring 'k' into scope.
-}
dataDeclChecks :: Name -> NewOrData
- -> LHsContext GhcRn -> [LConDecl GhcRn]
+ -> Maybe (LHsContext GhcRn) -> [LConDecl GhcRn]
-> TcM Bool
-dataDeclChecks tc_name new_or_data (L _ stupid_theta) cons
- = do { -- Check that we don't use GADT syntax in H98 world
- gadtSyntax_ok <- xoptM LangExt.GADTSyntax
+dataDeclChecks tc_name new_or_data mctxt cons
+ = do { let stupid_theta = fromMaybeContext mctxt
+ -- Check that we don't use GADT syntax in H98 world
+ ; gadtSyntax_ok <- xoptM LangExt.GADTSyntax
; let gadt_syntax = consUseGadtSyntax cons
; checkTc (gadtSyntax_ok || not gadt_syntax) (badGadtDecl tc_name)
@@ -3296,7 +3297,7 @@ tcConDecl new_or_data dd_info rep_tycon tc_bndrs res_kind tag_map
; (tclvl, wanted, (exp_tvbndrs, (ctxt, arg_tys, field_lbls, stricts)))
<- pushLevelAndSolveEqualitiesX "tcConDecl:H98" $
tcExplicitTKBndrs explicit_tkv_nms $
- do { ctxt <- tcHsMbContext hs_ctxt
+ do { ctxt <- tcHsContext hs_ctxt
; let exp_kind = getArgExpKind new_or_data res_kind
; btys <- tcConH98Args exp_kind hs_args
; field_lbls <- lookupConstructorFields name
@@ -3382,7 +3383,7 @@ tcConDecl new_or_data dd_info rep_tycon tc_bndrs _res_kind tag_map
; (tclvl, wanted, (outer_bndrs, (ctxt, arg_tys, res_ty, field_lbls, stricts)))
<- pushLevelAndSolveEqualitiesX "tcConDecl:GADT" $
tcOuterTKBndrs skol_info outer_hs_bndrs $
- do { ctxt <- tcHsMbContext cxt
+ do { ctxt <- tcHsContext cxt
; (res_ty, res_kind) <- tcInferLHsTypeKind hs_res_ty
-- See Note [GADT return kinds]
diff --git a/compiler/GHC/Tc/TyCl/Instance.hs b/compiler/GHC/Tc/TyCl/Instance.hs
index 2fb7c58101..657e1bffe7 100644
--- a/compiler/GHC/Tc/TyCl/Instance.hs
+++ b/compiler/GHC/Tc/TyCl/Instance.hs
@@ -857,7 +857,7 @@ TyVarEnv will simply be empty, and there is nothing to worry about.
-----------------------
tcDataFamInstHeader
:: AssocInstInfo -> TyCon -> HsOuterFamEqnTyVarBndrs GhcRn
- -> LexicalFixity -> LHsContext GhcRn
+ -> LexicalFixity -> Maybe (LHsContext GhcRn)
-> HsTyPats GhcRn -> Maybe (LHsKind GhcRn)
-> NewOrData
-> TcM ([TyVar], [Type], Kind, ThetaType)