[project @ 2002-10-22 10:31:21 by simonpj]
[ghc-hetmet.git] / ghc / compiler / typecheck / TcExpr.lhs
index c3dde2f..89b7d9b 100644 (file)
@@ -10,12 +10,15 @@ module TcExpr ( tcExpr, tcExpr_id, tcMonoExpr ) where
 
 #ifdef GHCI    /* Only if bootstrapped */
 import {-# SOURCE #-}  TcSplice( tcSpliceExpr, tcBracket )
-import TcEnv           ( bracketOK )
+import HsSyn           ( HsReify(..), ReifyFlavour(..) )
+import TcEnv           ( bracketOK, tcMetaTy, tcLookupGlobal,
+                         wellStaged, metaLevel )
 import TcSimplify      ( tcSimplifyBracket )
-import DsMeta          ( liftName )
+import Name            ( isExternalName )
+import qualified DsMeta
 #endif
 
-import HsSyn           ( HsExpr(..), HsLit(..), ArithSeqInfo(..), 
+import HsSyn           ( HsExpr(..), HsLit(..), ArithSeqInfo(..),
                          mkMonoBind, recBindFields
                        )
 import RnHsSyn         ( RenamedHsExpr, RenamedRecordBinds )
@@ -32,8 +35,7 @@ import Inst           ( InstOrigin(..),
                        )
 import TcBinds         ( tcBindsAndThen )
 import TcEnv           ( tcLookupClass, tcLookupGlobal_maybe, tcLookupIdLvl,
-                         tcLookupTyCon, tcLookupDataCon, tcLookupId,
-                         wellStaged, metaLevel
+                         tcLookupTyCon, tcLookupDataCon, tcLookupId
                        )
 import TcMatches       ( tcMatchesCase, tcMatchLambda, tcDoStmts )
 import TcMonoType      ( tcHsSigType, UserTypeCtxt(..) )
@@ -43,7 +45,7 @@ import TcMType                ( tcInstTyVars, tcInstType, newHoleTyVarTy, zapToType,
                          newTyVarTy, newTyVarTys, zonkTcType, readHoleResult )
 import TcType          ( TcType, TcSigmaType, TcRhoType, TyVarDetails(VanillaTv),
                          tcSplitFunTys, tcSplitTyConApp, mkTyVarTys,
-                         isSigmaTy, isTauTy, mkFunTy, mkFunTys,
+                         isSigmaTy, mkFunTy, mkFunTys,
                          mkTyConApp, mkClassPred, tcFunArgTy,
                          tyVarsOfTypes, isLinearPred,
                          liftedTypeKind, openTypeKind, 
@@ -53,7 +55,7 @@ import TcType         ( TcType, TcSigmaType, TcRhoType, TyVarDetails(VanillaTv),
 import FieldLabel      ( FieldLabel, fieldLabelName, fieldLabelType, fieldLabelTyCon )
 import Id              ( Id, idType, recordSelectorFieldLabel, isRecordSelector, isDataConWrapId_maybe )
 import DataCon         ( DataCon, dataConFieldLabels, dataConSig, dataConStrictMarks )
-import Name            ( Name, isExternalName )
+import Name            ( Name )
 import TyCon           ( TyCon, tyConTyVars, tyConTheta, isAlgTyCon, tyConDataCons )
 import Subst           ( mkTopTyVarSubst, substTheta, substTy )
 import VarSet          ( emptyVarSet, elemVarSet )
@@ -621,10 +623,11 @@ tcMonoExpr (PArrSeqIn _) _
 #ifdef GHCI    /* Only if bootstrapped */
        -- Rename excludes these cases otherwise
 
-tcMonoExpr (HsSplice n expr) res_ty = tcSpliceExpr n expr res_ty
+tcMonoExpr (HsSplice n expr loc) res_ty = addSrcLoc loc (tcSpliceExpr n expr res_ty)
   
-tcMonoExpr (HsBracket brack) res_ty
-  = getStage                                   `thenM` \ level ->
+tcMonoExpr (HsBracket brack loc) res_ty
+  = addSrcLoc loc                      $
+    getStage                           `thenM` \ level ->
     case bracketOK level of {
        Nothing         -> failWithTc (illegalBracket level) ;
        Just next_level ->
@@ -646,6 +649,17 @@ tcMonoExpr (HsBracket brack) res_ty
     readMutVar pending_splices         `thenM` \ pendings ->
     returnM (HsBracketOut brack pendings)
     }
+
+tcMonoExpr (HsReify (Reify flavour name)) res_ty
+  = addErrCtxt (ptext SLIT("At the reification of") <+> ppr name)      $
+    tcMetaTy  tycon_name       `thenM` \ reify_ty ->
+    unifyTauTy res_ty reify_ty `thenM_`
+    returnM (HsReify (ReifyOut flavour name))
+  where
+    tycon_name = case flavour of
+                  ReifyDecl -> DsMeta.decTyConName
+                  ReifyType -> DsMeta.typTyConName
+                  ReifyFixity -> pprPanic "tcMonoExpr: cant do reifyFixity yet" (ppr name)
 #endif GHCI
 \end{code}
 
@@ -833,7 +847,7 @@ tcId name   -- Look up the Id and instantiate its type
                    -- just going to flag an error for now
 
        setLIEVar lie_var       (
-       newMethodFromName orig id_ty liftName   `thenM` \ lift ->
+       newMethodFromName orig id_ty DsMeta.liftName    `thenM` \ lift ->
                -- Put the 'lift' constraint into the right LIE
        
        -- Update the pending splices
@@ -861,8 +875,8 @@ tcId name   -- Look up the Id and instantiate its type
        | want_method_inst fun_ty
        = tcInstType VanillaTv fun_ty           `thenM` \ (tyvars, theta, tau) ->
          newMethodWithGivenTy orig fun_id 
-               (mkTyVarTys tyvars) theta tau   `thenM` \ meth ->
-         loop (HsVar (instToId meth)) tau
+               (mkTyVarTys tyvars) theta tau   `thenM` \ meth_id ->
+         loop (HsVar meth_id) tau
 
     loop fun fun_ty 
        | isSigmaTy fun_ty