Major patch to fix reporting of unused imports
[ghc-hetmet.git] / compiler / typecheck / TcRnTypes.lhs
index ff8e3d6..c8d7550 100644 (file)
@@ -29,12 +29,12 @@ module TcRnTypes(
 
        -- Insts
        Inst(..), EqInstCo, InstOrigin(..), InstLoc(..), 
-       pprInstLoc, pprInstArising, instLocSpan, instLocOrigin,
+       pprInstLoc, pprInstArising, instLocSpan, instLocOrigin, setInstLoc,
        LIE, emptyLIE, unitLIE, plusLIE, consLIE, instLoc, instSpan,
        plusLIEs, mkLIE, isEmptyLIE, lieToList, listToLIE,
 
        -- Misc other types
-       TcId, TcIdSet, TcDictBinds,
+       TcId, TcIdSet, TcDictBinds, TcTyVarBind(..), TcTyVarBinds
        
   ) where
 
@@ -70,6 +70,7 @@ import FastString
 
 import Data.Maybe
 import Data.List
+import Data.Set (Set)
 \end{code}
 
 
@@ -98,6 +99,18 @@ type RnM  a = TcRn a         -- Historical
 type TcM  a = TcRn a           -- Historical
 \end{code}
 
+Representation of type bindings to uninstantiated meta variables used during
+constraint solving.
+
+\begin{code}
+data TcTyVarBind = TcTyVarBind TcTyVar TcType
+
+type TcTyVarBinds = Bag TcTyVarBind
+
+instance Outputable TcTyVarBind where
+  ppr (TcTyVarBind tv ty) = ppr tv <+> text ":=" <+> ppr ty
+\end{code}
+
 
 %************************************************************************
 %*                                                                     *
@@ -224,8 +237,11 @@ data TcGblEnv
        -- The binds, rules and foreign-decl fiels are collected
        -- initially in un-zonked form and are finally zonked in tcRnSrcDecls
 
-        tcg_rn_imports :: Maybe [LImportDecl Name],
         tcg_rn_exports :: Maybe [Located (IE Name)],
+        tcg_rn_imports :: [LImportDecl Name],
+               -- Keep the renamed imports regardless.  They are not 
+               -- voluminous and are needed if you want to report unused imports
+        tcg_used_rdrnames :: TcRef (Set RdrName),
        tcg_rn_decls :: Maybe (HsGroup Name),
           -- ^ Renamed decls, maybe.  @Nothing@ <=> Don't retain renamed
           -- decls.
@@ -343,15 +359,20 @@ data TcLclEnv             -- Changes as we move inside an expression
                -- We still need the unsullied global name env so that
                --   we can look up record field names
 
-       tcl_env  :: NameEnv TcTyThing,  -- The local type environment: Ids and TyVars
-                                       -- defined in this module
+       tcl_env  :: NameEnv TcTyThing,  -- The local type environment: Ids and
+                                       -- TyVars defined in this module
                                        
        tcl_tyvars :: TcRef TcTyVarSet, -- The "global tyvars"
                        -- Namely, the in-scope TyVars bound in tcl_env, 
-                       -- plus the tyvars mentioned in the types of Ids bound in tcl_lenv
-                       -- Why mutable? see notes with tcGetGlobalTyVars
+                       -- plus the tyvars mentioned in the types of Ids bound
+                       -- in tcl_lenv. 
+                        -- Why mutable? see notes with tcGetGlobalTyVars
 
-       tcl_lie   :: TcRef LIE          -- Place to accumulate type constraints
+       tcl_lie   :: TcRef LIE,         -- Place to accumulate type constraints
+
+        tcl_tybinds :: TcRef TcTyVarBinds -- Meta and coercion type variable
+                                          -- bindings accumulated during
+                                          -- constraint solving
     }
 
 
@@ -868,6 +889,9 @@ data InstLoc = InstLoc InstOrigin SrcSpan ErrCtxt
 instLoc :: Inst -> InstLoc
 instLoc inst = tci_loc inst
 
+setInstLoc :: Inst -> InstLoc -> Inst
+setInstLoc inst new_loc = inst { tci_loc = new_loc }
+
 instSpan :: Inst -> SrcSpan
 instSpan wanted = instLocSpan (instLoc wanted)
 
@@ -912,7 +936,13 @@ data InstOrigin
   | ExprSigOrigin      -- e :: ty
   | RecordUpdOrigin
   | ViewPatOrigin
+
   | InstScOrigin       -- Typechecking superclasses of an instance declaration
+
+  | NoScOrigin          -- A very special hack; see TcSimplify,
+                       --   Note [Recursive instances and superclases]
+                          
+
   | DerivOrigin                -- Typechecking deriving
   | StandAloneDerivOrigin -- Typechecking stand-alone deriving
   | DefaultOrigin      -- Typechecking a default decl
@@ -936,6 +966,7 @@ instance Outputable InstOrigin where
     ppr TupleOrigin          = ptext (sLit "a tuple")
     ppr NegateOrigin         = ptext (sLit "a use of syntactic negation")
     ppr InstScOrigin         = ptext (sLit "the superclasses of an instance declaration")
+    ppr NoScOrigin            = ptext (sLit "an instance declaration")
     ppr DerivOrigin          = ptext (sLit "the 'deriving' clause of a data type declaration")
     ppr StandAloneDerivOrigin = ptext (sLit "a 'deriving' declaration")
     ppr DefaultOrigin        = ptext (sLit "a 'default' declaration")