Skip to content

Commit 1f60855

Browse files
committed
---
yaml --- r: 65787 b: refs/heads/master c: 305f511 h: refs/heads/master i: 65785: 77364ea 65783: 34cda49 v: v3
1 parent 88072dd commit 1f60855

File tree

5 files changed

+61
-37
lines changed

5 files changed

+61
-37
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: 48c7bc17c68032d142dd6ce53b8f5933d52c2165
2+
refs/heads/master: 305f5110a7d4a1ccad32bd0b154e53df59664528
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/src/libextra/getopts.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,22 @@
3131
* file name following -o, and accepts both -h and --help as optional flags.
3232
*
3333
* ```
34-
* extern mod std;
35-
* use std::getopts::*;
34+
* extern mod extra;
35+
* use extra::getopts::*;
36+
* use std::os;
3637
*
3738
* fn do_work(in: &str, out: Option<~str>) {
38-
* io::println(in);
39-
* io::println(match out {
40-
* Some(x) => x,
41-
* None => ~"No Output"
42-
* });
39+
* println(in);
40+
* println(match out {
41+
* Some(x) => x,
42+
* None => ~"No Output"
43+
* });
4344
* }
4445
*
45-
* fn print_usage(program: &str, _opts: &[std::getopts::Opt]) {
46-
* io::println(fmt!("Usage: %s [options]", program));
47-
* io::println("-o\t\tOutput");
48-
* io::println("-h --help\tUsage");
46+
* fn print_usage(program: &str, _opts: &[Opt]) {
47+
* println(fmt!("Usage: %s [options]", program));
48+
* println("-o\t\tOutput");
49+
* println("-h --help\tUsage");
4950
* }
5051
*
5152
* fn main() {
@@ -58,9 +59,9 @@
5859
* optflag("h"),
5960
* optflag("help")
6061
* ];
61-
* let matches = match getopts(vec::tail(args), opts) {
62-
* result::Ok(m) => { m }
63-
* result::Err(f) => { fail!(fail_str(f)) }
62+
* let matches = match getopts(args.tail(), opts) {
63+
* Ok(m) => { m }
64+
* Err(f) => { fail!(fail_str(f)) }
6465
* };
6566
* if opt_present(&matches, "h") || opt_present(&matches, "help") {
6667
* print_usage(program, opts);

trunk/src/librustc/middle/trans/base.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3064,6 +3064,9 @@ pub fn trans_crate(sess: session::Session,
30643064
}
30653065
let int_type = T_int(targ_cfg);
30663066
let float_type = T_float(targ_cfg);
3067+
let task_type = T_task(targ_cfg);
3068+
let taskptr_type = T_ptr(task_type);
3069+
lib::llvm::associate_type(tn, @"taskptr", taskptr_type);
30673070
let tydesc_type = T_tydesc(targ_cfg);
30683071
lib::llvm::associate_type(tn, @"tydesc", tydesc_type);
30693072
let crate_map = decl_crate_map(sess, link_meta, llmod);
@@ -3128,6 +3131,7 @@ pub fn trans_crate(sess: session::Session,
31283131
tydesc_type: tydesc_type,
31293132
int_type: int_type,
31303133
float_type: float_type,
3134+
task_type: task_type,
31313135
opaque_vec_type: T_opaque_vec(targ_cfg),
31323136
builder: BuilderRef_res(unsafe { llvm::LLVMCreateBuilder() }),
31333137
shape_cx: mk_ctxt(llmod),

trunk/src/librustc/middle/trans/common.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ pub struct CrateContext {
221221
tydesc_type: TypeRef,
222222
int_type: TypeRef,
223223
float_type: TypeRef,
224+
task_type: TypeRef,
224225
opaque_vec_type: TypeRef,
225226
builder: BuilderRef_res,
226227
shape_cx: shape::Ctxt,
@@ -933,6 +934,28 @@ pub fn T_empty_struct() -> TypeRef { return T_struct([], false); }
933934
// they are described by this opaque type.
934935
pub fn T_vtable() -> TypeRef { T_array(T_ptr(T_i8()), 1u) }
935936

937+
pub fn T_task(targ_cfg: @session::config) -> TypeRef {
938+
let t = T_named_struct("task");
939+
940+
// Refcount
941+
// Delegate pointer
942+
// Stack segment pointer
943+
// Runtime SP
944+
// Rust SP
945+
// GC chain
946+
947+
948+
// Domain pointer
949+
// Crate cache pointer
950+
951+
let t_int = T_int(targ_cfg);
952+
let elems =
953+
~[t_int, t_int, t_int, t_int,
954+
t_int, t_int, t_int, t_int];
955+
set_struct_body(t, elems, false);
956+
return t;
957+
}
958+
936959
pub fn T_tydesc_field(cx: @CrateContext, field: uint) -> TypeRef {
937960
// Bit of a kludge: pick the fn typeref out of the tydesc..
938961

@@ -1062,6 +1085,8 @@ pub fn T_chan(cx: @CrateContext, _t: TypeRef) -> TypeRef {
10621085

10631086
}
10641087

1088+
pub fn T_taskptr(cx: @CrateContext) -> TypeRef { return T_ptr(cx.task_type); }
1089+
10651090

10661091
pub fn T_opaque_cbox_ptr(cx: @CrateContext) -> TypeRef {
10671092
// closures look like boxes (even when they are ~fn or &fn)

trunk/src/libstd/unstable/finally.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,20 @@ pub trait Finally<T> {
3131
fn finally(&self, dtor: &fn()) -> T;
3232
}
3333

34-
impl<'self,T> Finally<T> for &'self fn() -> T {
35-
fn finally(&self, dtor: &fn()) -> T {
36-
let _d = Finallyalizer {
37-
dtor: dtor
38-
};
39-
40-
(*self)()
34+
macro_rules! finally_fn {
35+
($fnty:ty) => {
36+
impl<T> Finally<T> for $fnty {
37+
fn finally(&self, dtor: &fn()) -> T {
38+
let _d = Finallyalizer {
39+
dtor: dtor
40+
};
41+
(*self)()
42+
}
43+
}
4144
}
4245
}
4346

44-
impl<T> Finally<T> for ~fn() -> T {
47+
impl<'self,T> Finally<T> for &'self fn() -> T {
4548
fn finally(&self, dtor: &fn()) -> T {
4649
let _d = Finallyalizer {
4750
dtor: dtor
@@ -51,15 +54,9 @@ impl<T> Finally<T> for ~fn() -> T {
5154
}
5255
}
5356

54-
impl<T> Finally<T> for @fn() -> T {
55-
fn finally(&self, dtor: &fn()) -> T {
56-
let _d = Finallyalizer {
57-
dtor: dtor
58-
};
59-
60-
(*self)()
61-
}
62-
}
57+
finally_fn!(~fn() -> T)
58+
finally_fn!(@fn() -> T)
59+
finally_fn!(extern "Rust" fn() -> T)
6360

6461
struct Finallyalizer<'self> {
6562
dtor: &'self fn()
@@ -108,10 +105,7 @@ fn test_retval() {
108105

109106
#[test]
110107
fn test_compact() {
111-
// FIXME #4727: Should be able to use a fn item instead
112-
// of a closure for do_some_fallible_work,
113-
// but it's a type error.
114-
let do_some_fallible_work: &fn() = || { };
108+
fn do_some_fallible_work() {}
115109
fn but_always_run_this_function() { }
116110
do_some_fallible_work.finally(
117111
but_always_run_this_function);
@@ -136,4 +130,4 @@ fn test_managed() {
136130
};
137131
assert_eq!(do managed.finally {}, 10);
138132
assert_eq!(*i, 20);
139-
}
133+
}

0 commit comments

Comments
 (0)