1
Fork 0

auto merge of #10561 : pcwalton/rust/procify, r=alexcrichton

r? @alexcrichton
This commit is contained in:
bors 2013-11-18 23:06:29 -08:00
commit f4c22f75d4
65 changed files with 186 additions and 265 deletions

View file

@ -213,7 +213,7 @@ msgstr ""
#. type: Plain text #. type: Plain text
#: doc/tutorial-tasks.md:102 #: doc/tutorial-tasks.md:102
msgid "" 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 " "Because it accepts only owned closures, and owned closures contain only "
"owned data, `spawn` can safely move the entire closure and all its " "owned data, `spawn` can safely move the entire closure and all its "
"associated state into an entirely different task for execution. Like any " "associated state into an entirely different task for execution. Like any "

View file

@ -3509,13 +3509,13 @@ msgstr "## 所有クロージャ"
#. type: Plain text #. type: Plain text
#: doc/tutorial.md:1510 #: doc/tutorial.md:1510
msgid "" 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 " "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 " "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, " "other code can access them. Owned closures are used in concurrent code, "
"particularly for spawning [tasks][tasks]." "particularly for spawning [tasks][tasks]."
msgstr "" msgstr ""
"`~` ポインタ型と同様に `~fn` 型 で書き表される所有クロージャは安全にプロセス" "`~` `proc` で書き表される所有クロージャは安全にプロセス"
"間で送信することができます。所有クローじゃはマネージドクロージャと全く同じよ" "間で送信することができます。所有クローじゃはマネージドクロージャと全く同じよ"
"うに閉じ込める値をコピーしますが、値を所有します。つまり、他のコードは閉じ込" "うに閉じ込める値をコピーしますが、値を所有します。つまり、他のコードは閉じ込"
"められた値にアクセスできなくなります。所有クロージャは並列プログラム、特に " "められた値にアクセスできなくなります。所有クロージャは並列プログラム、特に "
@ -3666,11 +3666,11 @@ msgstr ""
#: doc/tutorial.md:1582 #: doc/tutorial.md:1582
msgid "" msgid ""
"`do` is a convenient way to create tasks with the `task::spawn` function. " "`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." "function that takes an owned closure that takes no arguments."
msgstr "" msgstr ""
"`task::spawn` 関数を用いてタスクを生成する場合、 `do` を用いると便利です。" "`task::spawn` 関数を用いてタスクを生成する場合、 `do` を用いると便利です。"
"`spawn` は、 `spawn(fn: ~fn())` という方を持っています。言い換えると、" "`spawn` は、 `spawn(fn: proc())` という方を持っています。言い換えると、"
"`spawn` は「引数をとらない所有クロージャ」を引数としてとる関数ということで" "`spawn` は「引数をとらない所有クロージャ」を引数としてとる関数ということで"
"す。" "す。"

View file

@ -213,7 +213,7 @@ msgstr ""
#. type: Plain text #. type: Plain text
#: doc/tutorial-tasks.md:102 #: doc/tutorial-tasks.md:102
msgid "" 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 " "Because it accepts only owned closures, and owned closures contain only "
"owned data, `spawn` can safely move the entire closure and all its " "owned data, `spawn` can safely move the entire closure and all its "
"associated state into an entirely different task for execution. Like any " "associated state into an entirely different task for execution. Like any "

View file

@ -2683,7 +2683,7 @@ msgstr ""
#. type: Plain text #. type: Plain text
#: doc/tutorial.md:1510 #: doc/tutorial.md:1510
msgid "" 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 " "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 " "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, " "other code can access them. Owned closures are used in concurrent code, "
@ -2808,7 +2808,7 @@ msgstr ""
#: doc/tutorial.md:1582 #: doc/tutorial.md:1582
msgid "" msgid ""
"`do` is a convenient way to create tasks with the `task::spawn` function. " "`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." "function that takes an owned closure that takes no arguments."
msgstr "" msgstr ""

View file

@ -91,7 +91,7 @@ _owned types_. The language leaves the implementation details to the standard
library. library.
The `spawn` function has a very simple type signature: `fn spawn(f: 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 contain only owned data, `spawn` can safely move the entire closure
and all its associated state into an entirely different task for and all its associated state into an entirely different task for
execution. Like any closure, the function passed to `spawn` may capture execution. Like any closure, the function passed to `spawn` may capture

View file

@ -1409,7 +1409,7 @@ pervasively in Rust code.
## Owned closures ## 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 hold on to things that can safely be sent between
processes. They copy the values they close over, much like managed processes. They copy the values they close over, much like managed
closures, but they also own them: that is, no other code can access 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
code. code.
`do` is a convenient way to create tasks with the `task::spawn` `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 words, it is a function that takes an owned closure that takes no
arguments. arguments.

View file

