X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Frename%2FRnExpr.lhs;h=310d075d419e0c76697627437f8cf0b2da780977;hp=5598cc0580d97fcdc28bd73fa9960f94ecdd3185;hb=7836349556deef66f1b1d06fe8e9c7c0b841f0d0;hpb=76349636abcb764e8ed3b9ae548730ad2d85abb2 diff --git a/compiler/rename/RnExpr.lhs b/compiler/rename/RnExpr.lhs index 5598cc0..310d075 100644 --- a/compiler/rename/RnExpr.lhs +++ b/compiler/rename/RnExpr.lhs @@ -21,7 +21,7 @@ import {-# SOURCE #-} TcSplice( runQuasiQuoteExpr ) #endif /* GHCI */ import RnSource ( rnSrcDecls, findSplice ) -import RnBinds ( rnLocalBindsAndThen, rnValBindsLHS, rnValBindsRHS, +import RnBinds ( rnLocalBindsAndThen, rnLocalValBindsLHS, rnLocalValBindsRHS, rnMatchGroup, makeMiniFixityEnv) import HsSyn import TcRnMonad @@ -262,11 +262,15 @@ rnExpr (ExprWithTySig expr pty) where doc = text "In an expression type signature" -rnExpr (HsIf p b1 b2) - = rnLExpr p `thenM` \ (p', fvP) -> - rnLExpr b1 `thenM` \ (b1', fvB1) -> - rnLExpr b2 `thenM` \ (b2', fvB2) -> - return (HsIf p' b1' b2', plusFVs [fvP, fvB1, fvB2]) +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]) }} rnExpr (HsType a) = rnHsTypeFVs doc a `thenM` \ (t, fvT) -> @@ -430,8 +434,8 @@ convertOpFormsCmd (HsPar c) = HsPar (convertOpFormsLCmd c) convertOpFormsCmd (HsCase exp matches) = HsCase exp (convertOpFormsMatch matches) -convertOpFormsCmd (HsIf exp c1 c2) - = HsIf exp (convertOpFormsLCmd c1) (convertOpFormsLCmd c2) +convertOpFormsCmd (HsIf f exp c1 c2) + = HsIf f exp (convertOpFormsLCmd c1) (convertOpFormsLCmd c2) convertOpFormsCmd (HsLet binds cmd) = HsLet binds (convertOpFormsLCmd cmd) @@ -487,7 +491,7 @@ methodNamesCmd (HsArrForm {}) = emptyFVs methodNamesCmd (HsPar c) = methodNamesLCmd c -methodNamesCmd (HsIf _ c1 c2) +methodNamesCmd (HsIf _ _ c1 c2) = methodNamesLCmd c1 `plusFV` methodNamesLCmd c2 `addOneFV` choiceAName methodNamesCmd (HsLet _ c) = methodNamesLCmd c @@ -755,7 +759,9 @@ rnStmt ctxt (L loc (TransformStmt stmts _ using by)) thing_inside Just e -> do { (e', fvs) <- rnLExpr e; return (Just e', fvs) } ; (thing, fvs_thing) <- thing_inside bndrs ; let fvs = fvs_by `plusFV` fvs_thing - used_bndrs = filter (`elemNameSet` fvs_thing) bndrs + used_bndrs = filter (`elemNameSet` fvs) bndrs + -- The paper (Fig 5) has a bug here; we must treat any free varaible of + -- the "thing inside", **or of the by-expression**, as used ; return ((by', used_bndrs, thing), fvs) } ; return (([L loc (TransformStmt stmts' used_bndrs using' by')], thing), @@ -931,7 +937,7 @@ rn_rec_stmt_lhs _ (L _ (LetStmt binds@(HsIPBinds _))) = failWith (badIpBinds (ptext (sLit "an mdo expression")) binds) rn_rec_stmt_lhs fix_env (L loc (LetStmt (HsValBinds binds))) - = do (_bound_names, binds') <- rnValBindsLHS fix_env binds + = do (_bound_names, binds') <- rnLocalValBindsLHS fix_env binds return [(L loc (LetStmt (HsValBinds binds')), -- Warning: this is bogus; see function invariant emptyFVs @@ -995,7 +1001,7 @@ rn_rec_stmt _ (L _ (LetStmt binds@(HsIPBinds _))) _ rn_rec_stmt all_bndrs (L loc (LetStmt (HsValBinds binds'))) _ = do (binds', du_binds) <- -- fixities and unused are handled above in rn_rec_stmts_and_then - rnValBindsRHS (mkNameSet all_bndrs) binds' + rnLocalValBindsRHS (mkNameSet all_bndrs) binds' return [(duDefs du_binds, allUses du_binds, emptyNameSet, L loc (LetStmt (HsValBinds binds')))]