Skip to content

Commit

Permalink
option: rewrite the API to use composition
Browse files Browse the repository at this point in the history
  • Loading branch information
thestinger committed Oct 9, 2013
1 parent f647ccc commit 6a90e80
Show file tree
Hide file tree
Showing 80 changed files with 244 additions and 277 deletions.
10 changes: 5 additions & 5 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ pub fn parse_config(args: ~[~str]) -> config {
compile_lib_path: matches.opt_str("compile-lib-path").unwrap(),
run_lib_path: matches.opt_str("run-lib-path").unwrap(),
rustc_path: opt_path(matches, "rustc-path"),
clang_path: matches.opt_str("clang-path").map_move(|s| Path(s)),
llvm_bin_path: matches.opt_str("llvm-bin-path").map_move(|s| Path(s)),
clang_path: matches.opt_str("clang-path").map(|s| Path(s)),
llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| Path(s)),
src_base: opt_path(matches, "src-base"),
build_base: opt_path(matches, "build-base"),
aux_base: opt_path(matches, "aux-base"),
Expand All @@ -123,10 +123,10 @@ pub fn parse_config(args: ~[~str]) -> config {
} else {
None
},
logfile: matches.opt_str("logfile").map_move(|s| Path(s)),
save_metrics: matches.opt_str("save-metrics").map_move(|s| Path(s)),
logfile: matches.opt_str("logfile").map(|s| Path(s)),
save_metrics: matches.opt_str("save-metrics").map(|s| Path(s)),
ratchet_metrics:
matches.opt_str("ratchet-metrics").map_move(|s| Path(s)),
matches.opt_str("ratchet-metrics").map(|s| Path(s)),
ratchet_noise_percent:
matches.opt_str("ratchet-noise-percent").and_then(|s| from_str::<f64>(s)),
runtool: matches.opt_str("runtool"),
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<T: Send> GenericPort<T> for SyncPort<T> {
}

