Skip to content
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

switch Option to external iterators #7055

Merged
merged 3 commits into from
Jun 12, 2013
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
3 changes: 2 additions & 1 deletion src/compiletest/procsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

use core::prelude::*;
use core::iterator::IteratorUtil;

use core::os;
use core::run;
Expand Down Expand Up @@ -58,7 +59,7 @@ pub fn run(lib_path: &str,
err_fd: None
});

for input.each |input| {
for input.iter().advance |input| {
proc.input().write_str(*input);
}
let output = proc.finish_with_output();
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/par.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ pub fn any<A:Copy + Owned>(
fn_factory: &fn() -> ~fn(&A) -> bool) -> bool {
let mapped = map_slices(xs, || {
let f = fn_factory();
let result: ~fn(uint, &[A]) -> bool = |_, slice| slice.iter().any(f);
let result: ~fn(uint, &[A]) -> bool = |_, slice| slice.iter().any_(f);
result
});
mapped.iter().any(|&x| x)
mapped.iter().any_(|&x| x)
}
23 changes: 12 additions & 11 deletions src/libextra/treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ impl<T: TotalOrd> Set<T> for TreeSet<T> {
b = y.next();
}
}
return b.each(|&x| f(x)) && y.advance(f);
b.iter().advance(|&x| f(x)) && y.advance(f)
}

/// Visit the values (in-order) representing the intersection
Expand Down Expand Up @@ -485,7 +485,7 @@ impl<T: TotalOrd> Set<T> for TreeSet<T> {
a = x.next();
}
}
return b.each(|&x| f(x)) && y.advance(f);
b.iter().advance(|&x| f(x)) && y.advance(f)
}
}

Expand Down Expand Up @@ -527,14 +527,14 @@ impl<K: TotalOrd, V> TreeNode<K, V> {

fn each<'r, K: TotalOrd, V>(node: &'r Option<~TreeNode<K, V>>,
f: &fn(&'r K, &'r V) -> bool) -> bool {
node.each(|x| each(&x.left, f) && f(&x.key, &x.value) &&
each(&x.right, f))
node.iter().advance(|x| each(&x.left, f) && f(&x.key, &x.value) &&
each(&x.right, f))
}

fn each_reverse<'r, K: TotalOrd, V>(node: &'r Option<~TreeNode<K, V>>,
f: &fn(&'r K, &'r V) -> bool) -> bool {
node.each(|x| each_reverse(&x.right, f) && f(&x.key, &x.value) &&
each_reverse(&x.left, f))
node.iter().advance(|x| each_reverse(&x.right, f) && f(&x.key, &x.value) &&
each_reverse(&x.left, f))
}

