Skip to content

Commit f4c22f7

Browse files
committed
auto merge of #10561 : pcwalton/rust/procify, r=alexcrichton
r? @alexcrichton
2 parents f5f5d5a + f977bed commit f4c22f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+186
-265
lines changed

doc/po/ja/tutorial-tasks.md.po

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ msgstr ""
213213
#. type: Plain text
214214
#: doc/tutorial-tasks.md:102
215215
msgid ""
216-
"The `spawn` function has a very simple type signature: `fn spawn(f: ~fn())`. "
216+
"The `spawn` function has a very simple type signature: `fn spawn(f: proc())`. "
217217
"Because it accepts only owned closures, and owned closures contain only "
218218
"owned data, `spawn` can safely move the entire closure and all its "
219219
"associated state into an entirely different task for execution. Like any "

doc/po/ja/tutorial.md.po

+4-4
Original file line numberDiff line numberDiff line change
@@ -3509,13 +3509,13 @@ msgstr "## 所有クロージャ"
35093509
#. type: Plain text
35103510
#: doc/tutorial.md:1510
35113511
msgid ""
3512-
"Owned closures, written `~fn` in analogy to the `~` pointer type, hold on to "
3512+
"Owned closures, written `proc`, hold on to "
35133513
"things that can safely be sent between processes. They copy the values they "
35143514
"close over, much like managed closures, but they also own them: that is, no "
35153515
"other code can access them. Owned closures are used in concurrent code, "
35163516
"particularly for spawning [tasks][tasks]."
35173517
msgstr ""
3518-
"`~` ポインタ型と同様に `~fn` 型 で書き表される所有クロージャは安全にプロセス"
3518+
"`~` `proc` で書き表される所有クロージャは安全にプロセス"
35193519
"間で送信することができます。所有クローじゃはマネージドクロージャと全く同じよ"
35203520
"うに閉じ込める値をコピーしますが、値を所有します。つまり、他のコードは閉じ込"
35213521
"められた値にアクセスできなくなります。所有クロージャは並列プログラム、特に "
@@ -3666,11 +3666,11 @@ msgstr ""
36663666
#: doc/tutorial.md:1582
36673667
msgid ""
36683668
"`do` is a convenient way to create tasks with the `task::spawn` function. "
3669-
"`spawn` has the signature `spawn(fn: ~fn())`. In other words, it is a "
3669+
"`spawn` has the signature `spawn(fn: proc())`. In other words, it is a "
36703670
"function that takes an owned closure that takes no arguments."
36713671
msgstr ""
36723672
"`task::spawn` 関数を用いてタスクを生成する場合、 `do` を用いると便利です。"
3673-
"`spawn` は、 `spawn(fn: ~fn())` という方を持っています。言い換えると、"
3673+
"`spawn` は、 `spawn(fn: proc())` という方を持っています。言い換えると、"
36743674
"`spawn` は「引数をとらない所有クロージャ」を引数としてとる関数ということで"
36753675
"す。"
36763676

doc/po/tutorial-tasks.md.pot

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ msgstr ""
213213
#. type: Plain text
214214
#: doc/tutorial-tasks.md:102
215215
msgid ""
216-
"The `spawn` function has a very simple type signature: `fn spawn(f: ~fn())`. "
216+
"The `spawn` function has a very simple type signature: `fn spawn(f: proc())`. "
217217
"Because it accepts only owned closures, and owned closures contain only "
218218
"owned data, `spawn` can safely move the entire closure and all its "
219219
"associated state into an entirely different task for execution. Like any "

doc/po/tutorial.md.pot

+2-2
Original file line numberDiff line numberDiff line change
@@ -2683,7 +2683,7 @@ msgstr ""
26832683
#. type: Plain text
26842684
#: doc/tutorial.md:1510
26852685
msgid ""
2686-
"Owned closures, written `~fn` in analogy to the `~` pointer type, hold on to "
2686+
"Owned closures, written `proc`, hold on to "
26872687
"things that can safely be sent between processes. They copy the values they "
26882688
"close over, much like managed closures, but they also own them: that is, no "
26892689
"other code can access them. Owned closures are used in concurrent code, "
@@ -2808,7 +2808,7 @@ msgstr ""
28082808
#: doc/tutorial.md:1582
28092809
msgid ""
28102810
"`do` is a convenient way to create tasks with the `task::spawn` function. "
2811-
"`spawn` has the signature `spawn(fn: ~fn())`. In other words, it is a "
2811+
"`spawn` has the signature `spawn(fn: proc())`. In other words, it is a "
28122812
"function that takes an owned closure that takes no arguments."
28132813
msgstr ""
28142814

