Skip to content

Commit 2a01674

Browse files
committed
libcore: Remove fn@, fn~, and fn& from libcore. rs=defun
1 parent a9295f2 commit 2a01674

File tree

7 files changed

+51
-54
lines changed

7 files changed

+51
-54
lines changed

src/libcore/io.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ pub mod fsync {
11391139
pub struct Arg<t> {
11401140
val: t,
11411141
opt_level: Option<Level>,
1142-
fsync_fn: fn@(f: t, Level) -> int,
1142+
fsync_fn: @fn(f: t, Level) -> int,
11431143
}
11441144

11451145
// fsync file after executing blk
@@ -1150,9 +1150,9 @@ pub mod fsync {
11501150
unsafe {
11511151
blk(Res(Arg {
11521152
val: file.f, opt_level: opt_level,
1153-
fsync_fn: fn@(file: *libc::FILE, l: Level) -> int {
1153+
fsync_fn: |file, l| {
11541154
unsafe {
1155-
return os::fsync_fd(libc::fileno(file), l) as int;
1155+
os::fsync_fd(libc::fileno(file), l) as int
11561156
}
11571157
}
11581158
}));
@@ -1164,9 +1164,7 @@ pub mod fsync {
11641164
blk: fn(v: Res<fd_t>)) {
11651165
blk(Res(Arg {
11661166
val: fd.fd, opt_level: opt_level,
1167-
fsync_fn: fn@(fd: fd_t, l: Level) -> int {
1168-
return os::fsync_fd(fd, l) as int;
1169-
}
1167+
fsync_fn: |fd, l| os::fsync_fd(fd, l) as int
11701168
}));
11711169
}
11721170

@@ -1178,9 +1176,7 @@ pub mod fsync {
11781176
blk: fn(v: Res<FSyncable>)) {
11791177
blk(Res(Arg {
11801178
val: o, opt_level: opt_level,
1181-
fsync_fn: fn@(o: FSyncable, l: Level) -> int {
1182-
return o.fsync(l);
1183-
}
1179+
fsync_fn: |o, l| o.fsync(l)
11841180
}));
11851181
}
11861182
}

src/libcore/pipes.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -910,11 +910,10 @@ endpoint is passed to the new task.
910910
911911
*/
912912
pub fn spawn_service<T:Owned,Tb:Owned>(
913-
init: extern fn() -> (SendPacketBuffered<T, Tb>,
914-
RecvPacketBuffered<T, Tb>),
915-
service: fn~(v: RecvPacketBuffered<T, Tb>))
916-
-> SendPacketBuffered<T, Tb>
917-
{
913+
init: extern fn() -> (SendPacketBuffered<T, Tb>,
914+
RecvPacketBuffered<T, Tb>),
915+
service: ~fn(v: RecvPacketBuffered<T, Tb>))
916+
-> SendPacketBuffered<T, Tb> {
918917
let (client, server) = init();
919918
920919
// This is some nasty gymnastics required to safely move the pipe
@@ -932,11 +931,10 @@ receive state.
932931
933932
*/
934933
pub fn spawn_service_recv<T:Owned,Tb:Owned>(
935-
init: extern fn() -> (RecvPacketBuffered<T, Tb>,
936-
SendPacketBuffered<T, Tb>),
937-
service: fn~(v: SendPacketBuffered<T, Tb>))
938-
-> RecvPacketBuffered<T, Tb>
939-
{
934+
init: extern fn() -> (RecvPacketBuffered<T, Tb>,
935+
SendPacketBuffered<T, Tb>),
936+
service: ~fn(v: SendPacketBuffered<T, Tb>))
937+
-> RecvPacketBuffered<T, Tb> {
940938
let (client, server) = init();
941939
942940
// This is some nasty gymnastics required to safely move the pipe

src/libcore/reflect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,9 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
489489
}
490490

491491
fn visit_closure_ptr(&self, ck: uint) -> bool {
492-
self.align_to::<fn@()>();
492+
self.align_to::<@fn()>();
493493
if ! self.inner.visit_closure_ptr(ck) { return false; }
494-
self.bump_past::<fn@()>();
494+
self.bump_past::<@fn()>();
495495
true
496496
}
497497
}

src/libcore/task/mod.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pub struct TaskOpts {
191191
// FIXME (#3724): Replace the 'consumed' bit with move mode on self
192192
pub struct TaskBuilder {
193193
opts: TaskOpts,
194-
gen_body: fn@(v: fn~()) -> fn~(),
194+
gen_body: @fn(v: ~fn()) -> ~fn(),
195195
can_not_copy: Option<util::NonCopyable>,
196196
mut consumed: bool,
197197
}
@@ -357,7 +357,7 @@ pub impl TaskBuilder {
357357
* generator by applying the task body which results from the
358358
* existing body generator to the new body generator.
359359
*/
360-
fn add_wrapper(wrapper: fn@(v: fn~()) -> fn~()) -> TaskBuilder {
360+
fn add_wrapper(wrapper: @fn(v: ~fn()) -> ~fn()) -> TaskBuilder {
361361
let prev_gen_body = self.gen_body;
362362
let notify_chan = replace(&mut self.opts.notify_chan, None);
363363
TaskBuilder {
@@ -385,7 +385,7 @@ pub impl TaskBuilder {
385385
* When spawning into a new scheduler, the number of threads requested
386386
* must be greater than zero.
387387
*/
388-
fn spawn(f: fn~()) {
388+
fn spawn(f: ~fn()) {
389389
let notify_chan = replace(&mut self.opts.notify_chan, None);
390390
let x = self.consume();
391391
let opts = TaskOpts {
@@ -397,7 +397,7 @@ pub impl TaskBuilder {
397397
spawn::spawn_raw(opts, (x.gen_body)(f));
398398
}
399399
/// Runs a task, while transfering ownership of one argument to the child.
400-
fn spawn_with<A:Owned>(arg: A, f: fn~(v: A)) {
400+
fn spawn_with<A:Owned>(arg: A, f: ~fn(v: A)) {
401401
let arg = Cell(arg);
402402
do self.spawn {
403403
f(arg.take());
@@ -417,7 +417,7 @@ pub impl TaskBuilder {
417417
* # Failure
418418
* Fails if a future_result was already set for this task.
419419
*/
420-
fn try<T:Owned>(f: fn~() -> T) -> Result<T,()> {
420+
fn try<T:Owned>(f: ~fn() -> T) -> Result<T,()> {
421421
let (po, ch) = stream::<T>();
422422
let mut result = None;
423423
@@ -458,7 +458,7 @@ pub fn default_task_opts() -> TaskOpts {
458458
459459
/* Spawn convenience functions */
460460
461-
pub fn spawn(f: fn~()) {
461+
pub fn spawn(f: ~fn()) {
462462
/*!
463463
* Creates and executes a new child task
464464
*
@@ -471,7 +471,7 @@ pub fn spawn(f: fn~()) {
471471
task().spawn(f)
472472
}
473473
474-
pub fn spawn_unlinked(f: fn~()) {
474+
pub fn spawn_unlinked(f: ~fn()) {
475475
/*!
476476
* Creates a child task unlinked from the current one. If either this
477477
* task or the child task fails, the other will not be killed.
@@ -480,7 +480,7 @@ pub fn spawn_unlinked(f: fn~()) {
480480
task().unlinked().spawn(f)
481481
}
482482
483-
pub fn spawn_supervised(f: fn~()) {
483+
pub fn spawn_supervised(f: ~fn()) {
484484
/*!
485485
* Creates a child task unlinked from the current one. If either this
486486
* task or the child task fails, the other will not be killed.
@@ -489,7 +489,7 @@ pub fn spawn_supervised(f: fn~()) {
489489
task().supervised().spawn(f)
490490
}
491491
492-
pub fn spawn_with<A:Owned>(arg: A, f: fn~(v: A)) {
492+
pub fn spawn_with<A:Owned>(arg: A, f: ~fn(v: A)) {
493493
/*!
494494
* Runs a task, while transfering ownership of one argument to the
495495
* child.
@@ -503,7 +503,7 @@ pub fn spawn_with<A:Owned>(arg: A, f: fn~(v: A)) {
503503
task().spawn_with(arg, f)
504504
}
505505
506-
pub fn spawn_sched(mode: SchedMode, f: fn~()) {
506+
pub fn spawn_sched(mode: SchedMode, f: ~fn()) {
507507
/*!
508508
* Creates a new task on a new or existing scheduler
509509
@@ -519,7 +519,7 @@ pub fn spawn_sched(mode: SchedMode, f: fn~()) {
519519
task().sched_mode(mode).spawn(f)
520520
}
521521
522-
pub fn try<T:Owned>(f: fn~() -> T) -> Result<T,()> {
522+
pub fn try<T:Owned>(f: ~fn() -> T) -> Result<T,()> {
523523
/*!
524524
* Execute a function in another task and return either the return value
525525
* of the function or result::err.
@@ -840,11 +840,12 @@ fn test_add_wrapper() {
840840
let ch = Wrapper { f: Some(ch) };
841841
let b1 = do b0.add_wrapper |body| {
842842
let ch = Wrapper { f: Some(ch.f.swap_unwrap()) };
843-
fn~() {
843+
let result: ~fn() = || {
844844
let ch = ch.f.swap_unwrap();
845845
body();
846846
ch.send(());
847-
}
847+
};
848+
result
848849
};
849850
do b1.spawn { }
850851
po.recv();
@@ -1015,7 +1016,7 @@ fn test_spawn_sched_blocking() {
10151016
}
10161017

10171018
#[cfg(test)]
1018-
fn avoid_copying_the_body(spawnfn: fn(v: fn~())) {
1019+
fn avoid_copying_the_body(spawnfn: &fn(v: ~fn())) {
10191020
let (p, ch) = stream::<uint>();
10201021

10211022
let x = ~1;
@@ -1164,7 +1165,7 @@ fn test_child_doesnt_ref_parent() {
11641165
// (well, it would if the constant were 8000+ - I lowered it to be more
11651166
// valgrind-friendly. try this at home, instead..!)
11661167
const generations: uint = 16;
1167-
fn child_no(x: uint) -> fn~() {
1168+
fn child_no(x: uint) -> ~fn() {
11681169
return || {
11691170
if x < generations {
11701171
task::spawn(child_no(x+1));

src/libcore/task/spawn.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,19 @@ fn access_ancestors<U>(x: &unstable::Exclusive<AncestorNode>,
173173
// taskgroups that forward_blk already ran on successfully (Note: bail_blk
174174
// is NOT called on the block that forward_blk broke on!).
175175
// (3) As a bonus, coalesces away all 'dead' taskgroup nodes in the list.
176-
// FIXME(#2190): Change Option<fn@(...)> to Option<fn&(...)>, to save on
176+
// FIXME(#2190): Change Option<@fn(...)> to Option<&fn(...)>, to save on
177177
// allocations. Once that bug is fixed, changing the sigil should suffice.
178178
fn each_ancestor(list: &mut AncestorList,
179-
bail_opt: Option<fn@(TaskGroupInner)>,
180-
forward_blk: fn(TaskGroupInner) -> bool)
181-
-> bool {
179+
bail_opt: Option<@fn(TaskGroupInner)>,
180+
forward_blk: fn(TaskGroupInner) -> bool)
181+
-> bool {
182182
// "Kickoff" call - there was no last generation.
183183
return !coalesce(list, bail_opt, forward_blk, uint::max_value);
184184

185185
// Recursively iterates, and coalesces afterwards if needed. Returns
186186
// whether or not unwinding is needed (i.e., !successful iteration).
187187
fn coalesce(list: &mut AncestorList,
188-
bail_opt: Option<fn@(TaskGroupInner)>,
188+
bail_opt: Option<@fn(TaskGroupInner)>,
189189
forward_blk: fn(TaskGroupInner) -> bool,
190190
last_generation: uint) -> bool {
191191
// Need to swap the list out to use it, to appease borrowck.
@@ -213,9 +213,10 @@ fn each_ancestor(list: &mut AncestorList,
213213
// True if the supplied block did 'break', here or in any recursive
214214
// calls. If so, must call the unwinder on all previous nodes.
215215
fn iterate(ancestors: &AncestorList,
216-
bail_opt: Option<fn@(TaskGroupInner)>,
217-
forward_blk: fn(TaskGroupInner) -> bool,
218-
last_generation: uint) -> (Option<AncestorList>, bool) {
216+
bail_opt: Option<@fn(TaskGroupInner)>,
217+
forward_blk: &fn(TaskGroupInner) -> bool,
218+
last_generation: uint)
219+
-> (Option<AncestorList>, bool) {
219220
// At each step of iteration, three booleans are at play which govern
220221
// how the iteration should behave.
221222
// 'nobe_is_dead' - Should the list should be coalesced at this point?
@@ -532,7 +533,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
532533
}
533534
}
534535

535-
pub fn spawn_raw(opts: TaskOpts, f: fn~()) {
536+
pub fn spawn_raw(opts: TaskOpts, f: ~fn()) {
536537
let (child_tg, ancestors, is_main) =
537538
gen_child_taskgroup(opts.linked, opts.supervised);
538539

@@ -577,9 +578,10 @@ pub fn spawn_raw(opts: TaskOpts, f: fn~()) {
577578
fn make_child_wrapper(child: *rust_task, child_arc: TaskGroupArc,
578579
ancestors: AncestorList, is_main: bool,
579580
notify_chan: Option<Chan<TaskResult>>,
580-
f: fn~()) -> fn~() {
581+
f: ~fn())
582+
-> ~fn() {
581583
let child_data = Cell((child_arc, ancestors));
582-
return fn~() {
584+
let result: ~fn() = || {
583585
// Agh. Get move-mode items into the closure. FIXME (#2829)
584586
let mut (child_arc, ancestors) = child_data.take();
585587
// Child task runs this code.
@@ -613,6 +615,7 @@ pub fn spawn_raw(opts: TaskOpts, f: fn~()) {
613615
// FIXME #4428: Crashy.
614616
// unsafe { cleanup::annihilate(); }
615617
};
618+
return result;
616619

617620
// Set up membership in taskgroup and descendantship in all ancestor
618621
// groups. If any enlistment fails, Some task was already failing, so

src/libcore/unstable/finally.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ fn test_fail() {
7979

8080
#[test]
8181
fn test_retval() {
82-
let i = do (fn&() -> int {
83-
10
84-
}).finally { };
82+
let closure: &fn() -> int = || 10;
83+
let i = do closure.finally { };
8584
assert i == 10;
8685
}
8786

src/libcore/unstable/weak_task.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ pub unsafe fn weaken_task(f: &fn(Port<ShutdownMsg>)) {
4343
// Expect the weak task service to be alive
4444
assert service.try_send(RegisterWeakTask(task, shutdown_chan));
4545
unsafe { rust_dec_kernel_live_count(); }
46-
do fn&() {
46+
do (|| {
4747
f(shutdown_port.take())
48-
}.finally || {
48+
}).finally || {
4949
unsafe { rust_inc_kernel_live_count(); }
5050
// Service my have already exited
5151
service.send(UnregisterWeakTask(task));
@@ -74,13 +74,13 @@ fn create_global_service() -> ~WeakTaskService {
7474
do task().unlinked().spawn {
7575
debug!("running global weak task service");
7676
let port = Cell(port.take());
77-
do fn&() {
77+
do (|| {
7878
let port = port.take();
7979
// The weak task service is itself a weak task
8080
debug!("weakening the weak service task");
8181
unsafe { rust_dec_kernel_live_count(); }
8282
run_weak_task_service(port);
83-
}.finally {
83+
}).finally {
8484
debug!("unweakening the weak service task");
8585
unsafe { rust_inc_kernel_live_count(); }
8686
}

0 commit comments

Comments
 (0)