@ -36,7 +36,7 @@ pub struct Future<A> {
} }
enum FutureState<A> { enum FutureState<A> {
Pending(~fn() -> A), Pending(proc() -> A),
Evaluating, Evaluating,
Forced(A) Forced(A)
} }
@ -92,7 +92,7 @@ impl<A> Future<A> {
Future {state: Forced(val)} 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. * Create a future from a function.
* *
@ -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. * Create a future from a unique closure.
* *
@ -137,7 +137,7 @@ impl<A:Send> Future<A> {
Future::from_port(port) 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. * Create a future from a unique closure taking one argument.
* *

View file

@ -23,7 +23,7 @@ use std::vec;
#[cfg(test)] use std::task::SingleThreaded; #[cfg(test)] use std::task::SingleThreaded;
enum Msg<T> { enum Msg<T> {
Execute(~fn(&T)), Execute(proc(&T)),
Quit Quit
} }
@ -49,7 +49,7 @@ impl<T> TaskPool<T> {
/// local data to be kept around in that task. /// local data to be kept around in that task.
pub fn new(n_tasks: uint, pub fn new(n_tasks: uint,
opt_sched_mode: Option<SchedMode>, opt_sched_mode: Option<SchedMode>,
init_fn_factory: ~fn() -> ~fn(uint) -> T) init_fn_factory: &fn() -> proc(uint) -> T)
-> TaskPool<T> { -> TaskPool<T> {
assert!(n_tasks >= 1); assert!(n_tasks >= 1);
@ -57,7 +57,7 @@ impl<T> TaskPool<T> {
let (port, chan) = comm::stream::<Msg<T>>(); let (port, chan) = comm::stream::<Msg<T>>();
let init_fn = init_fn_factory(); let init_fn = init_fn_factory();
let task_body: ~fn() = || { let task_body: proc() = || {
let local_data = init_fn(i); let local_data = init_fn(i);
loop { loop {
match port.recv() { match port.recv() {
@ -88,7 +88,7 @@ impl<T> TaskPool<T> {
/// Executes the function `f` on a task in the pool. The function /// Executes the function `f` on a task in the pool. The function
/// receives a reference to the local data returned by the `init_fn`. /// 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.channels[self.next_index].send(Execute(f));
self.next_index += 1; self.next_index += 1;
if self.next_index == self.channels.len() { self.next_index = 0; } if self.next_index == self.channels.len() { self.next_index = 0; }
@ -97,8 +97,8 @@ impl<T> TaskPool<T> {
#[test] #[test]
fn test_task_pool() { fn test_task_pool() {
let f: ~fn() -> ~fn(uint) -> uint = || { let f: &fn() -> proc(uint) -> uint = || {
let g: ~fn(uint) -> uint = |i| i; let g: proc(uint) -> uint = |i| i;
g g
}; };
let mut pool = TaskPool::new(4, Some(SingleThreaded), f); let mut pool = TaskPool::new(4, Some(SingleThreaded), f);

View file

@ -74,6 +74,11 @@ 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, // A function that runs a test. If the function returns successfully,
// the test succeeds; if the function fails then the test fails. We // 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 // may need to come up with a more clever definition of test in order
@ -81,10 +86,10 @@ impl TestDesc {
pub enum TestFn { pub enum TestFn {
StaticTestFn(extern fn()), StaticTestFn(extern fn()),
StaticBenchFn(extern fn(&mut BenchHarness)), StaticBenchFn(extern fn(&mut BenchHarness)),
StaticMetricFn(~fn(&mut MetricMap)), StaticMetricFn(proc(&mut MetricMap)),
DynTestFn(~fn()), DynTestFn(proc()),
DynMetricFn(~fn(&mut MetricMap)), DynMetricFn(proc(&mut MetricMap)),
DynBenchFn(~fn(&mut BenchHarness)) DynBenchFn(~TDynBenchFn)
} }
impl TestFn { impl TestFn {
@ -859,7 +864,7 @@ pub fn run_test(force_ignore: bool,
fn run_test_inner(desc: TestDesc, fn run_test_inner(desc: TestDesc,
monitor_ch: SharedChan<MonitorMsg>, monitor_ch: SharedChan<MonitorMsg>,
testfn: ~fn()) { testfn: proc()) {
let testfn_cell = ::std::cell::Cell::new(testfn); let testfn_cell = ::std::cell::Cell::new(testfn);
do task::spawn { do task::spawn {
let mut task = task::task(); let mut task = task::task();
@ -878,8 +883,8 @@ pub fn run_test(force_ignore: bool,
} }
match testfn { match testfn {
DynBenchFn(benchfn) => { DynBenchFn(bencher) => {
let bs = ::test::bench::benchmark(benchfn); let bs = ::test::bench::benchmark(|harness| bencher.run(harness));
monitor_ch.send((desc, TrBench(bs))); monitor_ch.send((desc, TrBench(bs)));
return; return;
} }

View file

@ -394,14 +394,14 @@ impl<'self> Prep<'self> {
pub fn exec<T:Send + pub fn exec<T:Send +
Encodable<json::Encoder> + Encodable<json::Encoder> +
Decodable<json::Decoder>>( Decodable<json::Decoder>>(
&'self self, blk: ~fn(&mut Exec) -> T) -> T { &'self self, blk: proc(&mut Exec) -> T) -> T {
self.exec_work(blk).unwrap() self.exec_work(blk).unwrap()
} }
fn exec_work<T:Send + fn exec_work<T:Send +
Encodable<json::Encoder> + Encodable<json::Encoder> +
Decodable<json::Decoder>>( // FIXME(#5121) 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); let mut bo = Some(blk);
debug!("exec_work: looking up {} and {:?}", self.fn_name, debug!("exec_work: looking up {} and {:?}", self.fn_name,

View file

@ -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 fails without recording a fatal error then we've encountered a compiler
bug and need to present an error. bug and need to present an error.
*/ */
pub fn monitor(f: ~fn(@diagnostic::Emitter)) { pub fn monitor(f: proc(@diagnostic::Emitter)) {
use std::comm::*; use std::comm::*;
// XXX: This is a hack for newsched since it doesn't support split stacks. // XXX: This is a hack for newsched since it doesn't support split stacks.

View file

@ -1101,7 +1101,7 @@ mod test {
let handle2 = Cell::new(sched2.make_handle()); let handle2 = Cell::new(sched2.make_handle());
let tasksFriendHandle = 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); handle1.take().send(Shutdown);
handle2.take().send(Shutdown); handle2.take().send(Shutdown);
assert!(exit_status.is_success()); assert!(exit_status.is_success());
@ -1115,7 +1115,7 @@ mod test {
} }
} }
let test_function: ~fn() = || { let test_function: proc() = || {
let io = unsafe { local_io() }; let io = unsafe { local_io() };
let addr = next_test_ip4(); let addr = next_test_ip4();
let maybe_socket = io.udp_bind(addr); let maybe_socket = io.udp_bind(addr);

View file

@ -157,7 +157,7 @@ mod tests {
use io::*; use io::*;
use rt::comm::oneshot; 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 server = Cell::new(server);
let client = Cell::new(client); let client = Cell::new(client);
do run_in_mt_newsched_task { do run_in_mt_newsched_task {

View file

@ -478,11 +478,11 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
} }
fn visit_closure_ptr(&mut self, ck: uint) -> bool { fn visit_closure_ptr(&mut self, ck: uint) -> bool {
self.align_to::<~fn()>(); self.align_to::<proc()>();
if ! self.inner.visit_closure_ptr(ck) { if ! self.inner.visit_closure_ptr(ck) {
return false return false
} }
self.bump_past::<~fn()>(); self.bump_past::<proc()>();
true true
} }
} }

View file

@ -25,7 +25,7 @@ pub static RED_ZONE: uint = 20 * 1024;
// then misalign the regs again. // then misalign the regs again.
pub struct Context { pub struct Context {
/// The context entry point, saved here for later destruction /// 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 /// Hold the registers while the task or scheduler is suspended
priv regs: ~Registers, priv regs: ~Registers,
/// Lower bound and upper bound for the stack /// Lower bound and upper bound for the stack
@ -41,18 +41,24 @@ impl Context {
} }
} }
/// Create a new context that will resume execution by running ~fn() /// Create a new context that will resume execution by running proc()
pub fn new(start: ~fn(), stack: &mut StackSegment) -> Context { pub fn new(start: proc(), stack: &mut StackSegment) -> Context {
// FIXME #7767: Putting main into a ~ so it's a thin pointer and can // FIXME #7767: Putting main into a ~ so it's a thin pointer and can
// be passed to the spawn function. Another unfortunate // be passed to the spawn function. Another unfortunate
// allocation // allocation
let start = ~start; let start = ~start;
// The C-ABI function that is the task entry point // 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 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: *uint = stack.end();
let sp: *mut uint = unsafe { transmute_mut_unsafe(sp) }; let sp: *mut uint = unsafe { transmute_mut_unsafe(sp) };
// Save and then immediately load the current context, // Save and then immediately load the current context,

View file

@ -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 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". 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 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 the KillHandle of whichever task created the tombstone, and perhaps also any
tombstones that that task itself had, and finally also another tombstone, tombstones that that task itself had, and finally also another tombstone,
@ -205,7 +205,7 @@ struct KillHandleInner {
// Locklessly accessed; protected by the enclosing refcount's barriers. // Locklessly accessed; protected by the enclosing refcount's barriers.
any_child_failed: bool, any_child_failed: bool,
// A lazy list, consuming which may unwrap() many child tombstones. // 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. // Protects multiple children simultaneously creating tombstones.
graveyard_lock: LittleLock, graveyard_lock: LittleLock,
} }
@ -223,7 +223,7 @@ pub struct Death {
priv watching_parent: Option<KillHandle>, priv watching_parent: Option<KillHandle>,
// Action to be done with the exit code. If set, also makes the task wait // 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. // 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). // nesting level counter for task::unkillable calls (0 == killable).
priv unkillable: int, priv unkillable: int,
// nesting level counter for unstable::atomically calls (0 == can deschedule). // nesting level counter for unstable::atomically calls (0 == can deschedule).
@ -525,7 +525,8 @@ impl KillHandle {
// NB: Takes a pthread mutex -- 'blk' not allowed to reschedule. // NB: Takes a pthread mutex -- 'blk' not allowed to reschedule.
#[inline] #[inline]
fn add_lazy_tombstone(parent: &mut KillHandle, 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() }; let inner: &mut KillHandleInner = unsafe { &mut *parent.get() };
unsafe { unsafe {

View file

@ -207,7 +207,7 @@ pub mod borrowck;
/// # Return value /// # Return value
/// ///
/// The return value is used as the process return code. 0 on success, 101 on error. /// The return value is used as the process return code. 0 on success, 101 on error.
pub fn start(argc: int, argv: **u8, main: ~fn()) -> int { pub fn start(argc: int, argv: **u8, main: proc()) -> int {
init(argc, argv); init(argc, argv);
let exit_code = run(main); let exit_code = run(main);
@ -221,7 +221,7 @@ pub fn start(argc: int, argv: **u8, main: ~fn()) -> int {
/// ///
/// This is appropriate for running code that must execute on the main thread, /// This is appropriate for running code that must execute on the main thread,
/// such as the platform event loop and GUI. /// such as the platform event loop and GUI.
pub fn start_on_main_thread(argc: int, argv: **u8, main: ~fn()) -> int { pub fn start_on_main_thread(argc: int, argv: **u8, main: proc()) -> int {
init(argc, argv); init(argc, argv);
let exit_code = run_on_main_thread(main); let exit_code = run_on_main_thread(main);
cleanup(); cleanup();
@ -254,15 +254,15 @@ pub fn cleanup() {
/// Configures the runtime according to the environment, by default /// Configures the runtime according to the environment, by default
/// using a task scheduler with the same number of threads as cores. /// using a task scheduler with the same number of threads as cores.
/// Returns a process exit code. /// Returns a process exit code.
pub fn run(main: ~fn()) -> int { pub fn run(main: proc()) -> int {
run_(main, false) run_(main, false)
} }
pub fn run_on_main_thread(main: ~fn()) -> int { pub fn run_on_main_thread(main: proc()) -> int {
run_(main, true) run_(main, true)
} }
fn run_(main: ~fn(), use_main_sched: bool) -> int { fn run_(main: proc(), use_main_sched: bool) -> int {
static DEFAULT_ERROR_CODE: int = 101; static DEFAULT_ERROR_CODE: int = 101;
let nscheds = util::default_sched_threads(); let nscheds = util::default_sched_threads();
@ -341,7 +341,7 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int {
// When the main task exits, after all the tasks in the main // When the main task exits, after all the tasks in the main
// task tree, shut down the schedulers and set the exit code. // task tree, shut down the schedulers and set the exit code.
let handles = Cell::new(handles); let handles = Cell::new(handles);
let on_exit: ~fn(UnwindResult) = |exit_success| { let on_exit: proc(UnwindResult) = |exit_success| {
unsafe { unsafe {
assert!(!(*exited_already.get()).swap(true, SeqCst), assert!(!(*exited_already.get()).swap(true, SeqCst),
"the runtime already exited"); "the runtime already exited");

View file

@ -990,7 +990,9 @@ mod test {
assert!(Task::on_appropriate_sched()); assert!(Task::on_appropriate_sched());
}; };
let on_exit: ~fn(UnwindResult) = |exit_status| rtassert!(exit_status.is_success()); let on_exit: proc(UnwindResult) = |exit_status| {
rtassert!(exit_status.is_success())
};
task.death.on_exit = Some(on_exit); task.death.on_exit = Some(on_exit);
sched.bootstrap(task); sched.bootstrap(task);

View file

@ -139,7 +139,10 @@ impl Task {
// A helper to build a new task using the dynamically found // A helper to build a new task using the dynamically found
// scheduler and task. Only works in GreenTask context. // scheduler and task. Only works in GreenTask context.
pub fn build_homed_child(stack_size: Option<uint>, f: ~fn(), home: SchedHome) -> ~Task { pub fn build_homed_child(stack_size: Option<uint>,
f: proc(),
home: SchedHome)
-> ~Task {
let f = Cell::new(f); let f = Cell::new(f);
let home = Cell::new(home); let home = Cell::new(home);
do Local::borrow |running_task: &mut Task| { do Local::borrow |running_task: &mut Task| {
@ -153,11 +156,14 @@ impl Task {
} }
} }
pub fn build_child(stack_size: Option<uint>, f: ~fn()) -> ~Task { pub fn build_child(stack_size: Option<uint>, f: proc()) -> ~Task {
Task::build_homed_child(stack_size, f, AnySched) Task::build_homed_child(stack_size, f, AnySched)
} }
pub fn build_homed_root(stack_size: Option<uint>, f: ~fn(), home: SchedHome) -> ~Task { pub fn build_homed_root(stack_size: Option<uint>,
f: proc(),
home: SchedHome)
-> ~Task {
let f = Cell::new(f); let f = Cell::new(f);
let home = Cell::new(home); let home = Cell::new(home);
do Local::borrow |running_task: &mut Task| { do Local::borrow |running_task: &mut Task| {
@ -171,7 +177,7 @@ impl Task {
} }
} }
pub fn build_root(stack_size: Option<uint>, f: ~fn()) -> ~Task { pub fn build_root(stack_size: Option<uint>, f: proc()) -> ~Task {
Task::build_homed_root(stack_size, f, AnySched) Task::build_homed_root(stack_size, f, AnySched)
} }
@ -196,21 +202,21 @@ impl Task {
pub fn new_root(stack_pool: &mut StackPool, pub fn new_root(stack_pool: &mut StackPool,
stack_size: Option<uint>, stack_size: Option<uint>,
start: ~fn()) -> Task { start: proc()) -> Task {
Task::new_root_homed(stack_pool, stack_size, AnySched, start) Task::new_root_homed(stack_pool, stack_size, AnySched, start)
} }
pub fn new_child(&mut self, pub fn new_child(&mut self,
stack_pool: &mut StackPool, stack_pool: &mut StackPool,
stack_size: Option<uint>, stack_size: Option<uint>,
start: ~fn()) -> Task { start: proc()) -> Task {
self.new_child_homed(stack_pool, stack_size, AnySched, start) self.new_child_homed(stack_pool, stack_size, AnySched, start)
} }
pub fn new_root_homed(stack_pool: &mut StackPool, pub fn new_root_homed(stack_pool: &mut StackPool,
stack_size: Option<uint>, stack_size: Option<uint>,
home: SchedHome, home: SchedHome,
start: ~fn()) -> Task { start: proc()) -> Task {
Task { Task {
heap: LocalHeap::new(), heap: LocalHeap::new(),
gc: GarbageCollector, gc: GarbageCollector,
@ -233,7 +239,7 @@ impl Task {
stack_pool: &mut StackPool, stack_pool: &mut StackPool,
stack_size: Option<uint>, stack_size: Option<uint>,
home: SchedHome, home: SchedHome,
start: ~fn()) -> Task { start: proc()) -> Task {
Task { Task {
heap: LocalHeap::new(), heap: LocalHeap::new(),
gc: GarbageCollector, gc: GarbageCollector,
@ -404,7 +410,10 @@ impl Drop for Task {
impl Coroutine { impl Coroutine {
pub fn new(stack_pool: &mut StackPool, stack_size: Option<uint>, start: ~fn()) -> Coroutine { pub fn new(stack_pool: &mut StackPool,
stack_size: Option<uint>,
start: proc())
-> Coroutine {
let stack_size = match stack_size { let stack_size = match stack_size {
Some(size) => size, Some(size) => size,
None => env::min_stack() None => env::min_stack()
@ -425,9 +434,9 @@ impl Coroutine {
} }
} }
fn build_start_wrapper(start: ~fn()) -> ~fn() { fn build_start_wrapper(start: proc()) -> proc() {
let start_cell = Cell::new(start); let start_cell = Cell::new(start);
let wrapper: ~fn() = || { let wrapper: proc() = || {
// First code after swap to this new context. Run our // First code after swap to this new context. Run our
// cleanup job. // cleanup job.
unsafe { unsafe {

View file

@ -64,28 +64,28 @@ pub fn new_test_sched() -> Scheduler {
return sched; return sched;
} }
pub fn run_in_uv_task(f: ~fn()) { pub fn run_in_uv_task(f: proc()) {
let f = Cell::new(f); let f = Cell::new(f);
do run_in_bare_thread { do run_in_bare_thread {
run_in_uv_task_core(f.take()); run_in_uv_task_core(f.take());
} }
} }
pub fn run_in_newsched_task(f: ~fn()) { pub fn run_in_newsched_task(f: proc()) {
let f = Cell::new(f); let f = Cell::new(f);
do run_in_bare_thread { do run_in_bare_thread {
run_in_newsched_task_core(f.take()); run_in_newsched_task_core(f.take());
} }
} }
pub fn run_in_uv_task_core(f: ~fn()) { pub fn run_in_uv_task_core(f: proc()) {
use rt::sched::Shutdown; use rt::sched::Shutdown;
let mut sched = ~new_test_uv_sched(); let mut sched = ~new_test_uv_sched();
let exit_handle = Cell::new(sched.make_handle()); let exit_handle = Cell::new(sched.make_handle());
let on_exit: ~fn(UnwindResult) = |exit_status| { let on_exit: proc(UnwindResult) = |exit_status| {
exit_handle.take().send(Shutdown); exit_handle.take().send(Shutdown);
rtassert!(exit_status.is_success()); rtassert!(exit_status.is_success());
}; };
@ -95,13 +95,13 @@ pub fn run_in_uv_task_core(f: ~fn()) {
sched.bootstrap(task); sched.bootstrap(task);
} }
pub fn run_in_newsched_task_core(f: ~fn()) { pub fn run_in_newsched_task_core(f: proc()) {
use rt::sched::Shutdown; use rt::sched::Shutdown;
let mut sched = ~new_test_sched(); let mut sched = ~new_test_sched();
let exit_handle = Cell::new(sched.make_handle()); let exit_handle = Cell::new(sched.make_handle());
let on_exit: ~fn(UnwindResult) = |exit_status| { let on_exit: proc(UnwindResult) = |exit_status| {
exit_handle.take().send(Shutdown); exit_handle.take().send(Shutdown);
rtassert!(exit_status.is_success()); rtassert!(exit_status.is_success());
}; };
@ -195,7 +195,7 @@ pub fn prepare_for_lots_of_tests() {
/// Create more than one scheduler and run a function in a task /// Create more than one scheduler and run a function in a task
/// in one of the schedulers. The schedulers will stay alive /// in one of the schedulers. The schedulers will stay alive
/// until the function `f` returns. /// until the function `f` returns.
pub fn run_in_mt_newsched_task(f: ~fn()) { pub fn run_in_mt_newsched_task(f: proc()) {
use os; use os;
use from_str::FromStr; use from_str::FromStr;
use rt::sched::Shutdown; use rt::sched::Shutdown;
@ -245,7 +245,7 @@ pub fn run_in_mt_newsched_task(f: ~fn()) {
} }
let handles = Cell::new(handles); let handles = Cell::new(handles);
let on_exit: ~fn(UnwindResult) = |exit_status| { let on_exit: proc(UnwindResult) = |exit_status| {
let mut handles = handles.take(); let mut handles = handles.take();
// Tell schedulers to exit // Tell schedulers to exit
for handle in handles.mut_iter() { for handle in handles.mut_iter() {
@ -294,16 +294,16 @@ pub fn run_in_mt_newsched_task(f: ~fn()) {
} }
/// Test tasks will abort on failure instead of unwinding /// Test tasks will abort on failure instead of unwinding
pub fn spawntask(f: ~fn()) { pub fn spawntask(f: proc()) {
Scheduler::run_task(Task::build_child(None, f)); Scheduler::run_task(Task::build_child(None, f));
} }
/// Create a new task and run it right now. Aborts on failure /// Create a new task and run it right now. Aborts on failure
pub fn spawntask_later(f: ~fn()) { pub fn spawntask_later(f: proc()) {
Scheduler::run_task_later(Task::build_child(None, f)); Scheduler::run_task_later(Task::build_child(None, f));
} }
pub fn spawntask_random(f: ~fn()) { pub fn spawntask_random(f: proc()) {
use rand::{Rand, rng}; use rand::{Rand, rng};
let mut rng = rng(); let mut rng = rng();
@ -316,11 +316,11 @@ pub fn spawntask_random(f: ~fn()) {
} }
} }
pub fn spawntask_try(f: ~fn()) -> Result<(),()> { pub fn spawntask_try(f: proc()) -> Result<(),()> {
let (port, chan) = oneshot(); let (port, chan) = oneshot();
let chan = Cell::new(chan); let chan = Cell::new(chan);
let on_exit: ~fn(UnwindResult) = |exit_status| chan.take().send(exit_status); let on_exit: proc(UnwindResult) = |exit_status| chan.take().send(exit_status);
let mut new_task = Task::build_root(None, f); let mut new_task = Task::build_root(None, f);
new_task.death.on_exit = Some(on_exit); new_task.death.on_exit = Some(on_exit);
@ -333,7 +333,7 @@ pub fn spawntask_try(f: ~fn()) -> Result<(),()> {
} }
/// Spawn a new task in a new scheduler and return a thread handle. /// Spawn a new task in a new scheduler and return a thread handle.
pub fn spawntask_thread(f: ~fn()) -> Thread { pub fn spawntask_thread(f: proc()) -> Thread {
let f = Cell::new(f); let f = Cell::new(f);
@ -345,7 +345,7 @@ pub fn spawntask_thread(f: ~fn()) -> Thread {
} }
/// Get a ~Task for testing purposes other than actually scheduling it. /// Get a ~Task for testing purposes other than actually scheduling it.
pub fn with_test_task(blk: ~fn(~Task) -> ~Task) { pub fn with_test_task(blk: proc(~Task) -> ~Task) {
do run_in_bare_thread { do run_in_bare_thread {
let mut sched = ~new_test_sched(); let mut sched = ~new_test_sched();
let task = blk(~Task::new_root(&mut sched.stack_pool, None, ||{})); let task = blk(~Task::new_root(&mut sched.stack_pool, None, ||{}));

View file

@ -35,7 +35,7 @@ static DEFAULT_STACK_SIZE: libc::size_t = 1024*1024;
impl Thread { impl Thread {
pub fn start(main: ~fn()) -> Thread { pub fn start(main: proc()) -> Thread {
// This is the starting point of rust os threads. The first thing we do // This is the starting point of rust os threads. The first thing we do
// is make sure that we don't trigger __morestack (also why this has a // is make sure that we don't trigger __morestack (also why this has a
// no_split_stack annotation), and then we extract the main function // no_split_stack annotation), and then we extract the main function
@ -45,7 +45,7 @@ impl Thread {
use rt::context; use rt::context;
unsafe { unsafe {
context::record_stack_bounds(0, uint::max_value); context::record_stack_bounds(0, uint::max_value);
let f: ~~fn() = cast::transmute(trampoline); let f: ~proc() = cast::transmute(trampoline);
(*f)(); (*f)();
} }
unsafe { cast::transmute(0) } unsafe { cast::transmute(0) }
@ -67,7 +67,7 @@ impl Thread {
#[cfg(windows)] #[cfg(windows)]
fn native_thread_create(thread_start: extern "C" fn(*libc::c_void) -> rust_thread_return, fn native_thread_create(thread_start: extern "C" fn(*libc::c_void) -> rust_thread_return,
tramp: ~~fn()) -> rust_thread { tramp: ~proc()) -> rust_thread {
unsafe { unsafe {
let ptr: *mut libc::c_void = cast::transmute(tramp); let ptr: *mut libc::c_void = cast::transmute(tramp);
CreateThread(ptr::mut_null(), DEFAULT_STACK_SIZE, thread_start, ptr, 0, ptr::mut_null()) CreateThread(ptr::mut_null(), DEFAULT_STACK_SIZE, thread_start, ptr, 0, ptr::mut_null())
@ -82,7 +82,7 @@ fn native_thread_join(native: rust_thread) {
#[cfg(unix)] #[cfg(unix)]
fn native_thread_create(thread_start: extern "C" fn(*libc::c_void) -> rust_thread_return, fn native_thread_create(thread_start: extern "C" fn(*libc::c_void) -> rust_thread_return,
tramp: ~~fn()) -> rust_thread { tramp: ~proc()) -> rust_thread {
use unstable::intrinsics; use unstable::intrinsics;
let mut native: libc::pthread_t = unsafe { intrinsics::uninit() }; let mut native: libc::pthread_t = unsafe { intrinsics::uninit() };

View file

@ -195,7 +195,7 @@ pub struct TaskOpts {
// FIXME (#3724): Replace the 'consumed' bit with move mode on self // FIXME (#3724): Replace the 'consumed' bit with move mode on self
pub struct TaskBuilder { pub struct TaskBuilder {
opts: TaskOpts, opts: TaskOpts,
priv gen_body: Option<~fn(v: ~fn()) -> ~fn()>, priv gen_body: Option<proc(v: proc()) -> proc()>,
priv can_not_copy: Option<util::NonCopyable>, priv can_not_copy: Option<util::NonCopyable>,
priv consumed: bool, priv consumed: bool,
} }
@ -340,18 +340,18 @@ impl TaskBuilder {
* generator by applying the task body which results from the * generator by applying the task body which results from the
* existing body generator to the new body generator. * existing body generator to the new body generator.
*/ */
pub fn add_wrapper(&mut self, wrapper: ~fn(v: ~fn()) -> ~fn()) { pub fn add_wrapper(&mut self, wrapper: proc(v: proc()) -> proc()) {
let prev_gen_body = self.gen_body.take(); let prev_gen_body = self.gen_body.take();
let prev_gen_body = match prev_gen_body { let prev_gen_body = match prev_gen_body {
Some(gen) => gen, Some(gen) => gen,
None => { None => {
let f: ~fn(~fn()) -> ~fn() = |body| body; let f: proc(proc()) -> proc() = |body| body;
f f
} }
}; };
let prev_gen_body = Cell::new(prev_gen_body); let prev_gen_body = Cell::new(prev_gen_body);
let next_gen_body = { let next_gen_body = {
let f: ~fn(~fn()) -> ~fn() = |body| { let f: proc(proc()) -> proc() = |body| {
let prev_gen_body = prev_gen_body.take(); let prev_gen_body = prev_gen_body.take();
wrapper(prev_gen_body(body)) wrapper(prev_gen_body(body))
}; };
@ -372,7 +372,7 @@ impl TaskBuilder {
* When spawning into a new scheduler, the number of threads requested * When spawning into a new scheduler, the number of threads requested
* must be greater than zero. * must be greater than zero.
*/ */
pub fn spawn(&mut self, f: ~fn()) { pub fn spawn(&mut self, f: proc()) {
let gen_body = self.gen_body.take(); let gen_body = self.gen_body.take();
let notify_chan = self.opts.notify_chan.take(); let notify_chan = self.opts.notify_chan.take();
let name = self.opts.name.take(); let name = self.opts.name.take();
@ -399,7 +399,7 @@ impl TaskBuilder {
} }
/// Runs a task, while transferring ownership of one argument to the child. /// Runs a task, while transferring ownership of one argument to the child.
pub fn spawn_with<A:Send>(&mut self, arg: A, f: ~fn(v: A)) { pub fn spawn_with<A:Send>(&mut self, arg: A, f: proc(v: A)) {
let arg = Cell::new(arg); let arg = Cell::new(arg);
do self.spawn { do self.spawn {
f(arg.take()); f(arg.take());
@ -419,7 +419,7 @@ impl TaskBuilder {
* # Failure * # Failure
* Fails if a future_result was already set for this task. * Fails if a future_result was already set for this task.
*/ */
pub fn try<T:Send>(&mut self, f: ~fn() -> T) -> Result<T, ~Any> { pub fn try<T:Send>(&mut self, f: proc() -> T) -> Result<T, ~Any> {
let (po, ch) = stream::<T>(); let (po, ch) = stream::<T>();
let result = self.future_result(); let result = self.future_result();
@ -468,20 +468,20 @@ pub fn default_task_opts() -> TaskOpts {
/// the provided unique closure. /// the provided unique closure.
/// ///
/// This function is equivalent to `task().spawn(f)`. /// This function is equivalent to `task().spawn(f)`.
pub fn spawn(f: ~fn()) { pub fn spawn(f: proc()) {
let mut task = task(); let mut task = task();
task.spawn(f) task.spawn(f)
} }
/// Creates a child task unlinked from the current one. If either this /// Creates a child task unlinked from the current one. If either this
/// task or the child task fails, the other will not be killed. /// task or the child task fails, the other will not be killed.
pub fn spawn_unlinked(f: ~fn()) { pub fn spawn_unlinked(f: proc()) {
let mut task = task(); let mut task = task();
task.unlinked(); task.unlinked();
task.spawn(f) task.spawn(f)
} }
pub fn spawn_supervised(f: ~fn()) { pub fn spawn_supervised(f: proc()) {
/*! /*!
* Creates a child task supervised by the current one. If the child * Creates a child task supervised by the current one. If the child
* task fails, the parent will not be killed, but if the parent fails, * task fails, the parent will not be killed, but if the parent fails,
@ -498,13 +498,13 @@ pub fn spawn_supervised(f: ~fn()) {
/// (Note that this convenience wrapper still uses linked-failure, so the /// (Note that this convenience wrapper still uses linked-failure, so the
/// child's children will still be killable by the parent. For the fastest /// child's children will still be killable by the parent. For the fastest
/// possible spawn mode, use task::task().unlinked().indestructible().spawn.) /// possible spawn mode, use task::task().unlinked().indestructible().spawn.)
pub fn spawn_indestructible(f: ~fn()) { pub fn spawn_indestructible(f: proc()) {
let mut task = task(); let mut task = task();
task.indestructible(); task.indestructible();
task.spawn(f) task.spawn(f)
} }
pub fn spawn_with<A:Send>(arg: A, f: ~fn(v: A)) { pub fn spawn_with<A:Send>(arg: A, f: proc(v: A)) {
/*! /*!
* Runs a task, while transferring ownership of one argument to the * Runs a task, while transferring ownership of one argument to the
* child. * child.
@ -519,7 +519,7 @@ pub fn spawn_with<A:Send>(arg: A, f: ~fn(v: A)) {
task.spawn_with(arg, f) task.spawn_with(arg, f)
} }
pub fn spawn_sched(mode: SchedMode, f: ~fn()) { pub fn spawn_sched(mode: SchedMode, f: proc()) {
/*! /*!
* Creates a new task on a new or existing scheduler. * Creates a new task on a new or existing scheduler.
* *
@ -537,7 +537,7 @@ pub fn spawn_sched(mode: SchedMode, f: ~fn()) {
task.spawn(f) task.spawn(f)
} }
pub fn try<T:Send>(f: ~fn() -> T) -> Result<T, ~Any> { pub fn try<T:Send>(f: proc() -> T) -> Result<T, ~Any> {
/*! /*!
* Execute a function in another task and return either the return value * Execute a function in another task and return either the return value
* of the function or result::err. * of the function or result::err.
@ -1033,7 +1033,7 @@ fn test_add_wrapper() {
let ch = Cell::new(ch); let ch = Cell::new(ch);
do b0.add_wrapper |body| { do b0.add_wrapper |body| {
let ch = Cell::new(ch.take()); let ch = Cell::new(ch.take());
let result: ~fn() = || { let result: proc() = || {
let ch = ch.take(); let ch = ch.take();
body(); body();
ch.send(()); ch.send(());
@ -1201,7 +1201,7 @@ fn test_spawn_sched_blocking() {
} }
#[cfg(test)] #[cfg(test)]
fn avoid_copying_the_body(spawnfn: &fn(v: ~fn())) { fn avoid_copying_the_body(spawnfn: &fn(v: proc())) {
let (p, ch) = stream::<uint>(); let (p, ch) = stream::<uint>();
let x = ~1; let x = ~1;
@ -1327,7 +1327,7 @@ fn test_child_doesnt_ref_parent() {
// (well, it would if the constant were 8000+ - I lowered it to be more // (well, it would if the constant were 8000+ - I lowered it to be more
// valgrind-friendly. try this at home, instead..!) // valgrind-friendly. try this at home, instead..!)
static generations: uint = 16; static generations: uint = 16;
fn child_no(x: uint) -> ~fn() { fn child_no(x: uint) -> proc() {
return || { return || {
if x < generations { if x < generations {
let mut t = task(); let mut t = task();

View file

@ -562,13 +562,13 @@ fn enlist_many(child: &KillHandle, child_arc: &TaskGroupArc,
result result
} }
pub fn spawn_raw(mut opts: TaskOpts, f: ~fn()) { pub fn spawn_raw(mut opts: TaskOpts, f: proc()) {
assert!(in_green_task_context()); assert!(in_green_task_context());
let child_data = Cell::new(gen_child_taskgroup(opts.linked, opts.supervised)); let child_data = Cell::new(gen_child_taskgroup(opts.linked, opts.supervised));
let indestructible = opts.indestructible; let indestructible = opts.indestructible;
let child_wrapper: ~fn() = || { let child_wrapper: proc() = || {
// Child task runs this code. // Child task runs this code.
// If child data is 'None', the enlist is vacuously successful. // If child data is 'None', the enlist is vacuously successful.
@ -589,12 +589,14 @@ pub fn spawn_raw(mut opts: TaskOpts, f: ~fn()) {
} }
} }
}; };
// Should be run after the local-borrowed task is returned. // Should be run after the local-borrowed task is returned.
let f_cell = Cell::new(f);
if enlist_success { if enlist_success {
if indestructible { if indestructible {
do unkillable { f() } do unkillable { f_cell.take()() }
} else { } else {
f() f_cell.take()()
} }
} }
}; };
@ -683,7 +685,7 @@ pub fn spawn_raw(mut opts: TaskOpts, f: ~fn()) {
if opts.notify_chan.is_some() { if opts.notify_chan.is_some() {
let notify_chan = opts.notify_chan.take_unwrap(); let notify_chan = opts.notify_chan.take_unwrap();
let notify_chan = Cell::new(notify_chan); let notify_chan = Cell::new(notify_chan);
let on_exit: ~fn(UnwindResult) = |task_result| { let on_exit: proc(UnwindResult) = |task_result| {
notify_chan.take().send(task_result) notify_chan.take().send(task_result)
}; };
task.death.on_exit = Some(on_exit); task.death.on_exit = Some(on_exit);

View file

@ -54,7 +54,6 @@ impl<'self,T> Finally<T> for &'self fn() -> T {
} }
} }
finally_fn!(~fn() -> T)
finally_fn!(extern "Rust" fn() -> T) finally_fn!(extern "Rust" fn() -> T)
struct Finallyalizer<'self> { struct Finallyalizer<'self> {
@ -109,12 +108,3 @@ fn test_compact() {
but_always_run_this_function); but_always_run_this_function);
} }
#[test]
fn test_owned() {
fn spawn_with_finalizer(f: ~fn()) {
do spawn { do f.finally { } }
}
let owned: ~fn() = || { };
spawn_with_finalizer(owned);
}

View file

@ -36,7 +36,7 @@ for it to terminate.
The executing thread has no access to a task pointer and will be using The executing thread has no access to a task pointer and will be using
a normal large stack. a normal large stack.
*/ */
pub fn run_in_bare_thread(f: ~fn()) { pub fn run_in_bare_thread(f: proc()) {
use cell::Cell; use cell::Cell;
use rt::thread::Thread; use rt::thread::Thread;

View file

@ -41,7 +41,8 @@ pub enum ObsoleteSyntax {
ObsoleteLoopAsContinue, ObsoleteLoopAsContinue,
ObsoleteEnumWildcard, ObsoleteEnumWildcard,
ObsoleteStructWildcard, ObsoleteStructWildcard,
ObsoleteVecDotDotWildcard ObsoleteVecDotDotWildcard,
ObsoleteBoxedClosure,
} }
impl to_bytes::IterBytes for ObsoleteSyntax { impl to_bytes::IterBytes for ObsoleteSyntax {
@ -128,6 +129,11 @@ impl ParserObsoleteMethods for Parser {
"vec slice wildcard", "vec slice wildcard",
"use `..` instead of `.._` for matching slices" "use `..` instead of `.._` for matching slices"
), ),
ObsoleteBoxedClosure => (
"managed or owned closure",
"managed closures have been removed and owned closures are \
now written `proc()`"
),
}; };
self.report(sp, kind, kind_str, desc); self.report(sp, kind, kind_str, desc);

View file

@ -1273,15 +1273,17 @@ impl Parser {
pub fn parse_box_or_uniq_pointee(&self, pub fn parse_box_or_uniq_pointee(&self,
sigil: ast::Sigil, sigil: ast::Sigil,
ctor: &fn(v: mt) -> ty_) -> ty_ { ctor: &fn(v: mt) -> ty_) -> ty_ {
// ~'foo fn() or ~fn() are parsed directly as fn types: // ~'foo fn() or ~fn() are parsed directly as obsolete fn types:
match *self.token { match *self.token {
token::LIFETIME(*) => { token::LIFETIME(*) => {
let lifetime = self.parse_lifetime(); let lifetime = self.parse_lifetime();
self.obsolete(*self.last_span, ObsoleteBoxedClosure);
return self.parse_ty_closure(Some(sigil), Some(lifetime)); return self.parse_ty_closure(Some(sigil), Some(lifetime));
} }
token::IDENT(*) => { token::IDENT(*) if sigil == ast::BorrowedSigil => {
if self.token_is_old_style_closure_keyword() { if self.token_is_old_style_closure_keyword() {
self.obsolete(*self.last_span, ObsoleteBoxedClosure);
return self.parse_ty_closure(Some(sigil), None); return self.parse_ty_closure(Some(sigil), None);
} }
} }

View file

@ -53,7 +53,7 @@ fn grandchild_group(num_tasks: uint) {
// Master grandchild task exits early. // Master grandchild task exits early.
} }
fn spawn_supervised_blocking(myname: &str, f: ~fn()) { fn spawn_supervised_blocking(myname: &str, f: proc()) {
let mut builder = task::task(); let mut builder = task::task();
let res = builder.future_result(); let res = builder.future_result();
builder.supervised(); builder.supervised();

View file

@ -11,7 +11,7 @@
// xfail-test #2978 // xfail-test #2978
struct Foo { struct Foo {
f: ~fn() f: proc()
} }
fn call(x: @Foo) { fn call(x: @Foo) {

View file

@ -1,13 +1,8 @@
pub fn main() { pub fn main() {
let foo = ~3;
let _pfoo = &foo;
let _f: ~fn() -> int = || *foo + 5;
//~^ ERROR cannot move `foo`
// FIXME(#2202) - Due to the way that borrowck treats closures, // FIXME(#2202) - Due to the way that borrowck treats closures,
// you get two error reports here. // you get two error reports here.
let bar = ~3; let bar = ~3;
let _g = || { //~ ERROR capture of moved value let _g = || { //~ ERROR capture of moved value
let _h: ~fn() -> int = || *bar; //~ ERROR capture of moved value let _h: proc() -> int = || *bar; //~ ERROR capture of moved value
}; };
} }

View file

@ -1,4 +1,4 @@
fn call_f(f: ~fn:Send() -> int) -> int { fn call_f(f: proc() -> int) -> int {
f() f()
} }

View file

@ -9,10 +9,10 @@
// except according to those terms. // except according to those terms.
struct X { struct X {
field: ~fn:Send(), field: &'static fn:Send(),
} }
fn foo(blk: ~fn:()) -> X { fn foo(blk: &'static fn:()) -> X {
return X { field: blk }; //~ ERROR expected bounds `Send` but found no bounds return X { field: blk }; //~ ERROR expected bounds `Send` but found no bounds
} }

View file

@ -1,14 +0,0 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
let _: @'static whatever fn(); //~ ERROR expected `fn`, found `whatever`
let _: @'static fn();
}

View file

@ -14,7 +14,7 @@ fn foo(_x: @uint) {}
fn main() { fn main() {
let x = @3u; let x = @3u;
let _: ~fn() = || foo(x); //~ ERROR does not fulfill `Send` let _: proc() = || foo(x); //~ ERROR does not fulfill `Send`
let _: ~fn() = || foo(x); //~ ERROR does not fulfill `Send` let _: proc() = || foo(x); //~ ERROR does not fulfill `Send`
let _: ~fn() = || foo(x); //~ ERROR does not fulfill `Send` let _: proc() = || foo(x); //~ ERROR does not fulfill `Send`
} }

View file

@ -47,7 +47,7 @@ fn test<'a,T,U:Send>(_: &'a int) {
// but closure and object types can have lifetime bounds which make // but closure and object types can have lifetime bounds which make
// them not ok (FIXME #5121) // them not ok (FIXME #5121)
// assert_send::<~fn:'a()>(); // ERROR does not fulfill `Send` // assert_send::<proc:'a()>(); // ERROR does not fulfill `Send`
// assert_send::<~Dummy:'a>(); // ERROR does not fulfill `Send` // assert_send::<~Dummy:'a>(); // ERROR does not fulfill `Send`
// unsafe ptrs are ok unless they point at unsendable things // unsafe ptrs are ok unless they point at unsendable things

View file

@ -1,4 +1,4 @@
type Noncopyable = ~fn(); type Noncopyable = proc();
struct Foo { struct Foo {
copied: int, copied: int,

View file

@ -16,7 +16,7 @@ extern mod extra;
use extra::arc; use extra::arc;
use std::util; use std::util;
fn foo(blk: ~once fn()) { fn foo(blk: proc()) {
blk(); blk();
blk(); //~ ERROR use of moved value blk(); //~ ERROR use of moved value
} }

View file

@ -1,29 +0,0 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Testing guarantees provided by once functions.
// This program would segfault if it were legal.
extern mod extra;
use extra::arc;
use std::util;
fn foo(blk: ~fn()) {
blk();
blk();
}
fn main() {
let x = arc::Arc::new(true);
do foo {
assert!(*x.get());
util::ignore(x); //~ ERROR cannot move out of captured outer variable
}
}

View file

@ -11,7 +11,7 @@
// check that the &int here does not cause us to think that `foo` // check that the &int here does not cause us to think that `foo`
// contains region pointers // contains region pointers
struct foo(~fn(x: &int)); struct foo(proc(x: &int));
fn take_foo(x: foo<'static>) {} //~ ERROR wrong number of lifetime parameters fn take_foo(x: foo<'static>) {} //~ ERROR wrong number of lifetime parameters

View file

@ -51,7 +51,7 @@ fn main() {
zzz(); zzz();
sentinel(); sentinel();
let unique_closure: ~fn(int) = |x| { let unique_closure: proc(int) = |x| {
zzz(); zzz();
sentinel(); sentinel();

View file

@ -39,7 +39,7 @@ fn main() {
let owned = ~5; let owned = ~5;
let closure: ~fn() = || { let closure: proc() = || {
zzz(); zzz();
do_something(&constant, &a_struct.a, owned); do_something(&constant, &a_struct.a, owned);
}; };

View file

@ -12,5 +12,5 @@
fn from_foreign_fn(_x: fn()) { } fn from_foreign_fn(_x: fn()) { }
fn from_stack_closure(_x: ||) { } fn from_stack_closure(_x: ||) { }
fn from_unique_closure(_x: ~fn()) { } fn from_unique_closure(_x: proc()) { }
fn main() { } fn main() { }

View file

@ -18,7 +18,7 @@ fn failfn() {
fn main() { fn main() {
let y = ~0; let y = ~0;
let x: @~fn() = @(|| { let x: @proc() = @(|| {
error!("{:?}", y.clone()); error!("{:?}", y.clone());
}); });
failfn(); failfn();

View file

@ -10,7 +10,7 @@
extern mod extra; extern mod extra;
fn asSendfn( f : ~fn()->uint ) -> uint { fn asSendfn( f : proc()->uint ) -> uint {
return f(); return f();
} }

View file

@ -1,5 +1,5 @@
pub fn main() { pub fn main() {
let bar = ~3; let bar = ~3;
let h: ~fn() -> int = || *bar; let h: proc() -> int = || *bar;
assert_eq!(h(), 3); assert_eq!(h(), 3);
} }

View file

@ -13,11 +13,11 @@ use std::ptr;
pub fn main() { pub fn main() {
let x = ~3; let x = ~3;
let y = ptr::to_unsafe_ptr(&(*x)) as uint; let y = ptr::to_unsafe_ptr(&(*x)) as uint;
let snd_move: ~fn() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint; let snd_move: proc() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint;
assert_eq!(snd_move(), y); assert_eq!(snd_move(), y);
let x = ~4; let x = ~4;
let y = ptr::to_unsafe_ptr(&(*x)) as uint; let y = ptr::to_unsafe_ptr(&(*x)) as uint;
let lam_move: ~fn() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint; let lam_move: proc() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint;
assert_eq!(lam_move(), y); assert_eq!(lam_move(), y);
} }

View file

@ -19,7 +19,7 @@ struct Pair {
pub fn main() { pub fn main() {
let z = ~Pair { a : 10, b : 12}; let z = ~Pair { a : 10, b : 12};
let f: ~fn() = || { let f: proc() = || {
assert_eq!(z.a, 10); assert_eq!(z.a, 10);
assert_eq!(z.b, 12); assert_eq!(z.b, 12);
}; };

View file

@ -10,7 +10,7 @@
use std::comm; use std::comm;
fn foo(blk: ~fn:Send()) { fn foo(blk: proc()) {
blk(); blk();
} }

View file

@ -15,8 +15,8 @@ extern mod extra;
* *
* The hash should concentrate entropy in the lower bits. * The hash should concentrate entropy in the lower bits.
*/ */
type HashFn<K> = ~fn(K) -> uint; type HashFn<K> = proc(K) -> uint;
type EqFn<K> = ~fn(K, K) -> bool; type EqFn<K> = proc(K, K) -> bool;
struct LM { resize_at: uint, size: uint } struct LM { resize_at: uint, size: uint }

View file

@ -11,7 +11,7 @@
// xfail-test // xfail-test
static generations: uint = 1024+256+128+49; static generations: uint = 1024+256+128+49;
fn child_no(x: uint) -> ~fn() { fn child_no(x: uint) -> proc() {
|| { || {
if x < generations { if x < generations {
task::spawn(child_no(x+1)); task::spawn(child_no(x+1));

View file

@ -10,7 +10,7 @@
// xfail-test // xfail-test
type t = { type t = {
f: ~fn() f: proc()
}; };
pub fn main() { pub fn main() {

View file

@ -17,7 +17,7 @@ use std::path::{Path};
use std::path; use std::path;
use std::result; use std::result;
type rsrc_loader = ~fn(path: &Path) -> result::Result<~str, ~str>; type rsrc_loader = proc(path: &Path) -> result::Result<~str, ~str>;
fn tester() fn tester()
{ {

View file

@ -4,7 +4,7 @@ use std::comm::Chan;
use std::task; use std::task;
type RingBuffer = ~[f64]; type RingBuffer = ~[f64];
type SamplesFn = ~fn(samples: &RingBuffer); type SamplesFn = proc(samples: &RingBuffer);
enum Msg enum Msg
{ {

View file

@ -1,8 +0,0 @@
fn run(f: &fn()) {
f()
}
pub fn main() {
let f: ~fn() = || ();
run(f);
}

View file

@ -11,7 +11,7 @@
// Test that the lambda kind is inferred correctly as a return // Test that the lambda kind is inferred correctly as a return
// expression // expression
fn unique() -> ~fn() { return || (); } fn unique() -> proc() { return || (); }
pub fn main() { pub fn main() {
} }

View file

@ -11,7 +11,7 @@
// Test that the lambda kind is inferred correctly as a return // Test that the lambda kind is inferred correctly as a return
// expression // expression
fn unique() -> ~fn() { || () } fn unique() -> proc() { || () }
pub fn main() { pub fn main() {
} }

View file

@ -17,7 +17,7 @@ extern mod extra;
use extra::arc; use extra::arc;
use std::util; use std::util;
fn foo(blk: ~once fn()) { fn foo(blk: proc()) {
blk(); blk();
} }

View file

@ -69,6 +69,6 @@ pub fn main() {
assert_eq!(q.y, !(p.y)); assert_eq!(q.y, !(p.y));
// Issue #1733 // Issue #1733
let result: ~fn(int) = |_|(); let result: proc(int) = |_|();
result(p[true]); result(p[true]);
} }

View file

@ -1,46 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// xfail-fast
use std::task;
pub fn main() { test05(); }
#[deriving(Clone)]
struct Pair<A,B> {
a: A,
b: B,
}
fn make_generic_record<A,B>(a: A, b: B) -> Pair<A,B> {
return Pair {a: a, b: b};
}
fn test05_start(f: &~fn(v: f64, v: ~str) -> Pair<f64, ~str>) {
let p = (*f)(22.22, ~"Hi");
info!("{:?}", p.clone());
assert!(p.a == 22.22);
assert!(p.b == ~"Hi");
let q = (*f)(44.44, ~"Ho");
info!("{:?}", q.clone());
assert!(q.a == 44.44);
assert!(q.b == ~"Ho");
}
fn spawn<A,B>(f: extern fn(&~fn(A,B)->Pair<A,B>)) {
let arg: ~fn(A, B) -> Pair<A,B> = |a, b| make_generic_record(a, b);
task::spawn(|| f(&arg));
}
fn test05() {
spawn::<f64,~str>(test05_start);
}

View file

@ -13,13 +13,13 @@ use std::task;
pub fn main() { test05(); } pub fn main() { test05(); }
fn test05_start(f: ~fn(int)) { fn test05_start(f: proc(int)) {
f(22); f(22);
} }
fn test05() { fn test05() {
let three = ~3; let three = ~3;
let fn_to_send: ~fn(int) = |n| { let fn_to_send: proc(int) = |n| {
error!("{}", *three + n); // will copy x into the closure error!("{}", *three + n); // will copy x into the closure
assert_eq!(*three, 3); assert_eq!(*three, 3);
}; };

View file

@ -34,8 +34,8 @@ pub enum TestName {
} }
pub enum TestFn { pub enum TestFn {
DynTestFn(~fn()), DynTestFn(proc()),
DynBenchFn(~fn(&mut int)) DynBenchFn(proc(&mut int))
} }
pub struct TestDesc { pub struct TestDesc {

View file

@ -44,7 +44,7 @@ fn notify(ch: Chan<bool>, v: @mut bool) -> notify {
} }
} }
fn joinable(f: ~fn()) -> Port<bool> { fn joinable(f: proc()) -> Port<bool> {
fn wrapper(c: Chan<bool>, f: &fn()) { fn wrapper(c: Chan<bool>, f: &fn()) {
let b = @mut false; let b = @mut false;
error!("wrapper: task=%? allocated v=%x", error!("wrapper: task=%? allocated v=%x",

View file

@ -40,7 +40,7 @@ fn test_tempdir() {
fn test_rm_tempdir() { fn test_rm_tempdir() {
let (rd, wr) = stream(); let (rd, wr) = stream();
let f: ~fn() = || { let f: proc() = || {
let tmp = TempDir::new("test_rm_tempdir").unwrap(); let tmp = TempDir::new("test_rm_tempdir").unwrap();
wr.send(tmp.path().clone()); wr.send(tmp.path().clone());
fail!("fail to unwind past `tmp`"); fail!("fail to unwind past `tmp`");
@ -52,7 +52,7 @@ fn test_rm_tempdir() {
let tmp = TempDir::new("test_rm_tempdir").unwrap(); let tmp = TempDir::new("test_rm_tempdir").unwrap();
let path = tmp.path().clone(); let path = tmp.path().clone();
let cell = Cell::new(tmp); let cell = Cell::new(tmp);
let f: ~fn() = || { let f: proc() = || {
let _tmp = cell.take(); let _tmp = cell.take();
fail!("fail to unwind past `tmp`"); fail!("fail to unwind past `tmp`");
}; };
@ -61,7 +61,7 @@ fn test_rm_tempdir() {
let path; let path;
{ {
let f: ~fn() -> TempDir = || { let f: proc() -> TempDir = || {
TempDir::new("test_rm_tempdir").unwrap() TempDir::new("test_rm_tempdir").unwrap()
}; };
let tmp = task::try(f).expect("test_rm_tmdir"); let tmp = task::try(f).expect("test_rm_tmdir");

View file

@ -19,11 +19,11 @@ enum maybe_pointy {
struct Pointy { struct Pointy {
a : maybe_pointy, a : maybe_pointy,
d : ~fn() -> uint, d : proc() -> uint,
} }
fn make_uniq_closure<A:Send>(a: A) -> ~fn() -> uint { fn make_uniq_closure<A:Send>(a: A) -> proc() -> uint {
let result: ~fn() -> uint = || ptr::to_unsafe_ptr(&a) as uint; let result: proc() -> uint = || ptr::to_unsafe_ptr(&a) as uint;
result result
} }

View file

@ -18,7 +18,7 @@ enum maybe_pointy {
struct Pointy { struct Pointy {
a : maybe_pointy, a : maybe_pointy,
c : ~int, c : ~int,
d : ~fn()->(), d : proc()->(),
} }
fn empty_pointy() -> @mut Pointy { fn empty_pointy() -> @mut Pointy {