doc/tutorial-tasks.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ _owned types_. The language leaves the implementation details to the standard
9191
library.
9292

9393
The `spawn` function has a very simple type signature: `fn spawn(f:
94-
~fn())`. Because it accepts only owned closures, and owned closures
94+
proc())`. Because it accepts only owned closures, and owned closures
9595
contain only owned data, `spawn` can safely move the entire closure
9696
and all its associated state into an entirely different task for
9797
execution. Like any closure, the function passed to `spawn` may capture

doc/tutorial.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ pervasively in Rust code.
14091409
14101410
## Owned closures
14111411
1412-
Owned closures, written `~fn` in analogy to the `~` pointer type,
1412+
Owned closures, written `proc`,
14131413
hold on to things that can safely be sent between
14141414
processes. They copy the values they close over, much like managed
14151415
closures, but they also own them: that is, no other code can access
@@ -1484,7 +1484,7 @@ parentheses, where it looks more like a typical block of
14841484
code.
14851485
14861486
`do` is a convenient way to create tasks with the `task::spawn`
1487-
function. `spawn` has the signature `spawn(fn: ~fn())`. In other
1487+
function. `spawn` has the signature `spawn(fn: proc())`. In other
14881488
words, it is a function that takes an owned closure that takes no
14891489
arguments.
14901490

src/libextra/future.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub struct Future<A> {
3636
}
3737

3838
enum FutureState<A> {
39-
Pending(~fn() -> A),
39+
Pending(proc() -> A),
4040
Evaluating,
4141
Forced(A)
4242
}
@@ -92,7 +92,7 @@ impl<A> Future<A> {
9292
Future {state: Forced(val)}
9393
}
9494

95-
pub fn from_fn(f: ~fn() -> A) -> Future<A> {
95+
pub fn from_fn(f: proc() -> A) -> Future<A> {
9696
/*!
9797
* Create a future from a function.
9898
*
@@ -120,7 +120,7 @@ impl<A:Send> Future<A> {
120120
}
121121
}
122122

123-
pub fn spawn(blk: ~fn() -> A) -> Future<A> {
123+
pub fn spawn(blk: proc() -> A) -> Future<A> {
124124
/*!
125125
* Create a future from a unique closure.
126126
*
@@ -137,7 +137,7 @@ impl<A:Send> Future<A> {
137137
Future::from_port(port)
138138
}
139139

140-
pub fn spawn_with<B: Send>(v: B, blk: ~fn(B) -> A) -> Future<A> {
140+
pub fn spawn_with<B: Send>(v: B, blk: proc(B) -> A) -> Future<A> {
141141
/*!
142142
* Create a future from a unique closure taking one argument.
143143
*

src/libextra/task_pool.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::vec;
2323
#[cfg(test)] use std::task::SingleThreaded;
2424

2525
enum Msg<T> {
26-
Execute(~fn(&T)),
26+
Execute(proc(&T)),
2727
Quit
2828
}
2929

@@ -49,15 +49,15 @@ impl<T> TaskPool<T> {
4949
/// local data to be kept around in that task.
5050
pub fn new(n_tasks: uint,
5151
opt_sched_mode: Option<SchedMode>,
52-
init_fn_factory: ~fn() -> ~fn(uint) -> T)
52+
init_fn_factory: &fn() -> proc(uint) -> T)
5353
-> TaskPool<T> {
5454
assert!(n_tasks >= 1);
5555

5656
let channels = do vec::from_fn(n_tasks) |i| {
5757
let (port, chan) = comm::stream::<Msg<T>>();
5858
let init_fn = init_fn_factory();
5959

60-
let task_body: ~fn() = || {
60+
let task_body: proc() = || {
6161
let local_data = init_fn(i);
6262
loop {
6363
match port.recv() {
@@ -88,7 +88,7 @@ impl<T> TaskPool<T> {
8888

8989
/// Executes the function `f` on a task in the pool. The function
9090
/// receives a reference to the local data returned by the `init_fn`.
91-
pub fn execute(&mut self, f: ~fn(&T)) {
91+
pub fn execute(&mut self, f: proc(&T)) {
9292
self.channels[self.next_index].send(Execute(f));
9393
self.next_index += 1;
9494
if self.next_index == self.channels.len() { self.next_index = 0; }
@@ -97,8 +97,8 @@ impl<T> TaskPool<T> {
9797

9898
#[test]
9999
fn test_task_pool() {
100-
let f: ~fn() -> ~fn(uint) -> uint = || {
101-
let g: ~fn(uint) -> uint = |i| i;
100+
let f: &fn() -> proc(uint) -> uint = || {
101+
let g: proc(uint) -> uint = |i| i;
102102
g
103103
};
104104
let mut pool = TaskPool::new(4, Some(SingleThreaded), f);

src/libextra/test.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,22 @@ impl TestDesc {
7474
}
7575
}
7676

77+
/// Represents a benchmark function.
78+
pub trait TDynBenchFn {
79+
fn run(&self, harness: &mut BenchHarness);
80+
}
81+
7782
// A function that runs a test. If the function returns successfully,
7883
// the test succeeds; if the function fails then the test fails. We
7984
// may need to come up with a more clever definition of test in order
8085
// to support isolation of tests into tasks.
8186
pub enum TestFn {
8287
StaticTestFn(extern fn()),
8388
StaticBenchFn(extern fn(&mut BenchHarness)),
84-
StaticMetricFn(~fn(&mut MetricMap)),
85-
DynTestFn(~fn()),
86-
DynMetricFn(~fn(&mut MetricMap)),
87-
DynBenchFn(~fn(&mut BenchHarness))
89+
StaticMetricFn(proc(&mut MetricMap)),
90+
DynTestFn(proc()),
91+
DynMetricFn(proc(&mut MetricMap)),
92+
DynBenchFn(~TDynBenchFn)
8893
}
8994

9095
impl TestFn {
@@ -859,7 +864,7 @@ pub fn run_test(force_ignore: bool,
859864

860865
fn run_test_inner(desc: TestDesc,
861866
monitor_ch: SharedChan<MonitorMsg>,
862-
testfn: ~fn()) {
867+
testfn: proc()) {
863868
let testfn_cell = ::std::cell::Cell::new(testfn);
864869
do task::spawn {
865870
let mut task = task::task();
@@ -878,8 +883,8 @@ pub fn run_test(force_ignore: bool,
878883
}
879884

880885
match testfn {
881-
DynBenchFn(benchfn) => {
882-
let bs = ::test::bench::benchmark(benchfn);
886+
DynBenchFn(bencher) => {
887+
let bs = ::test::bench::benchmark(|harness| bencher.run(harness));
883888
monitor_ch.send((desc, TrBench(bs)));
884889
return;
885890
}

src/libextra/workcache.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -394,14 +394,14 @@ impl<'self> Prep<'self> {
394394
pub fn exec<T:Send +
395395
Encodable<json::Encoder> +
396396
Decodable<json::Decoder>>(
397-
&'self self, blk: ~fn(&mut Exec) -> T) -> T {
397+
&'self self, blk: proc(&mut Exec) -> T) -> T {
398398
self.exec_work(blk).unwrap()
399399
}
400400

401401
fn exec_work<T:Send +
402402
Encodable<json::Encoder> +
403403
Decodable<json::Decoder>>( // FIXME(#5121)
404-
&'self self, blk: ~fn(&mut Exec) -> T) -> Work<'self, T> {
404+
&'self self, blk: proc(&mut Exec) -> T) -> Work<'self, T> {
405405
let mut bo = Some(blk);
406406

407407
debug!("exec_work: looking up {} and {:?}", self.fn_name,

src/librustc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ diagnostic emitter which records when we hit a fatal error. If the task
322322
fails without recording a fatal error then we've encountered a compiler
323323
bug and need to present an error.
324324
*/
325-
pub fn monitor(f: ~fn(@diagnostic::Emitter)) {
325+
pub fn monitor(f: proc(@diagnostic::Emitter)) {
326326
use std::comm::*;
327327

328328
// XXX: This is a hack for newsched since it doesn't support split stacks.

src/librustuv/net.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ mod test {
11011101
let handle2 = Cell::new(sched2.make_handle());
11021102
let tasksFriendHandle = Cell::new(sched2.make_handle());
11031103
1104-
let on_exit: ~fn(UnwindResult) = |exit_status| {
1104+
let on_exit: proc(UnwindResult) = |exit_status| {
11051105
handle1.take().send(Shutdown);
11061106
handle2.take().send(Shutdown);
11071107
assert!(exit_status.is_success());
@@ -1115,7 +1115,7 @@ mod test {
11151115
}
11161116
}
11171117
1118-
let test_function: ~fn() = || {
1118+
let test_function: proc() = || {
11191119
let io = unsafe { local_io() };
11201120
let addr = next_test_ip4();
11211121
let maybe_socket = io.udp_bind(addr);

src/libstd/io/net/unix.rs

+1-1
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

+2-2
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

+11-5
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

+5-4
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 {

0 commit comments

Comments
 (0)