Make the treatment of equalities more uniform
[ghc-hetmet.git] / compiler / typecheck / TcType.lhs
index 0fc4dca..165018d 100644 (file)
@@ -19,7 +19,7 @@ is the principal client.
 -- The above warning supression flag is a temporary kludge.
 -- While working on this module you are encouraged to remove it and fix
 -- any warnings in the module. See
---     http://hackage.haskell.org/trac/ghc/wiki/CodingStyle#Warnings
+--     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
 -- for details
 
 module TcType (
@@ -38,7 +38,7 @@ module TcType (
   isImmutableTyVar, isSkolemTyVar, isMetaTyVar, isBoxyTyVar, 
   isSigTyVar, isExistentialTyVar,  isTyConableTyVar,
   metaTvRef, 
-  isFlexi, isIndirect, 
+  isFlexi, isIndirect, isRuntimeUnk, isUnk,
 
   --------------------------------
   -- Builders
@@ -457,7 +457,7 @@ pprSkolTvBinding tv
     ppr_details (MetaTv (SigTv info) _) = ppr_skol info
     ppr_details (SkolemTv info)                = ppr_skol info
 
-    ppr_skol UnkSkol       = empty     -- Unhelpful; omit
+    ppr_skol UnkSkol       = ptext SLIT("is an unknown type variable") -- Unhelpful
     ppr_skol RuntimeUnkSkol = ptext SLIT("is an unknown runtime type")
     ppr_skol info           = sep [ptext SLIT("is a rigid type variable bound by"),
                                   sep [pprSkolInfo info, 
@@ -556,6 +556,16 @@ isFlexi other     = False
 
 isIndirect (Indirect _) = True
 isIndirect other        = False
+
+isRuntimeUnk :: TyVar -> Bool
+isRuntimeUnk x | isTcTyVar x
+               , SkolemTv RuntimeUnkSkol <- tcTyVarDetails x = True
+               | otherwise = False
+
+isUnk :: TyVar -> Bool
+isUnk x | isTcTyVar x
+        , SkolemTv UnkSkol <- tcTyVarDetails x = True
+        | otherwise = False
 \end{code}
 
 
@@ -660,9 +670,7 @@ tcSplitPhiTy ty = split ty ty []
   split orig_ty ty tvs | Just ty' <- tcView ty = split orig_ty ty' tvs
 
   split orig_ty (ForAllTy tv ty) ts
-        | isCoVar tv = split ty ty (eq_pred:ts)
-        where
-           PredTy eq_pred = tyVarKind tv
+        | isCoVar tv = split ty ty (coVarPred tv : ts)
   split orig_ty (FunTy arg res) ts 
        | Just p <- tcSplitPredTy_maybe arg = split res res (p:ts)
   split orig_ty ty             ts = (reverse ts, orig_ty)
@@ -1052,6 +1060,15 @@ exactTyVarsOfType is used by the type checker to figure out exactly
 which type variables are mentioned in a type.  It's also used in the
 smart-app checking code --- see TcExpr.tcIdApp
 
+On the other hand, consider a *top-level* definition
+       f = (\x -> x) :: T a -> T a
+If we don't abstract over 'a' it'll get fixed to GHC.Prim.Any, and then
+if we have an application like (f "x") we get a confusing error message 
+involving Any.  So the conclusion is this: when generalising
+  - at top level use tyVarsOfType
+  - in nested bindings use exactTyVarsOfType
+See Trac #1813 for example.
+
 \begin{code}
 exactTyVarsOfType :: TcType -> TyVarSet
 -- Find the free type variables (of any kind)
@@ -1276,6 +1293,7 @@ legalFFITyCon tc
 marshalableTyCon dflags tc
   =  (dopt Opt_UnliftedFFITypes dflags 
       && isUnLiftedTyCon tc
+      && not (isUnboxedTupleTyCon tc)
       && case tyConPrimRep tc of       -- Note [Marshalling VoidRep]
           VoidRep -> False
           other   -> True)