2012-12-10 17:32:48 -08:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-10-23 04:49:18 -04:00
|
|
|
#[feature(managed_boxes)];
|
|
|
|
|
2013-05-20 17:07:24 -07:00
|
|
|
extern mod extra;
|
2012-06-02 17:42:48 -07:00
|
|
|
|
2013-05-20 17:07:24 -07:00
|
|
|
use extra::list::{List, Cons, Nil};
|
|
|
|
use extra::time::precise_time_s;
|
2013-05-24 19:35:29 -07:00
|
|
|
use std::os;
|
|
|
|
use std::task;
|
2012-06-02 17:42:48 -07:00
|
|
|
|
2013-01-31 17:12:29 -08:00
|
|
|
enum UniqueList {
|
|
|
|
ULNil, ULCons(~UniqueList)
|
|
|
|
}
|
|
|
|
|
2012-06-02 17:42:48 -07:00
|
|
|
fn main() {
|
2013-07-17 15:31:20 -04:00
|
|
|
let (repeat, depth) = if os::getenv("RUST_BENCH").is_some() {
|
2012-06-02 17:42:48 -07:00
|
|
|
(50, 1000)
|
|
|
|
} else {
|
|
|
|
(10, 10)
|
|
|
|
};
|
|
|
|
|
|
|
|
run(repeat, depth);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(repeat: int, depth: int) {
|
2013-08-05 23:43:06 -04:00
|
|
|
for _ in range(0, repeat) {
|
2013-10-21 13:08:31 -07:00
|
|
|
info!("starting {:.4f}", precise_time_s());
|
2014-01-27 18:29:50 -05:00
|
|
|
task::try(proc() {
|
2012-08-20 12:23:37 -07:00
|
|
|
recurse_or_fail(depth, None)
|
2014-01-27 18:29:50 -05:00
|
|
|
});
|
2013-10-21 13:08:31 -07:00
|
|
|
info!("stopping {:.4f}", precise_time_s());
|
2012-06-02 17:42:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-04 14:12:14 -07:00
|
|
|
type nillist = List<()>;
|
2012-06-02 17:42:48 -07:00
|
|
|
|
|
|
|
// Filled with things that have to be unwound
|
2013-01-28 18:55:44 -08:00
|
|
|
|
|
|
|
struct State {
|
2013-12-11 17:04:50 -08:00
|
|
|
managed: @nillist,
|
2013-01-28 18:55:44 -08:00
|
|
|
unique: ~nillist,
|
|
|
|
tuple: (@nillist, ~nillist),
|
|
|
|
vec: ~[@nillist],
|
|
|
|
res: r
|
2012-06-02 17:42:48 -07:00
|
|
|
}
|
|
|
|
|
2012-08-15 18:46:55 -07:00
|
|
|
struct r {
|
2012-09-06 19:40:15 -07:00
|
|
|
_l: @nillist,
|
2012-11-14 01:22:37 -05:00
|
|
|
}
|
|
|
|
|
2013-03-20 18:18:57 -07:00
|
|
|
#[unsafe_destructor]
|
2013-02-14 11:47:00 -08:00
|
|
|
impl Drop for r {
|
2013-09-16 21:18:07 -04:00
|
|
|
fn drop(&mut self) {}
|
2012-06-02 17:42:48 -07:00
|
|
|
}
|
|
|
|
|
2012-09-05 15:58:43 -07:00
|
|
|
fn r(l: @nillist) -> r {
|
|
|
|
r {
|
|
|
|
_l: l
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-28 18:55:44 -08:00
|
|
|
fn recurse_or_fail(depth: int, st: Option<State>) {
|
2012-06-02 17:42:48 -07:00
|
|
|
if depth == 0 {
|
2013-10-21 13:08:31 -07:00
|
|
|
info!("unwinding {:.4f}", precise_time_s());
|
|
|
|
fail!();
|
2012-06-02 17:42:48 -07:00
|
|
|
} else {
|
|
|
|
let depth = depth - 1;
|
|
|
|
|
2012-08-06 12:34:08 -07:00
|
|
|
let st = match st {
|
2012-08-20 12:23:37 -07:00
|
|
|
None => {
|
2013-01-28 18:55:44 -08:00
|
|
|
State {
|
2013-12-11 17:04:50 -08:00
|
|
|
managed: @Nil,
|
2012-09-04 14:12:14 -07:00
|
|
|
unique: ~Nil,
|
|
|
|
tuple: (@Nil, ~Nil),
|
|
|
|
vec: ~[@Nil],
|
|
|
|
res: r(@Nil)
|
2013-01-28 18:55:44 -08:00
|
|
|
}
|
2012-06-02 17:42:48 -07:00
|
|
|
}
|
2012-08-20 12:23:37 -07:00
|
|
|
Some(st) => {
|
2013-01-28 18:55:44 -08:00
|
|
|
State {
|
2013-12-11 17:04:50 -08:00
|
|
|
managed: @Cons((), st.managed),
|
2012-09-04 14:12:14 -07:00
|
|
|
unique: ~Cons((), @*st.unique),
|
|
|
|
tuple: (@Cons((), st.tuple.first()),
|
|
|
|
~Cons((), @*st.tuple.second())),
|
2013-12-23 15:08:23 +01:00
|
|
|
vec: st.vec + &[@Cons((), *st.vec.last().unwrap())],
|
2012-09-04 14:12:14 -07:00
|
|
|
res: r(@Cons((), st.res._l))
|
2013-01-28 18:55:44 -08:00
|
|
|
}
|
2012-06-02 17:42:48 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-02-15 02:44:18 -08:00
|
|
|
recurse_or_fail(depth, Some(st));
|
2012-06-02 17:42:48 -07:00
|
|
|
}
|
|
|
|
}
|