merge upstream HEAD
[ghc-hetmet.git] / compiler / rename / RnExpr.lhs
index 4b5071f..1b7eef0 100644 (file)
@@ -25,7 +25,7 @@ import RnBinds   ( rnLocalBindsAndThen, rnLocalValBindsLHS, rnLocalValBindsRHS,
                    rnMatchGroup, makeMiniFixityEnv) 
 import HsSyn
 import TcRnMonad
                    rnMatchGroup, makeMiniFixityEnv) 
 import HsSyn
 import TcRnMonad
-import TcEnv           ( thRnBrack )
+import TcEnv           ( thRnBrack, getHetMetLevel )
 import RnEnv
 import RnTypes         ( rnHsTypeFVs, rnSplice, checkTH,
                          mkOpFormRn, mkOpAppRn, mkNegAppRn, checkSectionPrec)
 import RnEnv
 import RnTypes         ( rnHsTypeFVs, rnSplice, checkTH,
                          mkOpFormRn, mkOpAppRn, mkNegAppRn, checkSectionPrec)
@@ -34,6 +34,7 @@ import DynFlags
 import BasicTypes      ( FixityDirection(..) )
 import PrelNames
 
 import BasicTypes      ( FixityDirection(..) )
 import PrelNames
 
+import Var              ( TyVar, varName )
 import Name
 import NameSet
 import RdrName
 import Name
 import NameSet
 import RdrName
@@ -84,6 +85,13 @@ rnExprs ls = rnExprs' ls emptyUniqSet
 Variables. We look up the variable and return the resulting name. 
 
 \begin{code}
 Variables. We look up the variable and return the resulting name. 
 
 \begin{code}
+
+-- during the renamer phase we only care about the length of the
+-- current HetMet level; the actual tyvars don't
+-- matter, so we use bottoms for them
+dummyTyVar :: TyVar
+dummyTyVar = error "tried to force RnExpr.dummyTyVar"
+
 rnLExpr :: LHsExpr RdrName -> RnM (LHsExpr Name, FreeVars)
 rnLExpr = wrapLocFstM rnExpr
 
 rnLExpr :: LHsExpr RdrName -> RnM (LHsExpr Name, FreeVars)
 rnLExpr = wrapLocFstM rnExpr
 
