Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

librustc: Convert ~fn() to proc() everywhere #10561

Merged
merged 5 commits into from
Nov 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/po/ja/tutorial-tasks.md.po
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ msgstr ""
#. type: Plain text
#: doc/tutorial-tasks.md:102
msgid ""
"The `spawn` function has a very simple type signature: `fn spawn(f: ~fn())`. "
"The `spawn` function has a very simple type signature: `fn spawn(f: proc())`. "
"Because it accepts only owned closures, and owned closures contain only "
"owned data, `spawn` can safely move the entire closure and all its "
"associated state into an entirely different task for execution. Like any "
Expand Down
8 changes: 4 additions & 4 deletions doc/po/ja/tutorial.md.po
Original file line number Diff line number Diff line change
Expand Up @@ -3509,13 +3509,13 @@ msgstr "## 所有クロージャ"
#. type: Plain text
#: doc/tutorial.md:1510
msgid ""
"Owned closures, written `~fn` in analogy to the `~` pointer type, hold on to "
"Owned closures, written `proc`, hold on to "
"things that can safely be sent between processes. They copy the values they "
"close over, much like managed closures, but they also own them: that is, no "
"other code can access them. Owned closures are used in concurrent code, "
"particularly for spawning [tasks][tasks]."
msgstr ""
"`~` ポインタ型と同様に `~fn` 型 で書き表される所有クロージャは安全にプロセス"
"`~` `proc` で書き表される所有クロージャは安全にプロセス"
"間で送信することができます。所有クローじゃはマネージドクロージャと全く同じよ"
"うに閉じ込める値をコピーしますが、値を所有します。つまり、他のコードは閉じ込"
"められた値にアクセスできなくなります。所有クロージャは並列プログラム、特に "
Expand Down Expand Up @@ -3666,11 +3666,11 @@ msgstr ""
#: doc/tutorial.md:1582
msgid ""
"`do` is a convenient way to create tasks with the `task::spawn` function. "
"`spawn` has the signature `spawn(fn: ~fn())`. In other words, it is a "
"`spawn` has the signature `spawn(fn: proc())`. In other words, it is a "
"function that takes an owned closure that takes no arguments."
msgstr ""
"`task::spawn` 関数を用いてタスクを生成する場合、 `do` を用いると便利です。"
"`spawn` は、 `spawn(fn: ~fn())` という方を持っています。言い換えると、"
"`spawn` は、 `spawn(fn: proc())` という方を持っています。言い換えると、"
"`spawn` は「引数をとらない所有クロージャ」を引数としてとる関数ということで"
"す。"

Expand Down
2 changes: 1 addition & 1 deletion doc/po/tutorial-tasks.md.pot
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ msgstr ""
#. type: Plain text
#: doc/tutorial-tasks.md:102
msgid ""
"The `spawn` function has a very simple type signature: `fn spawn(f: ~fn())`. "
"The `spawn` function has a very simple type signature: `fn spawn(f: proc())`. "
"Because it accepts only owned closures, and owned closures contain only "
"owned data, `spawn` can safely move the entire closure and all its "
"associated state into an entirely different task for execution. Like any "
Expand Down
4 changes: 2 additions & 2 deletions doc/po/tutorial.md.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2683,7 +2683,7 @@ msgstr ""
#. type: Plain text
#: doc/tutorial.md:1510
msgid ""
"Owned closures, written `~fn` in analogy to the `~` pointer type, hold on to "
"Owned closures, written `proc`, hold on to "
"things that can safely be sent between processes. They copy the values they "
"close over, much like managed closures, but they also own them: that is, no "
"other code can access them. Owned closures are used in concurrent code, "
Expand Down Expand Up @@ -2808,7 +2808,7 @@ msgstr ""
#: doc/tutorial.md:1582
msgid ""
"`do` is a convenient way to create tasks with the `task::spawn` function. "
"`spawn` has the signature `spawn(fn: ~fn())`. In other words, it is a "
"`spawn` has the signature `spawn(fn: proc())`. In other words, it is a "
"function that takes an owned closure that takes no arguments."
msgstr ""

Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ _owned types_. The language leaves the implementation details to the standard
library.

