rollup merge of #19918: pnkfelix/ast-refactor-make-place-in-exprbox-an-option

This is to allow us to migrate away from UnUniq in a followup commit,
and thus unify the code paths related to all forms of `box`.
This commit is contained in:
Alex Crichton 2014-12-17 08:35:40 -08:00
commit a02885e167
11 changed files with 35 additions and 25 deletions

View File

@ -462,15 +462,13 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
self.straightline(expr, pred, [r, l].iter().map(|&e| &**e))
}
ast::ExprBox(Some(ref l), ref r) |
ast::ExprIndex(ref l, ref r) |
ast::ExprBinary(_, ref l, ref r) => { // NB: && and || handled earlier
self.straightline(expr, pred, [l, r].iter().map(|&e| &**e))
}
ast::ExprBox(ref p, ref e) => {
self.straightline(expr, pred, [p, e].iter().map(|&e| &**e))
}
ast::ExprBox(None, ref e) |
ast::ExprAddrOf(_, ref e) |
ast::ExprCast(ref e, _) |
ast::ExprUnary(_, ref e) |

View File

@ -631,7 +631,10 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
}
ast::ExprBox(ref place, ref base) => {
self.consume_expr(&**place);
match *place {
Some(ref place) => self.consume_expr(&**place),
None => {}
}
self.consume_expr(&**base);
}

View File

@ -1199,7 +1199,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
ast::ExprIndex(ref l, ref r) |
ast::ExprBinary(_, ref l, ref r) |
ast::ExprBox(ref l, ref r) => {
ast::ExprBox(Some(ref l), ref r) => {
let r_succ = self.propagate_through_expr(&**r, succ);
self.propagate_through_expr(&**l, r_succ)
}
@ -1210,6 +1210,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
self.propagate_through_expr(&**e1, succ)
}
ast::ExprBox(None, ref e) |
ast::ExprAddrOf(_, ref e) |
ast::ExprCast(ref e, _) |
ast::ExprUnary(_, ref e) |

View File

@ -4320,12 +4320,13 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
ast::ExprLit(_) | // Note: LitStr is carved out above
ast::ExprUnary(..) |
ast::ExprBox(None, _) |
ast::ExprAddrOf(..) |
ast::ExprBinary(..) => {
RvalueDatumExpr
}
ast::ExprBox(ref place, _) => {
ast::ExprBox(Some(ref place), _) => {
// Special case `Box<T>` for now:
let definition = match tcx.def_map.borrow().get(&place.id) {
Some(&def) => def,

View File

@ -3472,7 +3472,8 @@ fn populate_scope_map(cx: &CrateContext,
walk_expr(cx, &**sub_exp, scope_stack, scope_map),
ast::ExprBox(ref place, ref sub_expr) => {
walk_expr(cx, &**place, scope_stack, scope_map);
place.as_ref().map(
|e| walk_expr(cx, &**e, scope_stack, scope_map));
walk_expr(cx, &**sub_expr, scope_stack, scope_map);
}

View File

@ -3662,22 +3662,25 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
let tcx = fcx.ccx.tcx;
let id = expr.id;
match expr.node {
ast::ExprBox(ref place, ref subexpr) => {
check_expr(fcx, &**place);
ast::ExprBox(ref opt_place, ref subexpr) => {
opt_place.as_ref().map(|place|check_expr(fcx, &**place));
check_expr(fcx, &**subexpr);
let mut checked = false;
if let ast::ExprPath(ref path) = place.node {
// FIXME(pcwalton): For now we hardcode the two permissible
// places: the exchange heap and the managed heap.
let definition = lookup_def(fcx, path.span, place.id);
let def_id = definition.def_id();
let referent_ty = fcx.expr_ty(&**subexpr);
if tcx.lang_items.exchange_heap() == Some(def_id) {
fcx.write_ty(id, ty::mk_uniq(tcx, referent_ty));
checked = true
opt_place.as_ref().map(|place| match place.node {
ast::ExprPath(ref path) => {
// FIXME(pcwalton): For now we hardcode the two permissible
// places: the exchange heap and the managed heap.
let definition = lookup_def(fcx, path.span, place.id);
let def_id = definition.def_id();
let referent_ty = fcx.expr_ty(&**subexpr);
if tcx.lang_items.exchange_heap() == Some(def_id) {
fcx.write_ty(id, ty::mk_uniq(tcx, referent_ty));
checked = true
}
}
}
_ => {}
});
if !checked {
span_err!(tcx.sess, expr.span, E0066,

View File

@ -696,7 +696,7 @@ pub struct Expr {
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum Expr_ {
/// First expr is the place; second expr is the value.
ExprBox(P<Expr>, P<Expr>),
ExprBox(Option<P<Expr>>, P<Expr>),
ExprVec(Vec<P<Expr>>),
ExprCall(P<Expr>, Vec<P<Expr>>),
ExprMethodCall(SpannedIdent, Vec<P<Ty>>, Vec<P<Expr>>),

View File

@ -1282,7 +1282,7 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
id: folder.new_id(id),
node: match node {
ExprBox(p, e) => {
ExprBox(folder.fold_expr(p), folder.fold_expr(e))
ExprBox(p.map(|e|folder.fold_expr(e)), folder.fold_expr(e))
}
ExprVec(exprs) => {
ExprVec(exprs.move_map(|x| folder.fold_expr(x)))

View File

@ -2888,7 +2888,7 @@ impl<'a> Parser<'a> {
}
let subexpression = self.parse_prefix_expr();
hi = subexpression.span.hi;
ex = ExprBox(place, subexpression);
ex = ExprBox(Some(place), subexpression);
return self.mk_expr(lo, hi, ex);
}
}
@ -2896,6 +2896,9 @@ impl<'a> Parser<'a> {
// Otherwise, we use the unique pointer default.
let subexpression = self.parse_prefix_expr();
hi = subexpression.span.hi;
// FIXME (pnkfelix): After working out kinks with box
// desugaring, should be `ExprBox(None, subexpression)`
// instead.
ex = self.mk_unary(UnUniq, subexpression);
}
_ => return self.parse_dot_or_call_expr()

View File

@ -1501,7 +1501,7 @@ impl<'a> State<'a> {
ast::ExprBox(ref p, ref e) => {
try!(word(&mut self.s, "box"));
try!(word(&mut self.s, "("));
try!(self.print_expr(&**p));
try!(p.as_ref().map_or(Ok(()), |e|self.print_expr(&**e)));
try!(self.word_space(")"));
try!(self.print_expr(&**e));
}

View File

@ -742,7 +742,7 @@ pub fn walk_mac<'v, V: Visitor<'v>>(_: &mut V, _: &'v Mac) {
pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
match expression.node {
ExprBox(ref place, ref subexpression) => {
visitor.visit_expr(&**place);
place.as_ref().map(|e|visitor.visit_expr(&**e));
visitor.visit_expr(&**subexpression)
}
ExprVec(ref subexpressions) => {