@@ -131,8 +139,8 @@ rnExpr (HsApp fun arg)
     rnLExpr arg                `thenM` \ (arg',fvArg) ->
     return (HsApp fun' arg', fvFun `plusFV` fvArg)
 
     rnLExpr arg                `thenM` \ (arg',fvArg) ->
     return (HsApp fun' arg', fvFun `plusFV` fvArg)
 
-rnExpr (OpApp e1 (L op_loc (HsVar op_rdr)) _ e2) 
-  = do { (e1', fv_e1) <- rnLExpr e1
+rnExpr (OpApp e1 (L op_loc (HsVar op_rdr)) _ e2)
+  = do  { (e1', fv_e1) <- rnLExpr e1
        ; (e2', fv_e2) <- rnLExpr e2
        ; op_name <- setSrcSpan op_loc (lookupOccRn op_rdr)
        ; (op', fv_op) <- finishHsVar op_name
        ; (e2', fv_e2) <- rnLExpr e2
        ; op_name <- setSrcSpan op_loc (lookupOccRn op_rdr)
        ; (op', fv_op) <- finishHsVar op_name
@@ -146,6 +154,10 @@ rnExpr (OpApp e1 (L op_loc (HsVar op_rdr)) _ e2)
        ; fixity <- lookupFixityRn op_name
        ; final_e <- mkOpAppRn e1' (L op_loc op') fixity e2'
        ; return (final_e, fv_e1 `plusFV` fv_op `plusFV` fv_e2) }
        ; fixity <- lookupFixityRn op_name
        ; final_e <- mkOpAppRn e1' (L op_loc op') fixity e2'
        ; return (final_e, fv_e1 `plusFV` fv_op `plusFV` fv_e2) }
+rnExpr (OpApp _ other_op _ _)
+  = failWith (vcat [ hang (ptext (sLit "Operator application with a non-variable operator:"))
+                        2 (ppr other_op)
+                   , ptext (sLit "(Probably resulting from a Template Haskell splice)") ])
 
 rnExpr (NegApp e _)
   = rnLExpr e                  `thenM` \ (e', fv_e) ->
 
 rnExpr (NegApp e _)
   = rnLExpr e                  `thenM` \ (e', fv_e) ->
@@ -153,6 +165,21 @@ rnExpr (NegApp e _)
     mkNegAppRn e' neg_name     `thenM` \ final_e ->
     return (final_e, fv_e `plusFV` fv_neg)
 
     mkNegAppRn e' neg_name     `thenM` \ final_e ->
     return (final_e, fv_e `plusFV` fv_neg)
 
+rnExpr (HsHetMetBrak c e)
+  = do { (e', fv_e) <- updLclEnv (\x -> x { tcl_hetMetLevel = dummyTyVar:(tcl_hetMetLevel x) }) $ rnLExpr e
+       ; return (HsHetMetBrak c e', fv_e)
+       }
+rnExpr (HsHetMetEsc c t e)
+  = do { (e', fv_e) <- updLclEnv (\x -> x { tcl_hetMetLevel = tail (tcl_hetMetLevel x) }) $ rnLExpr e
+       ; return (HsHetMetEsc c t e', fv_e)
+       }
+rnExpr (HsHetMetCSP c e)
+  = do { (e', fv_e) <- updLclEnv (\x -> x { tcl_hetMetLevel = tail (tcl_hetMetLevel x) }) $ rnLExpr e
+       ; return (HsHetMetCSP c e', fv_e)
+       }
+
+    
+
 ------------------------------------------
 -- Template Haskell extensions
 -- Don't ifdef-GHCI them because we want to fail gracefully
 ------------------------------------------
 -- Template Haskell extensions
 -- Don't ifdef-GHCI them because we want to fail gracefully
@@ -264,13 +291,10 @@ rnExpr (ExprWithTySig expr pty)
 
 rnExpr (HsIf _ p b1 b2)
   = do { (p', fvP) <- rnLExpr p
 
 rnExpr (HsIf _ p b1 b2)
   = do { (p', fvP) <- rnLExpr p
-    ; (b1', fvB1) <- rnLExpr b1
-    ; (b2', fvB2) <- rnLExpr b2
-    ; rebind <- xoptM Opt_RebindableSyntax
-    ; if not rebind
-       then return (HsIf Nothing p' b1' b2', plusFVs [fvP, fvB1, fvB2])
-       else do { c <- liftM HsVar (lookupOccRn (mkVarUnqual (fsLit "ifThenElse")))
-               ; return (HsIf (Just c) p' b1' b2', plusFVs [fvP, fvB1, fvB2]) }}
+       ; (b1', fvB1) <- rnLExpr b1
+       ; (b2', fvB2) <- rnLExpr b2
+       ; (mb_ite, fvITE) <- lookupIfThenElse
+       ; return (HsIf mb_ite p' b1' b2', plusFVs [fvITE, fvP, fvB1, fvB2]) }
 
 rnExpr (HsType a)
   = rnHsTypeFVs doc a  `thenM` \ (t, fvT) -> 
 
 rnExpr (HsType a)
   = rnHsTypeFVs doc a  `thenM` \ (t, fvT) -> 
@@ -870,13 +894,15 @@ rnRecStmtsAndThen s cont
 
          --    ...bring them and their fixities into scope
        ; let bound_names = collectLStmtsBinders (map fst new_lhs_and_fv)
 
          --    ...bring them and their fixities into scope
        ; let bound_names = collectLStmtsBinders (map fst new_lhs_and_fv)
+             -- Fake uses of variables introduced implicitly (warning suppression, see #4404)
+             implicit_uses = lStmtsImplicits (map fst new_lhs_and_fv)
        ; bindLocalNamesFV bound_names $
           addLocalFixities fix_env bound_names $ do
 
          -- (C) do the right-hand-sides and thing-inside
        { segs <- rn_rec_stmts bound_names new_lhs_and_fv
        ; (res, fvs) <- cont segs 
        ; bindLocalNamesFV bound_names $
           addLocalFixities fix_env bound_names $ do
 
          -- (C) do the right-hand-sides and thing-inside
        { segs <- rn_rec_stmts bound_names new_lhs_and_fv
        ; (res, fvs) <- cont segs 
-       ; warnUnusedLocalBinds bound_names fvs
+       ; warnUnusedLocalBinds bound_names (fvs `unionNameSets` implicit_uses)
        ; return (res, fvs) }}
 
 -- get all the fixity decls in any Let stmt
        ; return (res, fvs) }}
 
 -- get all the fixity decls in any Let stmt