The `spawn` function has a very simple type signature: `fn spawn(f:
~fn())`. Because it accepts only owned closures, and owned closures
proc())`. Because it accepts only owned closures, and owned closures
contain only owned data, `spawn` can safely move the entire closure
and all its associated state into an entirely different task for
execution. Like any closure, the function passed to `spawn` may capture
Expand Down
4 changes: 2 additions & 2 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ pervasively in Rust code.

## Owned closures

Owned closures, written `~fn` in analogy to the `~` pointer type,
Owned closures, written `proc`,
hold on to things that can safely be sent between
processes. They copy the values they close over, much like managed
closures, but they also own them: that is, no other code can access
Expand Down Expand Up @@ -1484,7 +1484,7 @@ parentheses, where it looks more like a typical block of
code.

`do` is a convenient way to create tasks with the `task::spawn`
function. `spawn` has the signature `spawn(fn: ~fn())`. In other
function. `spawn` has the signature `spawn(fn: proc())`. In other
words, it is a function that takes an owned closure that takes no
arguments.

Expand Down
8 changes: 4 additions & 4 deletions src/libextra/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct Future<A> {
}

enum FutureState<A> {
Pending(~fn() -> A),
Pending(proc() -> A),
Evaluating,
Forced(A)
}
Expand Down Expand Up @@ -92,7 +92,7 @@ impl<A> Future<A> {
Future {state: Forced(val)}
}

pub fn from_fn(f: ~fn() -> A) -> Future<A> {
pub fn from_fn(f: proc() -> A) -> Future<A> {
/*!
* Create a future from a function.
*
Expand Down Expand Up @@ -120,7 +120,7 @@ impl<A:Send> Future<A> {
}
}

pub fn spawn(blk: ~fn() -> A) -> Future<A> {
pub fn spawn(blk: proc() -> A) -> Future<A> {
/*!
* Create a future from a unique closure.
*
Expand All @@ -137,7 +137,7 @@ impl<A:Send> Future<A> {
Future::from_port(port)
}

pub fn spawn_with<B: Send>(v: B, blk: ~fn(B) -> A) -> Future<A> {
pub fn spawn_with<B: Send>(v: B, blk: proc(B) -> A) -> Future<A> {
/*!
* Create a future from a unique closure taking one argument.
*
Expand Down
12 changes: 6 additions & 6 deletions src/libextra/task_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::vec;
#[cfg(test)] use std::task::SingleThreaded;

enum Msg<T> {
Execute(~fn(&T)),
Execute(proc(&T)),
Quit
}

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

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

let task_body: ~fn() = || {
let task_body: proc() = || {
let local_data = init_fn(i);
loop {
match port.recv() {
Expand Down Expand Up @@ -88,7 +88,7 @@ impl<T> TaskPool<T> {

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

#[test]
fn test_task_pool() {
let f: ~fn() -> ~fn(uint) -> uint = || {
let g: ~fn(uint) -> uint = |i| i;
let f: &fn() -> proc(uint) -> uint = || {
let g: proc(uint) -> uint = |i| i;
g
};
let mut pool = TaskPool::new(4, Some(SingleThreaded), f);
Expand Down
19 changes: 12 additions & 7 deletions src/libextra/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,22 @@ impl TestDesc {
}
}

/// Represents a benchmark function.
pub trait TDynBenchFn {
fn run(&self, harness: &mut BenchHarness);
}

// A function that runs a test. If the function returns successfully,
// the test succeeds; if the function fails then the test fails. We
// may need to come up with a more clever definition of test in order
// to support isolation of tests into tasks.
pub enum TestFn {
StaticTestFn(extern fn()),
StaticBenchFn(extern fn(&mut BenchHarness)),
StaticMetricFn(~fn(&mut MetricMap)),
DynTestFn(~fn()),
DynMetricFn(~fn(&mut MetricMap)),
DynBenchFn(~fn(&mut BenchHarness))
StaticMetricFn(proc(&mut MetricMap)),
DynTestFn(proc()),
DynMetricFn(proc(&mut MetricMap)),
DynBenchFn(~TDynBenchFn)
}

impl TestFn {
Expand Down Expand Up @@ -859,7 +864,7 @@ pub fn run_test(force_ignore: bool,

fn run_test_inner(desc: TestDesc,
monitor_ch: SharedChan<MonitorMsg>,
testfn: ~fn()) {
testfn: proc()) {
let testfn_cell = ::std::cell::Cell::new(testfn);
do task::spawn {
let mut task = task::task();
Expand All @@ -878,8 +883,8 @@ pub fn run_test(force_ignore: bool,
}

match testfn {
DynBenchFn(benchfn) => {
let bs = ::test::bench::benchmark(benchfn);
DynBenchFn(bencher) => {
let bs = ::test::bench::benchmark(|harness| bencher.run(harness));
monitor_ch.send((desc, TrBench(bs)));
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/workcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,14 @@ impl<'self> Prep<'self> {
pub fn exec<T:Send +
Encodable<json::Encoder> +
Decodable<json::Decoder>>(
&'self self, blk: ~fn(&mut Exec) -> T) -> T {
&'self self, blk: proc(&mut Exec) -> T) -> T {
self.exec_work(blk).unwrap()
}

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

debug!("exec_work: looking up {} and {:?}", self.fn_name,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ diagnostic emitter which records when we hit a fatal error. If the task
fails without recording a fatal error then we've encountered a compiler
bug and need to present an error.
*/
pub fn monitor(f: ~fn(@diagnostic::Emitter)) {
pub fn monitor(f: proc(@diagnostic::Emitter)) {
use std::comm::*;

// XXX: This is a hack for newsched since it doesn't support split stacks.
Expand Down
4 changes: 2 additions & 2 deletions src/librustuv/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ mod test {
let handle2 = Cell::new(sched2.make_handle());
let tasksFriendHandle = Cell::new(sched2.make_handle());

let on_exit: ~fn(UnwindResult) = |exit_status| {
let on_exit: proc(UnwindResult) = |exit_status| {
handle1.take().send(Shutdown);
handle2.take().send(Shutdown);
assert!(exit_status.is_success());
Expand All @@ -1115,7 +1115,7 @@ mod test {
}
}

let test_function: ~fn() = || {
let test_function: proc() = || {
let io = unsafe { local_io() };
let addr = next_test_ip4();
let maybe_socket = io.udp_bind(addr);
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/io/net/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ mod tests {
use io::*;
use rt::comm::oneshot;

fn smalltest(server: ~fn(UnixStream), client: ~fn(UnixStream)) {
fn smalltest(server: proc(UnixStream), client: proc(UnixStream)) {
let server = Cell::new(server);
let client = Cell::new(client);
do run_in_mt_newsched_task {
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,11 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
}

fn visit_closure_ptr(&mut self, ck: uint) -> bool {
self.align_to::<~fn()>();
self.align_to::<proc()>();
if ! self.inner.visit_closure_ptr(ck) {
return false
}
self.bump_past::<~fn()>();
self.bump_past::<proc()>();
true
}
}
16 changes: 11 additions & 5 deletions src/libstd/rt/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub static RED_ZONE: uint = 20 * 1024;
// then misalign the regs again.
pub struct Context {
/// The context entry point, saved here for later destruction
priv start: Option<~~fn()>,
priv start: Option<~proc()>,
/// Hold the registers while the task or scheduler is suspended
priv regs: ~Registers,
/// Lower bound and upper bound for the stack
Expand All @@ -41,18 +41,24 @@ impl Context {
}
}

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

// The C-ABI function that is the task entry point
extern fn task_start_wrapper(f: &~fn()) { (*f)() }
extern fn task_start_wrapper(f: &proc()) {
// XXX(pcwalton): This may be sketchy.
unsafe {
let f: &|| = transmute(f);
(*f)()
}
}

let fp: *c_void = task_start_wrapper as *c_void;
let argp: *c_void = unsafe { transmute::<&~fn(), *c_void>(&*start) };
let argp: *c_void = unsafe { transmute::<&proc(), *c_void>(&*start) };
let sp: *uint = stack.end();
let sp: *mut uint = unsafe { transmute_mut_unsafe(sp) };
// Save and then immediately load the current context,
Expand Down
9 changes: 5 additions & 4 deletions src/libstd/rt/kill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ see a failure from the grandchild task. While we could achieve this by having
each intermediate task block on its handle, this keeps around the other resources
the task was using. To be more efficient, this is accomplished via "tombstones".

A tombstone is a closure, ~fn() -> bool, which will perform any waiting necessary
A tombstone is a closure, proc() -> bool, which will perform any waiting necessary
to collect the exit code of descendant tasks. In its environment is captured
the KillHandle of whichever task created the tombstone, and perhaps also any
tombstones that that task itself had, and finally also another tombstone,
Expand Down Expand Up @@ -205,7 +205,7 @@ struct KillHandleInner {
// Locklessly accessed; protected by the enclosing refcount's barriers.
any_child_failed: bool,
// A lazy list, consuming which may unwrap() many child tombstones.
child_tombstones: Option<~fn() -> bool>,
child_tombstones: Option<proc() -> bool>,
// Protects multiple children simultaneously creating tombstones.
graveyard_lock: LittleLock,
}
Expand All @@ -223,7 +223,7 @@ pub struct Death {
priv watching_parent: Option<KillHandle>,
// Action to be done with the exit code. If set, also makes the task wait
// until all its watched children exit before collecting the status.
on_exit: Option<~fn(UnwindResult)>,
on_exit: Option<proc(UnwindResult)>,
// nesting level counter for task::unkillable calls (0 == killable).
priv unkillable: int,
// nesting level counter for unstable::atomically calls (0 == can deschedule).
Expand Down Expand Up @@ -525,7 +525,8 @@ impl KillHandle {
// NB: Takes a pthread mutex -- 'blk' not allowed to reschedule.
#[inline]
fn add_lazy_tombstone(parent: &mut KillHandle,
blk: &fn(Option<~fn() -> bool>) -> ~fn() -> bool) {
blk: &fn(Option<proc() -> bool>)
-> proc() -> bool) {

let inner: &mut KillHandleInner = unsafe { &mut *parent.get() };
unsafe {
Expand Down
Loading