Skip to content

Commit 3e0400f

Browse files
committed
auto merge of #6223 : alexcrichton/rust/issue-6183, r=pcwalton
Closes #6183. The first commit changes the compiler's method of treating a `for` loop, and all the remaining commits are just dealing with the fallout. The biggest fallout was the `IterBytes` trait, although it's really a whole lot nicer now because all of the `iter_bytes_XX` methods are just and-ed together. Sadly there was a huge amount of stuff that's `cfg(stage0)` gated, but whoever lands the next snapshot is going to have a lot of fun deleting all this code!
2 parents d546493 + 606bd75 commit 3e0400f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2943
-304
lines changed

src/libcore/cleanup.rs

+30-2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ struct AnnihilateStats {
127127
n_bytes_freed: uint
128128
}
129129

130+
#[cfg(stage0)]
130131
unsafe fn each_live_alloc(read_next_before: bool,
131132
f: &fn(box: *mut BoxRepr, uniq: bool) -> bool) {
132133
//! Walks the internal list of allocations
@@ -141,8 +142,8 @@ unsafe fn each_live_alloc(read_next_before: bool,
141142
let uniq =
142143
(*box).header.ref_count == managed::raw::RC_MANAGED_UNIQUE;
143144

144-
if ! f(box, uniq) {
145-
break
145+
if !f(box, uniq) {
146+
return;
146147
}
147148

148149
if read_next_before {
@@ -152,6 +153,33 @@ unsafe fn each_live_alloc(read_next_before: bool,
152153
}
153154
}
154155
}
156+
#[cfg(not(stage0))]
157+
unsafe fn each_live_alloc(read_next_before: bool,
158+
f: &fn(box: *mut BoxRepr, uniq: bool) -> bool) -> bool {
159+
//! Walks the internal list of allocations
160+
161+
use managed;
162+
163+
let task: *Task = transmute(rustrt::rust_get_task());
164+
let box = (*task).boxed_region.live_allocs;
165+
let mut box: *mut BoxRepr = transmute(copy box);
166+
while box != mut_null() {
167+
let next_before = transmute(copy (*box).header.next);
168+
let uniq =
169+
(*box).header.ref_count == managed::raw::RC_MANAGED_UNIQUE;
170+
171+
if !f(box, uniq) {
172+
return false;
173+
}
174+
175+
if read_next_before {
176+
box = next_before;
177+
} else {
178+
box = transmute(copy (*box).header.next);
179+
}
180+
}
181+
return true;
182+
}
155183

156184
#[cfg(unix)]
157185
fn debug_mem() -> bool {

src/libcore/container.rs

+53
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,32 @@ pub trait Map<K, V>: Mutable {
3030
fn contains_key(&self, key: &K) -> bool;
3131

3232
// Visits all keys and values
33+
#[cfg(stage0)]
3334
fn each<'a>(&'a self, f: &fn(&K, &'a V) -> bool);
35+
// Visits all keys and values
36+
#[cfg(not(stage0))]
37+
fn each<'a>(&'a self, f: &fn(&K, &'a V) -> bool) -> bool;
3438

3539
/// Visit all keys
40+
#[cfg(stage0)]
3641
fn each_key(&self, f: &fn(&K) -> bool);
42+
/// Visit all keys
43+
#[cfg(not(stage0))]
44+
fn each_key(&self, f: &fn(&K) -> bool) -> bool;
3745

3846
/// Visit all values
47+
#[cfg(stage0)]
3948
fn each_value<'a>(&'a self, f: &fn(&'a V) -> bool);
49+
/// Visit all values
50+
#[cfg(not(stage0))]
51+
fn each_value<'a>(&'a self, f: &fn(&'a V) -> bool) -> bool;
4052

4153
/// Iterate over the map and mutate the contained values
54+
#[cfg(stage0)]
4255
fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool);
56+
/// Iterate over the map and mutate the contained values
57+
#[cfg(not(stage0))]
58+
fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool) -> bool;
4359

4460
/// Return a reference to the value corresponding to the key
4561
fn find<'a>(&'a self, key: &K) -> Option<&'a V>;
@@ -65,6 +81,7 @@ pub trait Map<K, V>: Mutable {
6581
fn pop(&mut self, k: &K) -> Option<V>;
6682
}
6783

84+
#[cfg(stage0)]
6885
pub trait Set<T>: Mutable {
6986
/// Return true if the set contains a value
7087
fn contains(&self, value: &T) -> bool;
@@ -99,3 +116,39 @@ pub trait Set<T>: Mutable {
99116
/// Visit the values representing the union
100117
fn union(&self, other: &Self, f: &fn(&T) -> bool);
101118
}
119+
120+
#[cfg(not(stage0))]
121+
pub trait Set<T>: Mutable {
122+
/// Return true if the set contains a value
123+
fn contains(&self, value: &T) -> bool;
124+
125+
/// Add a value to the set. Return true if the value was not already
126+
/// present in the set.
127+
fn insert(&mut self, value: T) -> bool;
128+
129+
/// Remove a value from the set. Return true if the value was
130+
/// present in the set.
131+
fn remove(&mut self, value: &T) -> bool;
132+
133+
/// Return true if the set has no elements in common with `other`.
134+
/// This is equivalent to checking for an empty intersection.
135+
fn is_disjoint(&self, other: &Self) -> bool;
136+
137+
/// Return true if the set is a subset of another
138+
fn is_subset(&self, other: &Self) -> bool;
139+
140+
/// Return true if the set is a superset of another
141+
fn is_superset(&self, other: &Self) -> bool;
142+
143+
/// Visit the values representing the difference
144+
fn difference(&self, other: &Self, f: &fn(&T) -> bool) -> bool;
145+
146+
/// Visit the values representing the symmetric difference
147+
fn symmetric_difference(&self, other: &Self, f: &fn(&T) -> bool) -> bool;
148+
149+
/// Visit the values representing the intersection
150+
fn intersection(&self, other: &Self, f: &fn(&T) -> bool) -> bool;
151+
152+
/// Visit the values representing the union
153+
fn union(&self, other: &Self, f: &fn(&T) -> bool) -> bool;
154+
}

src/libcore/core

9.02 MB
Binary file not shown.

src/libcore/gc.rs

+25-6
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ type Visitor<'self> = &'self fn(root: **Word, tydesc: *Word) -> bool;
129129

130130
// Walks the list of roots for the given safe point, and calls visitor
131131
// on each root.
132-
unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) {
132+
unsafe fn _walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) -> bool {
133133
let fp_bytes: *u8 = cast::transmute(fp);
134134
let sp_meta: *u32 = cast::transmute(sp.sp_meta);
135135

@@ -155,7 +155,7 @@ unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) {
155155
} else {
156156
ptr::null()
157157
};
158-
if !visitor(root, tydesc) { return; }
158+
if !visitor(root, tydesc) { return false; }
159159
}
160160
sri += 1;
161161
}
@@ -168,6 +168,16 @@ unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) {
168168
}
169169
rri += 1;
170170
}
171+
return true;
172+
}
173+
174+
#[cfg(stage0)]
175+
unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) {
176+
_walk_safe_point(fp, sp, visitor);
177+
}
178+
#[cfg(not(stage0))]
179+
unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) -> bool {
180+
_walk_safe_point(fp, sp, visitor)
171181
}
172182

