summaryrefslogtreecommitdiff
path: root/compiler/hsSyn
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2016-06-11 23:49:27 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2016-06-13 10:57:03 +0100
commit15b9bf4ba4ab47e6809bf2b3b36ec16e502aea72 (patch)
treee2e7336c63e9b7130ba70f3551ff290d4a25184b /compiler/hsSyn
parentd25cb61a1c2a135a2564143a332f8b2962f134bc (diff)
downloadhaskell-15b9bf4ba4ab47e6809bf2b3b36ec16e502aea72.tar.gz
Improve typechecking of let-bindings
This major commit was initially triggered by #11339, but it spiraled into a major review of the way in which type signatures for bindings are handled, especially partial type signatures. On the way I fixed a number of other bugs, namely #12069 #12033 #11700 #11339 #11670 The main change is that I completely reorganised the way in which type signatures in bindings are handled. The new story is in TcSigs Note [Overview of type signatures]. Some specific: * Changes in the data types for signatures in TcRnTypes: TcIdSigInfo and new TcIdSigInst * New module TcSigs deals with typechecking type signatures and pragmas. It contains code mostly moved from TcBinds, which is already too big * HsTypes: I swapped the nesting of HsWildCardBndrs and HsImplicitBndsrs, so that the wildcards are on the oustide not the insidde in a LHsSigWcType. This is just a matter of convenient, nothing deep. There are a host of other changes as knock-on effects, and it all took FAR longer than I anticipated :-). But it is a significant improvement, I think. Lots of error messages changed slightly, some just variants but some modest improvements. New tests * typecheck/should_compile * SigTyVars: a scoped-tyvar test * ExPat, ExPatFail: existential pattern bindings * T12069 * T11700 * T11339 * partial-sigs/should_compile * T12033 * T11339a * T11670 One thing to check: * Small change to output from ghc-api/landmines. Need to check with Alan Zimmerman
Diffstat (limited to 'compiler/hsSyn')
-rw-r--r--compiler/hsSyn/HsTypes.hs34
-rw-r--r--compiler/hsSyn/HsUtils.hs2
2 files changed, 15 insertions, 21 deletions
diff --git a/compiler/hsSyn/HsTypes.hs b/compiler/hsSyn/HsTypes.hs
index e5f0f9cde5..a0676c98d6 100644
--- a/compiler/hsSyn/HsTypes.hs
+++ b/compiler/hsSyn/HsTypes.hs
@@ -288,16 +288,12 @@ data HsWildCardBndrs name thing
-- See Note [The wildcard story for types]
= HsWC { hswc_wcs :: PostRn name [Name]
-- Wild cards, both named and anonymous
+ -- after the renamer
- , hswc_ctx :: Maybe SrcSpan
- -- Indicates whether hswc_body has an
- -- extra-constraint wildcard, and if so where
- -- e.g. (Eq a, _) => a -> a
- -- NB: the wildcard stays in HsQualTy inside the type!
- -- So for pretty printing purposes you can ignore
- -- hswc_ctx
-
- , hswc_body :: thing -- Main payload (type or list of types)
+ , hswc_body :: thing
+ -- Main payload (type or list of types)
+ -- If there is an extra-constraints wildcard,
+ -- it's still there in the hsc_body.
}
deriving instance (Data name, Data thing, Data (PostRn name [Name]))
@@ -308,7 +304,7 @@ deriving instance (Data name, Data thing, Data (PostRn name [Name]))
type LHsSigType name = HsImplicitBndrs name (LHsType name) -- Implicit only
type LHsWcType name = HsWildCardBndrs name (LHsType name) -- Wildcard only
-type LHsSigWcType name = HsImplicitBndrs name (LHsWcType name) -- Both
+type LHsSigWcType name = HsWildCardBndrs name (LHsSigType name) -- Both
-- See Note [Representing type signatures]
@@ -319,11 +315,11 @@ hsSigType :: LHsSigType name -> LHsType name
hsSigType = hsImplicitBody
hsSigWcType :: LHsSigWcType name -> LHsType name
-hsSigWcType sig_ty = hswc_body (hsib_body sig_ty)
+hsSigWcType sig_ty = hsib_body (hswc_body sig_ty)
dropWildCards :: LHsSigWcType name -> LHsSigType name
-- Drop the wildcard part of a LHsSigWcType
-dropWildCards sig_ty = sig_ty { hsib_body = hsSigWcType sig_ty }
+dropWildCards sig_ty = hswc_body sig_ty
{- Note [Representing type signatures]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -351,8 +347,7 @@ mkHsImplicitBndrs x = HsIB { hsib_body = x
mkHsWildCardBndrs :: thing -> HsWildCardBndrs RdrName thing
mkHsWildCardBndrs x = HsWC { hswc_body = x
- , hswc_wcs = PlaceHolder
- , hswc_ctx = Nothing }
+ , hswc_wcs = PlaceHolder }
-- Add empty binders. This is a bit suspicious; what if
-- the wrapped thing had free type variables?
@@ -362,8 +357,7 @@ mkEmptyImplicitBndrs x = HsIB { hsib_body = x
mkEmptyWildCardBndrs :: thing -> HsWildCardBndrs Name thing
mkEmptyWildCardBndrs x = HsWC { hswc_body = x
- , hswc_wcs = []
- , hswc_ctx = Nothing }
+ , hswc_wcs = [] }
--------------------------------------------------
@@ -789,8 +783,8 @@ hsWcScopedTvs :: LHsSigWcType Name -> [Name]
-- - the named wildcars; see Note [Scoping of named wildcards]
-- because they scope in the same way
hsWcScopedTvs sig_ty
- | HsIB { hsib_vars = vars, hsib_body = sig_ty1 } <- sig_ty
- , HsWC { hswc_wcs = nwcs, hswc_body = sig_ty2 } <- sig_ty1
+ | HsWC { hswc_wcs = nwcs, hswc_body = sig_ty1 } <- sig_ty
+ , HsIB { hsib_vars = vars, hsib_body = sig_ty2 } <- sig_ty1
= case sig_ty2 of
L _ (HsForAllTy { hst_bndrs = tvs }) -> vars ++ nwcs ++
map hsLTyVarName tvs
@@ -1237,10 +1231,10 @@ ppr_mono_ty _ (HsPArrTy ty) = paBrackets (ppr_mono_lty TopPrec ty)
ppr_mono_ty prec (HsIParamTy n ty) = maybeParen prec FunPrec (ppr n <+> dcolon <+> ppr_mono_lty TopPrec ty)
ppr_mono_ty _ (HsSpliceTy s _) = pprSplice s
ppr_mono_ty _ (HsCoreTy ty) = ppr ty
-ppr_mono_ty _ (HsExplicitListTy _ tys) = quote $ brackets (interpp'SP tys)
+ppr_mono_ty _ (HsExplicitListTy _ tys) = quote $ brackets (interpp'SP tys)
ppr_mono_ty _ (HsExplicitTupleTy _ tys) = quote $ parens (interpp'SP tys)
ppr_mono_ty _ (HsTyLit t) = ppr_tylit t
-ppr_mono_ty _ (HsWildCardTy (AnonWildCard _)) = char '_'
+ppr_mono_ty _ (HsWildCardTy {}) = char '_'
ppr_mono_ty ctxt_prec (HsEqTy ty1 ty2)
= maybeParen ctxt_prec TyOpPrec $
diff --git a/compiler/hsSyn/HsUtils.hs b/compiler/hsSyn/HsUtils.hs
index 43d60a3667..23c8d911ad 100644
--- a/compiler/hsSyn/HsUtils.hs
+++ b/compiler/hsSyn/HsUtils.hs
@@ -564,7 +564,7 @@ mkLHsSigType :: LHsType RdrName -> LHsSigType RdrName
mkLHsSigType ty = mkHsImplicitBndrs ty
mkLHsSigWcType :: LHsType RdrName -> LHsSigWcType RdrName
-mkLHsSigWcType ty = mkHsImplicitBndrs (mkHsWildCardBndrs ty)
+mkLHsSigWcType ty = mkHsWildCardBndrs (mkHsImplicitBndrs ty)
mkClassOpSigs :: [LSig RdrName] -> [LSig RdrName]
-- Convert TypeSig to ClassOpSig