- bexpr' <- trans (LetBinding:c) bexpr
- expr' <- trans (LetBody:c) expr
+ -- In the binding of a non-recursive let binding, no extra binders are
+ -- in scope.
+ bexpr' <- trans (LetBinding []:c) bexpr
+ -- In the body of a non-recursive let binding, the bound binder is in
+ -- scope.
+ expr' <- trans ((LetBody [b]):c) expr
where
transalt :: CoreAlt -> TransformMonad CoreAlt
transalt (con, binders, expr) = do
where
transalt :: CoreAlt -> TransformMonad CoreAlt
transalt (con, binders, expr) = do
return (con, binders, expr')
subeverywhere trans c (Var x) = return $ Var x
return (con, binders, expr')
subeverywhere trans c (Var x) = return $ Var x
reps' <- mapM (subs_bind bndr val) reps
-- And then perform the remaining substitutions
do_substitute reps' expr'
reps' <- mapM (subs_bind bndr val) reps
-- And then perform the remaining substitutions
do_substitute reps' expr'
-- Replace the given binder with the given expression in the
-- expression oft the given let binding
subs_bind :: CoreBndr -> CoreExpr -> (CoreBndr, CoreExpr) -> TransformMonad (CoreBndr, CoreExpr)
subs_bind bndr expr (b, v) = do
-- Replace the given binder with the given expression in the
-- expression oft the given let binding
subs_bind :: CoreBndr -> CoreExpr -> (CoreBndr, CoreExpr) -> TransformMonad (CoreBndr, CoreExpr)
subs_bind bndr expr (b, v) = do
is_local_var :: CoreSyn.CoreExpr -> TranslatorSession Bool
is_local_var (CoreSyn.Var v) = do
bndrs <- getGlobalBinders
is_local_var :: CoreSyn.CoreExpr -> TranslatorSession Bool
is_local_var (CoreSyn.Var v) = do
bndrs <- getGlobalBinders
- return $ v `notElem` bndrs
+ -- A datacon id is not a global binder, but not a local variable
+ -- either.
+ let is_dc = Id.isDataConWorkId v
+ return $ not is_dc && v `notElem` bndrs