Skip to content

libstd: Change all ~fn()s to procs in the standard library. #10554

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

Closed
wants to merge 1 commit into from
Closed
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 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
12 changes: 6 additions & 6 deletions src/libstd/rt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pub mod borrowck;
/// # Return value
///
/// 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);
let exit_code = run(main);
Expand All @@ -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,
/// 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);
let exit_code = run_on_main_thread(main);
cleanup();
Expand Down Expand Up @@ -254,15 +254,15 @@ pub fn cleanup() {
/// Configures the runtime according to the environment, by default
/// using a task scheduler with the same number of threads as cores.
/// Returns a process exit code.
pub fn run(main: ~fn()) -> int {
pub fn run(main: proc()) -> int {
run_(main, false)
}

pub fn run_on_main_thread(main: ~fn()) -> int {
pub fn run_on_main_thread(main: proc()) -> int {
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;

let nscheds = util::default_sched_threads();
Expand Down Expand Up @@ -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
// task tree, shut down the schedulers and set the exit code.
let handles = Cell::new(handles);
let on_exit: ~fn(UnwindResult) = |exit_success| {
let on_exit: proc(UnwindResult) = |exit_success| {
unsafe {
assert!(!(*exited_already.get()).swap(true, SeqCst),
"the runtime already exited");
Expand Down
4 changes: 3 additions & 1 deletion src/libstd/rt/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,9 @@ mod test {
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);

sched.bootstrap(task);
Expand Down
31 changes: 20 additions & 11 deletions src/libstd/rt/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ impl Task {

// A helper to build a new task using the dynamically found
// 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 home = Cell::new(home);
do Local::borrow |running_task: &mut Task| {
Expand All @@ -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)
}

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 home = Cell::new(home);
do Local::borrow |running_task: &mut Task| {
Expand All @@ -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)
}

Expand All @@ -196,21 +202,21 @@ impl Task {

pub fn new_root(stack_pool: &mut StackPool,
stack_size: Option<uint>,
start: ~fn()) -> Task {
start: proc()) -> Task {
Task::new_root_homed(stack_pool, stack_size, AnySched, start)
}

pub fn new_child(&mut self,
stack_pool: &mut StackPool,
stack_size: Option<uint>,
start: ~fn()) -> Task {
start: proc()) -> Task {
self.new_child_homed(stack_pool, stack_size, AnySched, start)
}

pub fn new_root_homed(stack_pool: &mut StackPool,
stack_size: Option<uint>,
home: SchedHome,
start: ~fn()) -> Task {
start: proc()) -> Task {
Task {
heap: LocalHeap::new(),
gc: GarbageCollector,
Expand All @@ -233,7 +239,7 @@ impl Task {
stack_pool: &mut StackPool,
stack_size: Option<uint>,
home: SchedHome,
start: ~fn()) -> Task {
start: proc()) -> Task {
Task {
heap: LocalHeap::new(),
gc: GarbageCollector,
Expand Down Expand Up @@ -404,7 +410,10 @@ impl Drop for Task {

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 {
Some(size) => size,
None => env::min_stack()
Expand All @@ -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 wrapper: ~fn() = || {
let wrapper: proc() = || {
// First code after swap to this new context. Run our
// cleanup job.
unsafe {
Expand Down
30 changes: 15 additions & 15 deletions src/libstd/rt/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,28 @@ pub fn new_test_sched() -> Scheduler {
return sched;
}

pub fn run_in_uv_task(f: ~fn()) {
pub fn run_in_uv_task(f: proc()) {
let f = Cell::new(f);
do run_in_bare_thread {
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);
do run_in_bare_thread {
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;

let mut sched = ~new_test_uv_sched();
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);
rtassert!(exit_status.is_success());
};
Expand All @@ -96,13 +96,13 @@ pub fn run_in_uv_task_core(f: ~fn()) {
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;

let mut sched = ~new_test_sched();
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);
rtassert!(exit_status.is_success());
};
Expand Down Expand Up @@ -196,7 +196,7 @@ pub fn prepare_for_lots_of_tests() {
/// Create more than one scheduler and run a function in a task
/// in one of the schedulers. The schedulers will stay alive
/// 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 from_str::FromStr;
use rt::sched::Shutdown;
Expand Down Expand Up @@ -246,7 +246,7 @@ pub fn run_in_mt_newsched_task(f: ~fn()) {
}

let handles = Cell::new(handles);
let on_exit: ~fn(UnwindResult) = |exit_status| {
let on_exit: proc(UnwindResult) = |exit_status| {
let mut handles = handles.take();
// Tell schedulers to exit
for handle in handles.mut_iter() {
Expand Down Expand Up @@ -295,16 +295,16 @@ pub fn run_in_mt_newsched_task(f: ~fn()) {
}

/// 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));
}

/// 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));
}

pub fn spawntask_random(f: ~fn()) {
pub fn spawntask_random(f: proc()) {
use rand::{Rand, rng};

let mut rng = rng();
Expand All @@ -317,11 +317,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 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);
new_task.death.on_exit = Some(on_exit);
Expand All @@ -334,7 +334,7 @@ pub fn spawntask_try(f: ~fn()) -> Result<(),()> {
}

/// 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);

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

/// 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 {
let mut sched = ~new_test_sched();
let task = blk(~Task::new_root(&mut sched.stack_pool, None, ||{}));
Expand Down
Loading