fn mutate_values<'r, K: TotalOrd, V>(node: &'r mut Option<~TreeNode<K, V>>,
Expand Down Expand Up @@ -625,7 +625,7 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>,
fn heir_swap<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>,
child: &mut Option<~TreeNode<K, V>>) {
// *could* be done without recursion, but it won't borrow check
for child.each_mut |x| {
for child.mut_iter().advance |x| {
if x.right.is_some() {
heir_swap(node, &mut x.right);
} else {
Expand Down Expand Up @@ -680,18 +680,18 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>,
save.level -= 1;

if right_level > save.level {
for save.right.each_mut |x| { x.level = save.level }
for save.right.mut_iter().advance |x| { x.level = save.level }
}

skew(save);

for save.right.each_mut |right| {
for save.right.mut_iter().advance |right| {
skew(right);
for right.right.each_mut |x| { skew(x) }
for right.right.mut_iter().advance |x| { skew(x) }
}

split(save);
for save.right.each_mut |x| { split(x) }
for save.right.mut_iter().advance |x| { split(x) }
}

return ret;
Expand Down Expand Up @@ -1111,6 +1111,7 @@ mod test_set {

let mut n = 0;
for m.each |x| {
println(fmt!("%?", x));
assert_eq!(*x, n);
n += 1
}
Expand Down
4 changes: 3 additions & 1 deletion src/librust/rust.rc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extern mod rusti;
extern mod rustc;

use core::prelude::*;
use core::iterator::IteratorUtil;

use core::io;
use core::os;
Expand Down Expand Up @@ -242,7 +243,8 @@ pub fn main() {
let args = os_args.tail();

if !args.is_empty() {
for find_cmd(*args.head()).each |command| {
let r = find_cmd(*args.head());
for r.iter().advance |command| {
let result = do_command(command, args.tail());
match result {
Valid(exit_code) => unsafe { exit(exit_code.to_i32()) },
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use middle::ty;
use middle;
use util::ppaux::ty_to_str;

use core::iterator::IteratorUtil;
use core::hash::HashUtil;
use core::hashmap::HashMap;
use core::int;
Expand Down Expand Up @@ -120,7 +121,7 @@ fn encode_region_param(ecx: @EncodeContext,
ebml_w: &mut writer::Encoder,
it: @ast::item) {
let opt_rp = ecx.tcx.region_paramd_items.find(&it.id);
for opt_rp.each |rp| {
for opt_rp.iter().advance |rp| {
ebml_w.start_tag(tag_region_param);
rp.encode(ebml_w);
ebml_w.end_tag();
Expand Down Expand Up @@ -240,7 +241,7 @@ fn encode_type(ecx: @EncodeContext,
fn encode_transformed_self_ty(ecx: @EncodeContext,
ebml_w: &mut writer::Encoder,
opt_typ: Option<ty::t>) {
for opt_typ.each |&typ| {
for opt_typ.iter().advance |&typ| {
ebml_w.start_tag(tag_item_method_transformed_self_ty);
write_type(ecx, ebml_w, typ);
ebml_w.end_tag();
Expand Down Expand Up @@ -956,7 +957,7 @@ fn encode_info_for_item(ecx: @EncodeContext,
ebml_w.writer.write(str::to_bytes(def_to_str(method_def_id)));
ebml_w.end_tag();
}
for opt_trait.each |ast_trait_ref| {
for opt_trait.iter().advance |ast_trait_ref| {
let trait_ref = ty::node_id_to_trait_ref(ecx.tcx, ast_trait_ref.ref_id);
encode_trait_ref(ebml_w, ecx, trait_ref, tag_item_trait_ref);
}
Expand Down
135 changes: 83 additions & 52 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use middle::{ty, typeck, moves};
use middle;
use util::ppaux::ty_to_str;

use core::iterator::IteratorUtil;
use core::at_vec;
use core::uint;
use extra::ebml::reader;
Expand Down Expand Up @@ -826,86 +827,113 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,

debug!("Encoding side tables for id %d", id);

for tcx.def_map.find(&id).each |def| {
do ebml_w.tag(c::tag_table_def) |ebml_w| {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) |ebml_w| {
(*def).encode(ebml_w)
{
let r = tcx.def_map.find(&id);
for r.iter().advance |def| {
do ebml_w.tag(c::tag_table_def) |ebml_w| {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) |ebml_w| {
(*def).encode(ebml_w)
}
}
}
}

for tcx.node_types.find(&(id as uint)).each |&ty| {
do ebml_w.tag(c::tag_table_node_type) |ebml_w| {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) |ebml_w| {
ebml_w.emit_ty(ecx, *ty);
{
let r = tcx.node_types.find(&(id as uint));
for r.iter().advance |&ty| {
do ebml_w.tag(c::tag_table_node_type) |ebml_w| {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) |ebml_w| {
ebml_w.emit_ty(ecx, *ty);
}
}
}
}

for tcx.node_type_substs.find(&id).each |tys| {
do ebml_w.tag(c::tag_table_node_type_subst) |ebml_w| {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) |ebml_w| {
ebml_w.emit_tys(ecx, **tys)
{
let r = tcx.node_type_substs.find(&id);
for r.iter().advance |tys| {
do ebml_w.tag(c::tag_table_node_type_subst) |ebml_w| {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) |ebml_w| {
ebml_w.emit_tys(ecx, **tys)
}
}
}
}

for tcx.freevars.find(&id).each |&fv| {
do ebml_w.tag(c::tag_table_freevars) |ebml_w| {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) |ebml_w| {
do ebml_w.emit_from_vec(**fv) |ebml_w, fv_entry| {
encode_freevar_entry(ebml_w, *fv_entry)
{
let r = tcx.freevars.find(&id);
for r.iter().advance |&fv| {
do ebml_w.tag(c::tag_table_freevars) |ebml_w| {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) |ebml_w| {
do ebml_w.emit_from_vec(**fv) |ebml_w, fv_entry| {
encode_freevar_entry(ebml_w, *fv_entry)
}
}
}
}
}

let lid = ast::def_id { crate: ast::local_crate, node: id };
for tcx.tcache.find(&lid).each |&tpbt| {
do ebml_w.tag(c::tag_table_tcache) |ebml_w| {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) |ebml_w| {
ebml_w.emit_tpbt(ecx, *tpbt);
{
let r = tcx.tcache.find(&lid);
for r.iter().advance |&tpbt| {
do ebml_w.tag(c::tag_table_tcache) |ebml_w| {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) |ebml_w| {
ebml_w.emit_tpbt(ecx, *tpbt);
}
}
}
}

for tcx.ty_param_defs.find(&id).each |&type_param_def| {
do ebml_w.tag(c::tag_table_param_defs) |ebml_w| {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) |ebml_w| {
ebml_w.emit_type_param_def(ecx, type_param_def)
{
let r = tcx.ty_param_defs.find(&id);
for r.iter().advance |&type_param_def| {
do ebml_w.tag(c::tag_table_param_defs) |ebml_w| {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) |ebml_w| {
ebml_w.emit_type_param_def(ecx, type_param_def)
}
}
}
}

for maps.method_map.find(&id).each |&mme| {
do ebml_w.tag(c::tag_table_method_map) |ebml_w| {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) |ebml_w| {
encode_method_map_entry(ecx, ebml_w, *mme)
{
let r = maps.method_map.find(&id);
for r.iter().advance |&mme| {
do ebml_w.tag(c::tag_table_method_map) |ebml_w| {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) |ebml_w| {
encode_method_map_entry(ecx, ebml_w, *mme)
}
}
}
}

for maps.vtable_map.find(&id).each |&dr| {
do ebml_w.tag(c::tag_table_vtable_map) |ebml_w| {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) |ebml_w| {
encode_vtable_res(ecx, ebml_w, *dr);
{
let r = maps.vtable_map.find(&id);
for r.iter().advance |&dr| {
do ebml_w.tag(c::tag_table_vtable_map) |ebml_w| {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) |ebml_w| {
encode_vtable_res(ecx, ebml_w, *dr);
}
}
}
}

for tcx.adjustments.find(&id).each |adj| {
do ebml_w.tag(c::tag_table_adjustments) |ebml_w| {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) |ebml_w| {
(**adj).encode(ebml_w)
{
let r = tcx.adjustments.find(&id);
for r.iter().advance |adj| {
do ebml_w.tag(c::tag_table_adjustments) |ebml_w| {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) |ebml_w| {
(**adj).encode(ebml_w)
}
}
}
}
Expand All @@ -916,12 +944,15 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
}
}

for maps.capture_map.find(&id).each |&cap_vars| {
do ebml_w.tag(c::tag_table_capture_map) |ebml_w| {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) |ebml_w| {
do ebml_w.emit_from_vec(*cap_vars) |ebml_w, cap_var| {
cap_var.encode(ebml_w);
{
let r = maps.capture_map.find(&id);
for r.iter().advance |&cap_vars| {
do ebml_w.tag(c::tag_table_capture_map) |ebml_w| {
ebml_w.id(id);
do ebml_w.tag(c::tag_table_val) |ebml_w| {
do ebml_w.emit_from_vec(*cap_vars) |ebml_w, cap_var| {
cap_var.encode(ebml_w);
}
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/librustc/middle/borrowck/check_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// 4. moves do not affect things loaned out in any way

use core::prelude::*;
use core::iterator::IteratorUtil;

use core::hashmap::HashSet;
use core::uint;
Expand Down Expand Up @@ -581,14 +582,15 @@ impl<'self> CheckLoanCtxt<'self> {
// FIXME(#4384) inadequare if/when we permit `move a.b`

// check for a conflicting loan:
for opt_loan_path(cmt).each |&lp| {
let r = opt_loan_path(cmt);
for r.iter().advance |&lp| {
for self.each_in_scope_restriction(cmt.id, lp) |loan, _| {
// Any restriction prevents moves.
return MoveWhileBorrowed(lp, loan.loan_path, loan.span);
}
}

return MoveOk;
MoveOk
}

pub fn check_call(&mut self,
Expand Down Expand Up @@ -700,9 +702,9 @@ fn check_loans_in_expr<'a>(expr: @ast::expr,
if !this.move_data.is_assignee(expr.id) {
let cmt = this.bccx.cat_expr_unadjusted(expr);
debug!("path cmt=%s", cmt.repr(this.tcx()));
for opt_loan_path(cmt).each |&lp| {
this.check_if_path_is_moved(expr.id, expr.span,
MovedInUse, lp);
let r = opt_loan_path(cmt);
for r.iter().advance |&lp| {
this.check_if_path_is_moved(expr.id, expr.span, MovedInUse, lp);
}
}
}
Expand Down
Loading