173183
// Is fp contained in segment?
@@ -222,7 +232,7 @@ static need_cleanup: Memory = exchange_heap | stack;
222232

223233
// Walks stack, searching for roots of the requested type, and passes
224234
// each root to the visitor.
225-
unsafe fn walk_gc_roots(mem: Memory, sentinel: **Word, visitor: Visitor) {
235+
unsafe fn _walk_gc_roots(mem: Memory, sentinel: **Word, visitor: Visitor) -> bool {
226236
let mut segment = rustrt::rust_get_stack_segment();
227237
let mut last_ret: *Word = ptr::null();
228238
// To avoid collecting memory used by the GC itself, skip stack
@@ -274,14 +284,14 @@ unsafe fn walk_gc_roots(mem: Memory, sentinel: **Word, visitor: Visitor) {
274284
// Root is a generic box.
275285
let refcount = **root;
276286
if mem | task_local_heap != 0 && refcount != -1 {
277-
if !visitor(root, tydesc) { return; }
287+
if !visitor(root, tydesc) { return false; }
278288
} else if mem | exchange_heap != 0 && refcount == -1 {
279-
if !visitor(root, tydesc) { return; }
289+
if !visitor(root, tydesc) { return false; }
280290
}
281291
} else {
282292
// Root is a non-immediate.
283293
if mem | stack != 0 {
284-
if !visitor(root, tydesc) { return; }
294+
if !visitor(root, tydesc) { return false; }
285295
}
286296
}
287297
}
@@ -290,8 +300,17 @@ unsafe fn walk_gc_roots(mem: Memory, sentinel: **Word, visitor: Visitor) {
290300
}
291301
reached_sentinel = delay_reached_sentinel;
292302
}
303+
return true;
293304
}
294305

306+
#[cfg(stage0)]
307+
unsafe fn walk_gc_roots(mem: Memory, sentinel: **Word, visitor: Visitor) {
308+
_walk_gc_roots(mem, sentinel, visitor);
309+
}
310+
#[cfg(not(stage0))]
311+
unsafe fn walk_gc_roots(mem: Memory, sentinel: **Word, visitor: Visitor) -> bool {
312+
_walk_gc_roots(mem, sentinel, visitor)
313+
}
295314
pub fn gc() {
296315
unsafe {
297316
// Abort when GC is disabled.

0 commit comments

Comments
 (0)