Removing support for the do syntax from libsyntax and librustc.

Fixes #10815.
This commit is contained in:
Scott Lawrence 2014-01-27 19:03:32 -05:00
parent 221670b5bc
commit a6867e259b
17 changed files with 48 additions and 212 deletions

View File

@ -398,7 +398,6 @@ impl CFGBuilder {
} }
ast::ExprAddrOf(_, e) | ast::ExprAddrOf(_, e) |
ast::ExprDoBody(e) |
ast::ExprCast(e, _) | ast::ExprCast(e, _) |
ast::ExprUnary(_, _, e) | ast::ExprUnary(_, _, e) |
ast::ExprParen(e) | ast::ExprParen(e) |

View File

@ -706,7 +706,6 @@ impl<'a, O:DataFlowOperator> PropagationContext<'a, O> {
ast::ExprPath(..) => {} ast::ExprPath(..) => {}
ast::ExprAddrOf(_, e) | ast::ExprAddrOf(_, e) |
ast::ExprDoBody(e) |
ast::ExprCast(e, _) | ast::ExprCast(e, _) |
ast::ExprUnary(_, _, e) | ast::ExprUnary(_, _, e) |
ast::ExprParen(e) | ast::ExprParen(e) |

View File

@ -538,7 +538,7 @@ fn visit_expr(v: &mut LivenessVisitor, expr: &Expr, this: @IrMaps) {
ExprIndex(..) | ExprField(..) | ExprVstore(..) | ExprVec(..) | ExprIndex(..) | ExprField(..) | ExprVstore(..) | ExprVec(..) |
ExprCall(..) | ExprMethodCall(..) | ExprTup(..) | ExprLogLevel | ExprCall(..) | ExprMethodCall(..) | ExprTup(..) | ExprLogLevel |
ExprBinary(..) | ExprAddrOf(..) | ExprBinary(..) | ExprAddrOf(..) |
ExprDoBody(..) | ExprCast(..) | ExprUnary(..) | ExprBreak(_) | ExprCast(..) | ExprUnary(..) | ExprBreak(_) |
ExprAgain(_) | ExprLit(_) | ExprRet(..) | ExprBlock(..) | ExprAgain(_) | ExprLit(_) | ExprRet(..) | ExprBlock(..) |
ExprAssign(..) | ExprAssignOp(..) | ExprMac(..) | ExprAssign(..) | ExprAssignOp(..) | ExprMac(..) |
ExprStruct(..) | ExprRepeat(..) | ExprParen(..) | ExprStruct(..) | ExprRepeat(..) | ExprParen(..) |
@ -1245,7 +1245,6 @@ impl Liveness {
} }
ExprAddrOf(_, e) | ExprAddrOf(_, e) |
ExprDoBody(e) |
ExprCast(e, _) | ExprCast(e, _) |
ExprUnary(_, _, e) | ExprUnary(_, _, e) |
ExprParen(e) => { ExprParen(e) => {
@ -1529,7 +1528,7 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
ExprCall(..) | ExprMethodCall(..) | ExprIf(..) | ExprMatch(..) | ExprCall(..) | ExprMethodCall(..) | ExprIf(..) | ExprMatch(..) |
ExprWhile(..) | ExprLoop(..) | ExprIndex(..) | ExprField(..) | ExprWhile(..) | ExprLoop(..) | ExprIndex(..) | ExprField(..) |
ExprVstore(..) | ExprVec(..) | ExprTup(..) | ExprLogLevel | ExprVstore(..) | ExprVec(..) | ExprTup(..) | ExprLogLevel |
ExprBinary(..) | ExprDoBody(..) | ExprBinary(..) |
ExprCast(..) | ExprUnary(..) | ExprRet(..) | ExprBreak(..) | ExprCast(..) | ExprUnary(..) | ExprRet(..) | ExprBreak(..) |
ExprAgain(..) | ExprLit(_) | ExprBlock(..) | ExprAgain(..) | ExprLit(_) | ExprBlock(..) |
ExprMac(..) | ExprAddrOf(..) | ExprStruct(..) | ExprRepeat(..) | ExprMac(..) | ExprAddrOf(..) | ExprStruct(..) | ExprRepeat(..) |

View File

@ -436,7 +436,7 @@ impl mem_categorization_ctxt {
ast::ExprAddrOf(..) | ast::ExprCall(..) | ast::ExprAddrOf(..) | ast::ExprCall(..) |
ast::ExprAssign(..) | ast::ExprAssignOp(..) | ast::ExprAssign(..) | ast::ExprAssignOp(..) |
ast::ExprFnBlock(..) | ast::ExprProc(..) | ast::ExprRet(..) | ast::ExprFnBlock(..) | ast::ExprProc(..) | ast::ExprRet(..) |
ast::ExprDoBody(..) | ast::ExprUnary(..) | ast::ExprUnary(..) |
ast::ExprMethodCall(..) | ast::ExprCast(..) | ast::ExprVstore(..) | ast::ExprMethodCall(..) | ast::ExprCast(..) | ast::ExprVstore(..) |
ast::ExprVec(..) | ast::ExprTup(..) | ast::ExprIf(..) | ast::ExprVec(..) | ast::ExprTup(..) | ast::ExprIf(..) |
ast::ExprLogLevel | ast::ExprBinary(..) | ast::ExprWhile(..) | ast::ExprLogLevel | ast::ExprBinary(..) | ast::ExprWhile(..) |

View File

@ -570,10 +570,6 @@ impl VisitContext {
self.consume_expr(count); self.consume_expr(count);
} }
ExprDoBody(base) => {
self.use_expr(base, comp_mode);
}
ExprFnBlock(ref decl, body) | ExprFnBlock(ref decl, body) |
ExprProc(ref decl, body) => { ExprProc(ref decl, body) => {
for a in decl.inputs.iter() { for a in decl.inputs.iter() {

View File

@ -2655,20 +2655,6 @@ fn populate_scope_map(cx: &CrateContext,
}) })
} }
ast::ExprDoBody(inner_exp) => {
let inner_expr_is_expr_fn_block = match *inner_exp {
ast::Expr { node: ast::ExprFnBlock(..), .. } => true,
_ => false
};
if !inner_expr_is_expr_fn_block {
cx.sess.span_bug(inner_exp.span, "debuginfo: Inner expression was expected \
to be an ast::expr_fn_block.");
}
walk_expr(cx, inner_exp, scope_stack, scope_map);
}
ast::ExprCall(fn_exp, ref args, _) => { ast::ExprCall(fn_exp, ref args, _) => {
walk_expr(cx, fn_exp, scope_stack, scope_map); walk_expr(cx, fn_exp, scope_stack, scope_map);

View File

@ -867,9 +867,6 @@ fn trans_rvalue_dps_unadjusted<'a>(bcx: &'a Block<'a>,
closure::trans_expr_fn(bcx, sigil, decl, body, closure::trans_expr_fn(bcx, sigil, decl, body,
expr.id, expr.id, dest) expr.id, expr.id, dest)
} }
ast::ExprDoBody(blk) => {
trans_into(bcx, blk, dest)
}
ast::ExprCall(f, ref args, _) => { ast::ExprCall(f, ref args, _) => {
callee::trans_call(bcx, expr, f, callee::trans_call(bcx, expr, f,
callee::ArgExprs(*args), expr.id, dest) callee::ArgExprs(*args), expr.id, dest)

View File

@ -3166,7 +3166,6 @@ pub fn expr_kind(tcx: ctxt,
ast::ExprMatch(..) | ast::ExprMatch(..) |
ast::ExprFnBlock(..) | ast::ExprFnBlock(..) |
ast::ExprProc(..) | ast::ExprProc(..) |
ast::ExprDoBody(..) |
ast::ExprBlock(..) | ast::ExprBlock(..) |
ast::ExprRepeat(..) | ast::ExprRepeat(..) |
ast::ExprVstore(_, ast::ExprVstoreSlice) | ast::ExprVstore(_, ast::ExprVstoreSlice) |

View File

@ -1640,8 +1640,6 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
} else { } else {
let suffix = match sugar { let suffix = match sugar {
ast::NoSugar => "", ast::NoSugar => "",
ast::DoSugar => " (including the closure passed by \
the `do` keyword)",
ast::ForSugar => " (including the closure passed by \ ast::ForSugar => " (including the closure passed by \
the `for` keyword)" the `for` keyword)"
}; };
@ -1690,8 +1688,7 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
for (i, arg) in args.iter().take(t).enumerate() { for (i, arg) in args.iter().take(t).enumerate() {
let is_block = match arg.node { let is_block = match arg.node {
ast::ExprFnBlock(..) | ast::ExprFnBlock(..) |
ast::ExprProc(..) | ast::ExprProc(..) => true,
ast::ExprDoBody(..) => true,
_ => false _ => false
}; };
@ -2928,44 +2925,6 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
Vanilla, Vanilla,
expected); expected);
} }
ast::ExprDoBody(b) => {
let expected_sty = unpack_expected(fcx,
expected,
|x| Some((*x).clone()));
let inner_ty = match expected_sty {
Some(ty::ty_closure(ref closure_ty))
if closure_ty.sigil == ast::OwnedSigil => {
expected.unwrap()
}
_ => match expected {
Some(expected_t) => {
fcx.type_error_message(expr.span, |actual| {
format!("last argument in `do` call \
has non-procedure type: {}",
actual)
}, expected_t, None);
let err_ty = ty::mk_err();
fcx.write_ty(id, err_ty);
err_ty
}
None => {
fcx.tcx().sess.impossible_case(
expr.span,
"do body must have expected type")
}
}
};
match b.node {
ast::ExprFnBlock(decl, body) => {
check_expr_fn(fcx, b, None,
decl, body, DoBlock, Some(inner_ty));
demand::suptype(fcx, b.span, inner_ty, fcx.expr_ty(b));
}
// argh
_ => fail!("expected fn ty")
}
fcx.write_ty(expr.id, fcx.node_ty(b.id));
}
ast::ExprBlock(b) => { ast::ExprBlock(b) => {
check_block_with_expected(fcx, b, expected); check_block_with_expected(fcx, b, expected);
fcx.write_ty(id, fcx.node_ty(b.id)); fcx.write_ty(id, fcx.node_ty(b.id));

View File

@ -1045,7 +1045,6 @@ pub mod guarantor {
ast::ExprMatch(..) | ast::ExprMatch(..) |
ast::ExprFnBlock(..) | ast::ExprFnBlock(..) |
ast::ExprProc(..) | ast::ExprProc(..) |
ast::ExprDoBody(..) |
ast::ExprBlock(..) | ast::ExprBlock(..) |
ast::ExprRepeat(..) | ast::ExprRepeat(..) |
ast::ExprVec(..) => { ast::ExprVec(..) => {

View File

@ -539,7 +539,6 @@ impl Expr {
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum CallSugar { pub enum CallSugar {
NoSugar, NoSugar,
DoSugar,
ForSugar ForSugar
} }
@ -566,7 +565,6 @@ pub enum Expr_ {
ExprMatch(@Expr, ~[Arm]), ExprMatch(@Expr, ~[Arm]),
ExprFnBlock(P<FnDecl>, P<Block>), ExprFnBlock(P<FnDecl>, P<Block>),
ExprProc(P<FnDecl>, P<Block>), ExprProc(P<FnDecl>, P<Block>),
ExprDoBody(@Expr),
ExprBlock(P<Block>), ExprBlock(P<Block>),
ExprAssign(@Expr, @Expr), ExprAssign(@Expr, @Expr),

View File

@ -752,7 +752,6 @@ pub fn noop_fold_expr<T: Folder>(e: @Expr, folder: &mut T) -> @Expr {
ExprUnary(callee_id, binop, ohs) => { ExprUnary(callee_id, binop, ohs) => {
ExprUnary(folder.new_id(callee_id), binop, folder.fold_expr(ohs)) ExprUnary(folder.new_id(callee_id), binop, folder.fold_expr(ohs))
} }
ExprDoBody(f) => ExprDoBody(folder.fold_expr(f)),
ExprLit(_) => e.node.clone(), ExprLit(_) => e.node.clone(),
ExprCast(expr, ty) => { ExprCast(expr, ty) => {
ExprCast(folder.fold_expr(expr), folder.fold_ty(ty)) ExprCast(folder.fold_expr(expr), folder.fold_ty(ty))

View File

@ -29,9 +29,7 @@ pub fn expr_requires_semi_to_be_stmt(e: @ast::Expr) -> bool {
| ast::ExprWhile(..) | ast::ExprWhile(..)
| ast::ExprLoop(..) | ast::ExprLoop(..)
| ast::ExprForLoop(..) | ast::ExprForLoop(..)
| ast::ExprCall(_, _, ast::DoSugar)
| ast::ExprCall(_, _, ast::ForSugar) | ast::ExprCall(_, _, ast::ForSugar)
| ast::ExprMethodCall(_, _, _, _, ast::DoSugar)
| ast::ExprMethodCall(_, _, _, _, ast::ForSugar) => false, | ast::ExprMethodCall(_, _, _, _, ast::ForSugar) => false,
_ => true _ => true
} }

View File

@ -13,7 +13,7 @@
use abi; use abi;
use abi::AbiSet; use abi::AbiSet;
use ast::{Sigil, BorrowedSigil, ManagedSigil, OwnedSigil}; use ast::{Sigil, BorrowedSigil, ManagedSigil, OwnedSigil};
use ast::{CallSugar, NoSugar, DoSugar}; use ast::{CallSugar, NoSugar};
use ast::{BareFnTy, ClosureTy}; use ast::{BareFnTy, ClosureTy};
use ast::{RegionTyParamBound, TraitTyParamBound}; use ast::{RegionTyParamBound, TraitTyParamBound};
use ast::{Provided, Public, Purity}; use ast::{Provided, Public, Purity};
@ -24,7 +24,7 @@ use ast::{Crate, CrateConfig, Decl, DeclItem};
use ast::{DeclLocal, DefaultBlock, UnDeref, BiDiv, EMPTY_CTXT, EnumDef, ExplicitSelf}; use ast::{DeclLocal, DefaultBlock, UnDeref, BiDiv, EMPTY_CTXT, EnumDef, ExplicitSelf};
use ast::{Expr, Expr_, ExprAddrOf, ExprMatch, ExprAgain}; use ast::{Expr, Expr_, ExprAddrOf, ExprMatch, ExprAgain};
use ast::{ExprAssign, ExprAssignOp, ExprBinary, ExprBlock, ExprBox}; use ast::{ExprAssign, ExprAssignOp, ExprBinary, ExprBlock, ExprBox};
use ast::{ExprBreak, ExprCall, ExprCast, ExprDoBody}; use ast::{ExprBreak, ExprCall, ExprCast};
use ast::{ExprField, ExprFnBlock, ExprIf, ExprIndex}; use ast::{ExprField, ExprFnBlock, ExprIf, ExprIndex};
use ast::{ExprLit, ExprLogLevel, ExprLoop, ExprMac}; use ast::{ExprLit, ExprLogLevel, ExprLoop, ExprMac};
use ast::{ExprMethodCall, ExprParen, ExprPath, ExprProc}; use ast::{ExprMethodCall, ExprParen, ExprPath, ExprProc};
@ -1796,9 +1796,6 @@ impl Parser {
return self.parse_if_expr(); return self.parse_if_expr();
} else if self.eat_keyword(keywords::For) { } else if self.eat_keyword(keywords::For) {
return self.parse_for_expr(None); return self.parse_for_expr(None);
} else if self.eat_keyword(keywords::Do) {
return self.parse_sugary_call_expr(lo, ~"do", DoSugar,
ExprDoBody);
} else if self.eat_keyword(keywords::While) { } else if self.eat_keyword(keywords::While) {
return self.parse_while_expr(); return self.parse_while_expr();
} else if Parser::token_is_lifetime(&self.token) { } else if Parser::token_is_lifetime(&self.token) {
@ -2541,75 +2538,6 @@ impl Parser {
self.mk_expr(lo, hi, ExprForLoop(pat, expr, loop_block, opt_ident)) self.mk_expr(lo, hi, ExprForLoop(pat, expr, loop_block, opt_ident))
} }
// parse a 'do'.
// the 'do' expression parses as a call, but looks like
// a function call followed by a closure expression.
pub fn parse_sugary_call_expr(&mut self,
lo: BytePos,
keyword: ~str,
sugar: CallSugar,
ctor: |v: @Expr| -> Expr_)
-> @Expr {
// Parse the callee `foo` in
// do foo || {
// do foo.bar || {
// etc, or the portion of the call expression before the lambda in
// do foo() || {
// or
// do foo.bar(a) || {
// Turn on the restriction to stop at | or || so we can parse
// them as the lambda arguments
let e = self.parse_expr_res(RESTRICT_NO_BAR_OR_DOUBLEBAR_OP);
match e.node {
ExprCall(f, ref args, NoSugar) => {
let block = self.parse_lambda_block_expr();
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
ctor(block));
let args = vec::append_one((*args).clone(), last_arg);
self.mk_expr(lo, block.span.hi, ExprCall(f, args, sugar))
}
ExprMethodCall(_, i, ref tps, ref args, NoSugar) => {
let block = self.parse_lambda_block_expr();
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
ctor(block));
let args = vec::append_one((*args).clone(), last_arg);
let method_call = self.mk_method_call(i,
(*tps).clone(),
args,
sugar);
self.mk_expr(lo, block.span.hi, method_call)
}
ExprField(f, i, ref tps) => {
let block = self.parse_lambda_block_expr();
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
ctor(block));
let method_call = self.mk_method_call(i,
(*tps).clone(),
~[f, last_arg],
sugar);
self.mk_expr(lo, block.span.hi, method_call)
}
ExprPath(..) | ExprCall(..) | ExprMethodCall(..) |
ExprParen(..) => {
let block = self.parse_lambda_block_expr();
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
ctor(block));
let call = self.mk_call(e, ~[last_arg], sugar);
self.mk_expr(lo, last_arg.span.hi, call)
}
_ => {
// There may be other types of expressions that can
// represent the callee in `do` expressions
// but they aren't represented by tests
debug!("sugary call on {:?}", e.node);
self.span_fatal(
e.span,
format!("`{}` must be followed by a block call", keyword));
}
}
}
pub fn parse_while_expr(&mut self) -> @Expr { pub fn parse_while_expr(&mut self) -> @Expr {
let lo = self.last_span.lo; let lo = self.last_span.lo;
let cond = self.parse_expr(); let cond = self.parse_expr();

View File

@ -433,51 +433,50 @@ declare_special_idents_and_keywords! {
(14, As, "as"); (14, As, "as");
(15, Break, "break"); (15, Break, "break");
(16, Const, "const"); (16, Const, "const");
(17, Do, "do"); (17, Else, "else");
(18, Else, "else"); (18, Enum, "enum");
(19, Enum, "enum"); (19, Extern, "extern");
(20, Extern, "extern"); (20, False, "false");
(21, False, "false"); (21, Fn, "fn");
(22, Fn, "fn"); (22, For, "for");
(23, For, "for"); (23, If, "if");
(24, If, "if"); (24, Impl, "impl");
(25, Impl, "impl"); (25, In, "in");
(26, In, "in"); (26, Let, "let");
(27, Let, "let"); (27, __LogLevel, "__log_level");
(28, __LogLevel, "__log_level"); (28, Loop, "loop");
(29, Loop, "loop"); (29, Match, "match");
(30, Match, "match"); (30, Mod, "mod");
(31, Mod, "mod"); (31, Mut, "mut");
(32, Mut, "mut"); (32, Once, "once");
(33, Once, "once"); (33, Priv, "priv");
(34, Priv, "priv"); (34, Pub, "pub");
(35, Pub, "pub"); (35, Ref, "ref");
(36, Ref, "ref"); (36, Return, "return");
(37, Return, "return");
// Static and Self are also special idents (prefill de-dupes) // Static and Self are also special idents (prefill de-dupes)
(super::STATIC_KEYWORD_NAME, Static, "static"); (super::STATIC_KEYWORD_NAME, Static, "static");
(super::SELF_KEYWORD_NAME, Self, "self"); (super::SELF_KEYWORD_NAME, Self, "self");
(38, Struct, "struct"); (37, Struct, "struct");
(39, Super, "super"); (38, Super, "super");
(40, True, "true"); (39, True, "true");
(41, Trait, "trait"); (40, Trait, "trait");
(42, Type, "type"); (41, Type, "type");
(43, Unsafe, "unsafe"); (42, Unsafe, "unsafe");
(44, Use, "use"); (43, Use, "use");
(45, While, "while"); (44, While, "while");
(46, Continue, "continue"); (45, Continue, "continue");
(47, Proc, "proc"); (46, Proc, "proc");
(48, Box, "box"); (47, Box, "box");
'reserved: 'reserved:
(49, Alignof, "alignof"); (48, Alignof, "alignof");
(50, Be, "be"); (49, Be, "be");
(51, Offsetof, "offsetof"); (50, Offsetof, "offsetof");
(52, Pure, "pure"); (51, Pure, "pure");
(53, Sizeof, "sizeof"); (52, Sizeof, "sizeof");
(54, Typeof, "typeof"); (53, Typeof, "typeof");
(55, Unsized, "unsized"); (54, Unsized, "unsized");
(56, Yield, "yield"); (55, Yield, "yield");
} }
} }

View File

@ -1088,10 +1088,6 @@ pub fn print_call_pre(s: &mut State,
base_args: &mut ~[@ast::Expr]) base_args: &mut ~[@ast::Expr])
-> Option<@ast::Expr> { -> Option<@ast::Expr> {
match sugar { match sugar {
ast::DoSugar => {
head(s, "do");
Some(base_args.pop().unwrap())
}
ast::ForSugar => { ast::ForSugar => {
head(s, "for"); head(s, "for");
Some(base_args.pop().unwrap()) Some(base_args.pop().unwrap())
@ -1111,19 +1107,8 @@ pub fn print_call_post(s: &mut State,
} }
if sugar != ast::NoSugar { if sugar != ast::NoSugar {
nbsp(s); nbsp(s);
match blk.unwrap().node { // not sure if this can happen
// need to handle closures specifically print_expr(s, blk.unwrap());
ast::ExprDoBody(e) => {
end(s); // we close our head box; closure
// will create it's own.
print_expr(s, e);
end(s); // close outer box, as closures don't
}
_ => {
// not sure if this can happen.
print_expr(s, blk.unwrap());
}
}
} }
} }
@ -1405,9 +1390,6 @@ pub fn print_expr(s: &mut State, expr: &ast::Expr) {
// empty box to satisfy the close. // empty box to satisfy the close.
ibox(s, 0); ibox(s, 0);
} }
ast::ExprDoBody(body) => {
print_expr(s, body);
}
ast::ExprBlock(blk) => { ast::ExprBlock(blk) => {
// containing cbox, will be closed by print-block at } // containing cbox, will be closed by print-block at }
cbox(s, indent_unit); cbox(s, indent_unit);

View File

@ -665,8 +665,7 @@ pub fn walk_expr<E: Clone, V: Visitor<E>>(visitor: &mut V, expression: &Expr, en
visitor.visit_expr(right_expression, env.clone()) visitor.visit_expr(right_expression, env.clone())
} }
ExprAddrOf(_, subexpression) | ExprAddrOf(_, subexpression) |
ExprUnary(_, _, subexpression) | ExprUnary(_, _, subexpression) => {
ExprDoBody(subexpression) => {
visitor.visit_expr(subexpression, env.clone()) visitor.visit_expr(subexpression, env.clone())
} }
ExprLit(_) => {} ExprLit(_) => {}