提交 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>{
pub struct Arg<t> {
val: t,
opt_level: Option<Level>,
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<Level>,
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<Level>,
blk: fn(v: Res<fd_t>)) {
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<Level>,
blk: fn(v: Res<FSyncable>)) {
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)
}));
}
}
......
......@@ -910,11 +910,10 @@ pub fn entangle<T>() -> (SendPacket<T>, RecvPacket<T>) {
*/
pub fn spawn_service<T:Owned,Tb:Owned>(
init: extern fn() -> (SendPacketBuffered<T, Tb>,
RecvPacketBuffered<T, Tb>),
service: fn~(v: RecvPacketBuffered<T, Tb>))
-> SendPacketBuffered<T, Tb>
{
init: extern fn() -> (SendPacketBuffered<T, Tb>,
RecvPacketBuffered<T, Tb>),
service: ~fn(v: RecvPacketBuffered<T, Tb>))
-> SendPacketBuffered<T, Tb> {
let (client, server) = init();
// This is some nasty gymnastics required to safely move the pipe
......@@ -932,11 +931,10 @@ pub fn spawn_service<T:Owned,Tb:Owned>(
*/
pub fn spawn_service_recv<T:Owned,Tb:Owned>(
init: extern fn() -> (RecvPacketBuffered<T, Tb>,
SendPacketBuffered<T, Tb>),
service: fn~(v: SendPacketBuffered<T, Tb>))
-> RecvPacketBuffered<T, Tb>
{
init: extern fn() -> (RecvPacketBuffered<T, Tb>,
SendPacketBuffered<T, Tb>),
service: ~fn(v: SendPacketBuffered<T, Tb>))
-> RecvPacketBuffered<T, Tb> {
let (client, server) = init();
// This is some nasty gymnastics required to safely move the pipe
......
......@@ -489,9 +489,9 @@ fn visit_constr(&self, inner: *TyDesc) -> 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; }
self.bump_past::<fn@()>();
self.bump_past::<@fn()>();
true
}
}
......@@ -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<util::NonCopyable>,
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<A:Owned>(arg: A, f: fn~(v: A)) {
fn spawn_with<A:Owned>(arg: A, f: ~fn(v: A)) {
let arg = Cell(arg);
do self.spawn {
f(arg.take());
......@@ -417,7 +417,7 @@ fn spawn_with<A:Owned>(arg: A, f: fn~(v: A)) {
* # Failure
* 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 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<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
* child.
......@@ -503,7 +503,7 @@ pub fn spawn_with<A:Owned>(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<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
* 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<int>, ch: &Chan<int>) {
}
#[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 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));
......
......@@ -173,19 +173,19 @@ fn access_ancestors<U>(x: &unstable::Exclusive<AncestorNode>,
// 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<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.
fn each_ancestor(list: &mut AncestorList,
bail_opt: Option<fn@(TaskGroupInner)>,
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<fn@(TaskGroupInner)>,
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<fn@(TaskGroupInner)>,
forward_blk: fn(TaskGroupInner) -> bool,
last_generation: uint) -> (Option<AncestorList>, bool) {
bail_opt: Option<@fn(TaskGroupInner)>,
forward_blk: &fn(TaskGroupInner) -> bool,
last_generation: uint)
-> (Option<AncestorList>, 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<Chan<TaskResult>>,
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
......
......@@ -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;
}
......
......@@ -43,9 +43,9 @@ pub unsafe fn weaken_task(f: &fn(Port<ShutdownMsg>)) {
// 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(); }
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册