summaryrefslogtreecommitdiff
path: root/compiler/typecheck/TcTyDecls.hs
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2019-02-15 09:53:48 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-02-23 21:31:47 -0500
commit6cce36f83aec33d33545e0ef2135894d22dff5ca (patch)
tree3bfa83e7ba313f7a10b9219cb58eb18a8d368b2d /compiler/typecheck/TcTyDecls.hs
parentac34e784775a0fa8b7284d42ff89571907afdc36 (diff)
downloadhaskell-6cce36f83aec33d33545e0ef2135894d22dff5ca.tar.gz
Add AnonArgFlag to FunTy
The big payload of this patch is: Add an AnonArgFlag to the FunTy constructor of Type, so that (FunTy VisArg t1 t2) means (t1 -> t2) (FunTy InvisArg t1 t2) means (t1 => t2) The big payoff is that we have a simple, local test to make when decomposing a type, leading to many fewer calls to isPredTy. To me the code seems a lot tidier, and probably more efficient (isPredTy has to take the kind of the type). See Note [Function types] in TyCoRep. There are lots of consequences * I made FunTy into a record, so that it'll be easier when we add a linearity field, something that is coming down the road. * Lots of code gets touched in a routine way, simply because it pattern matches on FunTy. * I wanted to make a pattern synonym for (FunTy2 arg res), which picks out just the argument and result type from the record. But alas the pattern-match overlap checker has a heart attack, and either reports false positives, or takes too long. In the end I gave up on pattern synonyms. There's some commented-out code in TyCoRep that shows what I wanted to do. * Much more clarity about predicate types, constraint types and (in particular) equality constraints in kinds. See TyCoRep Note [Types for coercions, predicates, and evidence] and Note [Constraints in kinds]. This made me realise that we need an AnonArgFlag on AnonTCB in a TyConBinder, something that was really plain wrong before. See TyCon Note [AnonTCB InivsArg] * When building function types we must know whether we need VisArg (mkVisFunTy) or InvisArg (mkInvisFunTy). This turned out to be pretty easy in practice. * Pretty-printing of types, esp in IfaceType, gets tidier, because we were already recording the (->) vs (=>) distinction in an ad-hoc way. Death to IfaceFunTy. * mkLamType needs to keep track of whether it is building (t1 -> t2) or (t1 => t2). See Type Note [mkLamType: dictionary arguments] Other minor stuff * Some tidy-up in validity checking involving constraints; Trac #16263
Diffstat (limited to 'compiler/typecheck/TcTyDecls.hs')
-rw-r--r--compiler/typecheck/TcTyDecls.hs22
1 files changed, 11 insertions, 11 deletions
diff --git a/compiler/typecheck/TcTyDecls.hs b/compiler/typecheck/TcTyDecls.hs
index dc983ca403..e40fd3abf4 100644
--- a/compiler/typecheck/TcTyDecls.hs
+++ b/compiler/typecheck/TcTyDecls.hs
@@ -82,14 +82,14 @@ synonymTyConsOfType ty
= nameEnvElts (go ty)
where
go :: Type -> NameEnv TyCon -- The NameEnv does duplicate elim
- go (TyConApp tc tys) = go_tc tc `plusNameEnv` go_s tys
- go (LitTy _) = emptyNameEnv
- go (TyVarTy _) = emptyNameEnv
- go (AppTy a b) = go a `plusNameEnv` go b
- go (FunTy a b) = go a `plusNameEnv` go b
- go (ForAllTy _ ty) = go ty
- go (CastTy ty co) = go ty `plusNameEnv` go_co co
- go (CoercionTy co) = go_co co
+ go (TyConApp tc tys) = go_tc tc `plusNameEnv` go_s tys
+ go (LitTy _) = emptyNameEnv
+ go (TyVarTy _) = emptyNameEnv
+ go (AppTy a b) = go a `plusNameEnv` go b
+ go (FunTy _ a b) = go a `plusNameEnv` go b
+ go (ForAllTy _ ty) = go ty
+ go (CastTy ty co) = go ty `plusNameEnv` go_co co
+ go (CoercionTy co) = go_co co
-- Note [TyCon cycles through coercions?!]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -598,7 +598,7 @@ irType = go
lcls' = extendVarSet lcls tv
; markNominal lcls (tyVarKind tv)
; go lcls' ty }
- go lcls (FunTy arg res) = go lcls arg >> go lcls res
+ go lcls (FunTy _ arg res) = go lcls arg >> go lcls res
go _ (LitTy {}) = return ()
-- See Note [Coercions in role inference]
go lcls (CastTy ty _) = go lcls ty
@@ -634,7 +634,7 @@ markNominal lcls ty = let nvars = fvVarList (FV.delFVs lcls $ get_ty_vars ty) in
get_ty_vars :: Type -> FV
get_ty_vars (TyVarTy tv) = unitFV tv
get_ty_vars (AppTy t1 t2) = get_ty_vars t1 `unionFV` get_ty_vars t2
- get_ty_vars (FunTy t1 t2) = get_ty_vars t1 `unionFV` get_ty_vars t2
+ get_ty_vars (FunTy _ t1 t2) = get_ty_vars t1 `unionFV` get_ty_vars t2
get_ty_vars (TyConApp _ tys) = mapUnionFV get_ty_vars tys
get_ty_vars (ForAllTy tvb ty) = tyCoFVsBndr tvb (get_ty_vars ty)
get_ty_vars (LitTy {}) = emptyFV
@@ -878,7 +878,7 @@ mkOneRecordSelector all_cons idDetails fl
sel_ty | is_naughty = unitTy -- See Note [Naughty record selectors]
| otherwise = mkSpecForAllTys data_tvs $
mkPhiTy (conLikeStupidTheta con1) $ -- Urgh!
- mkFunTy data_ty $
+ mkVisFunTy data_ty $
mkSpecForAllTys field_tvs $
mkPhiTy field_theta $
-- req_theta is empty for normal DataCon