2012-12-10 19:32:48 -06: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.
|
|
|
|
|
2012-06-02 19:42:48 -05:00
|
|
|
// xfail-win32
|
|
|
|
|
2013-05-20 19:07:24 -05:00
|
|
|
extern mod extra;
|
2012-06-02 19:42:48 -05:00
|
|
|
|
2013-05-20 19:07:24 -05:00
|
|
|
use extra::list::{List, Cons, Nil};
|
|
|
|
use extra::time::precise_time_s;
|
2013-05-24 21:35:29 -05:00
|
|
|
use std::os;
|
|
|
|
use std::task;
|
2012-06-02 19:42:48 -05:00
|
|
|
|
2013-01-31 19:12:29 -06:00
|
|
|
enum UniqueList {
|
|
|
|
ULNil, ULCons(~UniqueList)
|
|
|
|
}
|
|
|
|
|
2012-06-02 19:42:48 -05:00
|
|
|
fn main() {
|
2012-07-14 00:57:48 -05:00
|
|
|
let (repeat, depth) = if os::getenv(~"RUST_BENCH").is_some() {
|
2012-06-02 19:42:48 -05:00
|
|
|
(50, 1000)
|
|
|
|
} else {
|
|
|
|
(10, 10)
|
|
|
|
};
|
|
|
|
|
|
|
|
run(repeat, depth);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(repeat: int, depth: int) {
|
2013-04-28 23:03:55 -05:00
|
|
|
for (repeat as uint).times {
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("starting %.4f", precise_time_s());
|
2012-07-04 14:04:28 -05:00
|
|
|
do task::try {
|
2012-08-20 14:23:37 -05:00
|
|
|
recurse_or_fail(depth, None)
|
2012-06-02 19:42:48 -05:00
|
|
|
};
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("stopping %.4f", precise_time_s());
|
2012-06-02 19:42:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-04 16:12:14 -05:00
|
|
|
type nillist = List<()>;
|
2012-06-02 19:42:48 -05:00
|
|
|
|
|
|
|
// Filled with things that have to be unwound
|
2013-01-28 20:55:44 -06:00
|
|
|
|
|
|
|
struct State {
|
|
|
|
box: @nillist,
|
|
|
|
unique: ~nillist,
|
2013-03-01 17:55:31 -06:00
|
|
|
fn_box: @fn() -> @nillist,
|
2013-01-28 20:55:44 -06:00
|
|
|
tuple: (@nillist, ~nillist),
|
|
|
|
vec: ~[@nillist],
|
|
|
|
res: r
|
2012-06-02 19:42:48 -05:00
|
|
|
}
|
|
|
|
|
2012-08-15 20:46:55 -05:00
|
|
|
struct r {
|
2012-09-06 21:40:15 -05:00
|
|
|
_l: @nillist,
|
2012-11-14 00:22:37 -06:00
|
|
|
}
|
|
|
|
|
2013-03-20 20:18:57 -05:00
|
|
|
#[unsafe_destructor]
|
2013-02-14 13:47:00 -06:00
|
|
|
impl Drop for r {
|
2013-06-20 20:06:13 -05:00
|
|
|
fn drop(&self) {}
|
2012-06-02 19:42:48 -05:00
|
|
|
}
|
|
|
|
|
2012-09-05 17:58:43 -05:00
|
|
|
fn r(l: @nillist) -> r {
|
|
|
|
r {
|
|
|
|
_l: l
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-28 20:55:44 -06:00
|
|
|
fn recurse_or_fail(depth: int, st: Option<State>) {
|
2012-06-02 19:42:48 -05:00
|
|
|
if depth == 0 {
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("unwinding %.4f", precise_time_s());
|
2013-02-11 21:26:38 -06:00
|
|
|
fail!();
|
2012-06-02 19:42:48 -05:00
|
|
|
} else {
|
|
|
|
let depth = depth - 1;
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
let st = match st {
|
2012-08-20 14:23:37 -05:00
|
|
|
None => {
|
2013-01-28 20:55:44 -06:00
|
|
|
State {
|
2012-09-04 16:12:14 -05:00
|
|
|
box: @Nil,
|
|
|
|
unique: ~Nil,
|
2013-03-01 17:55:31 -06:00
|
|
|
fn_box: || @Nil::<()>,
|
2012-09-04 16:12:14 -05:00
|
|
|
tuple: (@Nil, ~Nil),
|
|
|
|
vec: ~[@Nil],
|
|
|
|
res: r(@Nil)
|
2013-01-28 20:55:44 -06:00
|
|
|
}
|
2012-06-02 19:42:48 -05:00
|
|
|
}
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(st) => {
|
2012-06-02 19:42:48 -05:00
|
|
|
let fn_box = st.fn_box;
|
|
|
|
|
2013-01-28 20:55:44 -06:00
|
|
|
State {
|
2012-09-04 16:12:14 -05:00
|
|
|
box: @Cons((), st.box),
|
|
|
|
unique: ~Cons((), @*st.unique),
|
2013-03-01 17:55:31 -06:00
|
|
|
fn_box: || @Cons((), fn_box()),
|
2012-09-04 16:12:14 -05:00
|
|
|
tuple: (@Cons((), st.tuple.first()),
|
|
|
|
~Cons((), @*st.tuple.second())),
|
2013-07-02 21:13:00 -05:00
|
|
|
vec: st.vec + &[@Cons((), *st.vec.last())],
|
2012-09-04 16:12:14 -05:00
|
|
|
res: r(@Cons((), st.res._l))
|
2013-01-28 20:55:44 -06:00
|
|
|
}
|
2012-06-02 19:42:48 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-02-15 04:44:18 -06:00
|
|
|
recurse_or_fail(depth, Some(st));
|
2012-06-02 19:42:48 -05:00
|
|
|
}
|
|
|
|
}
|