Skip to content

AST refactor: make the place in ExprBox an option. #19918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/librustc/middle/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
5 changes: 4 additions & 1 deletion src/librustc/middle/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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) |
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_trans/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
27 changes: 15 additions & 12 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3658,22 +3658,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,
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>),
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
5 changes: 4 additions & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2888,14 +2888,17 @@ 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);
}
}

// 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()
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,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));
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,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) => {
Expand Down