convert most of libcore records into structs
This commit is contained in:
parent
6e2ae2c2c1
commit
e4d4a1499b
7 changed files with 105 additions and 86 deletions
|
@ -87,7 +87,10 @@ unsafe fn get_safe_point_count() -> uint {
|
|||
return *module_meta;
|
||||
}
|
||||
|
||||
type SafePoint = { sp_meta: *Word, fn_meta: *Word };
|
||||
struct SafePoint {
|
||||
sp_meta: *Word,
|
||||
fn_meta: *Word,
|
||||
}
|
||||
|
||||
// Returns the safe point metadata for the given program counter, if
|
||||
// any.
|
||||
|
@ -106,7 +109,10 @@ unsafe fn is_safe_point(pc: *Word) -> Option<SafePoint> {
|
|||
let sp: **Word = bump(safe_points, spi*3);
|
||||
let sp_loc = *sp;
|
||||
if sp_loc == pc {
|
||||
return Some({sp_meta: *bump(sp, 1), fn_meta: *bump(sp, 2)});
|
||||
return Some(SafePoint {
|
||||
sp_meta: *bump(sp, 1),
|
||||
fn_meta: *bump(sp, 2),
|
||||
});
|
||||
}
|
||||
spi += 1;
|
||||
}
|
||||
|
|
|
@ -1086,11 +1086,9 @@ pub fn read_whole_file(file: &Path) -> Result<~[u8], ~str> {
|
|||
// fsync related
|
||||
|
||||
pub mod fsync {
|
||||
use prelude::*;
|
||||
use io::{FILERes, FdRes, fd_t};
|
||||
use kinds::Copy;
|
||||
use libc;
|
||||
use option::Option;
|
||||
use option;
|
||||
use os;
|
||||
|
||||
pub enum Level {
|
||||
|
@ -1127,11 +1125,11 @@ pub mod fsync {
|
|||
}
|
||||
}
|
||||
|
||||
pub type Arg<t> = {
|
||||
pub struct Arg<t> {
|
||||
val: t,
|
||||
opt_level: Option<Level>,
|
||||
fsync_fn: fn@(f: t, Level) -> int
|
||||
};
|
||||
fsync_fn: fn@(f: t, Level) -> int,
|
||||
}
|
||||
|
||||
// fsync file after executing blk
|
||||
// FIXME (#2004) find better way to create resources within lifetime of
|
||||
|
@ -1139,7 +1137,7 @@ pub mod fsync {
|
|||
pub fn FILE_res_sync(file: &FILERes, opt_level: Option<Level>,
|
||||
blk: fn(v: Res<*libc::FILE>)) {
|
||||
unsafe {
|
||||
blk(move Res({
|
||||
blk(Res(Arg {
|
||||
val: file.f, opt_level: opt_level,
|
||||
fsync_fn: fn@(file: *libc::FILE, l: Level) -> int {
|
||||
unsafe {
|
||||
|
@ -1153,7 +1151,7 @@ pub mod fsync {
|
|||
// fsync fd after executing blk
|
||||
pub fn fd_res_sync(fd: &FdRes, opt_level: Option<Level>,
|
||||
blk: fn(v: Res<fd_t>)) {
|
||||
blk(move Res({
|
||||
blk(Res(Arg {
|
||||
val: fd.fd, opt_level: opt_level,
|
||||
fsync_fn: fn@(fd: fd_t, l: Level) -> int {
|
||||
return os::fsync_fd(fd, l) as int;
|
||||
|
@ -1167,7 +1165,7 @@ pub mod fsync {
|
|||
// Call o.fsync after executing blk
|
||||
pub fn obj_sync(o: FSyncable, opt_level: Option<Level>,
|
||||
blk: fn(v: Res<FSyncable>)) {
|
||||
blk(Res({
|
||||
blk(Res(Arg {
|
||||
val: o, opt_level: opt_level,
|
||||
fsync_fn: fn@(o: FSyncable, l: Level) -> int {
|
||||
return o.fsync(l);
|
||||
|
|
|
@ -42,7 +42,10 @@ pub trait Rng {
|
|||
}
|
||||
|
||||
/// A value with a particular weight compared to other values
|
||||
pub type Weighted<T> = { weight: uint, item: T };
|
||||
pub struct Weighted<T> {
|
||||
weight: uint,
|
||||
item: T,
|
||||
}
|
||||
|
||||
/// Extension methods for random number generators
|
||||
impl Rng {
|
||||
|
@ -312,12 +315,12 @@ pub fn seeded_rng(seed: &~[u8]) -> Rng {
|
|||
}
|
||||
}
|
||||
|
||||
type XorShiftState = {
|
||||
struct XorShiftState {
|
||||
mut x: u32,
|
||||
mut y: u32,
|
||||
mut z: u32,
|
||||
mut w: u32
|
||||
};
|
||||
mut w: u32,
|
||||
}
|
||||
|
||||
impl XorShiftState: Rng {
|
||||
fn next() -> u32 {
|
||||
|
@ -338,7 +341,7 @@ pub pure fn xorshift() -> Rng {
|
|||
}
|
||||
|
||||
pub pure fn seeded_xorshift(x: u32, y: u32, z: u32, w: u32) -> Rng {
|
||||
{mut x: x, mut y: y, mut z: z, mut w: w} as Rng
|
||||
XorShiftState { x: x, y: y, z: z, w: w } as Rng
|
||||
}
|
||||
|
||||
|
||||
|
@ -492,21 +495,24 @@ pub mod tests {
|
|||
#[test]
|
||||
pub fn choose_weighted() {
|
||||
let r = rand::Rng();
|
||||
assert r.choose_weighted(~[{weight: 1u, item: 42}]) == 42;
|
||||
assert r.choose_weighted(~[
|
||||
{weight: 0u, item: 42},
|
||||
{weight: 1u, item: 43}
|
||||
rand::Weighted { weight: 1u, item: 42 },
|
||||
]) == 42;
|
||||
assert r.choose_weighted(~[
|
||||
rand::Weighted { weight: 0u, item: 42 },
|
||||
rand::Weighted { weight: 1u, item: 43 },
|
||||
]) == 43;
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn choose_weighted_option() {
|
||||
let r = rand::Rng();
|
||||
assert r.choose_weighted_option(~[{weight: 1u, item: 42}]) ==
|
||||
Some(42);
|
||||
assert r.choose_weighted_option(~[
|
||||
{weight: 0u, item: 42},
|
||||
{weight: 1u, item: 43}
|
||||
rand::Weighted { weight: 1u, item: 42 },
|
||||
]) == Some(42);
|
||||
assert r.choose_weighted_option(~[
|
||||
rand::Weighted { weight: 0u, item: 42 },
|
||||
rand::Weighted { weight: 1u, item: 43 },
|
||||
]) == Some(43);
|
||||
let v: Option<int> = r.choose_weighted_option([]);
|
||||
assert v.is_none();
|
||||
|
@ -518,9 +524,9 @@ pub mod tests {
|
|||
let empty: ~[int] = ~[];
|
||||
assert r.weighted_vec(~[]) == empty;
|
||||
assert r.weighted_vec(~[
|
||||
{weight: 0u, item: 3u},
|
||||
{weight: 1u, item: 2u},
|
||||
{weight: 2u, item: 1u}
|
||||
rand::Weighted { weight: 0u, item: 3u },
|
||||
rand::Weighted { weight: 1u, item: 2u },
|
||||
rand::Weighted { weight: 2u, item: 1u },
|
||||
]) == ~[2u, 1u, 1u];
|
||||
}
|
||||
|
||||
|
|
|
@ -220,11 +220,13 @@ pub fn start_program(prog: &str, args: &[~str]) -> Program {
|
|||
libc::close(pipe_err.out);
|
||||
}
|
||||
|
||||
type ProgRepr = {pid: pid_t,
|
||||
mut in_fd: c_int,
|
||||
out_file: *libc::FILE,
|
||||
err_file: *libc::FILE,
|
||||
mut finished: bool};
|
||||
struct ProgRepr {
|
||||
pid: pid_t,
|
||||
mut in_fd: c_int,
|
||||
out_file: *libc::FILE,
|
||||
err_file: *libc::FILE,
|
||||
mut finished: bool,
|
||||
}
|
||||
|
||||
fn close_repr_input(r: &ProgRepr) {
|
||||
let invalid_fd = -1i32;
|
||||
|
@ -274,12 +276,15 @@ pub fn start_program(prog: &str, args: &[~str]) -> Program {
|
|||
fn finish() -> int { finish_repr(&self.r) }
|
||||
fn destroy() { destroy_repr(&self.r); }
|
||||
}
|
||||
let repr = {pid: pid,
|
||||
mut in_fd: pipe_input.out,
|
||||
out_file: os::fdopen(pipe_output.in),
|
||||
err_file: os::fdopen(pipe_err.in),
|
||||
mut finished: false};
|
||||
return ProgRes(move repr) as Program;
|
||||
let repr = ProgRepr {
|
||||
pid: pid,
|
||||
in_fd: pipe_input.out,
|
||||
out_file: os::fdopen(pipe_output.in),
|
||||
err_file: os::fdopen(pipe_err.in),
|
||||
finished: false,
|
||||
};
|
||||
|
||||
ProgRes(repr) as Program
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -168,10 +168,10 @@ impl SchedMode : cmp::Eq {
|
|||
* default these foreign stacks have unspecified size, but with this
|
||||
* option their size can be precisely specified.
|
||||
*/
|
||||
pub type SchedOpts = {
|
||||
pub struct SchedOpts {
|
||||
mode: SchedMode,
|
||||
foreign_stack_size: Option<uint>
|
||||
};
|
||||
foreign_stack_size: Option<uint>,
|
||||
}
|
||||
|
||||
/**
|
||||
* Task configuration options
|
||||
|
@ -200,12 +200,12 @@ pub type SchedOpts = {
|
|||
* into foreign code that blocks. Without doing so in a different
|
||||
* scheduler other tasks will be impeded or even blocked indefinitely.
|
||||
*/
|
||||
pub type TaskOpts = {
|
||||
pub struct TaskOpts {
|
||||
linked: bool,
|
||||
supervised: bool,
|
||||
mut notify_chan: Option<Chan<TaskResult>>,
|
||||
sched: Option<SchedOpts>,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The task builder type.
|
||||
|
@ -251,15 +251,15 @@ priv impl TaskBuilder {
|
|||
self.consumed = true;
|
||||
let notify_chan = replace(&mut self.opts.notify_chan, None);
|
||||
TaskBuilder {
|
||||
opts: {
|
||||
opts: TaskOpts {
|
||||
linked: self.opts.linked,
|
||||
supervised: self.opts.supervised,
|
||||
mut notify_chan: move notify_chan,
|
||||
notify_chan: notify_chan,
|
||||
sched: self.opts.sched
|
||||
},
|
||||
gen_body: self.gen_body,
|
||||
can_not_copy: None,
|
||||
mut consumed: false
|
||||
consumed: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -272,10 +272,10 @@ impl TaskBuilder {
|
|||
fn unlinked() -> TaskBuilder {
|
||||
let notify_chan = replace(&mut self.opts.notify_chan, None);
|
||||
TaskBuilder {
|
||||
opts: {
|
||||
opts: TaskOpts {
|
||||
linked: false,
|
||||
supervised: self.opts.supervised,
|
||||
mut notify_chan: move notify_chan,
|
||||
notify_chan: notify_chan,
|
||||
sched: self.opts.sched
|
||||
},
|
||||
can_not_copy: None,
|
||||
|
@ -290,10 +290,10 @@ impl TaskBuilder {
|
|||
fn supervised() -> TaskBuilder {
|
||||
let notify_chan = replace(&mut self.opts.notify_chan, None);
|
||||
TaskBuilder {
|
||||
opts: {
|
||||
opts: TaskOpts {
|
||||
linked: false,
|
||||
supervised: true,
|
||||
mut notify_chan: move notify_chan,
|
||||
notify_chan: notify_chan,
|
||||
sched: self.opts.sched
|
||||
},
|
||||
can_not_copy: None,
|
||||
|
@ -307,10 +307,10 @@ impl TaskBuilder {
|
|||
fn linked() -> TaskBuilder {
|
||||
let notify_chan = replace(&mut self.opts.notify_chan, None);
|
||||
TaskBuilder {
|
||||
opts: {
|
||||
opts: TaskOpts {
|
||||
linked: true,
|
||||
supervised: false,
|
||||
mut notify_chan: move notify_chan,
|
||||
notify_chan: notify_chan,
|
||||
sched: self.opts.sched
|
||||
},
|
||||
can_not_copy: None,
|
||||
|
@ -352,10 +352,10 @@ impl TaskBuilder {
|
|||
|
||||
// Reconfigure self to use a notify channel.
|
||||
TaskBuilder {
|
||||
opts: {
|
||||
opts: TaskOpts {
|
||||
linked: self.opts.linked,
|
||||
supervised: self.opts.supervised,
|
||||
mut notify_chan: Some(move notify_pipe_ch),
|
||||
notify_chan: Some(notify_pipe_ch),
|
||||
sched: self.opts.sched
|
||||
},
|
||||
can_not_copy: None,
|
||||
|
@ -366,11 +366,14 @@ impl TaskBuilder {
|
|||
fn sched_mode(mode: SchedMode) -> TaskBuilder {
|
||||
let notify_chan = replace(&mut self.opts.notify_chan, None);
|
||||
TaskBuilder {
|
||||
opts: {
|
||||
opts: TaskOpts {
|
||||
linked: self.opts.linked,
|
||||
supervised: self.opts.supervised,
|
||||
mut notify_chan: move notify_chan,
|
||||
sched: Some({ mode: mode, foreign_stack_size: None})
|
||||
notify_chan: notify_chan,
|
||||
sched: Some(SchedOpts {
|
||||
mode: mode,
|
||||
foreign_stack_size: None,
|
||||
})
|
||||
},
|
||||
can_not_copy: None,
|
||||
.. self.consume()
|
||||
|
@ -393,10 +396,10 @@ impl TaskBuilder {
|
|||
let prev_gen_body = self.gen_body;
|
||||
let notify_chan = replace(&mut self.opts.notify_chan, None);
|
||||
TaskBuilder {
|
||||
opts: {
|
||||
opts: TaskOpts {
|
||||
linked: self.opts.linked,
|
||||
supervised: self.opts.supervised,
|
||||
mut notify_chan: move notify_chan,
|
||||
notify_chan: notify_chan,
|
||||
sched: self.opts.sched
|
||||
},
|
||||
// tjc: I think this is the line that gets miscompiled
|
||||
|
@ -424,10 +427,10 @@ impl TaskBuilder {
|
|||
fn spawn(f: fn~()) {
|
||||
let notify_chan = replace(&mut self.opts.notify_chan, None);
|
||||
let x = self.consume();
|
||||
let opts = {
|
||||
let opts = TaskOpts {
|
||||
linked: x.opts.linked,
|
||||
supervised: x.opts.supervised,
|
||||
mut notify_chan: move notify_chan,
|
||||
notify_chan: notify_chan,
|
||||
sched: x.opts.sched
|
||||
};
|
||||
spawn::spawn_raw(move opts, (x.gen_body)(move f));
|
||||
|
@ -482,10 +485,10 @@ pub fn default_task_opts() -> TaskOpts {
|
|||
* into the same scheduler, and do not post lifecycle notifications.
|
||||
*/
|
||||
|
||||
{
|
||||
TaskOpts {
|
||||
linked: true,
|
||||
supervised: false,
|
||||
mut notify_chan: None,
|
||||
notify_chan: None,
|
||||
sched: None
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,14 +114,14 @@ pub fn taskset_each(tasks: &TaskSet, blk: fn(v: *rust_task) -> bool) {
|
|||
}
|
||||
|
||||
// One of these per group of linked-failure tasks.
|
||||
type TaskGroupData = {
|
||||
struct TaskGroupData {
|
||||
// All tasks which might kill this group. When this is empty, the group
|
||||
// can be "GC"ed (i.e., its link in the ancestor list can be removed).
|
||||
mut members: TaskSet,
|
||||
// All tasks unidirectionally supervised by (directly or transitively)
|
||||
// tasks in this group.
|
||||
mut descendants: TaskSet,
|
||||
};
|
||||
}
|
||||
type TaskGroupArc = private::Exclusive<Option<TaskGroupData>>;
|
||||
|
||||
type TaskGroupInner = &mut Option<TaskGroupData>;
|
||||
|
@ -138,7 +138,7 @@ pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool {
|
|||
// taskgroup which was spawned-unlinked. Tasks from intermediate generations
|
||||
// have references to the middle of the list; when intermediate generations
|
||||
// die, their node in the list will be collected at a descendant's spawn-time.
|
||||
type AncestorNode = {
|
||||
struct AncestorNode {
|
||||
// Since the ancestor list is recursive, we end up with references to
|
||||
// exclusives within other exclusives. This is dangerous business (if
|
||||
// circular references arise, deadlock and memory leaks are imminent).
|
||||
|
@ -150,7 +150,8 @@ type AncestorNode = {
|
|||
mut parent_group: Option<TaskGroupArc>,
|
||||
// Recursive rest of the list.
|
||||
mut ancestors: AncestorList,
|
||||
};
|
||||
}
|
||||
|
||||
enum AncestorList = Option<private::Exclusive<AncestorNode>>;
|
||||
|
||||
// Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety.
|
||||
|
@ -450,11 +451,10 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
|
|||
// Main task, doing first spawn ever. Lazily initialise here.
|
||||
let mut members = new_taskset();
|
||||
taskset_insert(&mut members, spawner);
|
||||
let tasks =
|
||||
private::exclusive(Some({
|
||||
mut members: move members,
|
||||
mut descendants: new_taskset()
|
||||
}));
|
||||
let tasks = private::exclusive(Some(TaskGroupData {
|
||||
members: members,
|
||||
descendants: new_taskset(),
|
||||
}));
|
||||
// Main task/group has no ancestors, no notifier, etc.
|
||||
let group =
|
||||
@TCB(spawner, move tasks, AncestorList(None), true, None);
|
||||
|
@ -475,9 +475,9 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
|
|||
(move g, move a, spawner_group.is_main)
|
||||
} else {
|
||||
// Child is in a separate group from spawner.
|
||||
let g = private::exclusive(Some({
|
||||
mut members: new_taskset(),
|
||||
mut descendants: new_taskset()
|
||||
let g = private::exclusive(Some(TaskGroupData {
|
||||
members: new_taskset(),
|
||||
descendants: new_taskset(),
|
||||
}));
|
||||
let a = if supervised {
|
||||
// Child's ancestors start with the spawner.
|
||||
|
@ -495,10 +495,11 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
|
|||
};
|
||||
assert new_generation < uint::max_value;
|
||||
// Build a new node in the ancestor list.
|
||||
AncestorList(Some(private::exclusive(
|
||||
{ generation: new_generation,
|
||||
mut parent_group: Some(spawner_group.tasks.clone()),
|
||||
mut ancestors: move old_ancestors })))
|
||||
AncestorList(Some(private::exclusive(AncestorNode {
|
||||
generation: new_generation,
|
||||
parent_group: Some(spawner_group.tasks.clone()),
|
||||
ancestors: old_ancestors,
|
||||
})))
|
||||
} else {
|
||||
// Child has no ancestors.
|
||||
AncestorList(None)
|
||||
|
@ -685,9 +686,9 @@ fn test_spawn_raw_simple() {
|
|||
#[test]
|
||||
#[ignore(cfg(windows))]
|
||||
fn test_spawn_raw_unsupervise() {
|
||||
let opts = {
|
||||
let opts = task::TaskOpts {
|
||||
linked: false,
|
||||
mut notify_chan: None,
|
||||
notify_chan: None,
|
||||
.. default_task_opts()
|
||||
};
|
||||
do spawn_raw(move opts) {
|
||||
|
@ -700,8 +701,8 @@ fn test_spawn_raw_unsupervise() {
|
|||
fn test_spawn_raw_notify_success() {
|
||||
let (notify_po, notify_ch) = pipes::stream();
|
||||
|
||||
let opts = {
|
||||
notify_chan: Some(move notify_ch),
|
||||
let opts = task::TaskOpts {
|
||||
notify_chan: Some(notify_ch),
|
||||
.. default_task_opts()
|
||||
};
|
||||
do spawn_raw(move opts) {
|
||||
|
@ -715,9 +716,9 @@ fn test_spawn_raw_notify_failure() {
|
|||
// New bindings for these
|
||||
let (notify_po, notify_ch) = pipes::stream();
|
||||
|
||||
let opts = {
|
||||
let opts = task::TaskOpts {
|
||||
linked: false,
|
||||
notify_chan: Some(move notify_ch),
|
||||
notify_chan: Some(notify_ch),
|
||||
.. default_task_opts()
|
||||
};
|
||||
do spawn_raw(move opts) {
|
||||
|
|
|
@ -2027,10 +2027,10 @@ pub mod raw {
|
|||
unboxed: UnboxedVecRepr
|
||||
}
|
||||
|
||||
pub type SliceRepr = {
|
||||
pub struct SliceRepr {
|
||||
mut data: *u8,
|
||||
mut len: uint
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the length of a vector
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue