X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Ftypecheck%2FTcType.lhs;h=c68c10ffa6ed0b980f8979df32549255296a814c;hb=9fc1b8f32d66e7abf2bed504fb59461f37a77169;hp=74100920bbf1aa4dea009b7a3b35d9c715edd1d4;hpb=038a429f51ad0625ea6bb31a94a40b2aeaeebca6;p=ghc-hetmet.git diff --git a/compiler/typecheck/TcType.lhs b/compiler/typecheck/TcType.lhs index 7410092..c68c10f 100644 --- a/compiler/typecheck/TcType.lhs +++ b/compiler/typecheck/TcType.lhs @@ -28,7 +28,7 @@ module TcType ( MetaDetails(Flexi, Indirect), MetaInfo(..), SkolemInfo(..), pprSkolTvBinding, pprSkolInfo, isImmutableTyVar, isSkolemTyVar, isMetaTyVar, isMetaTyVarTy, - isSigTyVar, isExistentialTyVar, isTyConableTyVar, + isSigTyVar, isOverlappableTyVar, isTyConableTyVar, metaTvRef, isFlexi, isIndirect, isUnkSkol, isRuntimeUnkSkol, @@ -339,9 +339,6 @@ data SkolemInfo | RuntimeUnkSkol -- a type variable used to represent an unknown -- runtime type (used in the GHCi debugger) - | NoScSkol -- Used for the "self" superclass when solving - -- superclasses; don't generate superclasses of me - | UnkSkol -- Unhelpful info (until I improve it) ------------------------------------- @@ -451,6 +448,9 @@ pprSkolTvBinding tv sep [pprSkolInfo info, nest 2 (ptext (sLit "at") <+> ppr (getSrcLoc tv))]] +instance Outputable SkolemInfo where + ppr = pprSkolInfo + pprSkolInfo :: SkolemInfo -> SDoc -- Complete the sentence "is a rigid type variable bound by..." pprSkolInfo (SigSkol ctxt) = pprUserTypeCtxt ctxt @@ -458,7 +458,6 @@ pprSkolInfo (IPSkol ips) = ptext (sLit "the implicit-parameter bindings for") <+> pprWithCommas ppr ips pprSkolInfo (ClsSkol cls) = ptext (sLit "the class declaration for") <+> quotes (ppr cls) pprSkolInfo InstSkol = ptext (sLit "the instance declaration") -pprSkolInfo NoScSkol = ptext (sLit "the instance declaration (self)") pprSkolInfo FamInstSkol = ptext (sLit "the family instance declaration") pprSkolInfo (RuleSkol name) = ptext (sLit "the RULE") <+> doubleQuotes (ftext name) pprSkolInfo ArrowSkol = ptext (sLit "the arrow form") @@ -615,7 +614,7 @@ isImmutableTyVar tv | isTcTyVar tv = isSkolemTyVar tv | otherwise = True -isTyConableTyVar, isSkolemTyVar, isExistentialTyVar, +isTyConableTyVar, isSkolemTyVar, isOverlappableTyVar, isMetaTyVar :: TcTyVar -> Bool isTyConableTyVar tv @@ -634,11 +633,14 @@ isSkolemTyVar tv FlatSkol {} -> True MetaTv {} -> False -isExistentialTyVar tv -- Existential type variable, bound by a pattern +-- isOverlappableTyVar has a unique purpose. +-- See Note [Binding when looking up instances] in InstEnv. +isOverlappableTyVar tv = ASSERT( isTcTyVar tv ) case tcTyVarDetails tv of - SkolemTv (PatSkol {}) -> True - _ -> False + SkolemTv (PatSkol {}) -> True + SkolemTv (InstSkol {}) -> True + _ -> False isMetaTyVar tv = ASSERT2( isTcTyVar tv, ppr tv ) @@ -673,14 +675,10 @@ isIndirect _ = False isRuntimeUnkSkol :: TyVar -> Bool -- Called only in TcErrors; see Note [Runtime skolems] there -isRuntimeUnkSkol x - | isTcTyVar x - , SkolemTv info <- tcTyVarDetails x - = case info of - UnkSkol -> True - RuntimeUnkSkol -> True - _ -> False - | otherwise = False +isRuntimeUnkSkol x | isTcTyVar x + , SkolemTv RuntimeUnkSkol <- tcTyVarDetails x + = True + | otherwise = False isUnkSkol :: TyVar -> Bool isUnkSkol x | isTcTyVar x @@ -921,23 +919,24 @@ tcIsTyVarTy :: Type -> Bool tcIsTyVarTy ty = maybeToBool (tcGetTyVar_maybe ty) ----------------------- -tcSplitDFunTy :: Type -> ([TyVar], Class, [Type]) +tcSplitDFunTy :: Type -> ([TyVar], Int, Class, [Type]) -- Split the type of a dictionary function -- We don't use tcSplitSigmaTy, because a DFun may (with NDP) -- have non-Pred arguments, such as -- df :: forall m. (forall b. Eq b => Eq (m b)) -> C m tcSplitDFunTy ty - = case tcSplitForAllTys ty of { (tvs, rho) -> - case tcSplitDFunHead (drop_pred_tys rho) of { (clas, tys) -> - (tvs, clas, tys) }} + = case tcSplitForAllTys ty of { (tvs, rho) -> + case split_dfun_args 0 rho of { (n_theta, tau) -> + case tcSplitDFunHead tau of { (clas, tys) -> + (tvs, n_theta, clas, tys) }}} where - -- Discard the context of the dfun. This can be a mix of + -- Count the context of the dfun. This can be a mix of -- coercion and class constraints; or (in the general NDP case) -- some other function argument - drop_pred_tys ty | Just ty' <- tcView ty = drop_pred_tys ty' - drop_pred_tys (ForAllTy tv ty) = ASSERT( isCoVar tv ) drop_pred_tys ty - drop_pred_tys (FunTy _ ty) = drop_pred_tys ty - drop_pred_tys ty = ty + split_dfun_args n ty | Just ty' <- tcView ty = split_dfun_args n ty' + split_dfun_args n (ForAllTy tv ty) = ASSERT( isCoVar tv ) split_dfun_args (n+1) ty + split_dfun_args n (FunTy _ ty) = split_dfun_args (n+1) ty + split_dfun_args n ty = (n, ty) tcSplitDFunHead :: Type -> (Class, [Type]) tcSplitDFunHead tau @@ -958,6 +957,9 @@ tcInstHeadTyAppAllTyVars :: Type -> Bool -- Used in Haskell-98 mode, for the argument types of an instance head -- These must be a constructor applied to type variable arguments tcInstHeadTyAppAllTyVars ty + | Just ty' <- tcView ty -- Look through synonyms + = tcInstHeadTyAppAllTyVars ty' + | otherwise = case ty of TyConApp _ tys -> ok tys FunTy arg res -> ok [arg, res] @@ -1026,8 +1028,6 @@ getClassPredTys _ = panic "getClassPredTys" mkDictTy :: Class -> [Type] -> Type mkDictTy clas tys = mkPredTy (ClassP clas tys) - - isDictLikeTy :: Type -> Bool -- Note [Dictionary-like types] isDictLikeTy ty | Just ty' <- tcView ty = isDictTy ty'