fn try_recv(&self) -> Option<T> {
do self.duplex_stream.try_recv().map_move |val| {
do self.duplex_stream.try_recv().map |val| {
self.duplex_stream.try_send(());
val
}
Expand Down
33 changes: 18 additions & 15 deletions src/libextra/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl<T> DList<T> {
/// Remove the first Node and return it, or None if the list is empty
#[inline]
fn pop_front_node(&mut self) -> Option<~Node<T>> {
do self.list_head.take().map_move |mut front_node| {
do self.list_head.take().map |mut front_node| {
self.length -= 1;
match front_node.next.take() {
Some(node) => self.list_head = link_with_prev(node, Rawlink::none()),
Expand All @@ -191,7 +191,7 @@ impl<T> DList<T> {
/// Remove the last Node and return it, or None if the list is empty
#[inline]
fn pop_back_node(&mut self) -> Option<~Node<T>> {
do self.list_tail.resolve().map_move_default(None) |tail| {
do self.list_tail.resolve().map_default(None) |tail| {
self.length -= 1;
self.list_tail = tail.prev;
match tail.prev.resolve() {
Expand All @@ -206,25 +206,27 @@ impl<T> Deque<T> for DList<T> {
/// Provide a reference to the front element, or None if the list is empty
#[inline]
fn front<'a>(&'a self) -> Option<&'a T> {
self.list_head.map(|head| &head.value)
self.list_head.as_ref().map(|head| &head.value)
}

/// Provide a mutable reference to the front element, or None if the list is empty
#[inline]
fn front_mut<'a>(&'a mut self) -> Option<&'a mut T> {
self.list_head.map_mut(|head| &mut head.value)
self.list_head.as_mut().map(|head| &mut head.value)
}

/// Provide a reference to the back element, or None if the list is empty
#[inline]
fn back<'a>(&'a self) -> Option<&'a T> {
self.list_tail.resolve_immut().map(|tail| &tail.value)
let tmp = self.list_tail.resolve_immut(); // FIXME: #3511: shouldn't need variable
tmp.as_ref().map(|tail| &tail.value)
}

/// Provide a mutable reference to the back element, or None if the list is empty
#[inline]
fn back_mut<'a>(&'a mut self) -> Option<&'a mut T> {
self.list_tail.resolve().map_mut(|tail| &mut tail.value)
let mut tmp = self.list_tail.resolve(); // FIXME: #3511: shouldn't need variable
tmp.as_mut().map(|tail| &mut tail.value)
}

/// Add an element first in the list
Expand All @@ -238,7 +240,7 @@ impl<T> Deque<T> for DList<T> {
///
/// O(1)
fn pop_front(&mut self) -> Option<T> {
self.pop_front_node().map_move(|~Node{value, _}| value)
self.pop_front_node().map(|~Node{value, _}| value)
}

/// Add an element last in the list
Expand All @@ -252,7 +254,7 @@ impl<T> Deque<T> for DList<T> {
///
/// O(1)
fn pop_back(&mut self) -> Option<T> {
self.pop_back_node().map_move(|~Node{value, _}| value)
self.pop_back_node().map(|~Node{value, _}| value)
}
}

Expand All @@ -268,7 +270,7 @@ impl<T> DList<T> {
/// If the list is empty, do nothing.
#[inline]
pub fn rotate_forward(&mut self) {
do self.pop_back_node().map_move |tail| {
do self.pop_back_node().map |tail| {
self.push_front_node(tail)
};
}
Expand All @@ -278,7 +280,7 @@ impl<T> DList<T> {
/// If the list is empty, do nothing.
#[inline]
pub fn rotate_backward(&mut self) {
do self.pop_front_node().map_move |head| {
do self.pop_front_node().map |head| {
self.push_back_node(head)
};
}
Expand Down Expand Up @@ -442,7 +444,7 @@ impl<'self, A> Iterator<&'self A> for DListIterator<'self, A> {
if self.nelem == 0 {
return None;
}
do self.head.map |head| {
do self.head.as_ref().map |head| {
self.nelem -= 1;
self.head = &head.next;
&head.value
Expand All @@ -461,7 +463,8 @@ impl<'self, A> DoubleEndedIterator<&'self A> for DListIterator<'self, A> {
if self.nelem == 0 {
return None;
}
do self.tail.resolve().map_move |prev| {
let tmp = self.tail.resolve_immut(); // FIXME: #3511: shouldn't need variable
do tmp.as_ref().map |prev| {
self.nelem -= 1;
self.tail = prev.prev;
&prev.value
Expand All @@ -477,7 +480,7 @@ impl<'self, A> Iterator<&'self mut A> for MutDListIterator<'self, A> {
if self.nelem == 0 {
return None;
}
do self.head.resolve().map_move |next| {
do self.head.resolve().map |next| {
self.nelem -= 1;
self.head = match next.next {
Some(ref mut node) => Rawlink::some(&mut **node),
Expand All @@ -499,7 +502,7 @@ impl<'self, A> DoubleEndedIterator<&'self mut A> for MutDListIterator<'self, A>
if self.nelem == 0 {
return None;
}
do self.tail.resolve().map_move |prev| {
do self.tail.resolve().map |prev| {
self.nelem -= 1;
self.tail = prev.prev;
&mut prev.value
Expand Down Expand Up @@ -554,7 +557,7 @@ impl<'self, A> ListInsertion<A> for MutDListIterator<'self, A> {
if self.nelem == 0 {
return None
}
self.head.resolve().map_move(|head| &mut head.value)
self.head.resolve().map(|head| &mut head.value)
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/libextra/fileinput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,7 @@ mod test {
|i| format!("tmp/lib-fileinput-test-next-file-{}.tmp", i)),true);

for (i, filename) in filenames.iter().enumerate() {
let contents =
vec::from_fn(3, |j| format!("{} {}", i, j + 1));
let contents = vec::from_fn(3, |j| format!("{} {}", i, j + 1));
make_file(filename.get_ref(), contents);
}

Expand Down
6 changes: 3 additions & 3 deletions src/libextra/num/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ impl BigUint {
#[inline]
pub fn new(v: ~[BigDigit]) -> BigUint {
// omit trailing zeros
let new_len = v.iter().rposition(|n| *n != 0).map_move_default(0, |p| p + 1);
let new_len = v.iter().rposition(|n| *n != 0).map_default(0, |p| p + 1);

if new_len == v.len() { return BigUint { data: v }; }
let mut v = v;
Expand Down Expand Up @@ -1417,7 +1417,7 @@ impl BigInt {
start = 1;
}
return BigUint::parse_bytes(buf.slice(start, buf.len()), radix)
.map_move(|bu| BigInt::from_biguint(sign, bu));
.map(|bu| BigInt::from_biguint(sign, bu));
}
/// Converts this `BigInt` into a `BigUint`, if it's not negative.
Expand Down Expand Up @@ -2507,7 +2507,7 @@ mod bigint_tests {
#[test]
fn test_from_str_radix() {
fn check(s: &str, ans: Option<int>) {
let ans = ans.map_move(|n| {
let ans = ans.map(|n| {
let x: BigInt = FromPrimitive::from_int(n).unwrap();
x
});
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/smallintmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl<V> SmallIntMap<V> {
{
let values = replace(&mut self.v, ~[]);
values.move_iter().enumerate().filter_map(|(i, v)| {
v.map_move(|v| (i, v))
v.map(|v| (i, v))
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl Terminal {
let inf = ti.unwrap();
let nc = if inf.strings.find_equiv(&("setaf")).is_some()
&& inf.strings.find_equiv(&("setab")).is_some() {
inf.numbers.find_equiv(&("colors")).map_move_default(0, |&n| n)
inf.numbers.find_equiv(&("colors")).map_default(0, |&n| n)
} else { 0 };

return Ok(Terminal {out: out, ti: inf, num_colors: nc});
Expand Down Expand Up @@ -220,7 +220,7 @@ impl Terminal {
cap = self.ti.strings.find_equiv(&("op"));
}
}
let s = do cap.map_move_default(Err(~"can't find terminfo capability `sgr0`")) |op| {
let s = do cap.map_default(Err(~"can't find terminfo capability `sgr0`")) |op| {
expand(*op, [], &mut Variables::new())
};
if s.is_ok() {
Expand Down
8 changes: 4 additions & 4 deletions src/libextra/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,20 +241,20 @@ pub fn parse_opts(args: &[~str]) -> Option<OptRes> {
let run_ignored = matches.opt_present("ignored");

let logfile = matches.opt_str("logfile");
let logfile = logfile.map_move(|s| Path(s));
let logfile = logfile.map(|s| Path(s));

let run_benchmarks = matches.opt_present("bench");
let run_tests = ! run_benchmarks ||
matches.opt_present("test");

let ratchet_metrics = matches.opt_str("ratchet-metrics");
let ratchet_metrics = ratchet_metrics.map_move(|s| Path(s));
let ratchet_metrics = ratchet_metrics.map(|s| Path(s));

let ratchet_noise_percent = matches.opt_str("ratchet-noise-percent");
let ratchet_noise_percent = ratchet_noise_percent.map_move(|s| from_str::<f64>(s).unwrap());
let ratchet_noise_percent = ratchet_noise_percent.map(|s| from_str::<f64>(s).unwrap());

let save_metrics = matches.opt_str("save-metrics");
let save_metrics = save_metrics.map_move(|s| Path(s));
let save_metrics = save_metrics.map(|s| Path(s));

let test_shard = matches.opt_str("test-shard");
let test_shard = opt_shard(test_shard);
Expand Down
14 changes: 7 additions & 7 deletions src/libextra/treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,15 @@ impl<'self, T> Iterator<&'self T> for TreeSetIterator<'self, T> {
/// Advance the iterator to the next node (in order). If there are no more nodes, return `None`.
#[inline]
fn next(&mut self) -> Option<&'self T> {
do self.iter.next().map_move |(value, _)| { value }
do self.iter.next().map |(value, _)| { value }
}
}

impl<'self, T> Iterator<&'self T> for TreeSetRevIterator<'self, T> {
/// Advance the iterator to the next node (in order). If there are no more nodes, return `None`.
#[inline]
fn next(&mut self) -> Option<&'self T> {
do self.iter.next().map |&(value, _)| { value }
do self.iter.next().map |(value, _)| { value }
}
}

Expand Down Expand Up @@ -686,7 +686,7 @@ fn mutate_values<'r, K: TotalOrd, V>(node: &'r mut Option<~TreeNode<K, V>>,

// Remove left horizontal link by rotating right
fn skew<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>) {
if node.left.map_default(false, |x| x.level == node.level) {
if node.left.as_ref().map_default(false, |x| x.level == node.level) {
let mut save = node.left.take_unwrap();
swap(&mut node.left, &mut save.right); // save.right now None
swap(node, &mut save);
Expand All @@ -697,8 +697,8 @@ fn skew<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>) {
// Remove dual horizontal link by rotating left and increasing level of
// the parent
fn split<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>) {
if node.right.map_default(false,
|x| x.right.map_default(false, |y| y.level == node.level)) {
if node.right.as_ref().map_default(false,
|x| x.right.as_ref().map_default(false, |y| y.level == node.level)) {
let mut save = node.right.take_unwrap();
swap(&mut node.right, &mut save.left); // save.left now None
save.level += 1;
Expand Down Expand Up @@ -804,8 +804,8 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>,
};

if rebalance {
let left_level = save.left.map_default(0, |x| x.level);
let right_level = save.right.map_default(0, |x| x.level);
let left_level = save.left.as_ref().map_default(0, |x| x.level);
let right_level = save.right.as_ref().map_default(0, |x| x.level);

// re-balance, if necessary
if left_level < save.level - 1 || right_level < save.level - 1 {
Expand Down
2 changes: 1 addition & 1 deletion src/librust/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ fn rustdoc_help() {
fn find_cmd(command_string: &str) -> Option<Command> {
do COMMANDS.iter().find |command| {
command.cmd == command_string
}.map_move(|x| *x)
}.map(|x| *x)
}

fn cmd_help(args: &[~str]) -> ValidUsage {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ pub fn build_session_options(binary: @str,
} else if matches.opt_present("emit-llvm") {
link::output_type_bitcode
} else { link::output_type_exe };
let sysroot_opt = matches.opt_str("sysroot").map_move(|m| @Path(m));
let sysroot_opt = matches.opt_str("sysroot").map(|m| @Path(m));
let target = matches.opt_str("target").unwrap_or(host_triple());
let target_cpu = matches.opt_str("target-cpu").unwrap_or(~"generic");
let target_feature = matches.opt_str("target-feature").unwrap_or(~"");
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/front/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn fold_mod(cx: &Context, m: &ast::_mod) -> ast::_mod {
filter_item(cx, *a).and_then(|x| cx.fold_item(x))
}.collect();
let filtered_view_items = do m.view_items.iter().filter_map |a| {
do filter_view_item(cx, a).map_move |x| {
do filter_view_item(cx, a).map |x| {
cx.fold_view_item(x)
}
}.collect();
Expand All @@ -97,7 +97,7 @@ fn fold_foreign_mod(cx: &Context, nm: &ast::foreign_mod) -> ast::foreign_mod {
.filter_map(|a| filter_foreign_item(cx, *a))
.collect();
let filtered_view_items = do nm.view_items.iter().filter_map |a| {
do filter_view_item(cx, a).map_move |x| {
do filter_view_item(cx, a).map |x| {
cx.fold_view_item(x)
}
}.collect();
Expand Down Expand Up @@ -152,12 +152,12 @@ fn fold_block(cx: &Context, b: &ast::Block) -> ast::Block {
filter_stmt(cx, *a).and_then(|stmt| cx.fold_stmt(stmt))
}.collect();
let filtered_view_items = do b.view_items.iter().filter_map |a| {
filter_view_item(cx, a).map(|x| cx.fold_view_item(*x))
filter_view_item(cx, a).map(|x| cx.fold_view_item(x))
}.collect();
ast::Block {
view_items: filtered_view_items,
stmts: resulting_stmts,
expr: b.expr.map(|x| cx.fold_expr(*x)),
expr: b.expr.map(|x| cx.fold_expr(x)),
id: b.id,
rules: b.rules,
span: b.span,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1786,7 +1786,7 @@ impl TypeNames {
}

pub fn find_type(&self, s: &str) -> Option<Type> {
self.named_types.find_equiv(&s).map_move(|x| Type::from_ref(*x))
self.named_types.find_equiv(&s).map(|x| Type::from_ref(*x))
}

// We have a depth count, because we seem to make infinite types.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub fn add_extern_mod_stmt_cnum(cstore: &mut CStore,
pub fn find_extern_mod_stmt_cnum(cstore: &CStore,
emod_id: ast::NodeId)
-> Option<ast::CrateNum> {
cstore.extern_mod_crate_map.find(&emod_id).map_move(|x| *x)
cstore.extern_mod_crate_map.find(&emod_id).map(|x| *x)
}

#[deriving(Clone)]
Expand Down
Loading

5 comments on commit 6a90e80

@bors
Copy link
Contributor

@bors bors commented on 6a90e80 Oct 9, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 6a90e80 Oct 9, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging thestinger/rust/option = 6a90e80 into auto

@bors
Copy link
Contributor

@bors bors commented on 6a90e80 Oct 9, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thestinger/rust/option = 6a90e80 merged ok, testing candidate = a3b04c1

@bors
Copy link
Contributor

@bors bors commented on 6a90e80 Oct 9, 2013

@bors
Copy link
Contributor

@bors bors commented on 6a90e80 Oct 9, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = a3b04c1

Please sign in to comment.