提交 542119f6 编写于 作者: P Patrick Walton

libcore: Remove `fn@`, `fn~`, and `fn&` from libcore. rs=defun

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