Skip to content

Commit 632b6fe

Browse files
committed
libstd: Change all ~fn()s to procs in the standard library.
This makes `Cell`s no longer necessary in most cases.
1 parent 6c8b702 commit 632b6fe

File tree

13 files changed

+92
-82
lines changed

13 files changed

+92
-82
lines changed

src/libstd/io/net/unix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ mod tests {
157157
use io::*;
158158
use rt::comm::oneshot;
159159

160-
fn smalltest(server: ~fn(UnixStream), client: ~fn(UnixStream)) {
160+
fn smalltest(server: proc(UnixStream), client: proc(UnixStream)) {
161161
let server = Cell::new(server);
162162
let client = Cell::new(client);
163163
do run_in_mt_newsched_task {

src/libstd/reflect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,11 +478,11 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
478478
}
479479

480480
fn visit_closure_ptr(&mut self, ck: uint) -> bool {
481-
self.align_to::<~fn()>();
481+
self.align_to::<proc()>();
482482
if ! self.inner.visit_closure_ptr(ck) {
483483
return false
484484
}
485-
self.bump_past::<~fn()>();
485+
self.bump_past::<proc()>();
486486
true
487487
}
488488
}

src/libstd/rt/context.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub static RED_ZONE: uint = 20 * 1024;
2525
// then misalign the regs again.
2626
pub struct Context {
2727
/// The context entry point, saved here for later destruction
28-
priv start: Option<~~fn()>,
28+
priv start: Option<~proc()>,
2929
/// Hold the registers while the task or scheduler is suspended
3030
priv regs: ~Registers,
3131
/// Lower bound and upper bound for the stack
@@ -41,18 +41,24 @@ impl Context {
4141
}
4242
}
4343

44-
/// Create a new context that will resume execution by running ~fn()
45-
pub fn new(start: ~fn(), stack: &mut StackSegment) -> Context {
44+
/// Create a new context that will resume execution by running proc()
45+
pub fn new(start: proc(), stack: &mut StackSegment) -> Context {
4646
// FIXME #7767: Putting main into a ~ so it's a thin pointer and can
4747
// be passed to the spawn function. Another unfortunate
4848
// allocation
4949
let start = ~start;
5050

5151
// The C-ABI function that is the task entry point
52-
extern fn task_start_wrapper(f: &~fn()) { (*f)() }
52+
extern fn task_start_wrapper(f: &proc()) {
53+
// XXX(pcwalton): This may be sketchy.
54+
unsafe {
55+
let f: &|| = transmute(f);
56+
(*f)()
57+
}
58+
}
5359

5460
let fp: *c_void = task_start_wrapper as *c_void;
55-
let argp: *c_void = unsafe { transmute::<&~fn(), *c_void>(&*start) };
61+
let argp: *c_void = unsafe { transmute::<&proc(), *c_void>(&*start) };
5662
let sp: *uint = stack.end();
5763
let sp: *mut uint = unsafe { transmute_mut_unsafe(sp) };
5864
// Save and then immediately load the current context,

src/libstd/rt/kill.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ see a failure from the grandchild task. While we could achieve this by having
110110
each intermediate task block on its handle, this keeps around the other resources
111111
the task was using. To be more efficient, this is accomplished via "tombstones".
112112
113-
A tombstone is a closure, ~fn() -> bool, which will perform any waiting necessary
113+
A tombstone is a closure, proc() -> bool, which will perform any waiting necessary
114114
to collect the exit code of descendant tasks. In its environment is captured
115115
the KillHandle of whichever task created the tombstone, and perhaps also any
116116
tombstones that that task itself had, and finally also another tombstone,
@@ -205,7 +205,7 @@ struct KillHandleInner {
205205
// Locklessly accessed; protected by the enclosing refcount's barriers.
206206
any_child_failed: bool,
207207
// A lazy list, consuming which may unwrap() many child tombstones.
208-
child_tombstones: Option<~fn() -> bool>,
208+
child_tombstones: Option<proc() -> bool>,
209209
// Protects multiple children simultaneously creating tombstones.
210210
graveyard_lock: LittleLock,
211211
}
@@ -223,7 +223,7 @@ pub struct Death {
223223
priv watching_parent: Option<KillHandle>,
224224
// Action to be done with the exit code. If set, also makes the task wait
225225
// until all its watched children exit before collecting the status.
226-
on_exit: Option<~fn(UnwindResult)>,
226+
on_exit: Option<proc(UnwindResult)>,
227227
// nesting level counter for task::unkillable calls (0 == killable).
228228
priv unkillable: int,
229229
// nesting level counter for unstable::atomically calls (0 == can deschedule).
@@ -525,7 +525,8 @@ impl KillHandle {
525525
// NB: Takes a pthread mutex -- 'blk' not allowed to reschedule.
526526
#[inline]
527527
fn add_lazy_tombstone(parent: &mut KillHandle,
528-
blk: &fn(Option<~fn() -> bool>) -> ~fn() -> bool) {
528+
blk: &fn(Option<proc() -> bool>)
529+
-> proc() -> bool) {
529530

530531
let inner: &mut KillHandleInner = unsafe { &mut *parent.get() };
531532
unsafe {

src/libstd/rt/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ pub mod borrowck;
207207
/// # Return value
208208
///
209209
/// The return value is used as the process return code. 0 on success, 101 on error.
210-
pub fn start(argc: int, argv: **u8, main: ~fn()) -> int {
210+
pub fn start(argc: int, argv: **u8, main: proc()) -> int {
211211

212212
init(argc, argv);
213213
let exit_code = run(main);
@@ -221,7 +221,7 @@ pub fn start(argc: int, argv: **u8, main: ~fn()) -> int {
221221
///
222222
/// This is appropriate for running code that must execute on the main thread,
223223
/// such as the platform event loop and GUI.
224-
pub fn start_on_main_thread(argc: int, argv: **u8, main: ~fn()) -> int {
224+
pub fn start_on_main_thread(argc: int, argv: **u8, main: proc()) -> int {
225225
init(argc, argv);
226226
let exit_code = run_on_main_thread(main);
227227
cleanup();
@@ -254,15 +254,15 @@ pub fn cleanup() {
254254
/// Configures the runtime according to the environment, by default
255255
/// using a task scheduler with the same number of threads as cores.
256256
/// Returns a process exit code.
257-
pub fn run(main: ~fn()) -> int {
257+
pub fn run(main: proc()) -> int {
258258
run_(main, false)
259259
}
260260

261-
pub fn run_on_main_thread(main: ~fn()) -> int {
261+
pub fn run_on_main_thread(main: proc()) -> int {
262262
run_(main, true)
263263
}
264264

265-
fn run_(main: ~fn(), use_main_sched: bool) -> int {
265+
fn run_(main: proc(), use_main_sched: bool) -> int {
266266
static DEFAULT_ERROR_CODE: int = 101;
267267

268268
let nscheds = util::default_sched_threads();
@@ -341,7 +341,7 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int {
341341
// When the main task exits, after all the tasks in the main
342342
// task tree, shut down the schedulers and set the exit code.
343343
let handles = Cell::new(handles);
344-
let on_exit: ~fn(UnwindResult) = |exit_success| {
344+
let on_exit: proc(UnwindResult) = |exit_success| {
345345
unsafe {
346346
assert!(!(*exited_already.get()).swap(true, SeqCst),
347347
"the runtime already exited");

src/libstd/rt/sched.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,9 @@ mod test {
990990
assert!(Task::on_appropriate_sched());
991991
};
992992

993-
let on_exit: ~fn(UnwindResult) = |exit_status| rtassert!(exit_status.is_success());
993+
let on_exit: proc(UnwindResult) = |exit_status| {
994+
rtassert!(exit_status.is_success())
995+
};
994996
task.death.on_exit = Some(on_exit);
995997

996998
sched.bootstrap(task);

src/libstd/rt/task.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ impl Task {
139139

140140
// A helper to build a new task using the dynamically found
141141
// scheduler and task. Only works in GreenTask context.
142-
pub fn build_homed_child(stack_size: Option<uint>, f: ~fn(), home: SchedHome) -> ~Task {
142+
pub fn build_homed_child(stack_size: Option<uint>,
143+
f: proc(),
144+
home: SchedHome)
145+
-> ~Task {
143146
let f = Cell::new(f);
144147
let home = Cell::new(home);
145148
do Local::borrow |running_task: &mut Task| {
@@ -153,11 +156,14 @@ impl Task {
153156
}
154157
}
155158

156-
pub fn build_child(stack_size: Option<uint>, f: ~fn()) -> ~Task {
159+
pub fn build_child(stack_size: Option<uint>, f: proc()) -> ~Task {
157160
Task::build_homed_child(stack_size, f, AnySched)
158161
}
159162

160-
pub fn build_homed_root(stack_size: Option<uint>, f: ~fn(), home: SchedHome) -> ~Task {
163+
pub fn build_homed_root(stack_size: Option<uint>,
164+
f: proc(),
165+
home: SchedHome)
166+
-> ~Task {
161167
let f = Cell::new(f);
162168
let home = Cell::new(home);
163169
do Local::borrow |running_task: &mut Task| {
@@ -171,7 +177,7 @@ impl Task {
171177
}
172178
}
173179

174-
pub fn build_root(stack_size: Option<uint>, f: ~fn()) -> ~Task {
180+
pub fn build_root(stack_size: Option<uint>, f: proc()) -> ~Task {
175181
Task::build_homed_root(stack_size, f, AnySched)
176182
}
177183

@@ -196,21 +202,21 @@ impl Task {
196202

197203
pub fn new_root(stack_pool: &mut StackPool,
198204
stack_size: Option<uint>,
199-
start: ~fn()) -> Task {
205+
start: proc()) -> Task {
200206
Task::new_root_homed(stack_pool, stack_size, AnySched, start)
201207
}
202208

203209
pub fn new_child(&mut self,
204210
stack_pool: &mut StackPool,
205211
stack_size: Option<uint>,
206-
start: ~fn()) -> Task {
212+
start: proc()) -> Task {
207213
self.new_child_homed(stack_pool, stack_size, AnySched, start)
208214
}
209215

210216
pub fn new_root_homed(stack_pool: &mut StackPool,
211217
stack_size: Option<uint>,
212218
home: SchedHome,
213-
start: ~fn()) -> Task {
219+
start: proc()) -> Task {
214220
Task {
215221
heap: LocalHeap::new(),
216222
gc: GarbageCollector,
@@ -233,7 +239,7 @@ impl Task {
233239
stack_pool: &mut StackPool,
234240
stack_size: Option<uint>,
235241
home: SchedHome,
236-
start: ~fn()) -> Task {
242+
start: proc()) -> Task {
237243
Task {
238244
heap: LocalHeap::new(),
239245
gc: GarbageCollector,
@@ -404,7 +410,10 @@ impl Drop for Task {
404410

405411
impl Coroutine {
406412

407-
pub fn new(stack_pool: &mut StackPool, stack_size: Option<uint>, start: ~fn()) -> Coroutine {
413+
pub fn new(stack_pool: &mut StackPool,
414+
stack_size: Option<uint>,
415+
start: proc())
416+
-> Coroutine {
408417
let stack_size = match stack_size {
409418
Some(size) => size,
410419
None => env::min_stack()
@@ -425,9 +434,9 @@ impl Coroutine {
425434
}
426435
}
427436

428-
fn build_start_wrapper(start: ~fn()) -> ~fn() {
437+
fn build_start_wrapper(start: proc()) -> proc() {
429438
let start_cell = Cell::new(start);
430-
let wrapper: ~fn() = || {
439+
let wrapper: proc() = || {
431440
// First code after swap to this new context. Run our
432441
// cleanup job.
433442
unsafe {

src/libstd/rt/test.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,28 @@ pub fn new_test_sched() -> Scheduler {
6565
return sched;
6666
}
6767

68-
pub fn run_in_uv_task(f: ~fn()) {
68+
pub fn run_in_uv_task(f: proc()) {
6969
let f = Cell::new(f);
7070
do run_in_bare_thread {
7171
run_in_uv_task_core(f.take());
7272
}
7373
}
7474

75-
pub fn run_in_newsched_task(f: ~fn()) {
75+
pub fn run_in_newsched_task(f: proc()) {
7676
let f = Cell::new(f);
7777
do run_in_bare_thread {
7878
run_in_newsched_task_core(f.take());
7979
}
8080
}
8181

82-
pub fn run_in_uv_task_core(f: ~fn()) {
82+
pub fn run_in_uv_task_core(f: proc()) {
8383

8484
use rt::sched::Shutdown;
8585

8686
let mut sched = ~new_test_uv_sched();
8787
let exit_handle = Cell::new(sched.make_handle());
8888

89-
let on_exit: ~fn(UnwindResult) = |exit_status| {
89+
let on_exit: proc(UnwindResult) = |exit_status| {
9090
exit_handle.take().send(Shutdown);
9191
rtassert!(exit_status.is_success());
9292
};
@@ -96,13 +96,13 @@ pub fn run_in_uv_task_core(f: ~fn()) {
9696
sched.bootstrap(task);
9797
}
9898

99-
pub fn run_in_newsched_task_core(f: ~fn()) {
99+
pub fn run_in_newsched_task_core(f: proc()) {
100100
use rt::sched::Shutdown;
101101

102102
let mut sched = ~new_test_sched();
103103
let exit_handle = Cell::new(sched.make_handle());
104104

105-
let on_exit: ~fn(UnwindResult) = |exit_status| {
105+
let on_exit: proc(UnwindResult) = |exit_status| {
106106
exit_handle.take().send(Shutdown);
107107
rtassert!(exit_status.is_success());
108108
};
@@ -196,7 +196,7 @@ pub fn prepare_for_lots_of_tests() {
196196
/// Create more than one scheduler and run a function in a task
197197
/// in one of the schedulers. The schedulers will stay alive
198198
/// until the function `f` returns.
199-
pub fn run_in_mt_newsched_task(f: ~fn()) {
199+
pub fn run_in_mt_newsched_task(f: proc()) {
200200
use os;
201201
use from_str::FromStr;
202202
use rt::sched::Shutdown;
@@ -246,7 +246,7 @@ pub fn run_in_mt_newsched_task(f: ~fn()) {
246246
}
247247

248248
let handles = Cell::new(handles);
249-
let on_exit: ~fn(UnwindResult) = |exit_status| {
249+
let on_exit: proc(UnwindResult) = |exit_status| {
250250
let mut handles = handles.take();
251251
// Tell schedulers to exit
252252
for handle in handles.mut_iter() {
@@ -295,16 +295,16 @@ pub fn run_in_mt_newsched_task(f: ~fn()) {
295295
}
296296

297297
/// Test tasks will abort on failure instead of unwinding
298-
pub fn spawntask(f: ~fn()) {
298+
pub fn spawntask(f: proc()) {
299299
Scheduler::run_task(Task::build_child(None, f));
300300
}
301301

302302
/// Create a new task and run it right now. Aborts on failure
303-
pub fn spawntask_later(f: ~fn()) {
303+
pub fn spawntask_later(f: proc()) {
304304
Scheduler::run_task_later(Task::build_child(None, f));
305305
}
306306

307-
pub fn spawntask_random(f: ~fn()) {
307+
pub fn spawntask_random(f: proc()) {
308308
use rand::{Rand, rng};
309309

310310
let mut rng = rng();
@@ -317,11 +317,11 @@ pub fn spawntask_random(f: ~fn()) {
317317
}
318318
}
319319

320-
pub fn spawntask_try(f: ~fn()) -> Result<(),()> {
320+
pub fn spawntask_try(f: proc()) -> Result<(),()> {
321321

322322
let (port, chan) = oneshot();
323323
let chan = Cell::new(chan);
324-
let on_exit: ~fn(UnwindResult) = |exit_status| chan.take().send(exit_status);
324+
let on_exit: proc(UnwindResult) = |exit_status| chan.take().send(exit_status);
325325

326326
let mut new_task = Task::build_root(None, f);
327327
new_task.death.on_exit = Some(on_exit);
@@ -334,7 +334,7 @@ pub fn spawntask_try(f: ~fn()) -> Result<(),()> {
334334
}
335335

336336
/// Spawn a new task in a new scheduler and return a thread handle.
337-
pub fn spawntask_thread(f: ~fn()) -> Thread {
337+
pub fn spawntask_thread(f: proc()) -> Thread {
338338

339339
let f = Cell::new(f);
340340

@@ -346,7 +346,7 @@ pub fn spawntask_thread(f: ~fn()) -> Thread {
346346
}
347347

348348
/// Get a ~Task for testing purposes other than actually scheduling it.
349-
pub fn with_test_task(blk: ~fn(~Task) -> ~Task) {
349+
pub fn with_test_task(blk: proc(~Task) -> ~Task) {
350350
do run_in_bare_thread {
351351
let mut sched = ~new_test_sched();
352352
let task = blk(~Task::new_root(&mut sched.stack_pool, None, ||{}));

0 commit comments

Comments
 (0)