Keep track of family instance modules
[ghc-hetmet.git] / compiler / typecheck / TcGadt.lhs
index 558f97e..4e71827 100644 (file)
@@ -1,4 +1,5 @@
 %
+% (c) The University of Glasgow 2006
 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
 %
 
@@ -16,29 +17,26 @@ module TcGadt (
        tcUnifyTys, BindFlag(..)
   ) where
 
-import HsSyn   ( ExprCoFn(..), idCoercion, isIdCoercion )
-import Coercion        ( Coercion, mkSymCoercion, mkTransCoercion, mkUnsafeCoercion,
-                 mkLeftCoercion, mkRightCoercion, mkCoKind, coercionKindPredTy,
-                 splitCoercionKind, decomposeCo, coercionKind )
-import TcType  ( TvSubst(..), TvSubstEnv, substTy, mkTvSubst, 
-                 substTyVar, zipTopTvSubst, typeKind,
-                 eqKind, isSubKind, repSplitAppTy_maybe,
-                 tcView, tcGetTyVar_maybe
-               )
-import Type    ( Type, tyVarsOfType, tyVarsOfTypes, tcEqType, mkTyVarTy )
-import TypeRep ( Type(..), PredType(..) )
-import DataCon ( DataCon, dataConUnivTyVars, dataConEqSpec )
-import Var     ( CoVar, TyVar, tyVarKind, varUnique )
+#include "HsVersions.h"
+
+import HsSyn
+import Coercion
+import Type
+import TypeRep
+import DataCon
+import Var
 import VarEnv
 import VarSet
-import ErrUtils                ( Message )
-import Maybes          ( MaybeErr(..), isJust )
-import Control.Monad   ( foldM )
+import ErrUtils
+import Maybes
+import Control.Monad
 import Outputable
-import Unique          ( Unique )
-import UniqFM          ( ufmToList )
 
-#include "HsVersions.h"
+#ifdef DEBUG
+import Unique
+import UniqFM
+import TcType
+#endif
 \end{code}
 
 
@@ -62,29 +60,29 @@ emptyRefinement :: Refinement
 emptyRefinement = (Reft emptyInScopeSet emptyVarEnv)
 
 
-refineType :: Refinement -> Type -> (ExprCoFn, Type)
+refineType :: Refinement -> Type -> (HsWrapper, Type)
 -- Apply the refinement to the type.
 -- If (refineType r ty) = (co, ty')
 -- Then co :: ty:=:ty'
 refineType (Reft in_scope env) ty
   | not (isEmptyVarEnv env),           -- Common case
     any (`elemVarEnv` env) (varSetElems (tyVarsOfType ty))
-  = (ExprCoFn (substTy co_subst ty), substTy tv_subst ty)
+  = (WpCo (substTy co_subst ty), substTy tv_subst ty)
   | otherwise
-  = (idCoercion, ty)   -- The type doesn't mention any refined type variables
+  = (idHsWrapper, ty)  -- The type doesn't mention any refined type variables
   where
     tv_subst = mkTvSubst in_scope (mapVarEnv snd env)
     co_subst = mkTvSubst in_scope (mapVarEnv fst env)
  
-refineResType :: Refinement -> Type -> (ExprCoFn, Type)
+refineResType :: Refinement -> Type -> (HsWrapper, Type)
 -- Like refineType, but returns the 'sym' coercion
 -- If (refineResType r ty) = (co, ty')
 -- Then co :: ty':=:ty
 refineResType reft ty
   = case refineType reft ty of
-       (ExprCoFn co, ty1) -> (ExprCoFn (mkSymCoercion co), ty1)
-       (id_co,       ty1) -> ASSERT( isIdCoercion id_co )
-                             (idCoercion, ty1)
+       (WpCo co, ty1) -> (WpCo (mkSymCoercion co), ty1)
+       (id_co,   ty1) -> ASSERT( isIdHsWrapper id_co )
+                         (idHsWrapper, ty1)
 \end{code}
 
 
@@ -215,8 +213,8 @@ fixTvCoEnv in_scope env
       -- then use transitivity with the original coercion
       where
         (co_fn, ty') = refineType (Reft in_scope fixpt) ty
-        co1 | ExprCoFn co'' <- co_fn = mkTransCoercion co co''
-            | otherwise              = ASSERT( isIdCoercion co_fn ) co 
+        co1 | WpCo co'' <- co_fn = mkTransCoercion co co''
+            | otherwise          = ASSERT( isIdHsWrapper co_fn ) co 
 
 -----------------------------
 fixTvSubstEnv :: InScopeSet -> TvSubstEnv -> TvSubstEnv
@@ -261,6 +259,7 @@ type InternalReft = TyVarEnv (Coercion, Type)
 -- INVARIANT:   a->(co,ty)   then   co :: (a:=:ty)
 -- Not necessarily idemopotent
 
+#ifdef DEBUG
 badReftElts :: InternalReft -> [(Unique, (Coercion,Type))]
 -- Return the BAD elements of the refinement
 -- Should be empty; used in asserions only
@@ -273,6 +272,7 @@ badReftElts env
                     | otherwise = False
        where
          (ty1,ty2) = coercionKind co
+#endif
 
 emptyInternalReft :: InternalReft
 emptyInternalReft = emptyVarEnv
@@ -387,8 +387,10 @@ uUnrefined :: Bool                -- Whether the input is swapped
            -> UM InternalReft
 
 -- We know that tv1 isn't refined
--- PRE-CONDITION: in the call (uUnrefined r co tv ty ty'), we know that
---     co :: tv:=:ty
+-- PRE-CONDITION: in the call (uUnrefined False r co tv1 ty2 ty2'), we know that
+--     co :: tv1:=:ty2
+-- and if the first argument is True instead, we know
+--      co :: ty2:=:tv1
 
 uUnrefined swap subst co tv1 ty2 ty2'
   | Just ty2'' <- tcView ty2'
@@ -550,4 +552,4 @@ kindMisMatch tv1 t2
 occursCheck tv ty
   = hang (ptext SLIT("Can't construct the infinite type"))
        2 (ppr tv <+> equals <+> ppr ty)
-\end{code}
\ No newline at end of file
+\end{code}