Skip to content

Commit

Permalink
test: Fix tests and the pipe compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
pcwalton committed May 9, 2013
1 parent db4573a commit 278b487
Show file tree
Hide file tree
Showing 27 changed files with 151 additions and 126 deletions.
68 changes: 19 additions & 49 deletions src/libcore/repr.rs
Expand Up @@ -448,10 +448,15 @@ impl TyVisitor for ReprVisitor {
true
}

fn visit_enter_enum(&self, _n_variants: uint,
fn visit_enter_enum(&self,
_n_variants: uint,
get_disr: extern unsafe fn(ptr: *Opaque) -> int,
_sz: uint, _align: uint) -> bool {
let disr = unsafe { get_disr(transmute(self.ptr)) };
_sz: uint,
_align: uint) -> bool {
let var_stk: &mut ~[VariantState] = self.var_stk;
let disr = unsafe {
get_disr(transmute(*self.ptr))
};
self.var_stk.push(SearchingFor(disr));
true
}
Expand Down Expand Up @@ -484,31 +489,12 @@ impl TyVisitor for ReprVisitor {
true
}

<<<<<<< HEAD
fn visit_enum_variant_field(&self, i: uint, _offset: uint, inner: *TyDesc) -> bool {
match self.var_stk[vec::uniq_len(&const self.var_stk) - 1] {
=======
#[cfg(stage0)]
fn visit_enum_variant_field(&self, i: uint, inner: *TyDesc) -> bool {
match self.var_stk[vec::uniq_len(&const *self.var_stk) - 1] {
Degenerate | TagMatch => {
if i != 0 {
self.writer.write_str(", ");
}
if ! self.visit_inner(inner) {
return false;
}
}
TagMismatch => ()
}
true
}

#[cfg(not(stage0))]
fn visit_enum_variant_field(&self, i: uint, _: uint, inner: *TyDesc)
fn visit_enum_variant_field(&self,
i: uint,
_offset: uint,
inner: *TyDesc)
-> bool {
match self.var_stk[vec::uniq_len(&const *self.var_stk) - 1] {
>>>>>>> libcore: Remove mutable fields from repr
match self.var_stk[vec::uniq_len(&const self.var_stk) - 1] {
Matched => {
if i != 0 {
self.writer.write_str(", ");
Expand All @@ -522,26 +508,6 @@ impl TyVisitor for ReprVisitor {
true
}

<<<<<<< HEAD
=======
#[cfg(stage0)]
fn visit_leave_enum_variant(&self, _variant: uint,
_disr_val: int,
n_fields: uint,
_name: &str) -> bool {
match self.var_stk[vec::uniq_len(&const *self.var_stk) - 1] {
Degenerate | TagMatch => {
if n_fields > 0 {
self.writer.write_char(')');
}
}
TagMismatch => ()
}
true
}

#[cfg(not(stage0))]
>>>>>>> libcore: Remove mutable fields from repr
fn visit_leave_enum_variant(&self, _variant: uint,
_disr_val: int,
n_fields: uint,
Expand All @@ -557,9 +523,13 @@ impl TyVisitor for ReprVisitor {
true
}

fn visit_leave_enum(&self, _n_variants: uint,
fn visit_leave_enum(&self,
_n_variants: uint,
_get_disr: extern unsafe fn(ptr: *Opaque) -> int,
_sz: uint, _align: uint) -> bool {
_sz: uint,
_align: uint)
-> bool {
let var_stk: &mut ~[VariantState] = self.var_stk;
match self.var_stk.pop() {
SearchingFor(*) => fail!(~"enum value matched no variant"),
_ => true
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/task/mod.rs
Expand Up @@ -230,12 +230,14 @@ pub impl TaskBuilder {
/// the child.
fn supervised(&mut self) {
self.opts.supervised = true;
self.opts.linked = false;
}

/// Link the child task's and parent task's failures. If either fails, the
/// other will be killed.
fn linked(&mut self) {
self.opts.linked = true;
self.opts.supervised = false;
}

/**
Expand Down
9 changes: 5 additions & 4 deletions src/libsyntax/ext/pipes/pipec.rs
Expand Up @@ -64,6 +64,7 @@ impl gen_send for message {

let mut body = ~"{\n";
body += fmt!("use super::%s;\n", name);
body += ~"let mut pipe = pipe;\n";

if this.proto.is_bounded() {
let (sp, rp) = match (this.dir, next.dir) {
Expand All @@ -73,12 +74,12 @@ impl gen_send for message {
(recv, recv) => (~"c", ~"s")
};

body += ~"let b = pipe.reuse_buffer();\n";
body += ~"let mut b = pipe.reuse_buffer();\n";
body += fmt!("let %s = ::core::pipes::SendPacketBuffered(\
&(b.buffer.data.%s));\n",
&mut (b.buffer.data.%s));\n",
sp, next.name);
body += fmt!("let %s = ::core::pipes::RecvPacketBuffered(\
&(b.buffer.data.%s));\n",
&mut (b.buffer.data.%s));\n",
rp, next.name);
}
else {
Expand Down Expand Up @@ -366,7 +367,7 @@ impl gen_init for protocol {
fmt!("data.%s.set_buffer(buffer)",
s.name))),
ext_cx.parse_expr(fmt!(
"::core::ptr::to_unsafe_ptr(&(data.%s))",
"::core::ptr::to_mut_unsafe_ptr(&mut (data.%s))",
self.states[0].name))));

quote_expr!({
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/core-map.rs
Expand Up @@ -103,7 +103,7 @@ fn main() {
let mut rand = vec::with_capacity(n_keys);

{
let rng = core::rand::IsaacRng::new_seeded([1, 1, 1, 1, 1, 1, 1]);
let mut rng = core::rand::IsaacRng::new_seeded([1, 1, 1, 1, 1, 1, 1]);
let mut set = HashSet::new();
while set.len() != n_keys {
let next = rng.next() as uint;
Expand Down
33 changes: 21 additions & 12 deletions src/test/bench/core-set.rs
Expand Up @@ -31,8 +31,13 @@ fn timed(result: &mut float, op: &fn()) {
}

pub impl Results {
fn bench_int<T:Set<uint>, R: rand::Rng>(&mut self, rng: &R, num_keys: uint,
rand_cap: uint, f: &fn() -> T) {
fn bench_int<T:Set<uint>,
R: rand::Rng>(
&mut self,
rng: &mut R,
num_keys: uint,
rand_cap: uint,
f: &fn() -> T) {
{
let mut set = f();
do timed(&mut self.sequential_ints) {
Expand Down Expand Up @@ -69,8 +74,12 @@ pub impl Results {
}
}

fn bench_str<T:Set<~str>, R: rand::Rng>(&mut self, rng: &R, num_keys: uint,
f: &fn() -> T) {
fn bench_str<T:Set<~str>,
R:rand::Rng>(
&mut self,
rng: &mut R,
num_keys: uint,
f: &fn() -> T) {
{
let mut set = f();
do timed(&mut self.sequential_strings) {
Expand Down Expand Up @@ -155,25 +164,25 @@ fn main() {
let max = 200000;

{
let rng = rand::IsaacRng::new_seeded(seed);
let mut rng = rand::IsaacRng::new_seeded(seed);
let mut results = empty_results();
results.bench_int(&rng, num_keys, max, || HashSet::new::<uint>());
results.bench_str(&rng, num_keys, || HashSet::new::<~str>());
results.bench_int(&mut rng, num_keys, max, || HashSet::new::<uint>());
results.bench_str(&mut rng, num_keys, || HashSet::new::<~str>());
write_results("core::hashmap::HashSet", &results);
}

{
let rng = rand::IsaacRng::new_seeded(seed);
let mut rng = rand::IsaacRng::new_seeded(seed);
let mut results = empty_results();
results.bench_int(&rng, num_keys, max, || TreeSet::new::<uint>());
results.bench_str(&rng, num_keys, || TreeSet::new::<~str>());
results.bench_int(&mut rng, num_keys, max, || TreeSet::new::<uint>());
results.bench_str(&mut rng, num_keys, || TreeSet::new::<~str>());
write_results("std::treemap::TreeSet", &results);
}

{
let rng = rand::IsaacRng::new_seeded(seed);
let mut rng = rand::IsaacRng::new_seeded(seed);
let mut results = empty_results();
results.bench_int(&rng, num_keys, max, || BitvSet::new());
results.bench_int(&mut rng, num_keys, max, || BitvSet::new());
write_results("std::bitv::BitvSet", &results);
}
}
15 changes: 9 additions & 6 deletions src/test/bench/core-std.rs
Expand Up @@ -33,12 +33,15 @@ fn main() {
fn maybe_run_test(argv: &[~str], name: ~str, test: &fn()) {
let mut run_test = false;

if os::getenv(~"RUST_BENCH").is_some() { run_test = true }
else if argv.len() > 0 {
if os::getenv(~"RUST_BENCH").is_some() {
run_test = true
} else if argv.len() > 0 {
run_test = argv.contains(&~"all") || argv.contains(&name)
}

if !run_test { return }
if !run_test {
return
}

let start = precise_time_s();
test();
Expand Down Expand Up @@ -69,7 +72,7 @@ fn read_line() {
}

fn vec_plus() {
let r = rand::rng();
let mut r = rand::rng();

let mut v = ~[];
let mut i = 0;
Expand All @@ -86,7 +89,7 @@ fn vec_plus() {
}

fn vec_append() {
let r = rand::rng();
let mut r = rand::rng();

let mut v = ~[];
let mut i = 0;
Expand All @@ -103,7 +106,7 @@ fn vec_append() {
}

fn vec_push_all() {
let r = rand::rng();
let mut r = rand::rng();

let mut v = ~[];
for uint::range(0, 1500) |i| {
Expand Down
17 changes: 9 additions & 8 deletions src/test/bench/graph500-bfs.rs
Expand Up @@ -32,19 +32,20 @@ type graph = ~[~[node_id]];
type bfs_result = ~[node_id];

fn make_edges(scale: uint, edgefactor: uint) -> ~[(node_id, node_id)] {
let r = rand::XorShiftRng::new();

fn choose_edge<R: rand::Rng>(i: node_id, j: node_id, scale: uint, r: &R)
-> (node_id, node_id) {
let mut r = rand::XorShiftRng::new();

fn choose_edge<R: rand::Rng>(i: node_id,
j: node_id,
scale: uint,
r: &mut R)
-> (node_id, node_id) {
let A = 0.57;
let B = 0.19;
let C = 0.19;

if scale == 0u {
(i, j)
}
else {
} else {
let i = i * 2i64;
let j = j * 2i64;
let scale = scale - 1u;
Expand Down Expand Up @@ -73,7 +74,7 @@ fn make_edges(scale: uint, edgefactor: uint) -> ~[(node_id, node_id)] {
}

do vec::from_fn((1u << scale) * edgefactor) |_i| {
choose_edge(0i64, 0i64, scale, &r)
choose_edge(0i64, 0i64, scale, &mut r)
}
}

Expand Down Expand Up @@ -103,7 +104,7 @@ fn make_graph(N: uint, edges: ~[(node_id, node_id)]) -> graph {

fn gen_search_keys(graph: &[~[node_id]], n: uint) -> ~[node_id] {
let mut keys = HashSet::new();
let r = rand::rng();
let mut r = rand::rng();

while keys.len() < n {
let k = r.gen_uint_range(0u, graph.len());
Expand Down
8 changes: 4 additions & 4 deletions src/test/bench/msgsend-pipes-shared.rs
Expand Up @@ -65,15 +65,15 @@ fn run(args: &[~str]) {
let mut worker_results = ~[];
for uint::range(0, workers) |_i| {
let to_child = to_child.clone();
do task::task().future_result(|+r| {
worker_results.push(r);
}).spawn || {
let mut builder = task::task();
builder.future_result(|r| worker_results.push(r));
do builder.spawn {
for uint::range(0, size / workers) |_i| {
//error!("worker %?: sending %? bytes", i, num_bytes);
to_child.send(bytes(num_bytes));
}
//error!("worker %? exiting", i);
};
}
}
do task::spawn || {
server(&from_parent, &to_parent);
Expand Down
6 changes: 3 additions & 3 deletions src/test/bench/msgsend-pipes.rs
Expand Up @@ -62,9 +62,9 @@ fn run(args: &[~str]) {
for uint::range(0, workers) |_i| {
let (from_parent_, to_child) = stream();
from_parent.add(from_parent_);
do task::task().future_result(|+r| {
worker_results.push(r);
}).spawn || {
let mut builder = task::task();
builder.future_result(|r| worker_results.push(r));
do builder.spawn {
for uint::range(0, size / workers) |_i| {
//error!("worker %?: sending %? bytes", i, num_bytes);
to_child.send(bytes(num_bytes));
Expand Down
4 changes: 3 additions & 1 deletion src/test/bench/msgsend-ring-mutex-arcs.rs
Expand Up @@ -103,7 +103,9 @@ fn main() {
thread_ring(0, msg_per_task, num_chan.take(), num_port);

// synchronize
for futures.each |f| { f.get() };
for futures.each_mut |f| {
f.get()
}

let stop = time::precise_time_s();

Expand Down
4 changes: 3 additions & 1 deletion src/test/bench/msgsend-ring-pipes.rs
Expand Up @@ -96,7 +96,9 @@ fn main() {
thread_ring(0, msg_per_task, num_chan.take(), num_port);

// synchronize
for futures.each |f| { f.get() };
for futures.each_mut |f| {
let _ = f.get();
}

let stop = time::precise_time_s();

Expand Down
4 changes: 3 additions & 1 deletion src/test/bench/msgsend-ring-rw-arcs.rs
Expand Up @@ -104,7 +104,9 @@ fn main() {
thread_ring(0, msg_per_task, num_chan.take(), num_port);

// synchronize
for futures.each |f| { f.get() };
for futures.each_mut |f| {
let _ = f.get();
}

let stop = time::precise_time_s();

Expand Down

0 comments on commit 278b487

Please sign in to comment.