[project @ 2000-11-07 15:21:38 by simonmar]
[ghc-hetmet.git] / ghc / compiler / typecheck / TcExpr.lhs
index 72587b7..48f97dc 100644 (file)
@@ -25,10 +25,10 @@ import Inst         ( InstOrigin(..),
                          getIPsOfLIE, instToId, ipToId
                        )
 import TcBinds         ( tcBindsAndThen )
-import TcEnv           ( tcInstId,
-                         tcLookupValue, tcLookupClass, tcLookupGlobalId,
-                         tcLookupTyCon, tcLookupDataCon,
-                         tcExtendGlobalTyVars, tcLookupValueMaybe,
+import TcEnv           ( TcTyThing(..), tcInstId,
+                         tcLookupClass, tcLookupGlobalId, tcLookupGlobal_maybe,
+                         tcLookupTyCon, tcLookupDataCon, tcLookup,
+                         tcExtendGlobalTyVars
                        )
 import TcMatches       ( tcMatchesCase, tcMatchLambda, tcStmts )
 import TcMonoType      ( tcHsSigType, checkSigTyVars, sigCtxt )
@@ -47,7 +47,7 @@ import DataCon                ( dataConFieldLabels, dataConSig,
                        )
 import Name            ( Name, getName )
 import Type            ( mkFunTy, mkAppTy, mkTyVarTys, ipName_maybe,
-                         splitFunTy_maybe, splitFunTys, isNotUsgTy,
+                         splitFunTy_maybe, splitFunTys,
                          mkTyConApp, splitSigmaTy, 
                          splitRhoTy,
                          isTauTy, tyVarsOfType, tyVarsOfTypes, 
@@ -57,20 +57,21 @@ import Type         ( mkFunTy, mkAppTy, mkTyVarTys, ipName_maybe,
                        )
 import TyCon           ( TyCon, tyConTyVars )
 import Subst           ( mkTopTyVarSubst, substClasses, substTy )
-import UsageSPUtils     ( unannotTy )
 import VarSet          ( elemVarSet, mkVarSet )
 import TysWiredIn      ( boolTy )
 import TcUnify         ( unifyTauTy, unifyFunTy, unifyListTy, unifyTupleTy )
-import PrelNames       ( cCallableClassKey, cReturnableClassKey, 
-                         enumFromClassOpKey, enumFromThenClassOpKey,
-                         enumFromToClassOpKey, enumFromThenToClassOpKey,
-                         thenMClassOpKey, failMClassOpKey, returnMClassOpKey, ioTyConKey
+import PrelNames       ( cCallableClassName, 
+                         cReturnableClassName, 
+                         enumFromName, enumFromThenName,
+                         enumFromToName, enumFromThenToName,
+                         thenMName, failMName, returnMName, ioTyConName
                        )
 import Outputable
 import Maybes          ( maybeToBool, mapMaybe )
 import ListSetOps      ( minusList )
 import Util
-import CmdLineOpts      ( opt_WarnMissingFields )
+import CmdLineOpts
+import HscTypes                ( TyThing(..) )
 
 \end{code}
 
@@ -396,7 +397,7 @@ tcMonoExpr expr@(RecordCon con_name rbinds) res_ty
 
        -- Check that the record bindings match the constructor
        -- con_name is syntactically constrained to be a data constructor
-    tcLookupDataCon con_name   `thenTc` \ (data_con, _, _) ->
+    tcLookupDataCon con_name   `thenTc` \ data_con ->
     let
        bad_fields = badFields rbinds data_con
     in
@@ -417,7 +418,8 @@ tcMonoExpr expr@(RecordCon con_name rbinds) res_ty
     let
       missing_fields = missingFields rbinds data_con
     in
-    checkTcM (not (opt_WarnMissingFields && not (null missing_fields)))
+    doptsTc Opt_WarnMissingFields `thenNF_Tc` \ warn ->
+    checkTcM (not (warn && not (null missing_fields)))
        (mapNF_Tc ((warnTc True) . missingFieldCon con_name) missing_fields `thenNF_Tc_`
         returnNF_Tc ())  `thenNF_Tc_`
 
@@ -472,9 +474,8 @@ tcMonoExpr expr@(RecordUpd record_expr rbinds) res_ty
        -- STEP 1
        -- Figure out the tycon and data cons from the first field name
     let
-       (Just sel_id : _)         = maybe_sel_ids
-       (_, _, tau)               = ASSERT( isNotUsgTy (idType sel_id) )
-                                    splitSigmaTy (idType sel_id)       -- Selectors can be overloaded
+       (Just (AnId sel_id) : _)  = maybe_sel_ids
+       (_, _, tau)               = splitSigmaTy (idType sel_id)        -- Selectors can be overloaded
                                                                        -- when the data type has a context
        Just (data_ty, _)         = splitFunTy_maybe tau        -- Must succeed since sel_id is a selector
        (tycon, _, data_cons)       = splitAlgTyConApp data_ty
@@ -553,7 +554,7 @@ tcMonoExpr (ArithSeqIn seq@(From expr)) res_ty
   = unifyListTy res_ty                                 `thenTc` \ elt_ty ->  
     tcMonoExpr expr elt_ty                     `thenTc` \ (expr', lie1) ->
 
-    tcLookupGlobalId enumFromClassOpName       `thenNF_Tc` \ sel_id ->
+    tcLookupGlobalId enumFromName              `thenNF_Tc` \ sel_id ->
     newMethod (ArithSeqOrigin seq)
              sel_id [elt_ty]                   `thenNF_Tc` \ (lie2, enum_from_id) ->
 
@@ -565,7 +566,7 @@ tcMonoExpr in_expr@(ArithSeqIn seq@(FromThen expr1 expr2)) res_ty
     unifyListTy  res_ty                                `thenTc`    \ elt_ty ->  
     tcMonoExpr expr1 elt_ty                            `thenTc`    \ (expr1',lie1) ->
     tcMonoExpr expr2 elt_ty                            `thenTc`    \ (expr2',lie2) ->
-    tcLookupGlobalId enumFromThenClassOpName           `thenNF_Tc` \ sel_id ->
+    tcLookupGlobalId enumFromThenName                  `thenNF_Tc` \ sel_id ->
     newMethod (ArithSeqOrigin seq) sel_id [elt_ty]     `thenNF_Tc` \ (lie3, enum_from_then_id) ->
 
     returnTc (ArithSeqOut (HsVar enum_from_then_id)
@@ -577,7 +578,7 @@ tcMonoExpr in_expr@(ArithSeqIn seq@(FromTo expr1 expr2)) res_ty
     unifyListTy  res_ty                                `thenTc`    \ elt_ty ->  
     tcMonoExpr expr1 elt_ty                            `thenTc`    \ (expr1',lie1) ->
     tcMonoExpr expr2 elt_ty                            `thenTc`    \ (expr2',lie2) ->
-    tcLookupGlobalId enumFromToClassOpName             `thenNF_Tc` \ sel_id ->
+    tcLookupGlobalId enumFromToName                    `thenNF_Tc` \ sel_id ->
     newMethod (ArithSeqOrigin seq) sel_id [elt_ty]     `thenNF_Tc` \ (lie3, enum_from_to_id) ->
 
     returnTc (ArithSeqOut (HsVar enum_from_to_id)
@@ -590,7 +591,7 @@ tcMonoExpr in_expr@(ArithSeqIn seq@(FromThenTo expr1 expr2 expr3)) res_ty
     tcMonoExpr expr1 elt_ty                            `thenTc`    \ (expr1',lie1) ->
     tcMonoExpr expr2 elt_ty                            `thenTc`    \ (expr2',lie2) ->
     tcMonoExpr expr3 elt_ty                            `thenTc`    \ (expr3',lie3) ->
-    tcLookupGlobalId enumFromThenToClassOpName         `thenNF_Tc` \ sel_id ->
+    tcLookupGlobalId enumFromThenToName                        `thenNF_Tc` \ sel_id ->
     newMethod (ArithSeqOrigin seq) sel_id [elt_ty]     `thenNF_Tc` \ (lie4, eft_id) ->
 
     returnTc (ArithSeqOut (HsVar eft_id)
@@ -790,12 +791,6 @@ tcArg the_fun (arg, expected_arg_ty, arg_no)
 %*                                                                     *
 %************************************************************************
 
-Between the renamer and the first invocation of the UsageSP inference,
-identifiers read from interface files will have usage information in
-their types, whereas other identifiers will not.  The unannotTy here
-in @tcId@ prevents this information from pointlessly propagating
-further prior to the first usage inference.
-
 \begin{code}
 tcId :: Name -> NF_TcM (TcExpr, LIE, TcType)
 
@@ -806,7 +801,6 @@ tcId name
       ATcId tc_id      -> instantiate_it (OccurrenceOf tc_id) tc_id (idType tc_id)
       AGlobal (AnId id) -> tcInstId id                 `thenNF_Tc` \ (tyvars, theta, tau) ->
                           instantiate_it2 (OccurrenceOf id) id tyvars theta tau
-
   where
        -- The instantiate_it loop runs round instantiating the Id.
        -- It has to be a loop because we are now prepared to entertain
@@ -856,7 +850,7 @@ tcDoStmts do_or_lc stmts src_loc res_ty
        ListComp -> unifyListTy res_ty `thenTc_` returnTc ()
        _       -> returnTc ())                                 `thenTc_`
 
-    tcStmts do_or_lc (mkAppTy m) stmts elt_ty  `thenTc`   \ (stmts', stmts_lie) ->
+    tcStmts do_or_lc (mkAppTy m) elt_ty src_loc stmts          `thenTc`   \ ((stmts', _), stmts_lie) ->
 
        -- Build the then and zero methods in case we need them
        -- It's important that "then" and "return" appear just once in the final LIE,
@@ -866,9 +860,9 @@ tcDoStmts do_or_lc stmts src_loc res_ty
        --      then = then
        -- where the second "then" sees that it already exists in the "available" stuff.
        --
-    tcLookupGlobalId returnMClassOpName                `thenNF_Tc` \ return_sel_id ->
-    tcLookupGlobalId thenMClassOpName          `thenNF_Tc` \ then_sel_id ->
-    tcLookupGlobalId failMClassOpName          `thenNF_Tc` \ fail_sel_id ->
+    tcLookupGlobalId returnMName               `thenNF_Tc` \ return_sel_id ->
+    tcLookupGlobalId thenMName                 `thenNF_Tc` \ then_sel_id ->
+    tcLookupGlobalId failMName                 `thenNF_Tc` \ fail_sel_id ->
     newMethod DoOrigin return_sel_id [m]       `thenNF_Tc` \ (return_lie, return_id) ->
     newMethod DoOrigin then_sel_id [m]         `thenNF_Tc` \ (then_lie, then_id) ->
     newMethod DoOrigin fail_sel_id [m]         `thenNF_Tc` \ (fail_lie, fail_id) ->