X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Ftypes%2FType.lhs;h=7c05b6d8c480a3bec6cd105fd619f7d3ccbb9003;hp=b7f521a15d12e245bf5384bf21667c1547dd1d9c;hb=9da4639011348fb6c318e3cba4b08622f811d9c4;hpb=6fcf90065dc4e75b7dc6bbf238a9891a71ae5a86 diff --git a/compiler/types/Type.lhs b/compiler/types/Type.lhs index b7f521a..7c05b6d 100644 --- a/compiler/types/Type.lhs +++ b/compiler/types/Type.lhs @@ -12,7 +12,7 @@ module Type ( -- Kinds Kind, SimpleKind, KindVar, - kindFunResult, splitKindFunTys, + kindFunResult, splitKindFunTys, splitKindFunTysN, liftedTypeKindTyCon, openTypeKindTyCon, unliftedTypeKindTyCon, argTypeKindTyCon, ubxTupleKindTyCon, @@ -106,7 +106,7 @@ import TypeRep -- friends: import Var ( Var, TyVar, tyVarKind, tyVarName, - setTyVarName, setTyVarKind, mkWildTyVar ) + setTyVarName, setTyVarKind, mkWildCoVar ) import VarEnv import VarSet @@ -117,11 +117,12 @@ import PrelNames( openTypeKindTyConKey, unliftedTypeKindTyConKey, ubxTupleKindTyConKey, argTypeKindTyConKey ) import TyCon ( TyCon, isRecursiveTyCon, isPrimTyCon, isUnboxedTupleTyCon, isUnLiftedTyCon, - isFunTyCon, isNewTyCon, newTyConRep, newTyConRhs, + isFunTyCon, isNewTyCon, isClosedNewTyCon, + newTyConRep, newTyConRhs, isAlgTyCon, tyConArity, isSuperKindTyCon, tcExpandTyCon_maybe, coreExpandTyCon_maybe, tyConKind, PrimRep(..), tyConPrimRep, tyConUnique, - isCoercionTyCon_maybe, isCoercionTyCon + isCoercionTyCon ) -- others @@ -307,7 +308,7 @@ splitAppTys ty = split ty ty [] \begin{code} mkFunTy :: Type -> Type -> Type -mkFunTy (PredTy (EqPred ty1 ty2)) res = mkForAllTy (mkWildTyVar (PredTy (EqPred ty1 ty2))) res +mkFunTy (PredTy (EqPred ty1 ty2)) res = mkForAllTy (mkWildCoVar (PredTy (EqPred ty1 ty2))) res mkFunTy arg res = FunTy arg res mkFunTys :: [Type] -> Type -> Type @@ -448,7 +449,7 @@ repType looks through (b) synonyms (c) predicates (d) usage annotations - (e) all newtypes, including recursive ones + (e) all newtypes, including recursive ones, but not newtype families It's useful in the back end. \begin{code} @@ -457,7 +458,7 @@ repType :: Type -> Type repType ty | Just ty' <- coreView ty = repType ty' repType (ForAllTy _ ty) = repType ty repType (TyConApp tc tys) - | isNewTyCon tc = -- Recursive newtypes are opaque to coreView + | isClosedNewTyCon tc = -- Recursive newtypes are opaque to coreView -- but we must expand them here. Sure to -- be saturated because repType is only applied -- to types of kind * @@ -616,7 +617,7 @@ splitRecNewType_maybe :: Type -> Maybe Type -- Only applied to types of kind *, hence the newtype is always saturated splitRecNewType_maybe ty | Just ty' <- coreView ty = splitRecNewType_maybe ty' splitRecNewType_maybe (TyConApp tc tys) - | isNewTyCon tc + | isClosedNewTyCon tc = ASSERT( tys `lengthIs` tyConArity tc ) -- splitRecNewType_maybe only be applied -- to *types* (of kind *) ASSERT( isRecursiveTyCon tc ) -- Guaranteed by coreView @@ -1027,8 +1028,13 @@ cmpPredX env (IParam n1 ty1) (IParam n2 ty2) = (n1 `compare` n2) `thenCmp` cmpTy -- This comparison is used exclusively (I think) for the -- finite map built in TcSimplify cmpPredX env (ClassP c1 tys1) (ClassP c2 tys2) = (c1 `compare` c2) `thenCmp` cmpTypesX env tys1 tys2 -cmpPredX env (IParam _ _) (ClassP _ _) = LT -cmpPredX env (ClassP _ _) (IParam _ _) = GT +cmpPredX env (EqPred ty1 ty2) (EqPred ty1' ty2') = (cmpTypeX env ty1 ty1') `thenCmp` (cmpTypeX env ty2 ty2') + +-- Constructor order: IParam < ClassP < EqPred +cmpPredX env (IParam {}) _ = LT +cmpPredX env (ClassP {}) (IParam {}) = GT +cmpPredX env (ClassP {}) (EqPred {}) = LT +cmpPredX env (EqPred {}) _ = GT \end{code} PredTypes are used as a FM key in TcSimplify, @@ -1370,6 +1376,9 @@ kindFunResult k = funResultTy k splitKindFunTys :: Kind -> ([Kind],Kind) splitKindFunTys k = splitFunTys k +splitKindFunTysN :: Int -> Kind -> ([Kind],Kind) +splitKindFunTysN k = splitFunTysN k + isUbxTupleKind, isOpenTypeKind, isArgTypeKind, isUnliftedTypeKind :: Kind -> Bool isOpenTypeKindCon tc = tyConUnique tc == openTypeKindTyConKey @@ -1425,7 +1434,7 @@ isKind k = isSuperKind (typeKind k) isSubKind :: Kind -> Kind -> Bool -- (k1 `isSubKind` k2) checks that k1 <: k2 -isSubKind (TyConApp kc1 []) (TyConApp kc2 []) = kc1 `isSubKindCon` kc1 +isSubKind (TyConApp kc1 []) (TyConApp kc2 []) = kc1 `isSubKindCon` kc2 isSubKind (FunTy a1 r1) (FunTy a2 r2) = (a2 `isSubKind` a1) && (r1 `isSubKind` r2) isSubKind (PredTy (EqPred ty1 ty2)) (PredTy (EqPred ty1' ty2')) = ty1 `tcEqType` ty1' && ty2 `tcEqType` ty2'