Skip to content

Commit

Permalink
Merge the ExprFnBlock and ExprUnboxedClosure into one ExprClosure wit…
Browse files Browse the repository at this point in the history
…h an optional unboxed closure kind.
  • Loading branch information
nikomatsakis committed Nov 19, 2014
1 parent 8e44688 commit 3e2929d
Show file tree
Hide file tree
Showing 27 changed files with 126 additions and 187 deletions.
9 changes: 6 additions & 3 deletions src/librustc/middle/borrowck/mod.rs
Expand Up @@ -288,9 +288,12 @@ pub fn closure_to_block(closure_id: ast::NodeId,
match tcx.map.get(closure_id) {
ast_map::NodeExpr(expr) => match expr.node {
ast::ExprProc(_, ref block) |
ast::ExprFnBlock(_, _, ref block) |
ast::ExprUnboxedFn(_, _, _, ref block) => { block.id }
_ => panic!("encountered non-closure id: {}", closure_id)
ast::ExprClosure(_, _, _, ref block) => {
block.id
}
_ => {
panic!("encountered non-closure id: {}", closure_id)
}
},
_ => panic!("encountered non-expr id: {}", closure_id)
}
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/cfg/construct.rs
Expand Up @@ -496,9 +496,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
}

ast::ExprMac(..) |
ast::ExprFnBlock(..) |
ast::ExprClosure(..) |
ast::ExprProc(..) |
ast::ExprUnboxedFn(..) |
ast::ExprLit(..) |
ast::ExprPath(..) => {
self.straightline(expr, pred, None::<ast::Expr>.iter())
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/check_loop.rs
Expand Up @@ -48,9 +48,8 @@ impl<'a, 'v> Visitor<'v> for CheckLoopVisitor<'a> {
self.visit_expr(&**e);
self.with_context(Loop, |v| v.visit_block(&**b));
}
ast::ExprFnBlock(_, _, ref b) |
ast::ExprProc(_, ref b) |
ast::ExprUnboxedFn(_, _, _, ref b) => {
ast::ExprClosure(_, _, _, ref b) |
ast::ExprProc(_, ref b) => {
self.with_context(Closure, |v| v.visit_block(&**b));
}
ast::ExprBreak(_) => self.require_loop("break", e.span),
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/expr_use_visitor.rs
Expand Up @@ -496,8 +496,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
self.consume_expr(&**count);
}

ast::ExprFnBlock(..) |
ast::ExprUnboxedFn(..) |
ast::ExprClosure(..) |
ast::ExprProc(..) => {
self.walk_captures(expr)
}
Expand Down
11 changes: 5 additions & 6 deletions src/librustc/middle/liveness.rs
Expand Up @@ -458,7 +458,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
}
visit::walk_expr(ir, expr);
}
ast::ExprFnBlock(..) | ast::ExprProc(..) | ast::ExprUnboxedFn(..) => {
ast::ExprClosure(..) | ast::ExprProc(..) => {
// Interesting control flow (for loops can contain labeled
// breaks or continues)
ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
Expand Down Expand Up @@ -975,10 +975,9 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
self.propagate_through_expr(&**e, succ)
}

ast::ExprFnBlock(_, _, ref blk) |
ast::ExprProc(_, ref blk) |
ast::ExprUnboxedFn(_, _, _, ref blk) => {
debug!("{} is an ExprFnBlock, ExprProc, or ExprUnboxedFn",
ast::ExprClosure(_, _, _, ref blk) |
ast::ExprProc(_, ref blk) => {
debug!("{} is an ExprClosure or ExprProc",
expr_to_string(expr));

/*
Expand Down Expand Up @@ -1495,7 +1494,7 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
ast::ExprBreak(..) | ast::ExprAgain(..) | ast::ExprLit(_) |
ast::ExprBlock(..) | ast::ExprMac(..) | ast::ExprAddrOf(..) |
ast::ExprStruct(..) | ast::ExprRepeat(..) | ast::ExprParen(..) |
ast::ExprFnBlock(..) | ast::ExprProc(..) | ast::ExprUnboxedFn(..) |
ast::ExprClosure(..) | ast::ExprProc(..) |
ast::ExprPath(..) | ast::ExprBox(..) | ast::ExprSlice(..) => {
visit::walk_expr(this, expr);
}
Expand Down
7 changes: 3 additions & 4 deletions src/librustc/middle/mem_categorization.rs
Expand Up @@ -520,8 +520,8 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {

ast::ExprAddrOf(..) | ast::ExprCall(..) |
ast::ExprAssign(..) | ast::ExprAssignOp(..) |
ast::ExprFnBlock(..) | ast::ExprProc(..) |
ast::ExprUnboxedFn(..) | ast::ExprRet(..) |
ast::ExprClosure(..) | ast::ExprProc(..) |
ast::ExprRet(..) |
ast::ExprUnary(..) | ast::ExprSlice(..) |
ast::ExprMethodCall(..) | ast::ExprCast(..) |
ast::ExprVec(..) | ast::ExprTup(..) | ast::ExprIf(..) |
Expand Down Expand Up @@ -693,9 +693,8 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
};

match fn_expr.node {
ast::ExprFnBlock(_, _, ref body) |
ast::ExprProc(_, ref body) |
ast::ExprUnboxedFn(_, _, _, ref body) => body.id,
ast::ExprClosure(_, _, _, ref body) => body.id,
_ => unreachable!()
}
};
Expand Down
13 changes: 4 additions & 9 deletions src/librustc/middle/resolve.rs
Expand Up @@ -50,8 +50,8 @@ use util::nodemap::{NodeMap, NodeSet, DefIdSet, FnvHashMap};

use syntax::ast::{Arm, BindByRef, BindByValue, BindingMode, Block, Crate, CrateNum};
use syntax::ast::{DeclItem, DefId, Expr, ExprAgain, ExprBreak, ExprField};
use syntax::ast::{ExprFnBlock, ExprForLoop, ExprLoop, ExprWhile, ExprMethodCall};
use syntax::ast::{ExprPath, ExprProc, ExprStruct, ExprUnboxedFn, FnDecl};
use syntax::ast::{ExprClosure, ExprForLoop, ExprLoop, ExprWhile, ExprMethodCall};
use syntax::ast::{ExprPath, ExprProc, ExprStruct, FnDecl};
use syntax::ast::{ForeignItem, ForeignItemFn, ForeignItemStatic, Generics};
use syntax::ast::{Ident, ImplItem, Item, ItemEnum, ItemFn, ItemForeignMod};
use syntax::ast::{ItemImpl, ItemMac, ItemMod, ItemStatic, ItemStruct};
Expand Down Expand Up @@ -5903,24 +5903,19 @@ impl<'a> Resolver<'a> {
visit::walk_expr(self, expr);
}

ExprFnBlock(capture_clause, ref fn_decl, ref block) => {
ExprClosure(capture_clause, _, ref fn_decl, ref block) => {
self.capture_mode_map.insert(expr.id, capture_clause);
self.resolve_function(ClosureRibKind(expr.id, ast::DUMMY_NODE_ID),
Some(&**fn_decl), NoTypeParameters,
&**block);
}

ExprProc(ref fn_decl, ref block) => {
self.capture_mode_map.insert(expr.id, ast::CaptureByValue);
self.resolve_function(ClosureRibKind(expr.id, block.id),
Some(&**fn_decl), NoTypeParameters,
&**block);
}
ExprUnboxedFn(capture_clause, _, ref fn_decl, ref block) => {
self.capture_mode_map.insert(expr.id, capture_clause);
self.resolve_function(ClosureRibKind(expr.id, block.id),
Some(&**fn_decl), NoTypeParameters,
&**block);
}

ExprStruct(ref path, _, _) => {
// Resolve the path to the structure it goes to. We don't
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/ty.rs
Expand Up @@ -3922,9 +3922,8 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
ast::ExprTup(..) |
ast::ExprIf(..) |
ast::ExprMatch(..) |
ast::ExprFnBlock(..) |
ast::ExprClosure(..) |
ast::ExprProc(..) |
ast::ExprUnboxedFn(..) |
ast::ExprBlock(..) |
ast::ExprRepeat(..) |
ast::ExprVec(..) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/astconv.rs
Expand Up @@ -1047,7 +1047,7 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
}
ast::TyInfer => {
// TyInfer also appears as the type of arguments or return
// values in a ExprFnBlock, ExprProc, or ExprUnboxedFn, or as
// values in a ExprClosure or ExprProc, or as
// the type of local variables. Both of these cases are
// handled specially and will not descend into this routine.
this.ty_infer(ast_ty.span)
Expand Down
50 changes: 38 additions & 12 deletions src/librustc/middle/typeck/check/closure.rs
Expand Up @@ -26,12 +26,38 @@ use syntax::ast;
use syntax::ast_util;
use util::ppaux::Repr;

pub fn check_unboxed_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
expr: &ast::Expr,
kind: ast::UnboxedClosureKind,
decl: &ast::FnDecl,
body: &ast::Block,
expected: Expectation<'tcx>) {
pub fn check_expr_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
expr: &ast::Expr,
opt_kind: Option<ast::UnboxedClosureKind>,
decl: &ast::FnDecl,
body: &ast::Block,
expected: Expectation<'tcx>) {
match opt_kind {
None => { // old-school boxed closure
let region = astconv::opt_ast_region_to_region(fcx,
fcx.infcx(),
expr.span,
&None);
check_boxed_closure(fcx,
expr,
ty::RegionTraitStore(region, ast::MutMutable),
decl,
body,
expected);
}

Some(kind) => {
check_unboxed_closure(fcx, expr, kind, decl, body, expected)
}
}
}

fn check_unboxed_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
expr: &ast::Expr,
kind: ast::UnboxedClosureKind,
decl: &ast::FnDecl,
body: &ast::Block,
expected: Expectation<'tcx>) {
let expr_def_id = ast_util::local_def(expr.id);

let expected_sig_and_kind = match expected.resolve(fcx) {
Expand Down Expand Up @@ -215,12 +241,12 @@ fn deduce_unboxed_closure_expectations_from_obligations<'a,'tcx>(
}


pub fn check_expr_fn<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
expr: &ast::Expr,
store: ty::TraitStore,
decl: &ast::FnDecl,
body: &ast::Block,
expected: Expectation<'tcx>) {
pub fn check_boxed_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
expr: &ast::Expr,
store: ty::TraitStore,
decl: &ast::FnDecl,
body: &ast::Block,
expected: Expectation<'tcx>) {
let tcx = fcx.ccx.tcx;

// Find the expected input/output types (if any). Substitute
Expand Down
37 changes: 9 additions & 28 deletions src/librustc/middle/typeck/check/mod.rs
Expand Up @@ -2823,9 +2823,7 @@ fn check_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
};
for (i, arg) in args.iter().take(t).enumerate() {
let is_block = match arg.node {
ast::ExprFnBlock(..) |
ast::ExprProc(..) |
ast::ExprUnboxedFn(..) => true,
ast::ExprClosure(..) | ast::ExprProc(..) => true,
_ => false
};

Expand Down Expand Up @@ -4148,33 +4146,16 @@ fn check_expr_with_unifier<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
ast::ExprMatch(ref discrim, ref arms, _) => {
_match::check_match(fcx, expr, &**discrim, arms.as_slice());
}
ast::ExprFnBlock(_, ref decl, ref body) => {
let region = astconv::opt_ast_region_to_region(fcx,
fcx.infcx(),
expr.span,
&None);
closure::check_expr_fn(fcx,
expr,
ty::RegionTraitStore(region, ast::MutMutable),
&**decl,
&**body,
expected);
}
ast::ExprUnboxedFn(_, kind, ref decl, ref body) => {
closure::check_unboxed_closure(fcx,
expr,
kind,
&**decl,
&**body,
expected);
ast::ExprClosure(_, opt_kind, ref decl, ref body) => {
closure::check_expr_closure(fcx, expr, opt_kind, &**decl, &**body, expected);
}
ast::ExprProc(ref decl, ref body) => {
closure::check_expr_fn(fcx,
expr,
ty::UniqTraitStore,
&**decl,
&**body,
expected);
closure::check_boxed_closure(fcx,
expr,
ty::UniqTraitStore,
&**decl,
&**body,
expected);
}
ast::ExprBlock(ref b) => {
check_block_with_expected(fcx, &**b, expected);
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/typeck/check/regionck.rs
Expand Up @@ -742,9 +742,8 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
visit::walk_expr(rcx, expr);
}

ast::ExprFnBlock(_, _, ref body) |
ast::ExprProc(_, ref body) |
ast::ExprUnboxedFn(_, _, _, ref body) => {
ast::ExprClosure(_, _, _, ref body) => {
check_expr_fn_block(rcx, expr, &**body);
}

Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/typeck/check/writeback.rs
Expand Up @@ -122,9 +122,8 @@ impl<'cx, 'tcx, 'v> Visitor<'v> for WritebackCx<'cx, 'tcx> {
MethodCall::expr(e.id));

match e.node {
ast::ExprFnBlock(_, ref decl, _) |
ast::ExprProc(ref decl, _) |
ast::ExprUnboxedFn(_, _, ref decl, _) => {
ast::ExprClosure(_, _, ref decl, _) |
ast::ExprProc(ref decl, _) => {
for input in decl.inputs.iter() {
let _ = self.visit_node_id(ResolvingExpr(e.span),
input.id);
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_back/svh.rs
Expand Up @@ -241,8 +241,7 @@ mod svh_visitor {
SawExprIf,
SawExprWhile,
SawExprMatch,
SawExprFnBlock,
SawExprUnboxedFn,
SawExprClosure,
SawExprProc,
SawExprBlock,
SawExprAssign,
Expand Down Expand Up @@ -274,8 +273,7 @@ mod svh_visitor {
ExprWhile(..) => SawExprWhile,
ExprLoop(_, id) => SawExprLoop(id.map(content)),
ExprMatch(..) => SawExprMatch,
ExprFnBlock(..) => SawExprFnBlock,
ExprUnboxedFn(..) => SawExprUnboxedFn,
ExprClosure(..) => SawExprClosure,
ExprProc(..) => SawExprProc,
ExprBlock(..) => SawExprBlock,
ExprAssign(..) => SawExprAssign,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/save/mod.rs
Expand Up @@ -1345,7 +1345,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
"Expected struct type, but not ty_struct"),
}
},
ast::ExprFnBlock(_, ref decl, ref body) => {
ast::ExprClosure(_, _, ref decl, ref body) => {
if generated_code(body.span) {
return
}
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_trans/trans/base.rs
Expand Up @@ -1385,9 +1385,8 @@ fn has_nested_returns(tcx: &ty::ctxt, id: ast::NodeId) -> bool {
}
Some(ast_map::NodeExpr(e)) => {
match e.node {
ast::ExprFnBlock(_, _, ref blk) |
ast::ExprProc(_, ref blk) |
ast::ExprUnboxedFn(_, _, _, ref blk) => {
ast::ExprClosure(_, _, _, ref blk) |
ast::ExprProc(_, ref blk) => {
let mut explicit = CheckForNestedReturnsVisitor::explicit();
let mut implicit = CheckForNestedReturnsVisitor::implicit();
visit::walk_expr(&mut explicit, e);
Expand Down
8 changes: 3 additions & 5 deletions src/librustc_trans/trans/debuginfo.rs
Expand Up @@ -1232,9 +1232,8 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
}
ast_map::NodeExpr(ref expr) => {
match expr.node {
ast::ExprFnBlock(_, ref fn_decl, ref top_level_block) |
ast::ExprProc(ref fn_decl, ref top_level_block) |
ast::ExprUnboxedFn(_, _, ref fn_decl, ref top_level_block) => {
ast::ExprClosure(_, _, ref fn_decl, ref top_level_block) => {
let name = format!("fn{}", token::gensym("fn"));
let name = token::str_to_ident(name.as_slice());
(name, &**fn_decl,
Expand Down Expand Up @@ -1310,7 +1309,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
file_metadata,
&mut function_name);

// There is no ast_map::Path for ast::ExprFnBlock-type functions. For now,
// There is no ast_map::Path for ast::ExprClosure-type functions. For now,
// just don't put them into a namespace. In the future this could be improved
// somehow (storing a path in the ast_map, or construct a path using the
// enclosing function).
Expand Down Expand Up @@ -3578,9 +3577,8 @@ fn populate_scope_map(cx: &CrateContext,
})
}

ast::ExprFnBlock(_, ref decl, ref block) |
ast::ExprProc(ref decl, ref block) |
ast::ExprUnboxedFn(_, _, ref decl, ref block) => {
ast::ExprClosure(_, _, ref decl, ref block) => {
with_new_scope(cx,
block.span,
scope_stack,
Expand Down

0 comments on commit 3e2929d

Please sign in to comment.