diff --git a/src/libcore/io.rs b/src/libcore/io.rs index fdb622f653937a74e7675f8f564191b10247f929..4f9b8ccf7576cea0cecb298401b0b76ea753dc0a 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -1139,7 +1139,7 @@ pub fn Res(arg: Arg) -> Res{ pub struct Arg { val: t, opt_level: Option, - fsync_fn: fn@(f: t, Level) -> int, + fsync_fn: @fn(f: t, Level) -> int, } // fsync file after executing blk @@ -1150,9 +1150,9 @@ pub fn FILE_res_sync(file: &FILERes, opt_level: Option, unsafe { blk(Res(Arg { val: file.f, opt_level: opt_level, - fsync_fn: fn@(file: *libc::FILE, l: Level) -> int { + fsync_fn: |file, l| { unsafe { - return os::fsync_fd(libc::fileno(file), l) as int; + os::fsync_fd(libc::fileno(file), l) as int } } })); @@ -1164,9 +1164,7 @@ pub fn fd_res_sync(fd: &FdRes, opt_level: Option, blk: fn(v: Res)) { blk(Res(Arg { val: fd.fd, opt_level: opt_level, - fsync_fn: fn@(fd: fd_t, l: Level) -> int { - return os::fsync_fd(fd, l) as int; - } + fsync_fn: |fd, l| os::fsync_fd(fd, l) as int })); } @@ -1178,9 +1176,7 @@ pub fn obj_sync(o: FSyncable, opt_level: Option, blk: fn(v: Res)) { blk(Res(Arg { val: o, opt_level: opt_level, - fsync_fn: fn@(o: FSyncable, l: Level) -> int { - return o.fsync(l); - } + fsync_fn: |o, l| o.fsync(l) })); } } diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 58ab2ce78f5f98a1cf7007060c90bfc6bf58e099..e4fc9528f23fc2e31077af2d901493831d8ec7bf 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -910,11 +910,10 @@ pub fn entangle() -> (SendPacket, RecvPacket) { */ pub fn spawn_service( - init: extern fn() -> (SendPacketBuffered, - RecvPacketBuffered), - service: fn~(v: RecvPacketBuffered)) - -> SendPacketBuffered -{ + init: extern fn() -> (SendPacketBuffered, + RecvPacketBuffered), + service: ~fn(v: RecvPacketBuffered)) + -> SendPacketBuffered { let (client, server) = init(); // This is some nasty gymnastics required to safely move the pipe @@ -932,11 +931,10 @@ pub fn spawn_service( */ pub fn spawn_service_recv( - init: extern fn() -> (RecvPacketBuffered, - SendPacketBuffered), - service: fn~(v: SendPacketBuffered)) - -> RecvPacketBuffered -{ + init: extern fn() -> (RecvPacketBuffered, + SendPacketBuffered), + service: ~fn(v: SendPacketBuffered)) + -> RecvPacketBuffered { let (client, server) = init(); // This is some nasty gymnastics required to safely move the pipe diff --git a/src/libcore/reflect.rs b/src/libcore/reflect.rs index 2a688482f6186f8e2bf84387b165fd513605d04a..06ae4eb17a534614bee1fcc667230cc76942239b 100644 --- a/src/libcore/reflect.rs +++ b/src/libcore/reflect.rs @@ -489,9 +489,9 @@ fn visit_constr(&self, inner: *TyDesc) -> bool { } fn visit_closure_ptr(&self, ck: uint) -> bool { - self.align_to::(); + self.align_to::<@fn()>(); if ! self.inner.visit_closure_ptr(ck) { return false; } - self.bump_past::(); + self.bump_past::<@fn()>(); true } } diff --git a/src/libcore/task/mod.rs b/src/libcore/task/mod.rs index 49507897392de428f9dd0ecdb80dd36d9f40a883..0835d4400ede80b54d708277f59a6d20690ee1f2 100644 --- a/src/libcore/task/mod.rs +++ b/src/libcore/task/mod.rs @@ -191,7 +191,7 @@ pub struct TaskOpts { // FIXME (#3724): Replace the 'consumed' bit with move mode on self pub struct TaskBuilder { opts: TaskOpts, - gen_body: fn@(v: fn~()) -> fn~(), + gen_body: @fn(v: ~fn()) -> ~fn(), can_not_copy: Option, mut consumed: bool, } @@ -357,7 +357,7 @@ fn sched_mode(mode: SchedMode) -> TaskBuilder { * generator by applying the task body which results from the * existing body generator to the new body generator. */ - fn add_wrapper(wrapper: fn@(v: fn~()) -> fn~()) -> TaskBuilder { + fn add_wrapper(wrapper: @fn(v: ~fn()) -> ~fn()) -> TaskBuilder { let prev_gen_body = self.gen_body; let notify_chan = replace(&mut self.opts.notify_chan, None); TaskBuilder { @@ -385,7 +385,7 @@ fn add_wrapper(wrapper: fn@(v: fn~()) -> fn~()) -> TaskBuilder { * When spawning into a new scheduler, the number of threads requested * must be greater than zero. */ - fn spawn(f: fn~()) { + fn spawn(f: ~fn()) { let notify_chan = replace(&mut self.opts.notify_chan, None); let x = self.consume(); let opts = TaskOpts { @@ -397,7 +397,7 @@ fn spawn(f: fn~()) { spawn::spawn_raw(opts, (x.gen_body)(f)); } /// Runs a task, while transfering ownership of one argument to the child. - fn spawn_with(arg: A, f: fn~(v: A)) { + fn spawn_with(arg: A, f: ~fn(v: A)) { let arg = Cell(arg); do self.spawn { f(arg.take()); @@ -417,7 +417,7 @@ fn spawn_with(arg: A, f: fn~(v: A)) { * # Failure * Fails if a future_result was already set for this task. */ - fn try(f: fn~() -> T) -> Result { + fn try(f: ~fn() -> T) -> Result { let (po, ch) = stream::(); let mut result = None; @@ -458,7 +458,7 @@ pub fn default_task_opts() -> TaskOpts { /* Spawn convenience functions */ -pub fn spawn(f: fn~()) { +pub fn spawn(f: ~fn()) { /*! * Creates and executes a new child task * @@ -471,7 +471,7 @@ pub fn spawn(f: fn~()) { task().spawn(f) } -pub fn spawn_unlinked(f: fn~()) { +pub fn spawn_unlinked(f: ~fn()) { /*! * Creates a child task unlinked from the current one. If either this * task or the child task fails, the other will not be killed. @@ -480,7 +480,7 @@ pub fn spawn_unlinked(f: fn~()) { task().unlinked().spawn(f) } -pub fn spawn_supervised(f: fn~()) { +pub fn spawn_supervised(f: ~fn()) { /*! * Creates a child task unlinked from the current one. If either this * task or the child task fails, the other will not be killed. @@ -489,7 +489,7 @@ pub fn spawn_supervised(f: fn~()) { task().supervised().spawn(f) } -pub fn spawn_with(arg: A, f: fn~(v: A)) { +pub fn spawn_with(arg: A, f: ~fn(v: A)) { /*! * Runs a task, while transfering ownership of one argument to the * child. @@ -503,7 +503,7 @@ pub fn spawn_with(arg: A, f: fn~(v: A)) { task().spawn_with(arg, f) } -pub fn spawn_sched(mode: SchedMode, f: fn~()) { +pub fn spawn_sched(mode: SchedMode, f: ~fn()) { /*! * Creates a new task on a new or existing scheduler @@ -519,7 +519,7 @@ pub fn spawn_sched(mode: SchedMode, f: fn~()) { task().sched_mode(mode).spawn(f) } -pub fn try(f: fn~() -> T) -> Result { +pub fn try(f: ~fn() -> T) -> Result { /*! * Execute a function in another task and return either the return value * of the function or result::err. @@ -840,11 +840,12 @@ fn test_add_wrapper() { let ch = Wrapper { f: Some(ch) }; let b1 = do b0.add_wrapper |body| { let ch = Wrapper { f: Some(ch.f.swap_unwrap()) }; - fn~() { + let result: ~fn() = || { let ch = ch.f.swap_unwrap(); body(); ch.send(()); - } + }; + result }; do b1.spawn { } po.recv(); @@ -1015,7 +1016,7 @@ fn pingpong(po: &Port, ch: &Chan) { } #[cfg(test)] -fn avoid_copying_the_body(spawnfn: fn(v: fn~())) { +fn avoid_copying_the_body(spawnfn: &fn(v: ~fn())) { let (p, ch) = stream::(); let x = ~1; @@ -1164,7 +1165,7 @@ fn test_child_doesnt_ref_parent() { // (well, it would if the constant were 8000+ - I lowered it to be more // valgrind-friendly. try this at home, instead..!) const generations: uint = 16; - fn child_no(x: uint) -> fn~() { + fn child_no(x: uint) -> ~fn() { return || { if x < generations { task::spawn(child_no(x+1)); diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs index 6cc3657a32b4e106e3d7993f2f596a0ca99ba302..152e602eeee070902322b19d7961d60325358c8c 100644 --- a/src/libcore/task/spawn.rs +++ b/src/libcore/task/spawn.rs @@ -173,19 +173,19 @@ fn access_ancestors(x: &unstable::Exclusive, // taskgroups that forward_blk already ran on successfully (Note: bail_blk // is NOT called on the block that forward_blk broke on!). // (3) As a bonus, coalesces away all 'dead' taskgroup nodes in the list. -// FIXME(#2190): Change Option to Option, to save on +// FIXME(#2190): Change Option<@fn(...)> to Option<&fn(...)>, to save on // allocations. Once that bug is fixed, changing the sigil should suffice. fn each_ancestor(list: &mut AncestorList, - bail_opt: Option, - forward_blk: fn(TaskGroupInner) -> bool) - -> bool { + bail_opt: Option<@fn(TaskGroupInner)>, + forward_blk: fn(TaskGroupInner) -> bool) + -> bool { // "Kickoff" call - there was no last generation. return !coalesce(list, bail_opt, forward_blk, uint::max_value); // Recursively iterates, and coalesces afterwards if needed. Returns // whether or not unwinding is needed (i.e., !successful iteration). fn coalesce(list: &mut AncestorList, - bail_opt: Option, + bail_opt: Option<@fn(TaskGroupInner)>, forward_blk: fn(TaskGroupInner) -> bool, last_generation: uint) -> bool { // Need to swap the list out to use it, to appease borrowck. @@ -213,9 +213,10 @@ fn coalesce(list: &mut AncestorList, // True if the supplied block did 'break', here or in any recursive // calls. If so, must call the unwinder on all previous nodes. fn iterate(ancestors: &AncestorList, - bail_opt: Option, - forward_blk: fn(TaskGroupInner) -> bool, - last_generation: uint) -> (Option, bool) { + bail_opt: Option<@fn(TaskGroupInner)>, + forward_blk: &fn(TaskGroupInner) -> bool, + last_generation: uint) + -> (Option, bool) { // At each step of iteration, three booleans are at play which govern // how the iteration should behave. // 'nobe_is_dead' - Should the list should be coalesced at this point? @@ -532,7 +533,7 @@ fn share_ancestors(ancestors: &mut AncestorList) -> AncestorList { } } -pub fn spawn_raw(opts: TaskOpts, f: fn~()) { +pub fn spawn_raw(opts: TaskOpts, f: ~fn()) { let (child_tg, ancestors, is_main) = gen_child_taskgroup(opts.linked, opts.supervised); @@ -577,9 +578,10 @@ pub fn spawn_raw(opts: TaskOpts, f: fn~()) { fn make_child_wrapper(child: *rust_task, child_arc: TaskGroupArc, ancestors: AncestorList, is_main: bool, notify_chan: Option>, - f: fn~()) -> fn~() { + f: ~fn()) + -> ~fn() { let child_data = Cell((child_arc, ancestors)); - return fn~() { + let result: ~fn() = || { // Agh. Get move-mode items into the closure. FIXME (#2829) let mut (child_arc, ancestors) = child_data.take(); // Child task runs this code. @@ -613,6 +615,7 @@ fn make_child_wrapper(child: *rust_task, child_arc: TaskGroupArc, // FIXME #4428: Crashy. // unsafe { cleanup::annihilate(); } }; + return result; // Set up membership in taskgroup and descendantship in all ancestor // groups. If any enlistment fails, Some task was already failing, so diff --git a/src/libcore/unstable/finally.rs b/src/libcore/unstable/finally.rs index ff75963511c3806cced8bf47f7a970e2c67e6ad5..c995d914a7a65136d2dbff0b59a974c8a3b84440 100644 --- a/src/libcore/unstable/finally.rs +++ b/src/libcore/unstable/finally.rs @@ -79,9 +79,8 @@ fn test_fail() { #[test] fn test_retval() { - let i = do (fn&() -> int { - 10 - }).finally { }; + let closure: &fn() -> int = || 10; + let i = do closure.finally { }; assert i == 10; } diff --git a/src/libcore/unstable/weak_task.rs b/src/libcore/unstable/weak_task.rs index 0e1181f43dbc91c55ae7a25ccaa3f07cd2183aca..bff5e9750ec103cc973b371b9a968f405455f242 100644 --- a/src/libcore/unstable/weak_task.rs +++ b/src/libcore/unstable/weak_task.rs @@ -43,9 +43,9 @@ pub unsafe fn weaken_task(f: &fn(Port)) { // Expect the weak task service to be alive assert service.try_send(RegisterWeakTask(task, shutdown_chan)); unsafe { rust_dec_kernel_live_count(); } - do fn&() { + do (|| { f(shutdown_port.take()) - }.finally || { + }).finally || { unsafe { rust_inc_kernel_live_count(); } // Service my have already exited service.send(UnregisterWeakTask(task)); @@ -74,13 +74,13 @@ fn create_global_service() -> ~WeakTaskService { do task().unlinked().spawn { debug!("running global weak task service"); let port = Cell(port.take()); - do fn&() { + do (|| { let port = port.take(); // The weak task service is itself a weak task debug!("weakening the weak service task"); unsafe { rust_dec_kernel_live_count(); } run_weak_task_service(port); - }.finally { + }).finally { debug!("unweakening the weak service task"); unsafe { rust_inc_kernel_live_count(); } }