Merge remote-tracking branch 'mozilla/master' into incoming

Conflicts:
	src/librustc/middle/astencode.rs
	src/librustc/middle/check_const.rs
This commit is contained in:
Brian Anderson 2013-06-25 19:03:12 -07:00
commit 5d3ca4b843
137 changed files with 2252 additions and 1559 deletions

View file

@ -239,29 +239,29 @@ $(foreach target,$(CFG_TARGET_TRIPLES),\
# Standard library variables
######################################################################
STDLIB_CRATE := $(S)src/libstd/core.rc
STDLIB_CRATE := $(S)src/libstd/std.rs
STDLIB_INPUTS := $(wildcard $(addprefix $(S)src/libstd/, \
core.rc *.rs */*.rs */*/*rs */*/*/*rs))
*.rs */*.rs */*/*rs */*/*/*rs))
######################################################################
# Extra library variables
######################################################################
EXTRALIB_CRATE := $(S)src/libextra/std.rc
EXTRALIB_CRATE := $(S)src/libextra/extra.rs
EXTRALIB_INPUTS := $(wildcard $(addprefix $(S)src/libextra/, \
std.rc *.rs */*.rs))
*.rs */*.rs))
######################################################################
# rustc crate variables
######################################################################
COMPILER_CRATE := $(S)src/librustc/rustc.rc
COMPILER_CRATE := $(S)src/librustc/rustc.rs
COMPILER_INPUTS := $(wildcard $(addprefix $(S)src/librustc/, \
rustc.rc *.rs */*.rs */*/*.rs */*/*/*.rs))
*.rs */*.rs */*/*.rs */*/*/*.rs))
LIBSYNTAX_CRATE := $(S)src/libsyntax/syntax.rc
LIBSYNTAX_CRATE := $(S)src/libsyntax/syntax.rs
LIBSYNTAX_INPUTS := $(wildcard $(addprefix $(S)src/libsyntax/, \
syntax.rc *.rs */*.rs */*/*.rs))
*.rs */*.rs */*/*.rs))
DRIVER_CRATE := $(S)src/driver/driver.rs

View file

@ -1552,13 +1552,6 @@ fn each(v: &[int], op: &fn(v: &int)) {
}
~~~~
As an aside, the reason we pass in a *pointer* to an integer rather
than the integer itself is that this is how the actual `each()`
function for vectors works. `vec::each` though is a
[generic](#generics) function, so must be efficient to use for all
types. Passing the elements by pointer avoids copying potentially
large objects.
As a caller, if we use a closure to provide the final operator
argument, we can write it in a way that has a pleasant, block-like
structure.
@ -1616,6 +1609,9 @@ To enable `debug!` logging, set the RUST_LOG environment variable to the name of
## For loops
> ***Note:*** The closure-based protocol used `for` loop is on the way out. The `for` loop will
> use iterator objects in the future instead.
The most common way to express iteration in Rust is with a `for`
loop. Like `do`, `for` is a nice syntax for describing control flow
with closures. Additionally, within a `for` loop, `break`, `loop`,
@ -1640,7 +1636,16 @@ fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool {
And using this function to iterate over a vector:
~~~~
# use each = std::vec::each;
# fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool {
# let mut n = 0;
# while n < v.len() {
# if !op(&v[n]) {
# return false;
# }
# n += 1;
# }
# return true;
# }
each([2, 4, 8, 5, 16], |n| {
if *n % 2 != 0 {
println("found odd number!");
@ -1656,7 +1661,16 @@ out of the loop, you just write `break`. To skip ahead
to the next iteration, write `loop`.
~~~~
# use each = std::vec::each;
# fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool {
# let mut n = 0;
# while n < v.len() {
# if !op(&v[n]) {
# return false;
# }
# n += 1;
# }
# return true;
# }
for each([2, 4, 8, 5, 16]) |n| {
if *n % 2 != 0 {
println("found odd number!");
@ -1671,7 +1685,16 @@ normally allowed in closures, in a block that appears as the body of a
the enclosing function, not just the loop body.
~~~~
# use each = std::vec::each;
# fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool {
# let mut n = 0;
# while n < v.len() {
# if !op(&v[n]) {
# return false;
# }
# n += 1;
# }
# return true;
# }
fn contains(v: &[int], elt: int) -> bool {
for each(v) |x| {
if (*x == elt) { return true; }
@ -1686,7 +1709,16 @@ In these situations it can be convenient to lean on Rust's
argument patterns to bind `x` to the actual value, not the pointer.
~~~~
# use each = std::vec::each;
# fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool {
# let mut n = 0;
# while n < v.len() {
# if !op(&v[n]) {
# return false;
# }
# n += 1;
# }
# return true;
# }
# fn contains(v: &[int], elt: int) -> bool {
for each(v) |&x| {
if (x == elt) { return true; }
@ -1841,10 +1873,9 @@ vector consisting of the result of applying `function` to each element
of `vector`:
~~~~
# use std::vec;
fn map<T, U>(vector: &[T], function: &fn(v: &T) -> U) -> ~[U] {
let mut accumulator = ~[];
for vec::each(vector) |element| {
for vector.iter().advance |element| {
accumulator.push(function(element));
}
return accumulator;

View file

@ -12,23 +12,23 @@
# and host architectures
# The test runner that runs the cfail/rfail/rpass and bxench tests
COMPILETEST_CRATE := $(S)src/compiletest/compiletest.rc
COMPILETEST_INPUTS := $(wildcard $(S)src/compiletest/*rs)
COMPILETEST_CRATE := $(S)src/compiletest/compiletest.rs
COMPILETEST_INPUTS := $(wildcard $(S)src/compiletest/*.rs)
# Rustpkg, the package manager and build system
RUSTPKG_LIB := $(S)src/librustpkg/rustpkg.rc
RUSTPKG_INPUTS := $(wildcard $(S)src/librustpkg/*rs)
RUSTPKG_LIB := $(S)src/librustpkg/rustpkg.rs
RUSTPKG_INPUTS := $(wildcard $(S)src/librustpkg/*.rs)
# Rustdoc, the documentation tool
RUSTDOC_LIB := $(S)src/librustdoc/rustdoc.rc
RUSTDOC_LIB := $(S)src/librustdoc/rustdoc.rs
RUSTDOC_INPUTS := $(wildcard $(S)src/librustdoc/*.rs)
# Rusti, the JIT REPL
RUSTI_LIB := $(S)src/librusti/rusti.rc
RUSTI_LIB := $(S)src/librusti/rusti.rs
RUSTI_INPUTS := $(wildcard $(S)src/librusti/*.rs)
# Rust, the convenience tool
RUST_LIB := $(S)src/librust/rust.rc
RUST_LIB := $(S)src/librust/rust.rs
RUST_INPUTS := $(wildcard $(S)src/librust/*.rs)
# FIXME: These are only built for the host arch. Eventually we'll

View file

@ -529,7 +529,7 @@ fn compose_and_run_compiler(
let extra_link_args = ~[~"-L",
aux_output_dir_name(config, testfile).to_str()];
for vec::each(props.aux_builds) |rel_ab| {
for props.aux_builds.iter().advance |rel_ab| {
let abs_ab = config.aux_base.push_rel(&Path(*rel_ab));
let aux_args =
make_compile_args(config, props, ~[~"--lib"] + extra_link_args,

View file

@ -521,6 +521,7 @@ mod tests {
use core::cell::Cell;
use core::comm;
use core::task;
use core::uint;
#[test]
fn manually_share_arc() {
@ -790,18 +791,20 @@ mod tests {
}
assert_eq!(*state, 42);
*state = 31337;
// FIXME: #7372: hits type inference bug with iterators
// send to other readers
for vec::each(reader_convos) |x| {
match *x {
for uint::range(0, reader_convos.len()) |i| {
match reader_convos[i] {
(ref rc, _) => rc.send(()),
}
}
}
let read_mode = arc.downgrade(write_mode);
do (&read_mode).read |state| {
// FIXME: #7372: hits type inference bug with iterators
// complete handshake with other readers
for vec::each(reader_convos) |x| {
match *x {
for uint::range(0, reader_convos.len()) |i| {
match reader_convos[i] {
(_, ref rp) => rp.recv(),
}
}

View file

@ -41,30 +41,21 @@ use list::{MutList, MutCons, MutNil};
use core::at_vec;
use core::cast::{transmute, transmute_mut, transmute_mut_region};
use core::cast;
use core::libc::size_t;
use core::ptr;
use core::sys::TypeDesc;
use core::sys;
use core::uint;
use core::vec;
use core::unstable::intrinsics;
use core::unstable::intrinsics::{TyDesc};
pub mod rustrt {
use core::libc::size_t;
use core::sys::TypeDesc;
#[cfg(not(stage0))]
use core::unstable::intrinsics::{get_tydesc};
pub extern {
#[rust_stack]
unsafe fn rust_call_tydesc_glue(root: *u8,
tydesc: *TypeDesc,
field: size_t);
}
#[cfg(stage0)]
unsafe fn get_tydesc<T>() -> *TyDesc {
intrinsics::get_tydesc::<T>() as *TyDesc
}
// This probably belongs somewhere else. Needs to be kept in sync with
// changes to glue...
static tydesc_drop_glue_index: size_t = 3 as size_t;
// The way arena uses arrays is really deeply awful. The arrays are
// allocated, and have capacities reserved, but the fill for the array
// will always stay at 0.
@ -125,6 +116,19 @@ fn round_up_to(base: uint, align: uint) -> uint {
(base + (align - 1)) & !(align - 1)
}
#[inline]
#[cfg(not(stage0))]
unsafe fn call_drop_glue(tydesc: *TyDesc, data: *i8) {
// This function should be inlined when stage0 is gone
((*tydesc).drop_glue)(data);
}
#[inline]
#[cfg(stage0)]
unsafe fn call_drop_glue(tydesc: *TyDesc, data: *i8) {
((*tydesc).drop_glue)(0 as **TyDesc, data);
}
// Walk down a chunk, running the destructors for any objects stored
// in it.
unsafe fn destroy_chunk(chunk: &Chunk) {
@ -137,19 +141,18 @@ unsafe fn destroy_chunk(chunk: &Chunk) {
let (tydesc, is_done) = un_bitpack_tydesc_ptr(*tydesc_data);
let (size, align) = ((*tydesc).size, (*tydesc).align);
let after_tydesc = idx + sys::size_of::<*TypeDesc>();
let after_tydesc = idx + sys::size_of::<*TyDesc>();
let start = round_up_to(after_tydesc, align);
//debug!("freeing object: idx = %u, size = %u, align = %u, done = %b",
// start, size, align, is_done);
if is_done {
rustrt::rust_call_tydesc_glue(
ptr::offset(buf, start), tydesc, tydesc_drop_glue_index);
call_drop_glue(tydesc, ptr::offset(buf, start) as *i8);
}
// Find where the next tydesc lives
idx = round_up_to(start + size, sys::pref_align_of::<*TypeDesc>());
idx = round_up_to(start + size, sys::pref_align_of::<*TyDesc>());
}
}
@ -158,12 +161,12 @@ unsafe fn destroy_chunk(chunk: &Chunk) {
// is necessary in order to properly do cleanup if a failure occurs
// during an initializer.
#[inline]
unsafe fn bitpack_tydesc_ptr(p: *TypeDesc, is_done: bool) -> uint {
unsafe fn bitpack_tydesc_ptr(p: *TyDesc, is_done: bool) -> uint {
let p_bits: uint = transmute(p);
p_bits | (is_done as uint)
}
#[inline]
unsafe fn un_bitpack_tydesc_ptr(p: uint) -> (*TypeDesc, bool) {
unsafe fn un_bitpack_tydesc_ptr(p: uint) -> (*TyDesc, bool) {
(transmute(p & !1), p & 1 == 1)
}
@ -203,7 +206,7 @@ impl Arena {
#[inline]
fn alloc_pod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
unsafe {
let tydesc = sys::get_type_desc::<T>();
let tydesc = get_tydesc::<T>();
let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align);
let ptr: *mut T = transmute(ptr);
intrinsics::move_val_init(&mut (*ptr), op());
@ -231,13 +234,13 @@ impl Arena {
let head = transmute_mut_region(&mut self.head);
let tydesc_start = head.fill;
let after_tydesc = head.fill + sys::size_of::<*TypeDesc>();
let after_tydesc = head.fill + sys::size_of::<*TyDesc>();
let start = round_up_to(after_tydesc, align);
let end = start + n_bytes;
if end > at_vec::capacity(head.data) {
return self.alloc_nonpod_grow(n_bytes, align);
}
head.fill = round_up_to(end, sys::pref_align_of::<*TypeDesc>());
head.fill = round_up_to(end, sys::pref_align_of::<*TyDesc>());
//debug!("idx = %u, size = %u, align = %u, fill = %u",
// start, n_bytes, align, head.fill);
@ -250,7 +253,7 @@ impl Arena {
#[inline]
fn alloc_nonpod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
unsafe {
let tydesc = sys::get_type_desc::<T>();
let tydesc = get_tydesc::<T>();
let (ty_ptr, ptr) =
self.alloc_nonpod_inner((*tydesc).size, (*tydesc).align);
let ty_ptr: *mut uint = transmute(ty_ptr);

View file

@ -13,56 +13,62 @@
#[allow(missing_doc)];
use core::cast::transmute;
use core::sys;
#[cfg(stage0)]
use intrinsic::{get_tydesc};
#[cfg(not(stage0))]
use core::unstable::intrinsics::{get_tydesc};
pub mod rustrt {
use core::sys;
#[cfg(stage0)]
use intrinsic::{TyDesc};
#[cfg(not(stage0))]
use core::unstable::intrinsics::{TyDesc};
#[abi = "cdecl"]
pub extern {
pub unsafe fn debug_tydesc(td: *sys::TypeDesc);
pub unsafe fn debug_opaque(td: *sys::TypeDesc, x: *());
pub unsafe fn debug_box(td: *sys::TypeDesc, x: *());
pub unsafe fn debug_tag(td: *sys::TypeDesc, x: *());
pub unsafe fn debug_fn(td: *sys::TypeDesc, x: *());
pub unsafe fn debug_ptrcast(td: *sys::TypeDesc, x: *()) -> *();
pub unsafe fn debug_tydesc(td: *TyDesc);
pub unsafe fn debug_opaque(td: *TyDesc, x: *());
pub unsafe fn debug_box(td: *TyDesc, x: *());
pub unsafe fn debug_tag(td: *TyDesc, x: *());
pub unsafe fn debug_fn(td: *TyDesc, x: *());
pub unsafe fn debug_ptrcast(td: *TyDesc, x: *()) -> *();
pub unsafe fn rust_dbg_breakpoint();
}
}
pub fn debug_tydesc<T>() {
unsafe {
rustrt::debug_tydesc(sys::get_type_desc::<T>());
rustrt::debug_tydesc(get_tydesc::<T>());
}
}
pub fn debug_opaque<T>(x: T) {
unsafe {
rustrt::debug_opaque(sys::get_type_desc::<T>(), transmute(&x));
rustrt::debug_opaque(get_tydesc::<T>(), transmute(&x));
}
}
pub fn debug_box<T>(x: @T) {
unsafe {
rustrt::debug_box(sys::get_type_desc::<T>(), transmute(&x));
rustrt::debug_box(get_tydesc::<T>(), transmute(&x));
}
}
pub fn debug_tag<T>(x: T) {
unsafe {
rustrt::debug_tag(sys::get_type_desc::<T>(), transmute(&x));
rustrt::debug_tag(get_tydesc::<T>(), transmute(&x));
}
}
pub fn debug_fn<T>(x: T) {
unsafe {
rustrt::debug_fn(sys::get_type_desc::<T>(), transmute(&x));
rustrt::debug_fn(get_tydesc::<T>(), transmute(&x));
}
}
pub unsafe fn ptr_cast<T, U>(x: @T) -> @U {
transmute(
rustrt::debug_ptrcast(sys::get_type_desc::<T>(), transmute(x)))
rustrt::debug_ptrcast(get_tydesc::<T>(), transmute(x)))
}
/// Triggers a debugger breakpoint

View file

@ -418,10 +418,11 @@ pub fn opts_str(mm: &Matches, names: &[~str]) -> ~str {
*/
pub fn opt_strs(mm: &Matches, nm: &str) -> ~[~str] {
let mut acc: ~[~str] = ~[];
for vec::each(opt_vals(mm, nm)) |v| {
let r = opt_vals(mm, nm);
for r.iter().advance |v| {
match *v { Val(ref s) => acc.push(copy *s), _ => () }
}
return acc;
acc
}
/// Returns the string argument supplied to a matching option or none

View file

@ -1123,7 +1123,7 @@ impl Eq for Json {
&Object(ref d1) => {
if d0.len() == d1.len() {
let mut equal = true;
for d0.each |k, v0| {
for d0.iter().advance |(k, v0)| {
match d1.find(k) {
Some(v1) if v0 == v1 => { },
_ => { equal = false; break }
@ -1186,12 +1186,12 @@ impl Ord for Json {
let mut d1_flat = ~[];
// FIXME #4430: this is horribly inefficient...
for d0.each |k, v| {
for d0.iter().advance |(k, v)| {
d0_flat.push((@copy *k, @copy *v));
}
d0_flat.qsort();
for d1.each |k, v| {
for d1.iter().advance |(k, v)| {
d1_flat.push((@copy *k, @copy *v));
}
d1_flat.qsort();
@ -1326,7 +1326,7 @@ impl<A:ToJson> ToJson for ~[A] {
impl<A:ToJson + Copy> ToJson for HashMap<~str, A> {
fn to_json(&self) -> Json {
let mut d = HashMap::new();
for self.each |key, value| {
for self.iter().advance |(key, value)| {
d.insert(copy *key, value.to_json());
}
Object(~d)

View file

@ -207,7 +207,7 @@ pub fn encode_form_urlencoded(m: &HashMap<~str, ~[~str]>) -> ~str {
let mut out = ~"";
let mut first = true;
for m.each |key, values| {
for m.iter().advance |(key, values)| {
let key = encode_plus(*key);
for values.iter().advance |value| {

View file

@ -70,10 +70,12 @@ impl<T> Rc<T> {
impl<T> Drop for Rc<T> {
fn finalize(&self) {
unsafe {
(*self.ptr).count -= 1;
if (*self.ptr).count == 0 {
ptr::replace_ptr(self.ptr, intrinsics::uninit());
free(self.ptr as *c_void)
if self.ptr.is_not_null() {
(*self.ptr).count -= 1;
if (*self.ptr).count == 0 {
ptr::replace_ptr(self.ptr, intrinsics::uninit());
free(self.ptr as *c_void)
}
}
}
}
@ -220,10 +222,12 @@ impl<T> RcMut<T> {
impl<T> Drop for RcMut<T> {
fn finalize(&self) {
unsafe {
(*self.ptr).count -= 1;
if (*self.ptr).count == 0 {
ptr::replace_ptr(self.ptr, uninit());
free(self.ptr as *c_void)
if self.ptr.is_not_null() {
(*self.ptr).count -= 1;
if (*self.ptr).count == 0 {
ptr::replace_ptr(self.ptr, uninit());
free(self.ptr as *c_void)
}
}
}
}

View file

@ -710,7 +710,7 @@ impl<
fn encode(&self, e: &mut E) {
do e.emit_map(self.len()) |e| {
let mut i = 0;
for self.each |key, val| {
for self.iter().advance |(key, val)| {
e.emit_map_elt_key(i, |e| key.encode(e));
e.emit_map_elt_val(i, |e| val.encode(e));
i += 1;
@ -744,7 +744,7 @@ impl<
fn encode(&self, s: &mut S) {
do s.emit_seq(self.len()) |s| {
let mut i = 0;
for self.each |e| {
for self.iter().advance |e| {
s.emit_seq_elt(i, |s| e.encode(s));
i += 1;
}

View file

@ -56,38 +56,6 @@ impl<V> Map<uint, V> for SmallIntMap<V> {
self.find(key).is_some()
}
/// Visit all key-value pairs in order
fn each<'a>(&'a self, it: &fn(&uint, &'a V) -> bool) -> bool {
for uint::range(0, self.v.len()) |i| {
match self.v[i] {
Some(ref elt) => if !it(&i, elt) { return false; },
None => ()
}
}
return true;
}
/// Visit all keys in order
fn each_key(&self, blk: &fn(key: &uint) -> bool) -> bool {
self.each(|k, _| blk(k))
}
/// Visit all values in order
fn each_value<'a>(&'a self, blk: &fn(value: &'a V) -> bool) -> bool {
self.each(|_, v| blk(v))
}
/// Iterate over the map and mutate the contained values
fn mutate_values(&mut self, it: &fn(&uint, &mut V) -> bool) -> bool {
for uint::range(0, self.v.len()) |i| {
match self.v[i] {
Some(ref mut elt) => if !it(&i, elt) { return false; },
None => ()
}
}
return true;
}
/// Return a reference to the value corresponding to the key
fn find<'a>(&'a self, key: &uint) -> Option<&'a V> {
if *key < self.v.len() {
@ -156,6 +124,38 @@ impl<V> SmallIntMap<V> {
/// Create an empty SmallIntMap
pub fn new() -> SmallIntMap<V> { SmallIntMap{v: ~[]} }
/// Visit all key-value pairs in order
pub fn each<'a>(&'a self, it: &fn(&uint, &'a V) -> bool) -> bool {
for uint::range(0, self.v.len()) |i| {
match self.v[i] {
Some(ref elt) => if !it(&i, elt) { return false; },
None => ()
}
}
return true;
}
/// Visit all keys in order
pub fn each_key(&self, blk: &fn(key: &uint) -> bool) -> bool {
self.each(|k, _| blk(k))
}
/// Visit all values in order
pub fn each_value<'a>(&'a self, blk: &fn(value: &'a V) -> bool) -> bool {
self.each(|_, v| blk(v))
}
/// Iterate over the map and mutate the contained values
pub fn mutate_values(&mut self, it: &fn(&uint, &mut V) -> bool) -> bool {
for uint::range(0, self.v.len()) |i| {
match self.v[i] {
Some(ref mut elt) => if !it(&i, elt) { return false; },
None => ()
}
}
return true;
}
/// Visit all key-value pairs in reverse order
pub fn each_reverse<'a>(&'a self, it: &fn(uint, &'a V) -> bool) -> bool {
for uint::range_rev(self.v.len(), 0) |i| {

View file

@ -1094,7 +1094,8 @@ mod tests {
};
assert!(result.is_err());
// child task must have finished by the time try returns
for vec::each(p.recv()) |p| { p.recv(); } // wait on all its siblings
let r = p.recv();
for r.iter().advance |p| { p.recv(); } // wait on all its siblings
do m.lock_cond |cond| {
let woken = cond.broadcast();
assert_eq!(woken, 0);

View file

@ -107,26 +107,6 @@ impl<K: TotalOrd, V> Map<K, V> for TreeMap<K, V> {
self.find(key).is_some()
}
/// Visit all key-value pairs in order
fn each<'a>(&'a self, f: &fn(&'a K, &'a V) -> bool) -> bool {
each(&self.root, f)
}
/// Visit all keys in order
fn each_key(&self, f: &fn(&K) -> bool) -> bool {
self.each(|k, _| f(k))
}
/// Visit all values in order
fn each_value<'a>(&'a self, f: &fn(&'a V) -> bool) -> bool {
self.each(|_, v| f(v))
}
/// Iterate over the map and mutate the contained values
fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool) -> bool {
mutate_values(&mut self.root, f)
}
/// Return a reference to the value corresponding to the key
fn find<'a>(&'a self, key: &K) -> Option<&'a V> {
let mut current: &'a Option<~TreeNode<K, V>> = &self.root;
@ -184,6 +164,26 @@ impl<K: TotalOrd, V> TreeMap<K, V> {
/// Create an empty TreeMap
pub fn new() -> TreeMap<K, V> { TreeMap{root: None, length: 0} }
/// Visit all key-value pairs in order
pub fn each<'a>(&'a self, f: &fn(&'a K, &'a V) -> bool) -> bool {
each(&self.root, f)
}
/// Visit all keys in order
pub fn each_key(&self, f: &fn(&K) -> bool) -> bool {
self.each(|k, _| f(k))
}
/// Visit all values in order
pub fn each_value<'a>(&'a self, f: &fn(&'a V) -> bool) -> bool {
self.each(|_, v| f(v))
}
/// Iterate over the map and mutate the contained values
pub fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool) -> bool {
mutate_values(&mut self.root, f)
}
/// Visit all key-value pairs in reverse order
pub fn each_reverse<'a>(&'a self, f: &fn(&'a K, &'a V) -> bool) -> bool {
each_reverse(&self.root, f)

View file

@ -146,7 +146,7 @@ impl WorkMap {
impl<S:Encoder> Encodable<S> for WorkMap {
fn encode(&self, s: &mut S) {
let mut d = ~[];
for self.each |k, v| {
for self.iter().advance |(k, v)| {
d.push((copy *k, copy *v))
}
sort::tim_sort(d);
@ -320,7 +320,7 @@ impl TPrep for Prep {
}
fn all_fresh(&self, cat: &str, map: &WorkMap) -> bool {
for map.each |k, v| {
for map.iter().advance |(k, v)| {
if ! self.is_fresh(cat, k.kind, k.name, *v) {
return false;
}

View file

@ -8,9 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pub static rc_base_field_refcnt: uint = 0u;
pub static task_field_refcnt: uint = 0u;
@ -49,9 +46,7 @@ pub static tydesc_field_take_glue: uint = 2u;
pub static tydesc_field_drop_glue: uint = 3u;
pub static tydesc_field_free_glue: uint = 4u;
pub static tydesc_field_visit_glue: uint = 5u;
pub static tydesc_field_shape: uint = 6u;
pub static tydesc_field_shape_tables: uint = 7u;
pub static n_tydesc_fields: uint = 8u;
pub static n_tydesc_fields: uint = 6u;
// The two halves of a closure: code and environment.
pub static fn_field_code: uint = 0u;
@ -71,6 +66,4 @@ pub static vec_elt_elems: uint = 2u;
pub static slice_elt_base: uint = 0u;
pub static slice_elt_len: uint = 1u;
pub static worst_case_glue_call_args: uint = 7u;
pub static abi_version: uint = 1u;

View file

@ -206,9 +206,6 @@ pub fn compile_rest(sess: Session,
let mut crate = crate_opt.unwrap();
let (llcx, llmod, link_meta) = {
crate = time(time_passes, ~"intrinsic injection", ||
front::intrinsic_inject::inject_intrinsic(sess, crate));
crate = time(time_passes, ~"extra injection", ||
front::std_inject::maybe_inject_libstd_ref(sess, crate));

View file

@ -1,140 +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.
// NB: this file is include_str!'ed into the compiler, re-parsed
// and injected into each crate the compiler builds. Keep it small.
pub mod intrinsic {
#[allow(missing_doc)];
pub use intrinsic::rusti::visit_tydesc;
// FIXME (#3727): remove this when the interface has settled and the
// version in sys is no longer present.
pub fn get_tydesc<T>() -> *TyDesc {
unsafe {
rusti::get_tydesc::<T>() as *TyDesc
}
}
pub struct TyDesc {
size: uint,
align: uint
// Remaining fields not listed
}
pub enum Opaque { }
pub trait TyVisitor {
fn visit_bot(&self) -> bool;
fn visit_nil(&self) -> bool;
fn visit_bool(&self) -> bool;
fn visit_int(&self) -> bool;
fn visit_i8(&self) -> bool;
fn visit_i16(&self) -> bool;
fn visit_i32(&self) -> bool;
fn visit_i64(&self) -> bool;
fn visit_uint(&self) -> bool;
fn visit_u8(&self) -> bool;
fn visit_u16(&self) -> bool;
fn visit_u32(&self) -> bool;
fn visit_u64(&self) -> bool;
fn visit_float(&self) -> bool;
fn visit_f32(&self) -> bool;
fn visit_f64(&self) -> bool;
fn visit_char(&self) -> bool;
fn visit_str(&self) -> bool;
fn visit_estr_box(&self) -> bool;
fn visit_estr_uniq(&self) -> bool;
fn visit_estr_slice(&self) -> bool;
fn visit_estr_fixed(&self, n: uint, sz: uint, align: uint) -> bool;
fn visit_box(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_uniq(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_ptr(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_rptr(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_vec(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_unboxed_vec(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_evec_box(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_evec_uniq(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_evec_slice(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_evec_fixed(&self, n: uint, sz: uint, align: uint,
mtbl: uint, inner: *TyDesc) -> bool;
fn visit_enter_rec(&self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_rec_field(&self, i: uint, name: &str,
mtbl: uint, inner: *TyDesc) -> bool;
fn visit_leave_rec(&self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_enter_class(&self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_class_field(&self, i: uint, name: &str,
mtbl: uint, inner: *TyDesc) -> bool;
fn visit_leave_class(&self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_enter_tup(&self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_tup_field(&self, i: uint, inner: *TyDesc) -> bool;
fn visit_leave_tup(&self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_enter_enum(&self, n_variants: uint,
get_disr: extern unsafe fn(ptr: *Opaque) -> int,
sz: uint, align: uint) -> bool;
fn visit_enter_enum_variant(&self, variant: uint,
disr_val: int,
n_fields: uint,
name: &str) -> bool;
fn visit_enum_variant_field(&self, i: uint, offset: uint, inner: *TyDesc) -> bool;
fn visit_leave_enum_variant(&self, variant: uint,
disr_val: int,
n_fields: uint,
name: &str) -> bool;
fn visit_leave_enum(&self, n_variants: uint,
get_disr: extern unsafe fn(ptr: *Opaque) -> int,
sz: uint, align: uint) -> bool;
fn visit_enter_fn(&self, purity: uint, proto: uint,
n_inputs: uint, retstyle: uint) -> bool;
fn visit_fn_input(&self, i: uint, mode: uint, inner: *TyDesc) -> bool;
fn visit_fn_output(&self, retstyle: uint, inner: *TyDesc) -> bool;
fn visit_leave_fn(&self, purity: uint, proto: uint,
n_inputs: uint, retstyle: uint) -> bool;
fn visit_trait(&self) -> bool;
fn visit_var(&self) -> bool;
fn visit_var_integral(&self) -> bool;
fn visit_param(&self, i: uint) -> bool;
fn visit_self(&self) -> bool;
fn visit_type(&self) -> bool;
fn visit_opaque_box(&self) -> bool;
fn visit_constr(&self, inner: *TyDesc) -> bool;
fn visit_closure_ptr(&self, ck: uint) -> bool;
}
pub mod rusti {
use super::{TyDesc, TyVisitor};
#[abi = "rust-intrinsic"]
pub extern "rust-intrinsic" {
pub fn get_tydesc<T>() -> *();
pub fn visit_tydesc(td: *TyDesc, tv: @TyVisitor);
}
}
}

View file

@ -1,47 +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.
use core::prelude::*;
use core::vec;
use driver::session::Session;
use syntax::parse;
use syntax::ast;
use syntax::codemap::spanned;
pub fn inject_intrinsic(sess: Session, crate: @ast::crate) -> @ast::crate {
let intrinsic_module = include_str!("intrinsic.rs").to_managed();
let item = parse::parse_item_from_source_str(@"<intrinsic>",
intrinsic_module,
/*bad*/copy sess.opts.cfg,
~[],
sess.parse_sess);
let item =
match item {
Some(i) => i,
None => {
sess.fatal("no item found in intrinsic module");
}
};
let items = vec::append(~[item], crate.node.module.items);
@spanned {
node: ast::crate_ {
module: ast::_mod {
items: items,
.. /*bad*/copy crate.node.module
},
.. /*bad*/copy crate.node
},
.. /*bad*/copy *crate
}
}

View file

@ -86,7 +86,7 @@ pub fn have_crate_data(cstore: &CStore, cnum: ast::crate_num) -> bool {
pub fn iter_crate_data(cstore: &CStore,
i: &fn(ast::crate_num, @crate_metadata)) {
for cstore.metas.each |&k, &v| {
for cstore.metas.iter().advance |(&k, &v)| {
i(k, v);
}
}

View file

@ -35,7 +35,6 @@ use extra::ebml;
use extra::serialize::Decodable;
use syntax::ast_map;
use syntax::attr;
use syntax::diagnostic::span_handler;
use syntax::parse::token::{ident_interner, special_idents};
use syntax::print::pprust;
use syntax::{ast, ast_util};
@ -97,7 +96,8 @@ fn lookup_item(item_id: int, data: @~[u8]) -> ebml::Doc {
#[deriving(Eq)]
enum Family {
Const, // c
ImmStatic, // c
MutStatic, // b
Fn, // f
UnsafeFn, // u
StaticMethod, // F
@ -120,7 +120,8 @@ enum Family {
fn item_family(item: ebml::Doc) -> Family {
let fam = reader::get_doc(item, tag_items_data_item_family);
match reader::doc_as_u8(fam) as char {
'c' => Const,
'c' => ImmStatic,
'b' => MutStatic,
'f' => Fn,
'u' => UnsafeFn,
'F' => StaticMethod,
@ -317,7 +318,8 @@ fn item_to_def_like(item: ebml::Doc, did: ast::def_id, cnum: ast::crate_num)
-> def_like {
let fam = item_family(item);
match fam {
Const => dl_def(ast::def_const(did)),
ImmStatic => dl_def(ast::def_static(did, false)),
MutStatic => dl_def(ast::def_static(did, true)),
Struct => dl_def(ast::def_struct(did)),
UnsafeFn => dl_def(ast::def_fn(did, ast::unsafe_fn)),
Fn => dl_def(ast::def_fn(did, ast::impure_fn)),
@ -890,8 +892,8 @@ pub fn get_item_visibility(cdata: cmd, id: ast::node_id)
fn family_has_type_params(fam: Family) -> bool {
match fam {
Const | ForeignType | Mod | ForeignMod | PublicField | PrivateField
| ForeignFn => false,
ImmStatic | ForeignType | Mod | ForeignMod | PublicField | PrivateField
| ForeignFn | MutStatic => false,
_ => true
}
}
@ -921,7 +923,8 @@ fn describe_def(items: ebml::Doc, id: ast::def_id) -> ~str {
fn item_family_to_str(fam: Family) -> ~str {
match fam {
Const => ~"const",
ImmStatic => ~"static",
MutStatic => ~"static mut",
Fn => ~"fn",
UnsafeFn => ~"unsafe fn",
StaticMethod => ~"static method",

View file

@ -731,8 +731,8 @@ fn encode_info_for_method(ecx: &EncodeContext,
}
let mut combined_ty_params = opt_vec::Empty;
for owner_generics.ty_params.each |x| { combined_ty_params.push(copy *x) }
for method_generics.ty_params.each |x| { combined_ty_params.push(copy *x) }
for owner_generics.ty_params.iter().advance |x| { combined_ty_params.push(copy *x) }
for method_generics.ty_params.iter().advance |x| { combined_ty_params.push(copy *x) }
let len = combined_ty_params.len();
encode_type_param_bounds(ebml_w, ecx, &combined_ty_params);
@ -783,7 +783,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
let must_write =
match item.node {
item_enum(_, _) | item_impl(*) | item_trait(*) | item_struct(*) |
item_mod(*) | item_foreign_mod(*) | item_const(*) => true,
item_mod(*) | item_foreign_mod(*) | item_static(*) => true,
_ => false
};
if !must_write && !reachable(ecx, item.id) { return; }
@ -798,11 +798,15 @@ fn encode_info_for_item(ecx: &EncodeContext,
ecx.tcx.sess.codemap.span_to_str(item.span));
match item.node {
item_const(_, _) => {
item_static(_, m, _) => {
add_to_index();
ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, local_def(item.id));
encode_family(ebml_w, 'c');
if m == ast::m_mutbl {
encode_family(ebml_w, 'b');
} else {
encode_family(ebml_w, 'c');
}
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
encode_symbol(ecx, ebml_w, item.id);
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
@ -1105,9 +1109,13 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
}
encode_path(ecx, ebml_w, path, ast_map::path_name(nitem.ident));
}
foreign_item_const(*) => {
foreign_item_static(_, mutbl) => {
encode_def_id(ebml_w, local_def(nitem.id));
encode_family(ebml_w, 'c');
if mutbl {
encode_family(ebml_w, 'b');
} else {
encode_family(ebml_w, 'c');
}
encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, nitem.id));
encode_symbol(ecx, ebml_w, nitem.id);
encode_path(ecx, ebml_w, path, ast_map::path_name(nitem.ident));

View file

@ -373,7 +373,7 @@ impl tr for ast::def {
ast::def_self(nid, i) => ast::def_self(xcx.tr_id(nid), i),
ast::def_mod(did) => ast::def_mod(did.tr(xcx)),
ast::def_foreign_mod(did) => ast::def_foreign_mod(did.tr(xcx)),
ast::def_const(did) => ast::def_const(did.tr(xcx)),
ast::def_static(did, m) => ast::def_static(did.tr(xcx), m),
ast::def_arg(nid, b) => ast::def_arg(xcx.tr_id(nid), b),
ast::def_local(nid, b) => ast::def_local(xcx.tr_id(nid), b),
ast::def_variant(e_did, v_did) => {

View file

@ -43,7 +43,7 @@ pub fn check_item(sess: Session,
(_is_const, v): (bool,
visit::vt<bool>)) {
match it.node {
item_const(_, ex) => {
item_static(_, _, ex) => {
(v.visit_expr)(ex, (true, v));
check_item_recursion(sess, ast_map, def_map, it);
}
@ -124,7 +124,7 @@ pub fn check_expr(sess: Session,
items without type parameters");
}
match def_map.find(&e.id) {
Some(&def_const(_)) |
Some(&def_static(*)) |
Some(&def_fn(_, _)) |
Some(&def_variant(_, _)) |
Some(&def_struct(_)) => { }
@ -236,7 +236,7 @@ pub fn check_item_recursion(sess: Session,
fn visit_expr(e: @expr, (env, v): (env, visit::vt<env>)) {
match e.node {
expr_path(*) => match env.def_map.find(&e.id) {
Some(&def_const(def_id)) if ast_util::is_local(def_id) =>
Some(&def_static(def_id, _)) if ast_util::is_local(def_id) =>
match env.ast_map.get_copy(&def_id.node) {
ast_map::node_item(it, _) => {
(v.visit_item)(it, (env, v));

View file

@ -304,7 +304,7 @@ pub fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option<ctor> {
pat_ident(_, _, _) | pat_enum(_, _) => {
match cx.tcx.def_map.find(&pat.id) {
Some(&def_variant(_, id)) => Some(variant(id)),
Some(&def_const(did)) => {
Some(&def_static(did, false)) => {
let const_expr = lookup_const_by_id(cx.tcx, did).get();
Some(val(eval_const_expr(cx.tcx, const_expr)))
}
@ -339,7 +339,7 @@ pub fn is_wild(cx: @MatchCheckCtxt, p: @pat) -> bool {
pat_wild => { true }
pat_ident(_, _, _) => {
match cx.tcx.def_map.find(&pat.id) {
Some(&def_variant(_, _)) | Some(&def_const(*)) => { false }
Some(&def_variant(_, _)) | Some(&def_static(*)) => { false }
_ => { true }
}
}
@ -499,7 +499,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
None
}
}
Some(&def_const(did)) => {
Some(&def_static(did, _)) => {
let const_expr =
lookup_const_by_id(cx.tcx, did).get();
let e_v = eval_const_expr(cx.tcx, const_expr);
@ -549,7 +549,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
}
pat_enum(_, args) => {
match cx.tcx.def_map.get_copy(&pat_id) {
def_const(did) => {
def_static(did, _) => {
let const_expr =
lookup_const_by_id(cx.tcx, did).get();
let e_v = eval_const_expr(cx.tcx, const_expr);
@ -790,7 +790,7 @@ pub fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool {
return true;
}
}
Some(&def_const(*)) => return true,
Some(&def_static(*)) => return true,
_ => ()
}

View file

@ -166,7 +166,7 @@ pub fn classify(e: @expr,
pub fn lookup_const(tcx: ty::ctxt, e: @expr) -> Option<@expr> {
match tcx.def_map.find(&e.id) {
Some(&ast::def_const(def_id)) => lookup_const_by_id(tcx, def_id),
Some(&ast::def_static(def_id, false)) => lookup_const_by_id(tcx, def_id),
_ => None
}
}
@ -178,7 +178,7 @@ pub fn lookup_const_by_id(tcx: ty::ctxt,
match tcx.items.find(&def_id.node) {
None => None,
Some(&ast_map::node_item(it, _)) => match it.node {
item_const(_, const_expr) => Some(const_expr),
item_static(_, ast::m_imm, const_expr) => Some(const_expr),
_ => None
},
Some(_) => None
@ -195,7 +195,7 @@ pub fn lookup_const_by_id(tcx: ty::ctxt,
match csearch::maybe_get_item_ast(tcx, def_id,
|a, b, c, d| astencode::decode_inlined_item(a, b, maps, /*bar*/ copy c, d)) {
csearch::found(ast::ii_item(item)) => match item.node {
item_const(_, const_expr) => Some(const_expr),
item_static(_, ast::m_imm, const_expr) => Some(const_expr),
_ => None
},
_ => None

View file

@ -17,7 +17,7 @@ use middle::typeck::method_map;
use util::ppaux;
use syntax::ast::{deref, expr_call, expr_inline_asm, expr_method_call};
use syntax::ast::{expr_unary, node_id, unsafe_blk, unsafe_fn};
use syntax::ast::{expr_unary, node_id, unsafe_blk, unsafe_fn, expr_path};
use syntax::ast;
use syntax::codemap::span;
use syntax::visit::{fk_item_fn, fk_method};
@ -143,6 +143,14 @@ pub fn check_crate(tcx: ty::ctxt,
expr_inline_asm(*) => {
require_unsafe(expr.span, "use of inline assembly")
}
expr_path(*) => {
match ty::resolve_expr(tcx, expr) {
ast::def_static(_, true) => {
require_unsafe(expr.span, "use of mutable static")
}
_ => {}
}
}
_ => {}
}

View file

@ -240,7 +240,8 @@ fn check_fn(
// Check kinds on free variables:
do with_appropriate_checker(cx, fn_id) |chk| {
for vec::each(*freevars::get_freevars(cx.tcx, fn_id)) |fv| {
let r = freevars::get_freevars(cx.tcx, fn_id);
for r.iter().advance |fv| {
chk(cx, *fv);
}
}

View file

@ -76,16 +76,20 @@ pub enum LangItem {
UnrecordBorrowFnLangItem, // 36
StartFnLangItem, // 37
TyDescStructLangItem, // 38
TyVisitorTraitLangItem, // 39
OpaqueStructLangItem, // 40
}
pub struct LanguageItems {
items: [Option<def_id>, ..38]
items: [Option<def_id>, ..41]
}
impl LanguageItems {
pub fn new() -> LanguageItems {
LanguageItems {
items: [ None, ..38 ]
items: [ None, ..41 ]
}
}
@ -138,6 +142,10 @@ impl LanguageItems {
37 => "start",
38 => "ty_desc",
39 => "ty_visitor",
40 => "opaque",
_ => "???"
}
}
@ -262,6 +270,15 @@ impl LanguageItems {
pub fn start_fn(&const self) -> def_id {
self.items[StartFnLangItem as uint].get()
}
pub fn ty_desc(&const self) -> def_id {
self.items[TyDescStructLangItem as uint].get()
}
pub fn ty_visitor(&const self) -> def_id {
self.items[TyVisitorTraitLangItem as uint].get()
}
pub fn opaque(&const self) -> def_id {
self.items[OpaqueStructLangItem as uint].get()
}
}
fn LanguageItemCollector(crate: @crate,
@ -313,6 +330,9 @@ fn LanguageItemCollector(crate: @crate,
item_refs.insert(@"record_borrow", RecordBorrowFnLangItem as uint);
item_refs.insert(@"unrecord_borrow", UnrecordBorrowFnLangItem as uint);
item_refs.insert(@"start", StartFnLangItem as uint);
item_refs.insert(@"ty_desc", TyDescStructLangItem as uint);
item_refs.insert(@"ty_visitor", TyVisitorTraitLangItem as uint);
item_refs.insert(@"opaque", OpaqueStructLangItem as uint);
LanguageItemCollector {
crate: crate,
@ -416,7 +436,7 @@ impl LanguageItemCollector {
}
pub fn check_completeness(&self) {
for self.item_refs.each |&key, &item_ref| {
for self.item_refs.iter().advance |(&key, &item_ref)| {
match self.items.items[item_ref] {
None => {
self.session.err(fmt!("no item found for `%s`", key));

View file

@ -96,6 +96,8 @@ pub enum lint {
missing_doc,
unreachable_code,
warnings,
}
pub fn level_to_str(lv: level) -> &'static str {
@ -280,6 +282,13 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
desc: "detects unreachable code",
default: warn
}),
("warnings",
LintSpec {
lint: warnings,
desc: "mass-change the level for lints which produce warnings",
default: warn
}),
];
/*
@ -352,7 +361,7 @@ impl Context {
}
fn lint_to_str(&self, lint: lint) -> &'static str {
for self.dict.each |k, v| {
for self.dict.iter().advance |(k, v)| {
if v.lint == lint {
return *k;
}
@ -362,10 +371,11 @@ impl Context {
fn span_lint(&self, lint: lint, span: span, msg: &str) {
let (level, src) = match self.curr.find(&(lint as uint)) {
None => { return }
Some(&(warn, src)) => (self.get_level(warnings), src),
Some(&pair) => pair,
None => { return; }
};
if level == allow { return; }
if level == allow { return }
let mut note = None;
let msg = match src {
@ -709,28 +719,32 @@ fn check_item_default_methods(cx: &Context, item: @ast::item) {
}
fn check_item_ctypes(cx: &Context, it: @ast::item) {
fn check_ty(cx: &Context, ty: @ast::Ty) {
match ty.node {
ast::ty_path(_, _, id) => {
match cx.tcx.def_map.get_copy(&id) {
ast::def_prim_ty(ast::ty_int(ast::ty_i)) => {
cx.span_lint(ctypes, ty.span,
"found rust type `int` in foreign module, while \
libc::c_int or libc::c_long should be used");
}
ast::def_prim_ty(ast::ty_uint(ast::ty_u)) => {
cx.span_lint(ctypes, ty.span,
"found rust type `uint` in foreign module, while \
libc::c_uint or libc::c_ulong should be used");
}
_ => ()
}
}
_ => ()
}
}
fn check_foreign_fn(cx: &Context, decl: &ast::fn_decl) {
let tys = vec::map(decl.inputs, |a| a.ty );
for vec::each(vec::append_one(tys, decl.output)) |ty| {
match ty.node {
ast::ty_path(_, _, id) => {
match cx.tcx.def_map.get_copy(&id) {
ast::def_prim_ty(ast::ty_int(ast::ty_i)) => {
cx.span_lint(ctypes, ty.span,
"found rust type `int` in foreign module, while \
libc::c_int or libc::c_long should be used");
}
ast::def_prim_ty(ast::ty_uint(ast::ty_u)) => {
cx.span_lint(ctypes, ty.span,
"found rust type `uint` in foreign module, while \
libc::c_uint or libc::c_ulong should be used");
}
_ => ()
}
}
_ => ()
}
let r = vec::append_one(tys, decl.output);
for r.iter().advance |ty| {
check_ty(cx, *ty);
}
}
@ -738,11 +752,10 @@ fn check_item_ctypes(cx: &Context, it: @ast::item) {
ast::item_foreign_mod(ref nmod) if !nmod.abis.is_intrinsic() => {
for nmod.items.iter().advance |ni| {
match ni.node {
ast::foreign_item_fn(ref decl, _, _) => {
check_foreign_fn(cx, decl);
}
// FIXME #4622: Not implemented.
ast::foreign_item_const(*) => {}
ast::foreign_item_fn(ref decl, _, _) => {
check_foreign_fn(cx, decl);
}
ast::foreign_item_static(t, _) => { check_ty(cx, t); }
}
}
}
@ -1159,7 +1172,7 @@ pub fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
// If we missed any lints added to the session, then there's a bug somewhere
// in the iteration code.
for tcx.sess.lints.each |_, v| {
for tcx.sess.lints.iter().advance |(_, v)| {
for v.iter().advance |t| {
match *t {
(lint, span, ref msg) =>

View file

@ -447,19 +447,29 @@ impl mem_categorization_ctxt {
-> cmt {
match def {
ast::def_fn(*) | ast::def_static_method(*) | ast::def_mod(_) |
ast::def_foreign_mod(_) | ast::def_const(_) |
ast::def_foreign_mod(_) | ast::def_static(_, false) |
ast::def_use(_) | ast::def_variant(*) |
ast::def_trait(_) | ast::def_ty(_) | ast::def_prim_ty(_) |
ast::def_ty_param(*) | ast::def_struct(*) |
ast::def_typaram_binder(*) | ast::def_region(_) |
ast::def_label(_) | ast::def_self_ty(*) => {
@cmt_ {
id:id,
span:span,
cat:cat_static_item,
mutbl: McImmutable,
ty:expr_ty
}
@cmt_ {
id:id,
span:span,
cat:cat_static_item,
mutbl: McImmutable,
ty:expr_ty
}
}
ast::def_static(_, true) => {
@cmt_ {
id:id,
span:span,
cat:cat_static_item,
mutbl: McDeclared,
ty:expr_ty
}
}
ast::def_arg(vid, mutbl) => {
@ -894,7 +904,7 @@ impl mem_categorization_ctxt {
self.cat_pattern(cmt_field, subpat, op);
}
}
Some(&ast::def_const(*)) => {
Some(&ast::def_static(*)) => {
for subpats.iter().advance |&subpat| {
self.cat_pattern(cmt, subpat, op);
}

View file

@ -45,7 +45,7 @@ pub fn pat_is_const(dm: resolve::DefMap, pat: &pat) -> bool {
match pat.node {
pat_ident(_, _, None) | pat_enum(*) => {
match dm.find(&pat.id) {
Some(&def_const(*)) => true,
Some(&def_static(_, false)) => true,
_ => false
}
}

View file

@ -948,7 +948,7 @@ pub fn determine_rp_in_crate(sess: Session,
debug!("%s", {
debug!("Region variance results:");
let region_paramd_items = cx.region_paramd_items;
for region_paramd_items.each |&key, &value| {
for region_paramd_items.iter().advance |(&key, &value)| {
debug!("item %? (%s) is parameterized with variance %?",
key,
ast_map::node_id_to_str(ast_map, key,

View file

@ -101,6 +101,14 @@ pub enum Namespace {
ValueNS
}
#[deriving(Eq)]
pub enum NamespaceError {
NoError,
ModuleError,
TypeError,
ValueError
}
/// A NamespaceResult represents the result of resolving an import in
/// a particular namespace. The result is either definitely-resolved,
/// definitely- unresolved, or unknown.
@ -759,10 +767,12 @@ pub fn PrimitiveTypeTable() -> PrimitiveTypeTable {
}
pub fn namespace_to_str(ns: Namespace) -> ~str {
pub fn namespace_error_to_str(ns: NamespaceError) -> &'static str {
match ns {
TypeNS => ~"type",
ValueNS => ~"value",
NoError => "",
ModuleError => "module",
TypeError => "type",
ValueError => "value",
}
}
@ -993,21 +1003,25 @@ impl Resolver {
// * If no duplicate checking was requested at all, do
// nothing.
let mut is_duplicate = false;
let mut duplicate_type = NoError;
let ns = match duplicate_checking_mode {
ForbidDuplicateModules => {
is_duplicate = child.get_module_if_available().is_some();
if (child.get_module_if_available().is_some()) {
duplicate_type = ModuleError;
}
Some(TypeNS)
}
ForbidDuplicateTypes => {
match child.def_for_namespace(TypeNS) {
Some(def_mod(_)) | None => {}
Some(_) => is_duplicate = true
Some(_) => duplicate_type = TypeError
}
Some(TypeNS)
}
ForbidDuplicateValues => {
is_duplicate = child.defined_in_namespace(ValueNS);
if child.defined_in_namespace(ValueNS) {
duplicate_type = ValueError;
}
Some(ValueNS)
}
ForbidDuplicateTypesAndValues => {
@ -1016,31 +1030,31 @@ impl Resolver {
Some(def_mod(_)) | None => {}
Some(_) => {
n = Some(TypeNS);
is_duplicate = true;
duplicate_type = TypeError;
}
};
if child.defined_in_namespace(ValueNS) {
is_duplicate = true;
duplicate_type = ValueError;
n = Some(ValueNS);
}
n
}
OverwriteDuplicates => None
};
if is_duplicate {
if (duplicate_type != NoError) {
// Return an error here by looking up the namespace that
// had the duplicate.
let ns = ns.unwrap();
self.session.span_err(sp,
fmt!("duplicate definition of %s `%s`",
namespace_to_str(ns),
namespace_error_to_str(duplicate_type),
self.session.str_of(name)));
{
let r = child.span_for_namespace(ns);
for r.iter().advance |sp| {
self.session.span_note(*sp,
fmt!("first definition of %s %s here:",
namespace_to_str(ns),
fmt!("first definition of %s `%s` here",
namespace_error_to_str(duplicate_type),
self.session.str_of(name)));
}
}
@ -1146,12 +1160,13 @@ impl Resolver {
}
// These items live in the value namespace.
item_const(*) => {
item_static(_, m, _) => {
let (name_bindings, _) =
self.add_child(ident, parent, ForbidDuplicateValues, sp);
let mutbl = m == ast::m_mutbl;
name_bindings.define_value
(privacy, def_const(local_def(item.id)), sp);
(privacy, def_static(local_def(item.id), mutbl), sp);
}
item_fn(_, purity, _, _, _) => {
let (name_bindings, new_parent) =
@ -1385,7 +1400,7 @@ impl Resolver {
}
let def_id = local_def(item.id);
for method_names.each |name, _| {
for method_names.iter().advance |(name, _)| {
if !self.method_map.contains_key(name) {
self.method_map.insert(*name, HashSet::new());
}
@ -1565,8 +1580,8 @@ impl Resolver {
visit_foreign_item(foreign_item, (new_parent, visitor));
}
}
foreign_item_const(*) => {
let def = def_const(local_def(foreign_item.id));
foreign_item_static(_, m) => {
let def = def_static(local_def(foreign_item.id), m);
name_bindings.define_value(Public, def, foreign_item.span);
visit_foreign_item(foreign_item, (new_parent, visitor));
@ -1673,7 +1688,7 @@ impl Resolver {
let privacy = variant_visibility_to_privacy(visibility, true);
child_name_bindings.define_value(privacy, def, dummy_sp());
}
def_fn(*) | def_static_method(*) | def_const(*) => {
def_fn(*) | def_static_method(*) | def_static(*) => {
debug!("(building reduced graph for external \
crate) building value %s", final_ident);
child_name_bindings.define_value(privacy, def, dummy_sp());
@ -1703,7 +1718,7 @@ impl Resolver {
interned_method_names.insert(method_name);
}
}
for interned_method_names.each |name| {
for interned_method_names.iter().advance |name| {
if !self.method_map.contains_key(name) {
self.method_map.insert(*name, HashSet::new());
}
@ -2469,8 +2484,8 @@ impl Resolver {
assert_eq!(containing_module.glob_count, 0);
// Add all resolved imports from the containing module.
for containing_module.import_resolutions.each
|ident, target_import_resolution| {
for containing_module.import_resolutions.iter().advance
|(ident, target_import_resolution)| {
debug!("(resolving glob import) writing module resolution \
%? into `%s`",
@ -2554,13 +2569,13 @@ impl Resolver {
};
// Add all children from the containing module.
for containing_module.children.each |&ident, name_bindings| {
for containing_module.children.iter().advance |(&ident, name_bindings)| {
merge_import_resolution(ident, *name_bindings);
}
// Add external module children from the containing module.
for containing_module.external_module_children.each
|&ident, module| {
for containing_module.external_module_children.iter().advance
|(&ident, module)| {
let name_bindings =
@mut Resolver::create_name_bindings_from_module(*module);
merge_import_resolution(ident, name_bindings);
@ -3250,7 +3265,7 @@ impl Resolver {
pub fn add_exports_for_module(@mut self,
exports2: &mut ~[Export2],
module_: @mut Module) {
for module_.children.each |ident, namebindings| {
for module_.children.iter().advance |(ident, namebindings)| {
debug!("(computing exports) maybe export '%s'",
self.session.str_of(*ident));
self.add_exports_of_namebindings(&mut *exports2,
@ -3265,7 +3280,7 @@ impl Resolver {
false);
}
for module_.import_resolutions.each |ident, importresolution| {
for module_.import_resolutions.iter().advance |(ident, importresolution)| {
if importresolution.privacy != Public {
debug!("(computing exports) not reexporting private `%s`",
self.session.str_of(*ident));
@ -3664,7 +3679,7 @@ impl Resolver {
|| visit_foreign_item(*foreign_item,
((), visitor)));
}
foreign_item_const(_) => {
foreign_item_static(*) => {
visit_foreign_item(*foreign_item,
((), visitor));
}
@ -3686,7 +3701,7 @@ impl Resolver {
visitor);
}
item_const(*) => {
item_static(*) => {
self.with_constant_rib(|| {
visit_item(item, ((), visitor));
});
@ -3833,8 +3848,8 @@ impl Resolver {
pub fn resolve_type_parameters(@mut self,
type_parameters: &OptVec<TyParam>,
visitor: ResolveVisitor) {
for type_parameters.each |type_parameter| {
for type_parameter.bounds.each |bound| {
for type_parameters.iter().advance |type_parameter| {
for type_parameter.bounds.iter().advance |bound| {
self.resolve_type_parameter_bound(bound, visitor);
}
}
@ -4038,7 +4053,7 @@ impl Resolver {
for arm.pats.iter().enumerate().advance |(i, p)| {
let map_i = self.binding_mode_map(*p);
for map_0.each |&key, &binding_0| {
for map_0.iter().advance |(&key, &binding_0)| {
match map_i.find(&key) {
None => {
self.session.span_err(
@ -4059,7 +4074,7 @@ impl Resolver {
}
}
for map_i.each |&key, &binding| {
for map_i.iter().advance |(&key, &binding)| {
if !map_0.contains_key(&key) {
self.session.span_err(
binding.span,
@ -4180,13 +4195,13 @@ impl Resolver {
}
}
for bounds.each |bound| {
for bounds.iter().advance |bound| {
self.resolve_type_parameter_bound(bound, visitor);
}
}
ty_closure(c) => {
for c.bounds.each |bound| {
for c.bounds.iter().advance |bound| {
self.resolve_type_parameter_bound(bound, visitor);
}
visit_ty(ty, ((), visitor));
@ -4344,7 +4359,7 @@ impl Resolver {
Some(def @ def_struct(*)) => {
self.record_def(pattern.id, def);
}
Some(def @ def_const(*)) => {
Some(def @ def_static(*)) => {
self.enforce_default_binding_mode(
pattern,
binding_mode,
@ -4376,7 +4391,7 @@ impl Resolver {
Some(def @ def_fn(*)) |
Some(def @ def_variant(*)) |
Some(def @ def_struct(*)) |
Some(def @ def_const(*)) => {
Some(def @ def_static(*)) => {
self.record_def(pattern.id, def);
}
Some(_) => {
@ -4459,7 +4474,7 @@ impl Resolver {
def @ def_variant(*) | def @ def_struct(*) => {
return FoundStructOrEnumVariant(def);
}
def @ def_const(*) => {
def @ def_static(_, false) => {
return FoundConst(def);
}
_ => {
@ -5354,7 +5369,7 @@ impl Resolver {
}
debug!("Import resolutions:");
for module_.import_resolutions.each |name, import_resolution| {
for module_.import_resolutions.iter().advance |(name, import_resolution)| {
let value_repr;
match import_resolution.target_for_namespace(ValueNS) {
None => { value_repr = ~""; }

View file

@ -820,7 +820,7 @@ pub fn get_options(bcx: block, m: &[@Match], col: uint) -> ~[Opt] {
add_to_set(ccx.tcx, &mut found,
lit(UnitLikeStructLit(cur.id)));
}
Some(&ast::def_const(const_did)) => {
Some(&ast::def_static(const_did, false)) => {
add_to_set(ccx.tcx, &mut found,
lit(ConstLit(const_did)));
}
@ -836,7 +836,7 @@ pub fn get_options(bcx: block, m: &[@Match], col: uint) -> ~[Opt] {
add_to_set(ccx.tcx, &mut found,
variant_opt(bcx, cur.id));
}
Some(&ast::def_const(const_did)) => {
Some(&ast::def_static(const_did, false)) => {
add_to_set(ccx.tcx, &mut found,
lit(ConstLit(const_did)));
}
@ -1673,7 +1673,7 @@ pub fn trans_match_inner(scope_cx: block,
let mut arm_datas = ~[];
let mut matches = ~[];
for vec::each(arms) |arm| {
for arms.iter().advance |arm| {
let body = scope_block(bcx, arm.body.info(), "case_body");
let bindings_map = create_bindings_map(bcx, arm.pats[0]);
let arm_data = @ArmData {bodycx: body,
@ -1831,8 +1831,9 @@ pub fn bind_irrefutable_pat(bcx: block,
}
}
}
Some(&ast::def_const(*)) => {
bcx = bind_irrefutable_pat(bcx, pat, val, make_copy, binding_mode);
Some(&ast::def_static(_, false)) => {
bcx = bind_irrefutable_pat(bcx, pat, val, make_copy,
binding_mode);
}
_ => {
// Nothing to do here.

View file

@ -135,7 +135,7 @@ fn represent_type_uncached(cx: &mut CrateContext, t: ty::t) -> Repr {
ty::lookup_field_type(cx.tcx, def_id, field.id, substs)
};
let packed = ty::lookup_packed(cx.tcx, def_id);
let dtor = ty::ty_dtor(cx.tcx, def_id).is_present();
let dtor = ty::ty_dtor(cx.tcx, def_id).has_drop_flag();
let ftys =
if dtor { ftys + [ty::mk_bool()] } else { ftys };
return Univariant(mk_struct(cx, ftys, packed), dtor)

View file

@ -2122,14 +2122,19 @@ pub fn trans_item(ccx: @mut CrateContext, item: &ast::item) {
trans_enum_def(ccx, enum_definition, item.id, vi, &mut i);
}
}
ast::item_const(_, expr) => {
consts::trans_const(ccx, expr, item.id);
ast::item_static(_, m, expr) => {
consts::trans_const(ccx, m, item.id);
// Do static_assert checking. It can't really be done much earlier because we need to get
// the value of the bool out of LLVM
for item.attrs.iter().advance |attr| {
match attr.node.value.node {
ast::meta_word(x) => {
if x.slice(0, x.len()) == "static_assert" {
if m == ast::m_mutbl {
ccx.sess.span_fatal(expr.span,
"cannot have static_assert \
on a mutable static");
}
let v = ccx.const_values.get_copy(&item.id);
unsafe {
if !(llvm::LLVMConstIntGetZExtValue(v) as bool) {
@ -2398,13 +2403,14 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::node_id) -> ValueRef {
let my_path = vec::append(/*bad*/copy *pth,
[path_name(i.ident)]);
match i.node {
ast::item_const(_, expr) => {
ast::item_static(_, m, expr) => {
let typ = ty::node_id_to_type(ccx.tcx, i.id);
let s = mangle_exported_name(ccx, my_path, typ);
// We need the translated value here, because for enums the
// LLVM type is not fully determined by the Rust type.
let v = consts::const_expr(ccx, expr);
ccx.const_values.insert(id, v);
exprt = m == ast::m_mutbl;
unsafe {
let llty = llvm::LLVMTypeOf(v);
let g = str::as_c_str(s, |buf| {
@ -2457,7 +2463,7 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::node_id) -> ValueRef {
ni.id,
ni.attrs)
}
ast::foreign_item_const(*) => {
ast::foreign_item_static(*) => {
let typ = ty::node_id_to_type(ccx.tcx, ni.id);
let ident = token::ident_to_str(&ni.ident);
let g = do str::as_c_str(ident) |buf| {
@ -2939,7 +2945,7 @@ pub fn trans_crate(sess: session::Session,
}
if ccx.sess.count_llvm_insns() {
for ccx.stats.llvm_insns.each |&k, &v| {
for ccx.stats.llvm_insns.iter().advance |(&k, &v)| {
io::println(fmt!("%-7u %s", v, k));
}
}

View file

@ -143,7 +143,7 @@ pub fn trans(bcx: block, expr: @ast::expr) -> Callee {
datum_callee(bcx, ref_expr)
}
ast::def_mod(*) | ast::def_foreign_mod(*) | ast::def_trait(*) |
ast::def_const(*) | ast::def_ty(*) | ast::def_prim_ty(*) |
ast::def_static(*) | ast::def_ty(*) | ast::def_prim_ty(*) |
ast::def_use(*) | ast::def_typaram_binder(*) |
ast::def_region(*) | ast::def_label(*) | ast::def_ty_param(*) |
ast::def_self_ty(*) => {
@ -704,11 +704,11 @@ pub fn trans_args(cx: block,
// now that all arguments have been successfully built, we can revoke any
// temporary cleanups, as they are only needed if argument construction
// should fail (for example, cleanup of copy mode args).
for vec::each(temp_cleanups) |c| {
for temp_cleanups.iter().advance |c| {
revoke_clean(bcx, *c)
}
return bcx;
bcx
}
pub enum AutorefArg {

View file

@ -164,9 +164,9 @@ pub fn get_const_val(cx: @mut CrateContext, mut def_id: ast::def_id) -> ValueRef
}
match cx.tcx.items.get_copy(&def_id.node) {
ast_map::node_item(@ast::item {
node: ast::item_const(_, subexpr), _
node: ast::item_static(_, ast::m_imm, _), _
}, _) => {
trans_const(cx, subexpr, def_id.node);
trans_const(cx, ast::m_imm, def_id.node);
}
_ => cx.tcx.sess.bug("expected a const to be an item")
}
@ -538,7 +538,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, e: @ast::expr) -> ValueRef {
base::get_item_val(cx, def_id.node)
}
}
Some(&ast::def_const(def_id)) => {
Some(&ast::def_static(def_id, false)) => {
get_const_val(cx, def_id)
}
Some(&ast::def_variant(enum_did, variant_did)) => {
@ -587,7 +587,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, e: @ast::expr) -> ValueRef {
}
}
pub fn trans_const(ccx: @mut CrateContext, _e: @ast::expr, id: ast::node_id) {
pub fn trans_const(ccx: @mut CrateContext, m: ast::mutability, id: ast::node_id) {
unsafe {
let _icx = push_ctxt("trans_const");
let g = base::get_item_val(ccx, id);
@ -595,6 +595,8 @@ pub fn trans_const(ccx: @mut CrateContext, _e: @ast::expr, id: ast::node_id) {
// constant's initializer to determine its LLVM type.
let v = ccx.const_values.get_copy(&id);
llvm::LLVMSetInitializer(g, v);
llvm::LLVMSetGlobalConstant(g, True);
if m != ast::m_mutbl {
llvm::LLVMSetGlobalConstant(g, True);
}
}
}

View file

@ -945,7 +945,7 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
let _icx = push_ctxt("trans_def_lvalue");
let ccx = bcx.ccx();
match def {
ast::def_const(did) => {
ast::def_static(did, _) => {
let const_ty = expr_ty(bcx, ref_expr);
fn get_did(ccx: @mut CrateContext, did: ast::def_id)

View file

@ -332,7 +332,7 @@ pub fn trans_foreign_mod(ccx: @mut CrateContext,
}
}
}
ast::foreign_item_const(*) => {
ast::foreign_item_static(*) => {
let ident = token::ident_to_str(&foreign_item.ident);
ccx.item_symbols.insert(foreign_item.id, /* bad */ident.to_owned());
}
@ -681,9 +681,12 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
let static_ti = get_tydesc(ccx, tp_ty);
glue::lazily_emit_all_tydesc_glue(ccx, static_ti);
// FIXME (#3727): change this to ccx.tydesc_ty.ptr_to() when the
// core::sys copy of the get_tydesc interface dies off.
let td = PointerCast(bcx, static_ti.tydesc, Type::nil().ptr_to());
// FIXME (#3730): ideally this shouldn't need a cast,
// but there's a circularity between translating rust types to llvm
// types and having a tydesc type available. So I can't directly access
// the llvm type of intrinsic::TyDesc struct.
let userland_tydesc_ty = type_of::type_of(ccx, output_type);
let td = PointerCast(bcx, static_ti.tydesc, userland_tydesc_ty);
Store(bcx, td, fcx.llretptr.get());
}
"init" => {

View file

@ -232,7 +232,7 @@ pub fn lazily_emit_tydesc_glue(ccx: @mut CrateContext,
field: uint,
ti: @mut tydesc_info) {
let _icx = push_ctxt("lazily_emit_tydesc_glue");
let llfnty = type_of_glue_fn(ccx);
let llfnty = Type::glue_fn();
if lazily_emit_simplified_tydesc_glue(ccx, field, ti) {
return;
@ -338,9 +338,7 @@ pub fn call_tydesc_glue_full(bcx: block,
}
};
Call(bcx, llfn, [C_null(Type::nil().ptr_to()),
C_null(bcx.ccx().tydesc_type.ptr_to().ptr_to()),
llrawptr]);
Call(bcx, llfn, [C_null(Type::nil().ptr_to()), llrawptr]);
}
// See [Note-arg-mode]
@ -406,13 +404,8 @@ pub fn make_free_glue(bcx: block, v: ValueRef, t: ty::t) {
build_return(bcx);
}
pub fn trans_struct_drop(bcx: block,
t: ty::t,
v0: ValueRef,
dtor_did: ast::def_id,
class_did: ast::def_id,
substs: &ty::substs)
-> block {
pub fn trans_struct_drop_flag(bcx: block, t: ty::t, v0: ValueRef, dtor_did: ast::def_id,
class_did: ast::def_id, substs: &ty::substs) -> block {
let repr = adt::represent_type(bcx.ccx(), t);
let drop_flag = adt::trans_drop_flag_ptr(bcx, repr, v0);
do with_cond(bcx, IsNotNull(bcx, Load(bcx, drop_flag))) |cx| {
@ -454,6 +447,43 @@ pub fn trans_struct_drop(bcx: block,
}
}
pub fn trans_struct_drop(mut bcx: block, t: ty::t, v0: ValueRef, dtor_did: ast::def_id,
class_did: ast::def_id, substs: &ty::substs) -> block {
let repr = adt::represent_type(bcx.ccx(), t);
// Find and call the actual destructor
let dtor_addr = get_res_dtor(bcx.ccx(), dtor_did,
class_did, /*bad*/copy substs.tps);
// The second argument is the "self" argument for drop
let params = unsafe {
let ty = Type::from_ref(llvm::LLVMTypeOf(dtor_addr));
ty.element_type().func_params()
};
// Class dtors have no explicit args, so the params should
// just consist of the environment (self)
assert_eq!(params.len(), 1);
// Take a reference to the class (because it's using the Drop trait),
// do so now.
let llval = alloca(bcx, val_ty(v0));
Store(bcx, v0, llval);
let self_arg = PointerCast(bcx, llval, params[0]);
let args = ~[self_arg];
Call(bcx, dtor_addr, args);
// Drop the fields
let field_tys = ty::struct_fields(bcx.tcx(), class_did, substs);
for field_tys.iter().enumerate().advance |(i, fld)| {
let llfld_a = adt::trans_field_ptr(bcx, repr, v0, 0, i);
bcx = drop_ty(bcx, llfld_a, fld.mt.ty);
}
bcx
}
pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
// NB: v0 is an *alias* of type t here, not a direct value.
@ -474,7 +504,10 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
ty::ty_struct(did, ref substs) => {
let tcx = bcx.tcx();
match ty::ty_dtor(tcx, did) {
ty::TraitDtor(dtor) => {
ty::TraitDtor(dtor, true) => {
trans_struct_drop_flag(bcx, t, v0, dtor, did, substs)
}
ty::TraitDtor(dtor, false) => {
trans_struct_drop(bcx, t, v0, dtor, did, substs)
}
ty::NoDtor => {
@ -594,6 +627,23 @@ pub fn make_take_glue(bcx: block, v: ValueRef, t: ty::t) {
ty::ty_opaque_closure_ptr(ck) => {
closure::make_opaque_cbox_take_glue(bcx, ck, v)
}
ty::ty_struct(did, ref substs) => {
let tcx = bcx.tcx();
let bcx = iter_structural_ty(bcx, v, t, take_ty);
match ty::ty_dtor(tcx, did) {
ty::TraitDtor(dtor, false) => {
// Zero out the struct
unsafe {
let ty = Type::from_ref(llvm::LLVMTypeOf(v));
memzero(bcx, v, ty);
}
}
_ => { }
}
bcx
}
_ if ty::type_is_structural(t) => {
iter_structural_ty(bcx, v, t, take_ty)
}
@ -680,7 +730,7 @@ pub fn make_generic_glue_inner(ccx: @mut CrateContext,
let bcx = top_scope_block(fcx, None);
let lltop = bcx.llbb;
let rawptr0_arg = fcx.arg_pos(1u);
let rawptr0_arg = fcx.arg_pos(0u);
let llrawptr0 = unsafe { llvm::LLVMGetParam(llfn, rawptr0_arg as c_uint) };
let llty = type_of(ccx, t);
let llrawptr0 = PointerCast(bcx, llrawptr0, llty.ptr_to());
@ -715,7 +765,7 @@ pub fn emit_tydescs(ccx: &mut CrateContext) {
let _icx = push_ctxt("emit_tydescs");
// As of this point, allow no more tydescs to be created.
ccx.finished_tydescs = true;
let glue_fn_ty = Type::generic_glue_fn(ccx);
let glue_fn_ty = Type::generic_glue_fn(ccx).ptr_to();
let tyds = &mut ccx.tydescs;
for tyds.each_value |&val| {
let ti = val;
@ -765,19 +815,13 @@ pub fn emit_tydescs(ccx: &mut CrateContext) {
}
};
let shape = C_null(Type::i8p());
let shape_tables = C_null(Type::i8p());
let tydesc = C_named_struct(ccx.tydesc_type,
[ti.size, // size
ti.align, // align
take_glue, // take_glue
drop_glue, // drop_glue
free_glue, // free_glue
visit_glue, // visit_glue
shape, // shape
shape_tables]); // shape_tables
[ti.size, // size
ti.align, // align
take_glue, // take_glue
drop_glue, // drop_glue
free_glue, // free_glue
visit_glue]); // visit_glue
unsafe {
let gvar = ti.tydesc;
@ -788,8 +832,3 @@ pub fn emit_tydescs(ccx: &mut CrateContext) {
}
};
}
fn type_of_glue_fn(ccx: &CrateContext) -> Type {
let tydescpp = ccx.tydesc_type.ptr_to().ptr_to();
Type::func([ Type::nil().ptr_to(), tydescpp, Type::i8p() ], &Type::void())
}

View file

@ -146,7 +146,7 @@ fn traverse_public_item(cx: @mut ctx, item: @item) {
visit::mk_vt(@visit::Visitor {visit_ty: traverse_ty,
..*visit::default_visitor()})))
}
item_const(*) |
item_static(*) |
item_enum(*) | item_trait(*) => (),
item_mac(*) => fail!("item macros unimplemented")
}

View file

@ -274,9 +274,7 @@ impl Reflector {
let repr = adt::represent_type(bcx.ccx(), t);
let variants = ty::substd_enum_variants(ccx.tcx, did, substs);
let llptrty = type_of(ccx, t).ptr_to();
let (_, opaquety) =
ccx.tcx.intrinsic_defs.find_copy(&ccx.sess.ident_of("Opaque"))
.expect("Failed to resolve intrinsic::Opaque");
let opaquety = ty::get_opaque_ty(ccx.tcx);
let opaqueptrty = ty::mk_ptr(ccx.tcx, ty::mt { ty: opaquety, mutbl: ast::m_imm });
let make_get_disr = || {
@ -373,10 +371,8 @@ pub fn emit_calls_to_trait_visit_ty(bcx: block,
visitor_val: ValueRef,
visitor_trait_id: def_id)
-> block {
use syntax::parse::token::special_idents::tydesc;
let final = sub_block(bcx, "final");
assert!(bcx.ccx().tcx.intrinsic_defs.contains_key(&tydesc));
let (_, tydesc_ty) = bcx.ccx().tcx.intrinsic_defs.get_copy(&tydesc);
let tydesc_ty = ty::get_tydesc_ty(bcx.ccx().tcx);
let tydesc_ty = type_of(bcx.ccx(), tydesc_ty);
let mut r = Reflector {
visitor_val: visitor_val,

View file

@ -20,7 +20,6 @@ use middle::trans::base;
use syntax::ast;
use syntax::abi::{Architecture, X86, X86_64, Arm, Mips};
use back::abi;
use core::vec;
use core::cast;
@ -189,25 +188,26 @@ impl Type {
None => ()
}
let ty = cx.tydesc_type.get_field(abi::tydesc_field_drop_glue);
let ty = Type::glue_fn();
cx.tn.associate_type("glue_fn", &ty);
return ty;
}
pub fn glue_fn() -> Type {
Type::func([ Type::nil().ptr_to(), Type::i8p() ],
&Type::void())
}
pub fn tydesc(arch: Architecture) -> Type {
let mut tydesc = Type::named_struct("tydesc");
let tydescpp = tydesc.ptr_to().ptr_to();
let pvoid = Type::i8p();
let glue_fn_ty = Type::func([ Type::nil().ptr_to(), tydescpp, pvoid ],
&Type::void()).ptr_to();
let glue_fn_ty = Type::glue_fn().ptr_to();
let int_ty = Type::int(arch);
let elems = [
int_ty, int_ty,
glue_fn_ty, glue_fn_ty, glue_fn_ty, glue_fn_ty,
pvoid, pvoid
glue_fn_ty, glue_fn_ty, glue_fn_ty, glue_fn_ty
];
tydesc.set_struct_body(elems, false);
@ -265,10 +265,6 @@ impl Type {
cx.int_type
}
pub fn captured_tydescs(ctx: &CrateContext, num: uint) -> Type {
Type::struct_(vec::from_elem(num, ctx.tydesc_type.ptr_to()), false)
}
pub fn opaque_trait(ctx: &CrateContext, store: ty::TraitStore) -> Type {
let tydesc_ptr = ctx.tydesc_type.ptr_to();
match store {

View file

@ -213,7 +213,8 @@ pub fn type_needs_inner(cx: Context,
ty::ty_enum(did, ref substs) => {
if list::find(enums_seen, |id| *id == did).is_none() {
let seen = @Cons(did, enums_seen);
for vec::each(*ty::enum_variants(cx.ccx.tcx, did)) |v| {
let r = ty::enum_variants(cx.ccx.tcx, did);
for r.iter().advance |v| {
for v.args.iter().advance |aty| {
let t = ty::subst(cx.ccx.tcx, &(*substs), *aty);
type_needs_inner(cx, use_, t, seen);

View file

@ -21,7 +21,7 @@ use middle::ty;
use middle::subst::Subst;
use middle::typeck;
use middle;
use util::ppaux::{note_and_explain_region, bound_region_to_str, bound_region_ptr_to_str};
use util::ppaux::{note_and_explain_region, bound_region_ptr_to_str};
use util::ppaux::{trait_store_to_str, ty_to_str, vstore_to_str};
use util::ppaux::{Repr, UserString};
use util::common::{indenter};
@ -44,7 +44,6 @@ use syntax::attr;
use syntax::codemap::span;
use syntax::codemap;
use syntax::parse::token;
use syntax::parse::token::special_idents;
use syntax::{ast, ast_map};
use syntax::opt_vec::OptVec;
use syntax::opt_vec;
@ -276,8 +275,7 @@ struct ctxt_ {
trait_defs: @mut HashMap<def_id, @TraitDef>,
items: ast_map::map,
intrinsic_defs: @mut HashMap<ast::ident, (ast::def_id, t)>,
intrinsic_traits: @mut HashMap<ast::ident, @TraitRef>,
intrinsic_defs: @mut HashMap<ast::def_id, t>,
freevars: freevars::freevar_map,
tcache: type_cache,
rcache: creader_cache,
@ -954,7 +952,6 @@ pub fn mk_ctxt(s: session::Session,
node_type_substs: @mut HashMap::new(),
trait_refs: @mut HashMap::new(),
trait_defs: @mut HashMap::new(),
intrinsic_traits: @mut HashMap::new(),
items: amap,
intrinsic_defs: @mut HashMap::new(),
freevars: freevars,
@ -3269,7 +3266,7 @@ pub fn expr_kind(tcx: ctxt,
// Note: there is actually a good case to be made that
// def_args, particularly those of immediate type, ought to
// considered rvalues.
ast::def_const(*) |
ast::def_static(*) |
ast::def_binding(*) |
ast::def_upvar(*) |
ast::def_arg(*) |
@ -3855,7 +3852,7 @@ pub fn item_path_str(cx: ctxt, id: ast::def_id) -> ~str {
pub enum DtorKind {
NoDtor,
TraitDtor(def_id)
TraitDtor(def_id, bool)
}
impl DtorKind {
@ -3869,13 +3866,24 @@ impl DtorKind {
pub fn is_present(&const self) -> bool {
!self.is_not_present()
}
pub fn has_drop_flag(&self) -> bool {
match self {
&NoDtor => false,
&TraitDtor(_, flag) => flag
}
}
}
/* If struct_id names a struct with a dtor, return Some(the dtor's id).
Otherwise return none. */
pub fn ty_dtor(cx: ctxt, struct_id: def_id) -> DtorKind {
match cx.destructor_for_type.find(&struct_id) {
Some(&method_def_id) => TraitDtor(method_def_id),
Some(&method_def_id) => {
let flag = !has_attr(cx, struct_id, "no_drop_flag");
TraitDtor(method_def_id, flag)
}
None => NoDtor,
}
}
@ -4469,10 +4477,26 @@ pub fn get_impl_id(tcx: ctxt, trait_id: def_id, self_ty: t) -> def_id {
}
}
pub fn get_tydesc_ty(tcx: ctxt) -> t {
let tydesc_lang_item = tcx.lang_items.ty_desc();
tcx.intrinsic_defs.find_copy(&tydesc_lang_item)
.expect("Failed to resolve TyDesc")
}
pub fn get_opaque_ty(tcx: ctxt) -> t {
let opaque_lang_item = tcx.lang_items.opaque();
tcx.intrinsic_defs.find_copy(&opaque_lang_item)
.expect("Failed to resolve Opaque")
}
pub fn visitor_object_ty(tcx: ctxt) -> (@TraitRef, t) {
let ty_visitor_name = special_idents::ty_visitor;
assert!(tcx.intrinsic_traits.contains_key(&ty_visitor_name));
let trait_ref = tcx.intrinsic_traits.get_copy(&ty_visitor_name);
let substs = substs {
self_r: None,
self_ty: None,
tps: ~[]
};
let trait_lang_item = tcx.lang_items.ty_visitor();
let trait_ref = @TraitRef { def_id: trait_lang_item, substs: substs };
(trait_ref,
mk_trait(tcx, trait_ref.def_id, copy trait_ref.substs,
BoxTraitStore, ast::m_imm, EmptyBuiltinBounds()))

View file

@ -752,7 +752,7 @@ fn conv_builtin_bounds(tcx: ty::ctxt,
//! legal.
let mut builtin_bounds = ty::EmptyBuiltinBounds();
for ast_bounds.each |ast_bound| {
for ast_bounds.iter().advance |ast_bound| {
match *ast_bound {
ast::TraitTyParamBound(b) => {
match lookup_def_tcx(tcx, b.path.span, b.ref_id) {

View file

@ -107,7 +107,7 @@ use middle::typeck::{isr_alist, lookup_def_ccx};
use middle::typeck::no_params;
use middle::typeck::{require_same_types, method_map, vtable_map};
use util::common::{block_query, indenter, loop_query};
use util::ppaux::{bound_region_to_str,bound_region_ptr_to_str};
use util::ppaux::{bound_region_ptr_to_str};
use util::ppaux;
@ -585,7 +585,7 @@ pub fn check_item(ccx: @mut CrateCtxt, it: @ast::item) {
let _indenter = indenter();
match it.node {
ast::item_const(_, e) => check_const(ccx, it.span, e, it.id),
ast::item_static(_, _, e) => check_const(ccx, it.span, e, it.id),
ast::item_enum(ref enum_definition, _) => {
check_enum_variants(ccx,
it.span,
@ -3216,7 +3216,7 @@ pub fn ty_param_bounds_and_ty_for_def(fcx: @mut FnCtxt,
}
ast::def_fn(id, _) | ast::def_static_method(id, _, _) |
ast::def_const(id) | ast::def_variant(_, id) |
ast::def_static(id, _) | ast::def_variant(_, id) |
ast::def_struct(id) => {
return ty::lookup_item_type(fcx.ccx.tcx, id);
}
@ -3506,13 +3506,15 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
}
"get_tydesc" => {
// FIXME (#3730): return *intrinsic::tydesc, not *()
(1u, ~[], ty::mk_nil_ptr(ccx.tcx))
let tydesc_ty = ty::get_tydesc_ty(ccx.tcx);
let td_ptr = ty::mk_ptr(ccx.tcx, ty::mt {
ty: tydesc_ty,
mutbl: ast::m_imm
});
(1u, ~[], td_ptr)
}
"visit_tydesc" => {
let tydesc_name = special_idents::tydesc;
assert!(tcx.intrinsic_defs.contains_key(&tydesc_name));
let (_, tydesc_ty) = tcx.intrinsic_defs.get_copy(&tydesc_name);
let tydesc_ty = ty::get_tydesc_ty(ccx.tcx);
let (_, visitor_object_ty) = ty::visitor_object_ty(tcx);
let td_ptr = ty::mk_ptr(ccx.tcx, ty::mt {
ty: tydesc_ty,

View file

@ -16,10 +16,8 @@
use core::prelude::*;
use driver;
use metadata::csearch::{each_path, get_impl_trait};
use metadata::csearch::{get_impls_for_mod};
use metadata::csearch;
use metadata::cstore::{CStore, iter_crate_data};
use metadata::decoder::{dl_def, dl_field, dl_impl};
use middle::resolve::{Impl, MethodInfo};
@ -39,7 +37,7 @@ use middle::typeck::infer::combine::Combine;
use middle::typeck::infer::InferCtxt;
use middle::typeck::infer::{new_infer_ctxt, resolve_ivar};
use middle::typeck::infer::{resolve_nested_tvar, resolve_type};
use syntax::ast::{crate, def_id, def_mod, def_struct, def_trait, def_ty};
use syntax::ast::{crate, def_id, def_mod, def_struct, def_ty};
use syntax::ast::{item, item_enum, item_impl, item_mod, item_struct};
use syntax::ast::{local_crate, method, trait_ref, ty_path};
use syntax::ast;

View file

@ -62,55 +62,16 @@ use syntax::opt_vec::OptVec;
use syntax::opt_vec;
pub fn collect_item_types(ccx: @mut CrateCtxt, crate: @ast::crate) {
// FIXME (#2592): hooking into the "intrinsic" root module is crude.
// There ought to be a better approach. Attributes?
for crate.node.module.items.iter().advance |crate_item| {
if crate_item.ident
== ::syntax::parse::token::special_idents::intrinsic {
match crate_item.node {
ast::item_mod(ref m) => {
for m.items.iter().advance |intrinsic_item| {
let def_id = ast::def_id { crate: ast::local_crate,
node: intrinsic_item.id };
let substs = substs {
self_r: None,
self_ty: None,
tps: ~[]
};
match intrinsic_item.node {
ast::item_trait(*) => {
let tref = @ty::TraitRef {def_id: def_id,
substs: substs};
ccx.tcx.intrinsic_traits.insert
(intrinsic_item.ident, tref);
}
ast::item_enum(*) => {
let ty = ty::mk_enum(ccx.tcx, def_id, substs);
ccx.tcx.intrinsic_defs.insert
(intrinsic_item.ident, (def_id, ty));
}
ast::item_struct(*) => {
let ty = ty::mk_struct(ccx.tcx, def_id, substs);
ccx.tcx.intrinsic_defs.insert
(intrinsic_item.ident, (def_id, ty));
}
_ => {}
}
}
}
_ => { }
}
break;
}
fn collect_intrinsic_type(ccx: @mut CrateCtxt,
lang_item: ast::def_id) {
let ty::ty_param_bounds_and_ty { ty: ty, _ } =
ccx.get_item_ty(lang_item);
ccx.tcx.intrinsic_defs.insert(lang_item, ty);
}
collect_intrinsic_type(ccx, ccx.tcx.lang_items.ty_desc());
collect_intrinsic_type(ccx, ccx.tcx.lang_items.opaque());
visit::visit_crate(
crate, ((),
visit::mk_simple_visitor(@visit::SimpleVisitor {
@ -814,7 +775,7 @@ pub fn ensure_no_ty_param_bounds(ccx: &CrateCtxt,
span: span,
generics: &ast::Generics,
thing: &'static str) {
for generics.ty_params.each |ty_param| {
for generics.ty_params.iter().advance |ty_param| {
if ty_param.bounds.len() > 0 {
ccx.tcx.sess.span_err(
span,
@ -1060,7 +1021,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: @ast::item)
}
let rp = tcx.region_paramd_items.find(&it.id).map_consume(|x| *x);
match it.node {
ast::item_const(t, _) => {
ast::item_static(t, _, _) => {
let typ = ccx.to_ty(&empty_rscope, t);
let tpt = no_params(typ);
tcx.tcache.insert(local_def(it.id), tpt);
@ -1153,7 +1114,7 @@ pub fn ty_of_foreign_item(ccx: &CrateCtxt,
generics,
abis)
}
ast::foreign_item_const(t) => {
ast::foreign_item_static(t, _) => {
ty::ty_param_bounds_and_ty {
generics: ty::Generics {
type_param_defs: @~[],
@ -1211,7 +1172,7 @@ pub fn ty_generics(ccx: &CrateCtxt,
builtin_bounds: ty::EmptyBuiltinBounds(),
trait_bounds: ~[]
};
for ast_bounds.each |ast_bound| {
for ast_bounds.iter().advance |ast_bound| {
match *ast_bound {
TraitTyParamBound(b) => {
let ty = ty::mk_param(ccx.tcx, param_ty.idx, param_ty.def_id);

View file

@ -1285,7 +1285,7 @@ impl RegionVarBindings {
// It would be nice to write this using map():
let mut edges = vec::with_capacity(num_edges);
for self.constraints.each |constraint, span| {
for self.constraints.iter().advance |(constraint, span)| {
edges.push(GraphEdge {
next_edge: [uint::max_value, uint::max_value],
constraint: *constraint,

View file

@ -57,7 +57,7 @@ impl RegionParamNames {
}
fn has_ident(&self, ident: ast::ident) -> bool {
for self.each |region_param_name| {
for self.iter().advance |region_param_name| {
if *region_param_name == ident {
return true;
}

View file

@ -86,7 +86,6 @@ pub mod front {
pub mod config;
pub mod test;
pub mod std_inject;
pub mod intrinsic_inject;
}
pub mod back {
@ -167,7 +166,7 @@ Available lint options:
padded(max_key, "name"), "default", "meaning"));
io::println(fmt!(" %s %7.7s %s\n",
padded(max_key, "----"), "-------", "-------"));
for lint_dict.each |k, v| {
for lint_dict.iter().advance |(k, v)| {
let k = k.replace("_", "-");
io::println(fmt!(" %s %7.7s %s",
padded(max_key, k),

View file

@ -32,7 +32,6 @@ use syntax::parse::token;
use syntax::print::pprust;
use syntax::{ast, ast_util};
use core::str;
use core::vec;
/// Produces a string suitable for debugging output.

View file

@ -102,7 +102,7 @@ fn moddoc_from_mod(
fndoc_from_fn(ItemDoc)
))
}
ast::item_const(_, _) => {
ast::item_static(*) => {
Some(doc::ConstTag(
constdoc_from_const(ItemDoc)
))
@ -150,7 +150,7 @@ fn nmoddoc_from_mod(
ast::foreign_item_fn(*) => {
fns.push(fndoc_from_fn(ItemDoc));
}
ast::foreign_item_const(*) => {} // XXX: Not implemented.
ast::foreign_item_static(*) => {} // XXX: Not implemented.
}
}
doc::NmodDoc {

View file

@ -96,7 +96,7 @@ fn fold_const(
do astsrv::exec(srv) |ctxt| {
match ctxt.ast_map.get_copy(&doc.id()) {
ast_map::node_item(@ast::item {
node: ast::item_const(ty, _), _
node: ast::item_static(ty, _, _), _
}, _) => {
pprust::ty_to_str(ty, extract::interner())
}

View file

@ -96,7 +96,7 @@ impl Program {
code.push_str("fn main() {\n");
// It's easy to initialize things if we don't run things...
for self.local_vars.each |name, var| {
for self.local_vars.iter().advance |(name, var)| {
let mt = var.mt();
code.push_str(fmt!("let%s %s: %s = fail!();\n", mt, *name, var.ty));
var.alter(*name, &mut code);
@ -149,7 +149,7 @@ impl Program {
// Using this __tls_map handle, deserialize each variable binding that
// we know about
for self.local_vars.each |name, var| {
for self.local_vars.iter().advance |(name, var)| {
let mt = var.mt();
code.push_str(fmt!("let%s %s: %s = {
let data = __tls_map.get_copy(&~\"%s\");
@ -175,7 +175,7 @@ impl Program {
// After the input code is run, we can re-serialize everything back out
// into tls map (to be read later on by this task)
for self.local_vars.each |name, var| {
for self.local_vars.iter().advance |(name, var)| {
code.push_str(fmt!("{
let local: %s = %s;
let bytes = do ::std::io::with_bytes_writer |io| {
@ -237,7 +237,7 @@ impl Program {
/// program starts
pub fn set_cache(&self) {
let map = @mut HashMap::new();
for self.local_vars.each |name, value| {
for self.local_vars.iter().advance |(name, value)| {
map.insert(copy *name, @copy value.data);
}
unsafe {

View file

@ -25,13 +25,16 @@ use vec::ImmutableVector;
pub mod rustrt {
use libc;
use sys;
use vec;
#[cfg(stage0)]
use intrinsic::{TyDesc};
#[cfg(not(stage0))]
use unstable::intrinsics::{TyDesc};
#[abi = "cdecl"]
#[link_name = "rustrt"]
pub extern {
pub unsafe fn vec_reserve_shared_actual(t: *sys::TypeDesc,
pub unsafe fn vec_reserve_shared_actual(t: *TyDesc,
v: **vec::raw::VecRepr,
n: libc::size_t);
}
@ -197,6 +200,10 @@ pub mod raw {
use uint;
use unstable::intrinsics::{move_val_init};
use vec;
#[cfg(stage0)]
use intrinsic::{get_tydesc};
#[cfg(not(stage0))]
use unstable::intrinsics::{get_tydesc};
pub type VecRepr = vec::raw::VecRepr;
pub type SliceRepr = vec::raw::SliceRepr;
@ -258,7 +265,7 @@ pub mod raw {
// Only make the (slow) call into the runtime if we have to
if capacity(*v) < n {
let ptr: **VecRepr = transmute(v);
rustrt::vec_reserve_shared_actual(sys::get_type_desc::<T>(),
rustrt::vec_reserve_shared_actual(get_tydesc::<T>(),
ptr, n as libc::size_t);
}
}

View file

@ -10,24 +10,19 @@
#[doc(hidden)];
use libc::{c_char, c_void, intptr_t, uintptr_t};
use ptr::mut_null;
use libc::{c_char, intptr_t, uintptr_t};
use ptr::{mut_null};
use repr::BoxRepr;
use sys::TypeDesc;
use cast::transmute;
use unstable::intrinsics::TyDesc;
#[cfg(not(test))] use unstable::lang::clear_task_borrow_list;
#[cfg(not(test))] use ptr::to_unsafe_ptr;
/**
* Runtime structures
*
* NB: These must match the representation in the C++ runtime.
*/
type DropGlue<'self> = &'self fn(**TypeDesc, *c_void);
type FreeGlue<'self> = &'self fn(**TypeDesc, *c_void);
type TaskID = uintptr_t;
struct StackSegment { priv opaque: () }
@ -164,6 +159,19 @@ fn debug_mem() -> bool {
false
}
#[inline]
#[cfg(not(stage0))]
unsafe fn call_drop_glue(tydesc: *TyDesc, data: *i8) {
// This function should be inlined when stage0 is gone
((*tydesc).drop_glue)(data);
}
#[inline]
#[cfg(stage0)]
unsafe fn call_drop_glue(tydesc: *TyDesc, data: *i8) {
((*tydesc).drop_glue)(0 as **TyDesc, data);
}
/// Destroys all managed memory (i.e. @ boxes) held by the current task.
#[cfg(not(test))]
#[lang="annihilate"]
@ -205,9 +213,9 @@ pub unsafe fn annihilate() {
// callback, as the original value may have been freed.
for each_live_alloc(false) |box, uniq| {
if !uniq {
let tydesc: *TypeDesc = transmute(copy (*box).header.type_desc);
let drop_glue: DropGlue = transmute(((*tydesc).drop_glue, 0));
drop_glue(to_unsafe_ptr(&tydesc), transmute(&(*box).data));
let tydesc = (*box).header.type_desc;
let data = transmute(&(*box).data);
call_drop_glue(tydesc, data);
}
}

View file

@ -34,18 +34,6 @@ pub trait Map<K, V>: Mutable {
/// Return true if the map contains a value for the specified key
fn contains_key(&self, key: &K) -> bool;
/// Visits all keys and values
fn each<'a>(&'a self, f: &fn(&K, &'a V) -> bool) -> bool;
/// Visit all keys
fn each_key(&self, f: &fn(&K) -> bool) -> bool;
/// Visit all values
fn each_value<'a>(&'a self, f: &fn(&'a V) -> bool) -> bool;
/// Iterate over the map and mutate the contained values
fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool) -> bool;
/// Return a reference to the value corresponding to the key
fn find<'a>(&'a self, key: &K) -> Option<&'a V>;

View file

@ -40,12 +40,13 @@ with destructors.
use cast;
use container::{Map, Set};
use io;
use libc::{size_t, uintptr_t};
use libc::{uintptr_t};
use option::{None, Option, Some};
use ptr;
use hashmap::HashSet;
use stackwalk::walk_stack;
use sys;
use unstable::intrinsics::{TyDesc};
pub use stackwalk::Word;
@ -58,17 +59,11 @@ pub struct StackSegment {
}
pub mod rustrt {
use libc::size_t;
use stackwalk::Word;
use super::StackSegment;
#[link_name = "rustrt"]
pub extern {
#[rust_stack]
pub unsafe fn rust_call_tydesc_glue(root: *Word,
tydesc: *Word,
field: size_t);
#[rust_stack]
pub unsafe fn rust_gc_metadata() -> *Word;
@ -125,7 +120,7 @@ unsafe fn is_safe_point(pc: *Word) -> Option<SafePoint> {
return None;
}
type Visitor<'self> = &'self fn(root: **Word, tydesc: *Word) -> bool;
type Visitor<'self> = &'self fn(root: **Word, tydesc: *TyDesc) -> bool;
// Walks the list of roots for the given safe point, and calls visitor
// on each root.
@ -139,7 +134,7 @@ unsafe fn _walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) -> bool {
let stack_roots: *u32 = bump(sp_meta, 2);
let reg_roots: *u8 = bump(stack_roots, num_stack_roots);
let addrspaces: *Word = align_to_pointer(bump(reg_roots, num_reg_roots));
let tydescs: ***Word = bump(addrspaces, num_stack_roots);
let tydescs: ***TyDesc = bump(addrspaces, num_stack_roots);
// Stack roots
let mut sri = 0;
@ -321,6 +316,19 @@ fn expect_sentinel() -> bool { true }
#[cfg(nogc)]
fn expect_sentinel() -> bool { false }
#[inline]
#[cfg(not(stage0))]
unsafe fn call_drop_glue(tydesc: *TyDesc, data: *i8) {
// This function should be inlined when stage0 is gone
((*tydesc).drop_glue)(data);
}
#[inline]
#[cfg(stage0)]
unsafe fn call_drop_glue(tydesc: *TyDesc, data: *i8) {
((*tydesc).drop_glue)(0 as **TyDesc, data);
}
// Entry point for GC-based cleanup. Walks stack looking for exchange
// heap and stack allocations requiring drop, and runs all
// destructors.
@ -364,7 +372,7 @@ pub fn cleanup_stack_for_failure() {
// FIXME #4420: Destroy this box
// FIXME #4330: Destroy this box
} else {
rustrt::rust_call_tydesc_glue(*root, tydesc, 3 as size_t);
call_drop_glue(tydesc, *root as *i8);
}
}
}

View file

@ -307,34 +307,6 @@ impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> {
}
}
/// Visit all key-value pairs
fn each<'a>(&'a self, blk: &fn(&K, &'a V) -> bool) -> bool {
self.iter().advance(|(k, v)| blk(k, v))
}
/// Visit all keys
fn each_key(&self, blk: &fn(k: &K) -> bool) -> bool {
self.iter().advance(|(k, _)| blk(k))
}
/// Visit all values
fn each_value<'a>(&'a self, blk: &fn(v: &'a V) -> bool) -> bool {
self.iter().advance(|(_, v)| blk(v))
}
/// Iterate over the map and mutate the contained values
fn mutate_values(&mut self, blk: &fn(&K, &mut V) -> bool) -> bool {
for uint::range(0, self.buckets.len()) |i| {
match self.buckets[i] {
Some(Bucket{key: ref key, value: ref mut value, _}) => {
if !blk(key, value) { return false; }
}
None => ()
}
}
return true;
}
/// Return a reference to the value corresponding to the key
fn find<'a>(&'a self, k: &K) -> Option<&'a V> {
match self.bucket_for_key(k) {
@ -516,6 +488,29 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
}
}
/// Visit all keys
pub fn each_key(&self, blk: &fn(k: &K) -> bool) -> bool {
self.iter().advance(|(k, _)| blk(k))
}
/// Visit all values
pub fn each_value<'a>(&'a self, blk: &fn(v: &'a V) -> bool) -> bool {
self.iter().advance(|(_, v)| blk(v))
}
/// Iterate over the map and mutate the contained values
pub fn mutate_values(&mut self, blk: &fn(&K, &mut V) -> bool) -> bool {
for uint::range(0, self.buckets.len()) |i| {
match self.buckets[i] {
Some(Bucket{key: ref key, value: ref mut value, _}) => {
if !blk(key, value) { return false; }
}
None => ()
}
}
return true;
}
/// An iterator visiting all key-value pairs in arbitrary order.
/// Iterator element type is (&'a K, &'a V).
pub fn iter<'a>(&'a self) -> HashMapIterator<'a, K, V> {
@ -718,12 +713,6 @@ impl<T:Hash + Eq> HashSet<T> {
self.map.contains_key_equiv(value)
}
/// Visit all elements in arbitrary order
/// FIXME: #6978: Remove when all callers are converted
pub fn each(&self, f: &fn(&T) -> bool) -> bool {
self.iter().advance(f)
}
/// An iterator visiting all elements in arbitrary order.
/// Iterator element type is &'a T.
pub fn iter<'a>(&'a self) -> HashSetIterator<'a, T> {

View file

@ -43,7 +43,6 @@ pub trait Iterator<A> {
/// Return a lower bound and upper bound on the remaining length of the iterator.
///
/// The common use case for the estimate is pre-allocating space to store the results.
#[cfg(not(stage0))]
fn size_hint(&self) -> (Option<uint>, Option<uint>) { (None, None) }
}
@ -610,7 +609,6 @@ impl<A, T: Iterator<A>, U: Iterator<A>> Iterator<A> for ChainIterator<A, T, U> {
}
#[inline]
#[cfg(not(stage0))]
fn size_hint(&self) -> (Option<uint>, Option<uint>) {
let (a_lower, a_upper) = self.a.size_hint();
let (b_lower, b_upper) = self.b.size_hint();
@ -664,7 +662,6 @@ impl<'self, A, B, T: Iterator<A>> Iterator<B> for MapIterator<'self, A, B, T> {
}
#[inline]
#[cfg(not(stage0))]
fn size_hint(&self) -> (Option<uint>, Option<uint>) {
self.iter.size_hint()
}
@ -690,7 +687,6 @@ impl<'self, A, T: Iterator<A>> Iterator<A> for FilterIterator<'self, A, T> {
}
#[inline]
#[cfg(not(stage0))]
fn size_hint(&self) -> (Option<uint>, Option<uint>) {
let (_, upper) = self.iter.size_hint();
(None, upper) // can't know a lower bound, due to the predicate
@ -716,7 +712,6 @@ impl<'self, A, B, T: Iterator<A>> Iterator<B> for FilterMapIterator<'self, A, B,
}
#[inline]
#[cfg(not(stage0))]
fn size_hint(&self) -> (Option<uint>, Option<uint>) {
let (_, upper) = self.iter.size_hint();
(None, upper) // can't know a lower bound, due to the predicate

File diff suppressed because it is too large Load diff

View file

@ -15,7 +15,7 @@ use ptr::to_unsafe_ptr;
#[cfg(not(test))] use cmp::{Eq, Ord};
pub mod raw {
use intrinsic::TyDesc;
use std::unstable::intrinsics::TyDesc;
pub static RC_EXCHANGE_UNIQUE : uint = (-1) as uint;
pub static RC_MANAGED_UNIQUE : uint = (-2) as uint;

View file

@ -758,7 +758,7 @@ pub fn list_dir(p: &Path) -> ~[~str] {
FindFirstFileW(
path_ptr,
::cast::transmute(wfd_ptr));
if find_handle as int != INVALID_HANDLE_VALUE {
if find_handle as libc::c_int != INVALID_HANDLE_VALUE {
let mut more_files = 1 as libc::c_int;
while more_files != 0 {
let fp_buf = rust_list_dir_wfd_fp_buf(wfd_ptr);

View file

@ -16,8 +16,10 @@ Runtime type reflection
#[allow(missing_doc)];
use intrinsic::{TyDesc, TyVisitor};
use intrinsic::Opaque;
#[cfg(stage0)]
use intrinsic::{Opaque, TyDesc, TyVisitor};
#[cfg(not(stage0))]
use unstable::intrinsics::{Opaque, TyDesc, TyVisitor};
use libc::c_void;
use sys;
use vec;

View file

@ -19,9 +19,6 @@ More runtime type reflection
use cast::transmute;
use char;
use container::Container;
use intrinsic;
use intrinsic::{TyDesc, TyVisitor, visit_tydesc};
use intrinsic::Opaque;
use io::{Writer, WriterUtil};
use iterator::IteratorUtil;
use libc::c_void;
@ -34,6 +31,10 @@ use to_str::ToStr;
use vec::raw::{VecRepr, SliceRepr};
use vec;
use vec::{OwnedVector, UnboxedVecRepr};
#[cfg(stage0)]
use intrinsic::{Opaque, TyDesc, TyVisitor, get_tydesc, visit_tydesc};
#[cfg(not(stage0))]
use unstable::intrinsics::{Opaque, TyDesc, TyVisitor, get_tydesc, visit_tydesc};
#[cfg(test)] use io;
@ -564,6 +565,7 @@ impl TyVisitor for ReprVisitor {
fn visit_self(&self) -> bool { true }
fn visit_type(&self) -> bool { true }
#[cfg(not(stage0))]
fn visit_opaque_box(&self) -> bool {
self.writer.write_char('@');
do self.get::<&managed::raw::BoxRepr> |b| {
@ -571,6 +573,16 @@ impl TyVisitor for ReprVisitor {
self.visit_ptr_inner(p, b.header.type_desc);
}
}
#[cfg(stage0)]
fn visit_opaque_box(&self) -> bool {
self.writer.write_char('@');
do self.get::<&managed::raw::BoxRepr> |b| {
let p = ptr::to_unsafe_ptr(&b.data) as *c_void;
unsafe {
self.visit_ptr_inner(p, transmute(b.header.type_desc));
}
}
}
// Type no longer exists, vestigial function.
fn visit_constr(&self, _inner: *TyDesc) -> bool { fail!(); }
@ -581,7 +593,7 @@ impl TyVisitor for ReprVisitor {
pub fn write_repr<T>(writer: @Writer, object: &T) {
unsafe {
let ptr = ptr::to_unsafe_ptr(object) as *c_void;
let tydesc = intrinsic::get_tydesc::<T>();
let tydesc = get_tydesc::<T>();
let u = ReprVisitor(ptr, writer);
let v = reflect::MovePtrAdaptor(u);
visit_tydesc(tydesc, @v as @TyVisitor)

View file

@ -8,26 +8,22 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use sys::{TypeDesc, size_of};
use sys::{size_of};
use libc::{c_void, size_t, uintptr_t};
use c_malloc = libc::malloc;
use c_free = libc::free;
use managed::raw::{BoxHeaderRepr, BoxRepr};
use cast::transmute;
use unstable::intrinsics::{atomic_xadd,atomic_xsub};
use unstable::intrinsics::{atomic_xadd,atomic_xsub,TyDesc};
use ptr::null;
use intrinsic::TyDesc;
pub unsafe fn malloc(td: *TypeDesc, size: uint) -> *c_void {
pub unsafe fn malloc(td: *TyDesc, size: uint) -> *c_void {
assert!(td.is_not_null());
let total_size = get_box_size(size, (*td).align);
let p = c_malloc(total_size as size_t);
assert!(p.is_not_null());
// FIXME #3475: Converting between our two different tydesc types
let td: *TyDesc = transmute(td);
let box: &mut BoxRepr = transmute(p);
box.header.ref_count = -1; // Exchange values not ref counted
box.header.type_desc = td;

View file

@ -17,23 +17,11 @@ use cast;
use gc;
use io;
use libc;
use libc::{c_void, c_char, size_t};
use libc::{c_char, size_t};
use repr;
use str;
use unstable::intrinsics;
pub type FreeGlue<'self> = &'self fn(*TypeDesc, *c_void);
// Corresponds to runtime type_desc type
pub struct TypeDesc {
size: uint,
align: uint,
take_glue: uint,
drop_glue: uint,
free_glue: uint
// Remaining fields not listed
}
/// The representation of a Rust closure
pub struct Closure {
code: *(),
@ -51,23 +39,6 @@ pub mod rustrt {
}
}
/**
* Returns a pointer to a type descriptor.
*
* Useful for calling certain function in the Rust runtime or otherwise
* performing dark magick.
*/
#[inline]
pub fn get_type_desc<T>() -> *TypeDesc {
unsafe { intrinsics::get_tydesc::<T>() as *TypeDesc }
}
/// Returns a pointer to a type descriptor.
#[inline]
pub fn get_type_desc_val<T>(_val: &T) -> *TypeDesc {
get_type_desc::<T>()
}
/// Returns the size of a type
#[inline]
pub fn size_of<T>() -> uint {

View file

@ -111,7 +111,7 @@ fn taskset_remove(tasks: &mut TaskSet, task: *rust_task) {
assert!(was_present);
}
pub fn taskset_each(tasks: &TaskSet, blk: &fn(v: *rust_task) -> bool) -> bool {
tasks.each(|k| blk(*k))
tasks.iter().advance(|k| blk(*k))
}
// One of these per group of linked-failure tasks.

View file

@ -18,11 +18,9 @@ use str::OwnedStr;
use hashmap::HashMap;
use hashmap::HashSet;
use iterator::IteratorUtil;
use container::Map;
use hash::Hash;
use cmp::Eq;
use vec::ImmutableVector;
use iterator::IteratorUtil;
/// A generic trait for converting a value to a string
pub trait ToStr {
@ -179,7 +177,7 @@ impl<A:ToStr> ToStr for @[A] {
mod tests {
use hashmap::HashMap;
use hashmap::HashSet;
use container::Set;
use container::{Set,Map};
#[test]
fn test_simple_types() {
assert_eq!(1i.to_str(), ~"1");

View file

@ -58,30 +58,6 @@ impl<T> Map<uint, T> for TrieMap<T> {
self.find(key).is_some()
}
/// Visit all key-value pairs in order
#[inline]
fn each<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
self.root.each(f)
}
/// Visit all keys in order
#[inline]
fn each_key(&self, f: &fn(&uint) -> bool) -> bool {
self.each(|k, _| f(k))
}
/// Visit all values in order
#[inline]
fn each_value<'a>(&'a self, f: &fn(&'a T) -> bool) -> bool {
self.each(|_, v| f(v))
}
/// Iterate over the map and mutate the contained values
#[inline]
fn mutate_values(&mut self, f: &fn(&uint, &mut T) -> bool) -> bool {
self.root.mutate_values(f)
}
/// Return a reference to the value corresponding to the key
#[inline]
fn find<'a>(&'a self, key: &uint) -> Option<&'a T> {
@ -158,6 +134,30 @@ impl<T> TrieMap<T> {
self.root.each_reverse(f)
}
/// Visit all key-value pairs in order
#[inline]
pub fn each<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
self.root.each(f)
}
/// Visit all keys in order
#[inline]
pub fn each_key(&self, f: &fn(&uint) -> bool) -> bool {
self.each(|k, _| f(k))
}
/// Visit all values in order
#[inline]
pub fn each_value<'a>(&'a self, f: &fn(&'a T) -> bool) -> bool {
self.each(|_, v| f(v))
}
/// Iterate over the map and mutate the contained values
#[inline]
pub fn mutate_values(&mut self, f: &fn(&uint, &mut T) -> bool) -> bool {
self.root.mutate_values(f)
}
/// Visit all keys in reverse order
#[inline]
pub fn each_key_reverse(&self, f: &fn(&uint) -> bool) -> bool {

View file

@ -62,6 +62,7 @@ pub struct AtomicPtr<T> {
/**
* An owned atomic pointer. Ensures that only a single reference to the data is held at any time.
*/
#[no_drop_flag]
pub struct AtomicOption<T> {
priv p: *mut c_void
}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use sys::{TypeDesc, size_of};
use sys::size_of;
use libc::{c_void, size_t};
use c_malloc = libc::malloc;
use c_free = libc::free;
@ -16,18 +16,18 @@ use managed::raw::{BoxHeaderRepr, BoxRepr};
use cast::transmute;
use unstable::intrinsics::{atomic_xadd,atomic_xsub};
use ptr::null;
#[cfg(stage0)]
use intrinsic::TyDesc;
#[cfg(not(stage0))]
use unstable::intrinsics::TyDesc;
pub unsafe fn malloc(td: *TypeDesc, size: uint) -> *c_void {
pub unsafe fn malloc(td: *TyDesc, size: uint) -> *c_void {
assert!(td.is_not_null());
let total_size = get_box_size(size, (*td).align);
let p = c_malloc(total_size as size_t);
assert!(p.is_not_null());
// FIXME #3475: Converting between our two different tydesc types
let td: *TyDesc = transmute(td);
let box: &mut BoxRepr = transmute(p);
box.header.ref_count = -1; // Exchange values not ref counted
box.header.type_desc = td;

View file

@ -32,6 +32,130 @@ A quick refresher on memory ordering:
*/
// This is needed to prevent duplicate lang item definitions.
#[cfg(test)]
pub use realstd::unstable::intrinsics::{TyDesc, Opaque, TyVisitor};
#[cfg(not(stage0))]
pub type GlueFn = extern "Rust" fn(*i8);
#[cfg(stage0)]
pub type GlueFn = extern "Rust" fn(**TyDesc, *i8);
// NB: this has to be kept in sync with the Rust ABI.
#[lang="ty_desc"]
#[cfg(not(test))]
pub struct TyDesc {
size: uint,
align: uint,
take_glue: GlueFn,
drop_glue: GlueFn,
free_glue: GlueFn,
visit_glue: GlueFn,
}
#[lang="opaque"]
#[cfg(not(test))]
pub enum Opaque { }
#[lang="ty_visitor"]
#[cfg(not(test))]
pub trait TyVisitor {
fn visit_bot(&self) -> bool;
fn visit_nil(&self) -> bool;
fn visit_bool(&self) -> bool;
fn visit_int(&self) -> bool;
fn visit_i8(&self) -> bool;
fn visit_i16(&self) -> bool;
fn visit_i32(&self) -> bool;
fn visit_i64(&self) -> bool;
fn visit_uint(&self) -> bool;
fn visit_u8(&self) -> bool;
fn visit_u16(&self) -> bool;
fn visit_u32(&self) -> bool;
fn visit_u64(&self) -> bool;
fn visit_float(&self) -> bool;
fn visit_f32(&self) -> bool;
fn visit_f64(&self) -> bool;
fn visit_char(&self) -> bool;
fn visit_str(&self) -> bool;
fn visit_estr_box(&self) -> bool;
fn visit_estr_uniq(&self) -> bool;
fn visit_estr_slice(&self) -> bool;
fn visit_estr_fixed(&self, n: uint, sz: uint, align: uint) -> bool;
fn visit_box(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_uniq(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_ptr(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_rptr(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_vec(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_unboxed_vec(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_evec_box(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_evec_uniq(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_evec_slice(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_evec_fixed(&self, n: uint, sz: uint, align: uint,
mtbl: uint, inner: *TyDesc) -> bool;
fn visit_enter_rec(&self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_rec_field(&self, i: uint, name: &str,
mtbl: uint, inner: *TyDesc) -> bool;
fn visit_leave_rec(&self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_enter_class(&self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_class_field(&self, i: uint, name: &str,
mtbl: uint, inner: *TyDesc) -> bool;
fn visit_leave_class(&self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_enter_tup(&self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_tup_field(&self, i: uint, inner: *TyDesc) -> bool;
fn visit_leave_tup(&self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_enter_enum(&self, n_variants: uint,
get_disr: extern unsafe fn(ptr: *Opaque) -> int,
sz: uint, align: uint) -> bool;
fn visit_enter_enum_variant(&self, variant: uint,
disr_val: int,
n_fields: uint,
name: &str) -> bool;
fn visit_enum_variant_field(&self, i: uint, offset: uint, inner: *TyDesc) -> bool;
fn visit_leave_enum_variant(&self, variant: uint,
disr_val: int,
n_fields: uint,
name: &str) -> bool;
fn visit_leave_enum(&self, n_variants: uint,
get_disr: extern unsafe fn(ptr: *Opaque) -> int,
sz: uint, align: uint) -> bool;
fn visit_enter_fn(&self, purity: uint, proto: uint,
n_inputs: uint, retstyle: uint) -> bool;
fn visit_fn_input(&self, i: uint, mode: uint, inner: *TyDesc) -> bool;
fn visit_fn_output(&self, retstyle: uint, inner: *TyDesc) -> bool;
fn visit_leave_fn(&self, purity: uint, proto: uint,
n_inputs: uint, retstyle: uint) -> bool;
fn visit_trait(&self) -> bool;
fn visit_var(&self) -> bool;
fn visit_var_integral(&self) -> bool;
fn visit_param(&self, i: uint) -> bool;
fn visit_self(&self) -> bool;
fn visit_type(&self) -> bool;
fn visit_opaque_box(&self) -> bool;
fn visit_constr(&self, inner: *TyDesc) -> bool;
fn visit_closure_ptr(&self, ck: uint) -> bool;
}
#[abi = "rust-intrinsic"]
pub extern "rust-intrinsic" {
@ -42,9 +166,7 @@ pub extern "rust-intrinsic" {
/// Atomic compare and exchange, release ordering.
pub fn atomic_cxchg_rel(dst: &mut int, old: int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_cxchg_acqrel(dst: &mut int, old: int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_cxchg_relaxed(dst: &mut int, old: int, src: int) -> int;
@ -53,7 +175,6 @@ pub extern "rust-intrinsic" {
/// Atomic load, acquire ordering.
pub fn atomic_load_acq(src: &int) -> int;
#[cfg(not(stage0))]
pub fn atomic_load_relaxed(src: &int) -> int;
/// Atomic store, sequentially consistent.
@ -61,7 +182,6 @@ pub extern "rust-intrinsic" {
/// Atomic store, release ordering.
pub fn atomic_store_rel(dst: &mut int, val: int);
#[cfg(not(stage0))]
pub fn atomic_store_relaxed(dst: &mut int, val: int);
/// Atomic exchange, sequentially consistent.
@ -70,9 +190,7 @@ pub extern "rust-intrinsic" {
pub fn atomic_xchg_acq(dst: &mut int, src: int) -> int;
/// Atomic exchange, release ordering.
pub fn atomic_xchg_rel(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_xchg_acqrel(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_xchg_relaxed(dst: &mut int, src: int) -> int;
/// Atomic addition, sequentially consistent.
@ -81,9 +199,7 @@ pub extern "rust-intrinsic" {
pub fn atomic_xadd_acq(dst: &mut int, src: int) -> int;
/// Atomic addition, release ordering.
pub fn atomic_xadd_rel(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_xadd_acqrel(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_xadd_relaxed(dst: &mut int, src: int) -> int;
/// Atomic subtraction, sequentially consistent.
@ -92,97 +208,55 @@ pub extern "rust-intrinsic" {
pub fn atomic_xsub_acq(dst: &mut int, src: int) -> int;
/// Atomic subtraction, release ordering.
pub fn atomic_xsub_rel(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_xsub_acqrel(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_xsub_relaxed(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_and(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_and_acq(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_and_rel(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_and_acqrel(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_and_relaxed(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_nand(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_nand_acq(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_nand_rel(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_nand_acqrel(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_nand_relaxed(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_or(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_or_acq(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_or_rel(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_or_acqrel(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_or_relaxed(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_xor(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_xor_acq(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_xor_rel(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_xor_acqrel(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_xor_relaxed(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_max(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_max_acq(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_max_rel(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_max_acqrel(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_max_relaxed(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_min(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_min_acq(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_min_rel(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_min_acqrel(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_min_relaxed(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_umin(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_umin_acq(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_umin_rel(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_umin_acqrel(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_umin_relaxed(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_umax(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_umax_acq(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_umax_rel(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_umax_acqrel(dst: &mut int, src: int) -> int;
#[cfg(not(stage0))]
pub fn atomic_umax_relaxed(dst: &mut int, src: int) -> int;
/// The size of a type in bytes.
@ -209,6 +283,9 @@ pub extern "rust-intrinsic" {
pub fn pref_align_of<T>() -> uint;
/// Get a static pointer to a type descriptor.
#[cfg(not(stage0))]
pub fn get_tydesc<T>() -> *TyDesc;
#[cfg(stage0)]
pub fn get_tydesc<T>() -> *();
/// Create a value initialized to zero.
@ -231,9 +308,8 @@ pub extern "rust-intrinsic" {
/// Returns `true` if a type requires drop glue.
pub fn needs_drop<T>() -> bool;
// XXX: intrinsic uses legacy modes and has reference to TyDesc
// and TyVisitor which are in librustc
//fn visit_tydesc(++td: *TyDesc, &&tv: TyVisitor) -> ();
#[cfg(not(stage0))]
pub fn visit_tydesc(td: *TyDesc, tv: @TyVisitor);
pub fn frame_address(f: &once fn(*u8));

View file

@ -30,6 +30,10 @@ use sys;
use sys::size_of;
use uint;
use unstable::intrinsics;
#[cfg(stage0)]
use intrinsic::{get_tydesc};
#[cfg(not(stage0))]
use unstable::intrinsics::{get_tydesc};
use vec;
use util;
@ -37,19 +41,22 @@ use util;
pub mod rustrt {
use libc;
use sys;
use vec::raw;
#[cfg(stage0)]
use intrinsic::{TyDesc};
#[cfg(not(stage0))]
use unstable::intrinsics::{TyDesc};
#[abi = "cdecl"]
pub extern {
// These names are terrible. reserve_shared applies
// to ~[] and reserve_shared_actual applies to @[].
#[fast_ffi]
unsafe fn vec_reserve_shared(t: *sys::TypeDesc,
unsafe fn vec_reserve_shared(t: *TyDesc,
v: **raw::VecRepr,
n: libc::size_t);
#[fast_ffi]
unsafe fn vec_reserve_shared_actual(t: *sys::TypeDesc,
unsafe fn vec_reserve_shared_actual(t: *TyDesc,
v: **raw::VecRepr,
n: libc::size_t);
}
@ -78,7 +85,7 @@ pub fn reserve<T>(v: &mut ~[T], n: uint) {
if capacity(v) < n {
unsafe {
let ptr: **raw::VecRepr = cast::transmute(v);
let td = sys::get_type_desc::<T>();
let td = get_tydesc::<T>();
if ((**ptr).box_header.ref_count ==
managed::raw::RC_MANAGED_UNIQUE) {
rustrt::vec_reserve_shared_actual(td, ptr, n as libc::size_t);
@ -437,7 +444,7 @@ pub fn partitioned<T:Copy>(v: &[T], f: &fn(&T) -> bool) -> (~[T], ~[T]) {
let mut lefts = ~[];
let mut rights = ~[];
for each(v) |elt| {
for v.iter().advance |elt| {
if f(elt) {
lefts.push(copy *elt);
} else {
@ -843,7 +850,7 @@ pub fn grow_set<T:Copy>(v: &mut ~[T], index: uint, initval: &T, val: T) {
/// Apply a function to each element of a vector and return the results
pub fn map<T, U>(v: &[T], f: &fn(t: &T) -> U) -> ~[U] {
let mut result = with_capacity(v.len());
for each(v) |elem| {
for v.iter().advance |elem| {
result.push(f(elem));
}
result
@ -879,7 +886,7 @@ pub fn mapi<T, U>(v: &[T], f: &fn(uint, t: &T) -> U) -> ~[U] {
*/
pub fn flat_map<T, U>(v: &[T], f: &fn(t: &T) -> ~[U]) -> ~[U] {
let mut result = ~[];
for each(v) |elem| { result.push_all_move(f(elem)); }
for v.iter().advance |elem| { result.push_all_move(f(elem)); }
result
}
@ -932,7 +939,7 @@ pub fn filter_mapped<T, U: Copy>(
*/
let mut result = ~[];
for each(v) |elem| {
for v.iter().advance |elem| {
match f(elem) {
None => {/* no-op */ }
Some(result_elem) => { result.push(result_elem); }
@ -967,7 +974,7 @@ pub fn filter<T>(v: ~[T], f: &fn(t: &T) -> bool) -> ~[T] {
*/
pub fn filtered<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[T] {
let mut result = ~[];
for each(v) |elem| {
for v.iter().advance |elem| {
if f(elem) { result.push(copy *elem); }
}
result
@ -1051,7 +1058,7 @@ impl<'self, T:Copy> VectorVector<T> for &'self [&'self [T]] {
/// Return true if a vector contains an element with the given value
pub fn contains<T:Eq>(v: &[T], x: &T) -> bool {
for each(v) |elt| { if *x == *elt { return true; } }
for v.iter().advance |elt| { if *x == *elt { return true; } }
false
}
@ -1202,7 +1209,7 @@ pub fn bsearch_elem<T:TotalOrd>(v: &[T], x: &T) -> Option<uint> {
*/
pub fn unzip_slice<T:Copy,U:Copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
let mut (ts, us) = (~[], ~[]);
for each(v) |p| {
for v.iter().advance |p| {
let (t, u) = copy *p;
ts.push(t);
us.push(u);
@ -1340,69 +1347,6 @@ pub fn reversed<T:Copy>(v: &const [T]) -> ~[T] {
rs
}
/**
* Iterates over a vector, yielding each element to a closure.
*
* # Arguments
*
* * `v` - A vector, to be iterated over
* * `f` - A closure to do the iterating. Within this closure, return true to
* * continue iterating, false to break.
*
* # Examples
*
* ~~~ {.rust}
* [1,2,3].each(|&i| {
* io::println(int::str(i));
* true
* });
* ~~~
*
* ~~~ {.rust}
* [1,2,3,4,5].each(|&i| {
* if i < 4 {
* io::println(int::str(i));
* true
* }
* else {
* false
* }
* });
* ~~~
*
* You probably will want to use each with a `for`/`do` expression, depending
* on your iteration needs:
*
* ~~~ {.rust}
* for [1,2,3].each |&i| {
* io::println(int::str(i));
* }
* ~~~
*/
#[inline]
pub fn each<'r,T>(v: &'r [T], f: &fn(&'r T) -> bool) -> bool {
// ^^^^
// NB---this CANNOT be &const [T]! The reason
// is that you are passing it to `f()` using
// an immutable.
let mut broke = false;
do as_imm_buf(v) |p, n| {
let mut n = n;
let mut p = p;
while n > 0u {
unsafe {
let q = cast::copy_lifetime_vec(v, &*p);
if !f(q) { break; }
p = ptr::offset(p, 1u);
}
n -= 1u;
}
broke = n > 0;
}
return !broke;
}
/**
* Iterate over all permutations of vector `v`.
*
@ -2446,7 +2390,6 @@ macro_rules! iterator {
}
#[inline]
#[cfg(not(stage0))]
fn size_hint(&self) -> (Option<uint>, Option<uint>) {
let exact = Some(((self.end as uint) - (self.ptr as uint)) / size_of::<$elem>());
(exact, exact)
@ -3063,36 +3006,6 @@ mod tests {
assert_eq!(v, ~[1, 3, 5]);
}
#[test]
fn test_each_empty() {
for each::<int>([]) |_v| {
fail!(); // should never be executed
}
}
#[test]
fn test_each_nonempty() {
let mut i = 0;
for each([1, 2, 3]) |v| {
i += *v;
}
assert_eq!(i, 6);
}
#[test]
fn test_each_ret_len0() {
let a0 : [int, .. 0] = [];
assert_eq!(each(a0, |_p| fail!()), true);
}
#[test]
fn test_each_ret_len1() {
let a1 = [17];
assert_eq!(each(a1, |_p| true), true);
assert_eq!(each(a1, |_p| false), false);
}
#[test]
fn test_each_permutation() {
let mut results: ~[~[int]];
@ -3848,21 +3761,6 @@ mod tests {
};
}
#[test]
#[ignore(windows)]
#[should_fail]
fn test_each_fail() {
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
let mut i = 0;
do each(v) |_elt| {
if i == 2 {
fail!()
}
i += 0;
false
};
}
#[test]
#[ignore(windows)]
#[should_fail]
@ -3929,7 +3827,6 @@ mod tests {
}
#[test]
#[cfg(not(stage0))]
fn test_iterator() {
use iterator::*;
let xs = [1, 2, 5, 10, 11];

View file

@ -190,7 +190,7 @@ pub enum def {
def_self_ty(/* trait id */ node_id),
def_mod(def_id),
def_foreign_mod(def_id),
def_const(def_id),
def_static(def_id, bool /* is_mutbl */),
def_arg(node_id, bool /* is_mutbl */),
def_local(node_id, bool /* is_mutbl */),
def_variant(def_id /* enum */, def_id /* variant */),
@ -1093,7 +1093,7 @@ pub struct item {
#[deriving(Eq, Encodable, Decodable)]
pub enum item_ {
item_const(@Ty, @expr),
item_static(@Ty, mutability, @expr),
item_fn(fn_decl, purity, AbiSet, Generics, blk),
item_mod(_mod),
item_foreign_mod(foreign_mod),
@ -1122,7 +1122,7 @@ pub struct foreign_item {
#[deriving(Eq, Encodable, Decodable)]
pub enum foreign_item_ {
foreign_item_fn(fn_decl, purity, Generics),
foreign_item_const(@Ty)
foreign_item_static(@Ty, /* is_mutbl */ bool),
}
// The data we save and restore about an inlined item or method. This is not

View file

@ -339,7 +339,7 @@ pub fn node_id_to_str(map: map, id: node_id, itr: @ident_interner) -> ~str {
Some(&node_item(item, path)) => {
let path_str = path_ident_to_str(path, item.ident, itr);
let item_str = match item.node {
item_const(*) => ~"const",
item_static(*) => ~"static",
item_fn(*) => ~"fn",
item_mod(*) => ~"mod",
item_foreign_mod(*) => ~"foreign mod",

View file

@ -59,7 +59,7 @@ pub fn variant_def_ids(d: def) -> Option<(def_id, def_id)> {
pub fn def_id_of_def(d: def) -> def_id {
match d {
def_fn(id, _) | def_static_method(id, _, _) | def_mod(id) |
def_foreign_mod(id) | def_const(id) |
def_foreign_mod(id) | def_static(id, _) |
def_variant(_, id) | def_ty(id) | def_ty_param(id, _) |
def_use(id) | def_struct(id) | def_trait(id) => {
id
@ -394,10 +394,10 @@ impl id_range {
pub fn id_visitor<T: Copy>(vfn: @fn(node_id, T)) -> visit::vt<T> {
let visit_generics: @fn(&Generics, T) = |generics, t| {
for generics.ty_params.each |p| {
for generics.ty_params.iter().advance |p| {
vfn(p.id, copy t);
}
for generics.lifetimes.each |p| {
for generics.lifetimes.iter().advance |p| {
vfn(p.id, copy t);
}
};

View file

@ -324,11 +324,11 @@ impl<'self> TraitDef<'self> {
let mut trait_generics = self.generics.to_generics(cx, span, type_ident, generics);
// Copy the lifetimes
for generics.lifetimes.each |l| {
for generics.lifetimes.iter().advance |l| {
trait_generics.lifetimes.push(copy *l)
};
// Create the type parameters.
for generics.ty_params.each |ty_param| {
for generics.ty_params.iter().advance |ty_param| {
// I don't think this can be moved out of the loop, since
// a TyParamBound requires an ast id
let mut bounds = opt_vec::from(

View file

@ -374,7 +374,7 @@ impl gen_init for protocol {
fn buffer_ty_path(&self, cx: @ExtCtxt) -> @ast::Ty {
let mut params: OptVec<ast::TyParam> = opt_vec::Empty;
for (copy self.states).iter().advance |s| {
for s.generics.ty_params.each |tp| {
for s.generics.ty_params.iter().advance |tp| {
match params.iter().find_(|tpp| tp.ident == tpp.ident) {
None => params.push(*tp),
_ => ()
@ -392,7 +392,7 @@ impl gen_init for protocol {
let ext_cx = cx;
let mut params: OptVec<ast::TyParam> = opt_vec::Empty;
let fields = do (copy self.states).iter().transform |s| {
for s.generics.ty_params.each |tp| {
for s.generics.ty_params.iter().advance |tp| {
match params.iter().find_(|tpp| tp.ident == tpp.ident) {
None => params.push(*tp),
_ => ()

View file

@ -236,8 +236,8 @@ fn noop_fold_foreign_item(ni: @foreign_item, fld: @ast_fold)
purity,
fold_generics(generics, fld))
}
foreign_item_const(t) => {
foreign_item_const(fld.fold_ty(t))
foreign_item_static(t, m) => {
foreign_item_static(fld.fold_ty(t), m)
}
},
id: fld.new_id(ni.id),
@ -270,7 +270,7 @@ fn noop_fold_struct_field(sf: @struct_field, fld: @ast_fold)
pub fn noop_fold_item_underscore(i: &item_, fld: @ast_fold) -> item_ {
match *i {
item_const(t, e) => item_const(fld.fold_ty(t), fld.fold_expr(e)),
item_static(t, m, e) => item_static(fld.fold_ty(t), m, fld.fold_expr(e)),
item_fn(ref decl, purity, abi, ref generics, ref body) => {
item_fn(
fold_fn_decl(decl, fld),

View file

@ -38,13 +38,6 @@ pub fn from<T>(t: ~[T]) -> OptVec<T> {
}
impl<T> OptVec<T> {
fn each(&self, blk: &fn(v: &T) -> bool) -> bool {
match *self {
Empty => true,
Vec(ref v) => v.iter().advance(blk)
}
}
fn push(&mut self, t: T) {
match *self {
Vec(ref mut v) => {

View file

@ -33,8 +33,8 @@ use ast::{expr_vec, expr_vstore, expr_vstore_mut_box};
use ast::{expr_vstore_slice, expr_vstore_box};
use ast::{expr_vstore_mut_slice, expr_while, extern_fn, field, fn_decl};
use ast::{expr_vstore_uniq, Onceness, Once, Many};
use ast::{foreign_item, foreign_item_const, foreign_item_fn, foreign_mod};
use ast::{ident, impure_fn, inherited, item, item_, item_const};
use ast::{foreign_item, foreign_item_static, foreign_item_fn, foreign_mod};
use ast::{ident, impure_fn, inherited, item, item_, item_static};
use ast::{item_enum, item_fn, item_foreign_mod, item_impl};
use ast::{item_mac, item_mod, item_struct, item_trait, item_ty, lit, lit_};
use ast::{lit_bool, lit_float, lit_float_unsuffixed, lit_int};
@ -60,7 +60,7 @@ use ast::{view_item_, view_item_extern_mod, view_item_use};
use ast::{view_path, view_path_glob, view_path_list, view_path_simple};
use ast::visibility;
use ast;
use ast_util::{as_prec, ident_to_path, operator_prec};
use ast_util::{as_prec, operator_prec};
use ast_util;
use codemap::{span, BytePos, spanned, mk_sp};
use codemap;
@ -3556,13 +3556,14 @@ impl Parser {
}
fn parse_item_const(&self) -> item_info {
let m = if self.eat_keyword(keywords::Mut) {m_mutbl} else {m_imm};
let id = self.parse_ident();
self.expect(&token::COLON);
let ty = self.parse_ty(false);
self.expect(&token::EQ);
let e = self.parse_expr();
self.expect(&token::SEMI);
(id, item_const(ty, e), None)
(id, item_static(ty, m, e), None)
}
// parse a mod { ...} item
@ -3683,6 +3684,7 @@ impl Parser {
} else {
self.expect_keyword(keywords::Static);
}
let mutbl = self.eat_keyword(keywords::Mut);
let ident = self.parse_ident();
self.expect(&token::COLON);
@ -3691,7 +3693,7 @@ impl Parser {
self.expect(&token::SEMI);
@ast::foreign_item { ident: ident,
attrs: attrs,
node: foreign_item_const(ty),
node: foreign_item_static(ty, mutbl),
id: self.get_id(),
span: mk_sp(lo, hi),
vis: vis }

View file

@ -331,21 +331,18 @@ pub mod special_idents {
pub static str : ident = ident { name: 19, ctxt: 0}; // for the type
/* outside of libsyntax */
pub static ty_visitor : ident = ident { name: 20, ctxt: 0};
pub static arg : ident = ident { name: 21, ctxt: 0};
pub static descrim : ident = ident { name: 22, ctxt: 0};
pub static clownshoe_abi : ident = ident { name: 23, ctxt: 0};
pub static clownshoe_stack_shim : ident = ident { name: 24, ctxt: 0};
pub static tydesc : ident = ident { name: 25, ctxt: 0};
pub static main : ident = ident { name: 26, ctxt: 0};
pub static opaque : ident = ident { name: 27, ctxt: 0};
pub static blk : ident = ident { name: 28, ctxt: 0};
pub static statik : ident = ident { name: 29, ctxt: 0};
pub static intrinsic : ident = ident { name: 30, ctxt: 0};
pub static clownshoes_foreign_mod: ident = ident { name: 31, ctxt: 0};
pub static unnamed_field: ident = ident { name: 32, ctxt: 0};
pub static c_abi: ident = ident { name: 33, ctxt: 0};
pub static type_self: ident = ident { name: 34, ctxt: 0}; // `Self`
pub static arg : ident = ident { name: 20, ctxt: 0};
pub static descrim : ident = ident { name: 21, ctxt: 0};
pub static clownshoe_abi : ident = ident { name: 22, ctxt: 0};
pub static clownshoe_stack_shim : ident = ident { name: 23, ctxt: 0};
pub static main : ident = ident { name: 24, ctxt: 0};
pub static opaque : ident = ident { name: 25, ctxt: 0};
pub static blk : ident = ident { name: 26, ctxt: 0};
pub static statik : ident = ident { name: 27, ctxt: 0};
pub static clownshoes_foreign_mod: ident = ident { name: 28, ctxt: 0};
pub static unnamed_field: ident = ident { name: 29, ctxt: 0};
pub static c_abi: ident = ident { name: 30, ctxt: 0};
pub static type_self: ident = ident { name: 31, ctxt: 0}; // `Self`
}
/**
@ -426,59 +423,56 @@ fn mk_fresh_ident_interner() -> @ident_interner {
"tt", // 17
"matchers", // 18
"str", // 19
"TyVisitor", // 20
"arg", // 21
"descrim", // 22
"__rust_abi", // 23
"__rust_stack_shim", // 24
"TyDesc", // 25
"main", // 26
"<opaque>", // 27
"blk", // 28
"static", // 29
"intrinsic", // 30
"__foreign_mod__", // 31
"__field__", // 32
"C", // 33
"Self", // 34
"arg", // 20
"descrim", // 21
"__rust_abi", // 22
"__rust_stack_shim", // 23
"main", // 24
"<opaque>", // 25
"blk", // 26
"static", // 27
"__foreign_mod__", // 28
"__field__", // 29
"C", // 30
"Self", // 31
"as", // 35
"break", // 36
"const", // 37
"copy", // 38
"do", // 39
"else", // 40
"enum", // 41
"extern", // 42
"false", // 43
"fn", // 44
"for", // 45
"if", // 46
"impl", // 47
"let", // 48
"__log", // 49
"loop", // 50
"match", // 51
"mod", // 52
"mut", // 53
"once", // 54
"priv", // 55
"pub", // 56
"pure", // 57
"ref", // 58
"return", // 59
"static", // 29 -- also a special ident
"as", // 32
"break", // 33
"const", // 34
"copy", // 35
"do", // 36
"else", // 37
"enum", // 38
"extern", // 39
"false", // 40
"fn", // 41
"for", // 42
"if", // 43
"impl", // 44
"let", // 45
"__log", // 46
"loop", // 47
"match", // 48
"mod", // 49
"mut", // 50
"once", // 51
"priv", // 52
"pub", // 53
"pure", // 54
"ref", // 55
"return", // 56
"static", // 27 -- also a special ident
"self", // 8 -- also a special ident
"struct", // 60
"super", // 61
"true", // 62
"trait", // 63
"type", // 64
"unsafe", // 65
"use", // 66
"while", // 67
"struct", // 57
"super", // 58
"true", // 59
"trait", // 60
"type", // 61
"unsafe", // 62
"use", // 63
"while", // 64
"be", // 68
"be", // 65
];
@ident_interner {
@ -612,42 +606,42 @@ pub mod keywords {
impl Keyword {
pub fn to_ident(&self) -> ident {
match *self {
As => ident { name: 35, ctxt: 0 },
Break => ident { name: 36, ctxt: 0 },
Const => ident { name: 37, ctxt: 0 },
Copy => ident { name: 38, ctxt: 0 },
Do => ident { name: 39, ctxt: 0 },
Else => ident { name: 40, ctxt: 0 },
Enum => ident { name: 41, ctxt: 0 },
Extern => ident { name: 42, ctxt: 0 },
False => ident { name: 43, ctxt: 0 },
Fn => ident { name: 44, ctxt: 0 },
For => ident { name: 45, ctxt: 0 },
If => ident { name: 46, ctxt: 0 },
Impl => ident { name: 47, ctxt: 0 },
Let => ident { name: 48, ctxt: 0 },
__Log => ident { name: 49, ctxt: 0 },
Loop => ident { name: 50, ctxt: 0 },
Match => ident { name: 51, ctxt: 0 },
Mod => ident { name: 52, ctxt: 0 },
Mut => ident { name: 53, ctxt: 0 },
Once => ident { name: 54, ctxt: 0 },
Priv => ident { name: 55, ctxt: 0 },
Pub => ident { name: 56, ctxt: 0 },
Pure => ident { name: 57, ctxt: 0 },
Ref => ident { name: 58, ctxt: 0 },
Return => ident { name: 59, ctxt: 0 },
Static => ident { name: 29, ctxt: 0 },
As => ident { name: 32, ctxt: 0 },
Break => ident { name: 33, ctxt: 0 },
Const => ident { name: 34, ctxt: 0 },
Copy => ident { name: 35, ctxt: 0 },
Do => ident { name: 36, ctxt: 0 },
Else => ident { name: 37, ctxt: 0 },
Enum => ident { name: 38, ctxt: 0 },
Extern => ident { name: 39, ctxt: 0 },
False => ident { name: 40, ctxt: 0 },
Fn => ident { name: 41, ctxt: 0 },
For => ident { name: 42, ctxt: 0 },
If => ident { name: 43, ctxt: 0 },
Impl => ident { name: 44, ctxt: 0 },
Let => ident { name: 45, ctxt: 0 },
__Log => ident { name: 46, ctxt: 0 },
Loop => ident { name: 47, ctxt: 0 },
Match => ident { name: 48, ctxt: 0 },
Mod => ident { name: 49, ctxt: 0 },
Mut => ident { name: 50, ctxt: 0 },
Once => ident { name: 51, ctxt: 0 },
Priv => ident { name: 52, ctxt: 0 },
Pub => ident { name: 53, ctxt: 0 },
Pure => ident { name: 54, ctxt: 0 },
Ref => ident { name: 55, ctxt: 0 },
Return => ident { name: 56, ctxt: 0 },
Static => ident { name: 27, ctxt: 0 },
Self => ident { name: 8, ctxt: 0 },
Struct => ident { name: 60, ctxt: 0 },
Super => ident { name: 61, ctxt: 0 },
True => ident { name: 62, ctxt: 0 },
Trait => ident { name: 63, ctxt: 0 },
Type => ident { name: 64, ctxt: 0 },
Unsafe => ident { name: 65, ctxt: 0 },
Use => ident { name: 66, ctxt: 0 },
While => ident { name: 67, ctxt: 0 },
Be => ident { name: 68, ctxt: 0 },
Struct => ident { name: 57, ctxt: 0 },
Super => ident { name: 58, ctxt: 0 },
True => ident { name: 59, ctxt: 0 },
Trait => ident { name: 60, ctxt: 0 },
Type => ident { name: 61, ctxt: 0 },
Unsafe => ident { name: 62, ctxt: 0 },
Use => ident { name: 63, ctxt: 0 },
While => ident { name: 64, ctxt: 0 },
Be => ident { name: 65, ctxt: 0 },
}
}
}
@ -663,7 +657,7 @@ pub fn is_keyword(kw: keywords::Keyword, tok: &Token) -> bool {
pub fn is_any_keyword(tok: &Token) -> bool {
match *tok {
token::IDENT(sid, false) => match sid.name {
8 | 29 | 35 .. 68 => true,
8 | 27 | 32 .. 65 => true,
_ => false,
},
_ => false
@ -673,7 +667,7 @@ pub fn is_any_keyword(tok: &Token) -> bool {
pub fn is_strict_keyword(tok: &Token) -> bool {
match *tok {
token::IDENT(sid, false) => match sid.name {
8 | 29 | 35 .. 67 => true,
8 | 27 | 32 .. 64 => true,
_ => false,
},
_ => false,
@ -683,7 +677,7 @@ pub fn is_strict_keyword(tok: &Token) -> bool {
pub fn is_reserved_keyword(tok: &Token) -> bool {
match *tok {
token::IDENT(sid, false) => match sid.name {
68 => true,
65 => true,
_ => false,
},
_ => false,

View file

@ -458,8 +458,11 @@ pub fn print_foreign_item(s: @ps, item: @ast::foreign_item) {
word(s.s, ";");
end(s); // end the outer fn box
}
ast::foreign_item_const(t) => {
ast::foreign_item_static(t, m) => {
head(s, "static");
if m {
word_space(s, "mut");
}
print_ident(s, item.ident);
word_space(s, ":");
print_type(s, t);
@ -477,8 +480,11 @@ pub fn print_item(s: @ps, item: @ast::item) {
let ann_node = node_item(s, item);
(s.ann.pre)(ann_node);
match item.node {
ast::item_const(ty, expr) => {
ast::item_static(ty, m, expr) => {
head(s, visibility_qualified(item.vis, "static"));
if m == ast::m_mutbl {
word_space(s, "mut");
}
print_ident(s, item.ident);
word_space(s, ":");
print_type(s, ty);
@ -1737,7 +1743,7 @@ pub fn print_bounds(s: @ps, bounds: @OptVec<ast::TyParamBound>) {
if !bounds.is_empty() {
word(s.s, ":");
let mut first = true;
for bounds.each |bound| {
for bounds.iter().advance |bound| {
nbsp(s);
if first {
first = false;

View file

@ -148,7 +148,7 @@ fn visit_trait_ref<E: Copy>(tref: @ast::trait_ref, (e, v): (E, vt<E>)) {
pub fn visit_item<E: Copy>(i: @item, (e, v): (E, vt<E>)) {
match i.node {
item_const(t, ex) => {
item_static(t, _, ex) => {
(v.visit_ty)(t, (copy e, v));
(v.visit_expr)(ex, (copy e, v));
}
@ -326,7 +326,7 @@ pub fn visit_foreign_item<E: Copy>(ni: @foreign_item, (e, v): (E, vt<E>)) {
visit_fn_decl(fd, (copy e, v));
(v.visit_generics)(generics, (e, v));
}
foreign_item_const(t) => {
foreign_item_static(t, _) => {
(v.visit_ty)(t, (e, v));
}
}
@ -334,7 +334,7 @@ pub fn visit_foreign_item<E: Copy>(ni: @foreign_item, (e, v): (E, vt<E>)) {
pub fn visit_ty_param_bounds<E: Copy>(bounds: &OptVec<TyParamBound>,
(e, v): (E, vt<E>)) {
for bounds.each |bound| {
for bounds.iter().advance |bound| {
match *bound {
TraitTyParamBound(ty) => visit_trait_ref(ty, (copy e, v)),
RegionTyParamBound => {}
@ -343,7 +343,7 @@ pub fn visit_ty_param_bounds<E: Copy>(bounds: &OptVec<TyParamBound>,
}
pub fn visit_generics<E: Copy>(generics: &Generics, (e, v): (E, vt<E>)) {
for generics.ty_params.each |tp| {
for generics.ty_params.iter().advance |tp| {
visit_ty_param_bounds(tp.bounds, (copy e, v));
}
}

View file

@ -154,6 +154,16 @@ debug_abi_2(floats f) {
return ff;
}
extern "C" int
debug_static_mut;
int debug_static_mut = 3;
extern "C" void
debug_static_mut_check_four() {
assert(debug_static_mut == 4);
}
/* Debug builtins for std::dbg. */
static void
@ -729,15 +739,6 @@ rust_task_deref(rust_task *task) {
task->deref();
}
// Must call on rust stack.
extern "C" CDECL void
rust_call_tydesc_glue(void *root, size_t *tydesc, size_t glue_index) {
void (*glue_fn)(void *, void *, void *) =
(void (*)(void *, void *, void *))tydesc[glue_index];
if (glue_fn)
glue_fn(0, 0, root);
}
// Don't run on the Rust stack!
extern "C" void
rust_log_str(uint32_t level, const char *str, size_t size) {

View file

@ -183,7 +183,11 @@ void task_start_wrapper(spawn_args *a)
if(env) {
// free the environment (which should be a unique closure).
const type_desc *td = env->td;
td->drop_glue(NULL, NULL, box_body(env));
td->drop_glue(NULL,
#ifdef _RUST_STAGE0
NULL,
#endif
box_body(env));
task->kernel->region()->free(env);
}

Some files were not shown because too many files have changed in this diff Show more