Skip to content

Commit 6296dc0

Browse files
committed
auto merge of #8141 : graydon/rust/foreach-in-sketch, r=brson
This is a preliminary implementation of `for ... in ... { ...}` using a transitionary keyword `foreach`. Codesize seems to be a little bit down (10% or less non-opt) and otherwise it seems quite trivial to rewrite lambda-based loops to use it. Once we've rewritten the codebase away from lambda-based `for` we can retarget that word at the same production, snapshot, rewrite the keywords in one go, and expire `foreach`. Feedback welcome. It's a desugaring-based approach which is arguably something we should have been doing for other constructs before. I apologize both for the laziness associated with doing it this way and with any sense that I'm bending rules I put in place previously concerning "never doing desugarings". I put the expansion in `expand.rs` and would be amenable to the argument that the code there needs better factoring / more helpers / to move to a submodule or helper function. It does seem to work at this point, though, and I gather we'd like to get the shift done relatively quickly.
2 parents 8b7e241 + a696f0f commit 6296dc0

25 files changed

+374
-4
lines changed

src/librustc/middle/cfg/construct.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ impl CFGBuilder {
239239
expr_exit
240240
}
241241

242+
ast::expr_for_loop(*) => fail!("non-desugared expr_for_loop"),
243+
242244
ast::expr_loop(ref body, _) => {
243245
//
244246
// [pred]

src/librustc/middle/dataflow.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,8 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> {
583583
copy_bits(new_loop_scope.break_bits, in_out);
584584
}
585585

586+
ast::expr_for_loop(*) => fail!("non-desugared expr_for_loop"),
587+
586588
ast::expr_loop(ref blk, _) => {
587589
//
588590
// (expr) <--+

src/librustc/middle/liveness.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ fn visit_expr(expr: @expr, (this, vt): (@mut IrMaps, vt<@mut IrMaps>)) {
503503
this.add_live_node_for_node(expr.id, ExprNode(expr.span));
504504
visit::visit_expr(expr, (this, vt));
505505
}
506+
expr_for_loop(*) => fail!("non-desugared expr_for_loop"),
506507
expr_binary(_, op, _, _) if ast_util::lazy_binop(op) => {
507508
this.add_live_node_for_node(expr.id, ExprNode(expr.span));
508509
visit::visit_expr(expr, (this, vt));
@@ -1057,6 +1058,8 @@ impl Liveness {
10571058
self.propagate_through_loop(expr, Some(cond), blk, succ)
10581059
}
10591060

1061+
expr_for_loop(*) => fail!("non-desugared expr_for_loop"),
1062+
10601063
// Note that labels have been resolved, so we don't need to look
10611064
// at the label ident
10621065
expr_loop(ref blk, _) => {
@@ -1487,6 +1490,7 @@ fn check_expr(expr: @expr, (this, vt): (@Liveness, vt<@Liveness>)) {
14871490
expr_paren(*) | expr_fn_block(*) | expr_path(*) | expr_self(*) => {
14881491
visit::visit_expr(expr, (this, vt));
14891492
}
1493+
expr_for_loop(*) => fail!("non-desugared expr_for_loop")
14901494
}
14911495
}
14921496

src/librustc/middle/mem_categorization.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,8 @@ impl mem_categorization_ctxt {
435435
ast::expr_inline_asm(*) => {
436436
return self.cat_rvalue_node(expr, expr_ty);
437437
}
438+
439+
ast::expr_for_loop(*) => fail!("non-desugared expr_for_loop")
438440
}
439441
}
440442

src/librustc/middle/moves.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,8 @@ impl VisitContext {
487487
self.consume_block(blk, visitor);
488488
}
489489

490+
expr_for_loop(*) => fail!("non-desugared expr_for_loop"),
491+
490492
expr_unary(_, _, lhs) => {
491493
if !self.use_overloaded_operator(
492494
expr, lhs, [], visitor)

src/librustc/middle/resolve.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5016,6 +5016,8 @@ impl Resolver {
50165016
}
50175017
}
50185018

5019+
expr_for_loop(*) => fail!("non-desugared expr_for_loop"),
5020+
50195021
expr_break(Some(label)) | expr_again(Some(label)) => {
50205022
match self.search_ribs(self.label_ribs, label, expr.span,
50215023
DontAllowCapturingSelf) {

src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,7 @@ pub fn register_fn_fuller(ccx: @mut CrateContext,
22662266
sp: span,
22672267
sym: ~str,
22682268
node_id: ast::NodeId,
2269-
node_type: ty::t,
2269+
_node_type: ty::t,
22702270
cc: lib::llvm::CallConv,
22712271
fn_ty: Type)
22722272
-> ValueRef {

src/librustc/middle/trans/type_use.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,9 @@ pub fn mark_for_expr(cx: &Context, e: &expr) {
401401
expr_match(*) | expr_block(_) | expr_if(*) | expr_while(*) |
402402
expr_break(_) | expr_again(_) | expr_unary(*) | expr_lit(_) |
403403
expr_mac(_) | expr_addr_of(*) | expr_ret(_) | expr_loop(*) |
404-
expr_loop_body(_) | expr_do_body(_) => ()
404+
expr_loop_body(_) | expr_do_body(_) => (),
405+
406+
expr_for_loop(*) => fail!("non-desugared expr_for_loop")
405407
}
406408
}
407409

src/librustc/middle/ty.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3240,6 +3240,8 @@ pub fn expr_kind(tcx: ctxt,
32403240
RvalueStmtExpr
32413241
}
32423242

3243+
ast::expr_for_loop(*) => fail!("non-desugared expr_for_loop"),
3244+
32433245
ast::expr_lit(_) | // Note: lit_str is carved out above
32443246
ast::expr_unary(*) |
32453247
ast::expr_addr_of(*) |

src/librustc/middle/typeck/check/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2559,6 +2559,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
25592559
fcx.write_nil(id);
25602560
}
25612561
}
2562+
ast::expr_for_loop(*) =>
2563+
fail!("non-desugared expr_for_loop"),
25622564
ast::expr_loop(ref body, _) => {
25632565
check_block_no_value(fcx, (body));
25642566
if !may_break(tcx, expr.id, body) {

0 commit comments

Comments
 (0)