Skip to content

Commit ab17c03

Browse files
committed
---
yaml --- r: 23225 b: refs/heads/master c: 4377802 h: refs/heads/master i: 23223: 84adc6c v: v3
1 parent 7f0c3e6 commit ab17c03

File tree

4 files changed

+69
-14
lines changed

4 files changed

+69
-14
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 821fa337ffbc81fe5dad7dd1b3fa49dac84aa4ef
2+
refs/heads/master: 4377802202d59eb5aeb36bb6b656d376bbdf67dc
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/libcore/option.rs

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ pure fn map<T, U>(opt: option<T>, f: fn(T) -> U) -> option<U> {
4646
match opt { some(x) => some(f(x)), none => none }
4747
}
4848

49-
pure fn map_consume<T, U>(-opt: option<T>, f: fn(-T) -> U) -> option<U> {
49+
pure fn map_ref<T, U>(opt: &option<T>, f: fn(x: &T) -> U) -> option<U> {
50+
//! Maps a `some` value by reference from one type to another
51+
52+
match *opt { some(ref x) => some(f(x)), none => none }
53+
}
54+
55+
pure fn map_consume<T, U>(+opt: option<T>, f: fn(+T) -> U) -> option<U> {
5056
/*!
5157
* As `map`, but consumes the option and gives `f` ownership to avoid
5258
* copying.
@@ -63,6 +69,16 @@ pure fn chain<T, U>(opt: option<T>, f: fn(T) -> option<U>) -> option<U> {
6369
match opt { some(x) => f(x), none => none }
6470
}
6571

72+
pure fn chain_ref<T, U>(opt: &option<T>,
73+
f: fn(x: &T) -> option<U>) -> option<U> {
74+
/*!
75+
* Update an optional value by optionally running its content by reference
76+
* through a function that returns an option.
77+
*/
78+
79+
match *opt { some(ref x) => f(x), none => none }
80+
}
81+
6682
#[inline(always)]
6783
pure fn while_some<T>(+x: option<T>, blk: fn(+T) -> option<T>) {
6884
//! Applies a function zero or more times until the result is none.
@@ -97,14 +113,28 @@ pure fn map_default<T, U>(opt: option<T>, +def: U, f: fn(T) -> U) -> U {
97113
match opt { none => def, some(t) => f(t) }
98114
}
99115

116+
// This should replace map_default.
117+
pure fn map_default_ref<T, U>(opt: &option<T>, +def: U,
118+
f: fn(x: &T) -> U) -> U {
119+
//! Applies a function to the contained value or returns a default
120+
121+
match *opt { none => def, some(ref t) => f(t) }
122+
}
123+
124+
// This should change to by-copy mode; use iter_ref below for by reference
100125
pure fn iter<T>(opt: option<T>, f: fn(T)) {
101126
//! Performs an operation on the contained value or does nothing
102127
103128
match opt { none => (), some(t) => f(t) }
104129
}
105130

131+
pure fn iter_ref<T>(opt: &option<T>, f: fn(x: &T)) {
132+
//! Performs an operation on the contained value by reference
133+
match *opt { none => (), some(ref t) => f(t) }
134+
}
135+
106136
#[inline(always)]
107-
pure fn unwrap<T>(-opt: option<T>) -> T {
137+
pure fn unwrap<T>(+opt: option<T>) -> T {
108138
/*!
109139
* Moves a value out of an option type and returns it.
110140
*
@@ -130,12 +160,13 @@ fn swap_unwrap<T>(opt: &mut option<T>) -> T {
130160
unwrap(util::replace(opt, none))
131161
}
132162

133-
pure fn unwrap_expect<T>(-opt: option<T>, reason: &str) -> T {
163+
pure fn unwrap_expect<T>(+opt: option<T>, reason: &str) -> T {
134164
//! As unwrap, but with a specified failure message.
135165
if opt.is_none() { fail reason.to_unique(); }
136166
unwrap(opt)
137167
}
138168

169+
// Some of these should change to be &option<T>, some should not. See below.
139170
impl<T> option<T> {
140171
/**
141172
* Update an optional value by optionally running its content through a
@@ -155,6 +186,23 @@ impl<T> option<T> {
155186
pure fn map<U>(f: fn(T) -> U) -> option<U> { map(self, f) }
156187
}
157188

189+
impl<T> &option<T> {
190+
/**
191+
* Update an optional value by optionally running its content by reference
192+
* through a function that returns an option.
193+
*/
194+
pure fn chain_ref<U>(f: fn(x: &T) -> option<U>) -> option<U> {
195+
chain_ref(self, f)
196+
}
197+
/// Applies a function to the contained value or returns a default
198+
pure fn map_default_ref<U>(+def: U, f: fn(x: &T) -> U) -> U
199+
{ map_default_ref(self, def, f) }
200+
/// Performs an operation on the contained value by reference
201+
pure fn iter_ref(f: fn(x: &T)) { iter_ref(self, f) }
202+
/// Maps a `some` value from one type to another by reference
203+
pure fn map_ref<U>(f: fn(x: &T) -> U) -> option<U> { map_ref(self, f) }
204+
}
205+
158206
impl<T: copy> option<T> {
159207
/**
160208
* Gets the value out of an option

trunk/src/libcore/send_map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ mod linear {
237237
}
238238

239239
impl<K,V> &const linear_map<K,V> {
240-
fn len() -> uint {
240+
pure fn len() -> uint {
241241
self.size
242242
}
243243

244-
fn is_empty() -> bool {
244+
pure fn is_empty() -> bool {
245245
self.len() == 0
246246
}
247247

trunk/src/libcore/task.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// NB: transitionary, de-mode-ing.
2+
#[forbid(deprecated_mode)];
3+
#[forbid(deprecated_pattern)];
4+
15
/*!
26
* Task management.
37
*
@@ -730,8 +734,8 @@ type taskgroup_arc = unsafe::Exclusive<option<taskgroup_data>>;
730734
type taskgroup_inner = &mut option<taskgroup_data>;
731735

732736
// A taskgroup is 'dead' when nothing can cause it to fail; only members can.
733-
fn taskgroup_is_dead(tg: taskgroup_data) -> bool {
734-
(&mut tg.members).is_empty()
737+
pure fn taskgroup_is_dead(tg: &taskgroup_data) -> bool {
738+
(&tg.members).is_empty()
735739
}
736740

737741
// A list-like structure by which taskgroups keep track of all ancestor groups
@@ -841,8 +845,11 @@ fn each_ancestor(list: &mut ancestor_list,
841845
do with_parent_tg(&mut nobe.parent_group) |tg_opt| {
842846
// Decide whether this group is dead. Note that the
843847
// group being *dead* is disjoint from it *failing*.
844-
do tg_opt.iter |tg| {
845-
nobe_is_dead = taskgroup_is_dead(tg);
848+
match *tg_opt {
849+
some(ref tg) => {
850+
nobe_is_dead = taskgroup_is_dead(tg);
851+
},
852+
none => { }
846853
}
847854
// Call iterator block. (If the group is dead, it's
848855
// safe to skip it. This will leave our *rust_task
@@ -1100,7 +1107,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
11001107
}
11011108
}
11021109

1103-
fn spawn_raw(opts: task_opts, +f: fn~()) {
1110+
fn spawn_raw(+opts: task_opts, +f: fn~()) {
11041111
let (child_tg, ancestors, is_main) =
11051112
gen_child_taskgroup(opts.linked, opts.supervised);
11061113

@@ -1138,10 +1145,10 @@ fn spawn_raw(opts: task_opts, +f: fn~()) {
11381145
// (3a) If any of those fails, it leaves all groups, and does nothing.
11391146
// (3b) Otherwise it builds a task control structure and puts it in TLS,
11401147
// (4) ...and runs the provided body function.
1141-
fn make_child_wrapper(child: *rust_task, -child_arc: taskgroup_arc,
1142-
-ancestors: ancestor_list, is_main: bool,
1148+
fn make_child_wrapper(child: *rust_task, +child_arc: taskgroup_arc,
1149+
+ancestors: ancestor_list, is_main: bool,
11431150
notify_chan: option<comm::chan<notification>>,
1144-
-f: fn~()) -> fn~() {
1151+
+f: fn~()) -> fn~() {
11451152
let child_data = ~mut some((child_arc, ancestors));
11461153
return fn~() {
11471154
// Agh. Get move-mode items into the closure. FIXME (#2829)

0 commit comments

Comments
 (0)