diff --git a/mk/crates.mk b/mk/crates.mk index c95576f6252aa3feca7b16ef2c458ec7de17f04e..5bc4505fb05c742bf92f22bf21d65320820112d2 100644 --- a/mk/crates.mk +++ b/mk/crates.mk @@ -51,7 +51,7 @@ TARGET_CRATES := libc std green rustuv native flate arena glob term semver \ uuid serialize sync getopts collections num test time rand \ - url log regex graphviz core rlibc alloc debug rustrt \ + url log regex graphviz core rbml rlibc alloc debug rustrt \ unicode HOST_CRATES := syntax rustc rustdoc fourcc hexfloat regex_macros fmt_macros \ rustc_llvm rustc_back @@ -71,7 +71,7 @@ DEPS_green := std native:context_switch DEPS_rustuv := std native:uv native:uv_support DEPS_native := std DEPS_syntax := std term serialize log fmt_macros debug -DEPS_rustc := syntax flate arena serialize getopts \ +DEPS_rustc := syntax flate arena serialize getopts rbml \ time log graphviz debug rustc_llvm rustc_back DEPS_rustc_llvm := native:rustllvm libc std DEPS_rustc_back := std syntax rustc_llvm flate log libc @@ -82,6 +82,7 @@ DEPS_arena := std DEPS_graphviz := std DEPS_glob := std DEPS_serialize := std log +DEPS_rbml := std log serialize DEPS_term := std log DEPS_semver := std DEPS_uuid := std serialize @@ -91,7 +92,7 @@ DEPS_collections := core alloc unicode DEPS_fourcc := rustc syntax std DEPS_hexfloat := rustc syntax std DEPS_num := std -DEPS_test := std getopts serialize term time regex native:rust_test_helpers +DEPS_test := std getopts serialize rbml term time regex native:rust_test_helpers DEPS_time := std serialize DEPS_rand := core DEPS_url := std diff --git a/src/doc/complement-lang-faq.md b/src/doc/complement-lang-faq.md index ce037251e46b44940fa754d5c8f6185647cfff9d..c5ddd180ee8e13186d23b6de106d3cd5bb6bb78a 100644 --- a/src/doc/complement-lang-faq.md +++ b/src/doc/complement-lang-faq.md @@ -1,6 +1,5 @@ % Language FAQ - ## Are there any big programs written in it yet? I want to read big samples. There aren't many large programs yet. The Rust [compiler][rustc], 60,000+ lines at the time of writing, is written in Rust. As the oldest body of Rust code it has gone through many iterations of the language, and some parts are nicer to look at than others. It may not be the best code to learn from, but [borrowck] and [resolve] were written recently. @@ -29,6 +28,18 @@ You may also be interested in browsing [GitHub's Rust][github-rust] page. [github-rust]: https://github.com/trending?l=rust +## Is anyone using Rust in production? + +Currently, Rust is still pre-1.0, and so we don't recommend that you use Rust +in production unless you know exactly what you're getting into. + +That said, there are two production deployments of Rust that we're aware of: + +* [OpenDNS](http://labs.opendns.com/2013/10/04/zeromq-helping-us-block-malicious-domains/) +* [Skylight](http://skylight.io) + +Let the fact that this is an easily countable number be a warning. + ## Does it run on Windows? Yes. All development happens in lock-step on all 3 target platforms. Using MinGW, not Cygwin. Note that the windows implementation currently has some limitations: in particular 64-bit build is [not fully supported yet][win64], and all executables created by rustc [depend on libgcc DLL at runtime][libgcc]. diff --git a/src/doc/guide-lifetimes.md b/src/doc/guide-lifetimes.md index b7e8c8b0d486d5358b1a3ae89fc12f6af9b90be0..66faee3fa04c802e1ea199603477d95c71ae387e 100644 --- a/src/doc/guide-lifetimes.md +++ b/src/doc/guide-lifetimes.md @@ -431,36 +431,6 @@ In any case, whatever the lifetime of `r` is, the pointer produced by field of a struct is valid as long as the struct is valid. Therefore, the compiler accepts the function `get_x()`. -To emphasize this point, let’s look at a variation on the example, this -time one that does not compile: - -~~~ {.ignore} -struct Point {x: f64, y: f64} -fn get_x_sh(p: &Point) -> &f64 { - &p.x // Error reported here -} -~~~ - -Here, the function `get_x_sh()` takes a reference as input and -returns a reference. As before, the lifetime of the reference -that will be returned is a parameter (specified by the -caller). That means that `get_x_sh()` promises to return a reference -that is valid for as long as the caller would like: this is -subtly different from the first example, which promised to return a -pointer that was valid for as long as its pointer argument was valid. - -Within `get_x_sh()`, we see the expression `&p.x` which takes the -address of a field of a Point. The presence of this expression -implies that the compiler must guarantee that , so long as the -resulting pointer is valid, the original Point won't be moved or changed. - -But recall that `get_x_sh()` also promised to -return a pointer that was valid for as long as the caller wanted it to -be. Clearly, `get_x_sh()` is not in a position to make both of these -guarantees; in fact, it cannot guarantee that the pointer will remain -valid at all once it returns, as the parameter `p` may or may not be -live in the caller. Therefore, the compiler will report an error here. - In general, if you borrow a struct or box to create a reference, it will only be valid within the function and cannot be returned. This is why the typical way to return references diff --git a/src/doc/guide-pointers.md b/src/doc/guide-pointers.md index 5ec16e852a5f94917ae4e3cdea15e1643e3fec2d..8dca82cc087c874cf226716781a7323049431056 100644 --- a/src/doc/guide-pointers.md +++ b/src/doc/guide-pointers.md @@ -578,12 +578,12 @@ fn main() { Notice we changed the signature of `add_one()` to request a mutable reference. -# Best practices +## Best practices Boxes are appropriate to use in two situations: Recursive data structures, and occasionally, when returning data. -## Recursive data structures +### Recursive data structures Sometimes, you need a recursive data structure. The simplest is known as a 'cons list': @@ -615,7 +615,7 @@ we don't know the size, and therefore, we need to heap allocate our list. Working with recursive or other unknown-sized data structures is the primary use-case for boxes. -## Returning data +### Returning data This is important enough to have its own section entirely. The TL;DR is this: you don't generally want to return pointers, even when you might in a language @@ -733,18 +733,15 @@ This part is coming soon. Here's a quick rundown of Rust's pointer types: -| Type | Name | Summary | -|--------------|---------------------|-------------------------------------------| -| `&T` | Reference | Allows one or more references to read `T` | -| `&mut T` | Mutable Reference | Allows a single reference to | -| | | read and write `T` | -| `Box` | Box | Heap allocated `T` with a single owner | -| | | that may read and write `T`. | -| `Rc` | "arr cee" pointer | Heap allocated `T` with many readers | -| `Arc` | Arc pointer | Same as above, but safe sharing across | -| | | threads | -| `*const T` | Raw pointer | Unsafe read access to `T` | -| `*mut T` | Mutable raw pointer | Unsafe read and write access to `T` | +| Type | Name | Summary | +|--------------|---------------------|---------------------------------------------------------------------| +| `&T` | Reference | Allows one or more references to read `T` | +| `&mut T` | Mutable Reference | Allows a single reference to read and write `T` | +| `Box` | Box | Heap allocated `T` with a single owner that may read and write `T`. | +| `Rc` | "arr cee" pointer | Heap allocated `T` with many readers | +| `Arc` | Arc pointer | Same as above, but safe sharing across threads | +| `*const T` | Raw pointer | Unsafe read access to `T` | +| `*mut T` | Mutable raw pointer | Unsafe read and write access to `T` | # Related resources diff --git a/src/doc/tutorial.md b/src/doc/tutorial.md index b6485f711ee7a4f75ff647aa627fad6afa6d4391..b0ce038cf572204dd2c9d1c8f59e1969092544ab 100644 --- a/src/doc/tutorial.md +++ b/src/doc/tutorial.md @@ -1503,7 +1503,7 @@ reference. We also call this _borrowing_ the local variable `on_the_stack`, because we are creating an alias: that is, another route to the same data. -Likewise, in the case of `owned_box`, +Likewise, in the case of `on_the_heap`, the `&` operator is used in conjunction with the `*` operator to take a reference to the contents of the box. diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index b31931c6de3bc86be1eee077244516157a82769e..35914aa354159ea07caf43f2cf981f81a7f2abe7 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -226,7 +226,7 @@ impl Rc { /// data is cloned if the reference count is greater than one. #[inline] #[experimental] - pub fn make_unique<'a>(&'a mut self) -> &'a mut T { + pub fn make_unique(&mut self) -> &mut T { // Note that we hold a strong reference, which also counts as // a weak reference, so we only clone if there is an // additional reference of either kind. @@ -247,7 +247,7 @@ pub fn make_unique<'a>(&'a mut self) -> &'a mut T { impl Deref for Rc { /// Borrow the value contained in the reference-counted box #[inline(always)] - fn deref<'a>(&'a self) -> &'a T { + fn deref(&self) -> &T { &self.inner().value } } @@ -390,7 +390,7 @@ fn clone(&self) -> Weak { #[doc(hidden)] trait RcBoxPtr { - fn inner<'a>(&'a self) -> &'a RcBox; + fn inner(&self) -> &RcBox; #[inline] fn strong(&self) -> uint { self.inner().strong.get() } @@ -413,12 +413,12 @@ fn weak(&self) -> uint { self.inner().weak.get() } impl RcBoxPtr for Rc { #[inline(always)] - fn inner<'a>(&'a self) -> &'a RcBox { unsafe { &(*self._ptr) } } + fn inner(&self) -> &RcBox { unsafe { &(*self._ptr) } } } impl RcBoxPtr for Weak { #[inline(always)] - fn inner<'a>(&'a self) -> &'a RcBox { unsafe { &(*self._ptr) } } + fn inner(&self) -> &RcBox { unsafe { &(*self._ptr) } } } #[cfg(test)] diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index e672c555b804df163b6d259d4a29ce09590c0f2d..5d316cdb51e37ab2f25ac883d64de1290e924d5b 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -207,7 +207,7 @@ fn alloc_copy_inner(&self, n_bytes: uint, align: uint) -> *const u8 { } #[inline] - fn alloc_copy<'a, T>(&'a self, op: || -> T) -> &'a T { + fn alloc_copy(&self, op: || -> T) -> &T { unsafe { let ptr = self.alloc_copy_inner(mem::size_of::(), mem::min_align_of::()); @@ -261,7 +261,7 @@ fn alloc_noncopy_inner(&self, n_bytes: uint, } #[inline] - fn alloc_noncopy<'a, T>(&'a self, op: || -> T) -> &'a T { + fn alloc_noncopy(&self, op: || -> T) -> &T { unsafe { let tydesc = get_tydesc::(); let (ty_ptr, ptr) = @@ -285,7 +285,7 @@ fn alloc_noncopy<'a, T>(&'a self, op: || -> T) -> &'a T { /// Allocate a new item in the arena, using `op` to initialize the value /// and returning a reference to it. #[inline] - pub fn alloc<'a, T>(&'a self, op: || -> T) -> &'a T { + pub fn alloc(&self, op: || -> T) -> &T { unsafe { if intrinsics::needs_drop::() { self.alloc_noncopy(op) @@ -458,13 +458,13 @@ pub fn with_capacity(capacity: uint) -> TypedArena { /// Allocates an object in the TypedArena, returning a reference to it. #[inline] - pub fn alloc<'a>(&'a self, object: T) -> &'a T { + pub fn alloc(&self, object: T) -> &T { if self.ptr == self.end { self.grow() } - let ptr: &'a T = unsafe { - let ptr: &'a mut T = mem::transmute(self.ptr); + let ptr: &T = unsafe { + let ptr: &mut T = mem::transmute(self.ptr); ptr::write(ptr, object); self.ptr.set(self.ptr.get().offset(1)); ptr diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 8db59bd370e76bcfd292139bca09518ac09a7336..3f739b86a1b0975a2ee03a1cd6ce1feae00da50f 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -149,7 +149,7 @@ fn partial_cmp(&self, other: &Ordering) -> Option { /// If the first ordering is different, the first ordering is all that must be returned. /// If the first ordering is equal, then second ordering is returned. #[inline] -#[deprecated = "Just call .cmp() on an Ordering"] +#[deprecated = "Just call .cmp() on a tuple"] pub fn lexical_ordering(o1: Ordering, o2: Ordering) -> Ordering { match o1 { Equal => o2, diff --git a/src/libcore/failure.rs b/src/libcore/failure.rs index 5965603770ba7ca671152abb34b476666a5a160b..f5cfa2611d5e66ef260a07d4be8a7aca05714bc4 100644 --- a/src/libcore/failure.rs +++ b/src/libcore/failure.rs @@ -16,7 +16,7 @@ //! interface for failure is: //! //! ```ignore -//! fn begin_unwind(fmt: &fmt::Arguments, file: &str, line: uint) -> !; +//! fn begin_unwind(fmt: &fmt::Arguments, &(&'static str, uint)) -> !; //! ``` //! //! This definition allows for failing with any general message, but it does not @@ -33,6 +33,7 @@ use fmt; use intrinsics; +#[cfg(stage0)] #[cold] #[inline(never)] // this is the slow path, always #[lang="fail_"] fn fail_(expr: &'static str, file: &'static str, line: uint) -> ! { @@ -43,6 +44,7 @@ fn fail_(expr: &'static str, file: &'static str, line: uint) -> ! { unsafe { intrinsics::abort() } } +#[cfg(stage0)] #[cold] #[lang="fail_bounds_check"] fn fail_bounds_check(file: &'static str, line: uint, @@ -53,7 +55,31 @@ fn fail_bounds_check(file: &'static str, line: uint, unsafe { intrinsics::abort() } } -#[cold] +#[cfg(not(stage0))] +#[cold] #[inline(never)] // this is the slow path, always +#[lang="fail_"] +fn fail_(expr_file_line: &(&'static str, &'static str, uint)) -> ! { + let (expr, file, line) = *expr_file_line; + let ref file_line = (file, line); + format_args!(|args| -> () { + begin_unwind(args, file_line); + }, "{}", expr); + + unsafe { intrinsics::abort() } +} + +#[cfg(not(stage0))] +#[cold] #[inline(never)] +#[lang="fail_bounds_check"] +fn fail_bounds_check(file_line: &(&'static str, uint), + index: uint, len: uint) -> ! { + format_args!(|args| -> () { + begin_unwind(args, file_line); + }, "index out of bounds: the len is {} but the index is {}", len, index); + unsafe { intrinsics::abort() } +} + +#[cold] #[inline(never)] pub fn begin_unwind(fmt: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! { #[allow(ctypes)] extern { diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 84b402a68dd120100226eb29358c5268de1bfcbc..f8293aeb03d1910651677ceb44175a797730e9ab 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -143,6 +143,7 @@ use cmp::{PartialEq, Eq, Ord}; use default::Default; +use slice::Vector; use iter::{Iterator, DoubleEndedIterator, FromIterator, ExactSize}; use mem; use slice; @@ -216,15 +217,6 @@ pub fn as_mut<'r>(&'r mut self) -> Option<&'r mut T> { match *self { Some(ref mut x) => Some(x), None => None } } - /// Convert from `Option` to `&[T]` (without copying) - #[inline] - pub fn as_slice<'r>(&'r self) -> &'r [T] { - match *self { - Some(ref x) => slice::ref_slice(x), - None => &[] - } - } - /// Convert from `Option` to `&mut [T]` (without copying) #[inline] pub fn as_mut_slice<'r>(&'r mut self) -> &'r mut [T] { @@ -526,6 +518,17 @@ pub fn unwrap_or_default(self) -> T { // Trait implementations ///////////////////////////////////////////////////////////////////////////// +impl Vector for Option { + /// Convert from `Option` to `&[T]` (without copying) + #[inline] + fn as_slice<'a>(&'a self) -> &'a [T] { + match *self { + Some(ref x) => slice::ref_slice(x), + None => &[] + } + } +} + impl Default for Option { #[inline] fn default() -> Option { None } diff --git a/src/libfourcc/lib.rs b/src/libfourcc/lib.rs index aa8d84bec1711010c25973642ad12c24a5ff8708..4596c98cffdedb0f475bec7d022a7c32de5fd898 100644 --- a/src/libfourcc/lib.rs +++ b/src/libfourcc/lib.rs @@ -40,7 +40,8 @@ fn main() { */ #![crate_name = "fourcc"] -#![experimental] +#![deprecated = "This is now a cargo package located at: \ + https://github.com/rust-lang/fourcc"] #![crate_type = "rlib"] #![crate_type = "dylib"] #![license = "MIT/ASL2"] diff --git a/src/libhexfloat/lib.rs b/src/libhexfloat/lib.rs index 2859e1c985f5e5beb96666faeb8d916150e054ba..9adeeb2e4c9241997a3da22806604f26e9b225c5 100644 --- a/src/libhexfloat/lib.rs +++ b/src/libhexfloat/lib.rs @@ -37,7 +37,8 @@ fn main() { */ #![crate_name = "hexfloat"] -#![experimental] +#![deprecated = "This is now a cargo package located at: \ + https://github.com/rust-lang/hexfloat"] #![crate_type = "rlib"] #![crate_type = "dylib"] #![license = "MIT/ASL2"] diff --git a/src/librustc/util/io.rs b/src/librbml/io.rs similarity index 99% rename from src/librustc/util/io.rs rename to src/librbml/io.rs index f153aca7fac7bf8754990ae2a60fc62840802ca9..9ab163c5f474055fdb80ecc54ff25205111e0c88 100644 --- a/src/librustc/util/io.rs +++ b/src/librbml/io.rs @@ -39,7 +39,7 @@ fn combine(seek: SeekStyle, cur: uint, end: uint, offset: i64) -> IoResult /// /// ```rust /// # #![allow(unused_must_use)] -/// use std::io::SeekableMemWriter; +/// use rbml::io::SeekableMemWriter; /// /// let mut w = SeekableMemWriter::new(); /// w.write([0, 1, 2]); @@ -128,6 +128,7 @@ fn seek(&mut self, pos: i64, style: SeekStyle) -> IoResult<()> { #[cfg(test)] mod tests { + extern crate test; use super::SeekableMemWriter; use std::io; use test::Bencher; diff --git a/src/libserialize/ebml.rs b/src/librbml/lib.rs similarity index 89% rename from src/libserialize/ebml.rs rename to src/librbml/lib.rs index c3434466836175f85242aabbbbff81c343fc3469..f77d36d1e0648fa6e7dde3d3cdb586e023ba4d1e 100644 --- a/src/libserialize/ebml.rs +++ b/src/librbml/lib.rs @@ -8,16 +8,35 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +//! Really Bad Markup Language (rbml) is a temporary measure until we migrate +//! the rust object metadata to a better serialization format. It is not +//! intended to be used by users. +//! +//! It is loosely based on the Extensible Binary Markup Language (ebml): +//! http://www.matroska.org/technical/specs/rfc/index.html + +#![crate_name = "rbml"] +#![experimental] +#![crate_type = "rlib"] +#![crate_type = "dylib"] +#![license = "MIT/ASL2"] +#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", + html_favicon_url = "http://www.rust-lang.org/favicon.ico", + html_root_url = "http://doc.rust-lang.org/master/", + html_playground_url = "http://play.rust-lang.org/")] +#![feature(macro_rules, phase)] #![allow(missing_doc)] -use std::io; +extern crate serialize; + +#[phase(plugin, link)] extern crate log; +#[cfg(test)] extern crate test; + use std::str; -// Simple Extensible Binary Markup Language (ebml) reader and writer on a -// cursor model. See the specification here: -// http://www.matroska.org/technical/specs/rfc/index.html +pub mod io; -// Common data structures +/// Common data structures #[deriving(Clone)] pub struct Doc<'a> { pub data: &'a [u8], @@ -86,7 +105,7 @@ pub enum EbmlEncoderTag { pub enum Error { IntTooBig(uint), Expected(String), - IoError(io::IoError) + IoError(std::io::IoError) } // -------------------------------------- @@ -107,7 +126,7 @@ pub mod reader { Expected }; pub type DecodeResult = Result; - // ebml reading + // rbml reading macro_rules! try_or( ($e:expr, $r:expr) => ( @@ -637,7 +656,7 @@ pub mod writer { pub type EncodeResult = io::IoResult<()>; - // ebml writing + // rbml writing pub struct Encoder<'a, W> { pub writer: &'a mut W, size_positions: Vec, @@ -671,7 +690,7 @@ fn write_vuint(w: &mut W, n: uint) -> EncodeResult { }) } - // FIXME (#2741): Provide a function to write the standard ebml header. + // FIXME (#2741): Provide a function to write the standard rbml header. impl<'a, W: Writer + Seek> Encoder<'a, W> { pub fn new(w: &'a mut W) -> Encoder<'a, W> { Encoder { @@ -1018,130 +1037,16 @@ fn emit_map_elt_val(&mut self, #[cfg(test)] mod tests { - use super::Doc; - use ebml::reader; - use ebml::writer; - use {Encodable, Decodable}; + use super::{Doc, reader, writer}; + use super::io::SeekableMemWriter; + + use serialize::{Encodable, Decodable}; use std::io::{IoError, IoResult, SeekStyle}; use std::io; use std::option::{None, Option, Some}; use std::slice; - static BUF_CAPACITY: uint = 128; - - fn combine(seek: SeekStyle, cur: uint, end: uint, offset: i64) -> IoResult { - // compute offset as signed and clamp to prevent overflow - let pos = match seek { - io::SeekSet => 0, - io::SeekEnd => end, - io::SeekCur => cur, - } as i64; - - if offset + pos < 0 { - Err(IoError { - kind: io::InvalidInput, - desc: "invalid seek to a negative offset", - detail: None - }) - } else { - Ok((offset + pos) as u64) - } - } - - /// Writes to an owned, growable byte vector that supports seeking. - /// - /// # Example - /// - /// ```rust - /// # #![allow(unused_must_use)] - /// use std::io::SeekableMemWriter; - /// - /// let mut w = SeekableMemWriter::new(); - /// w.write([0, 1, 2]); - /// - /// assert_eq!(w.unwrap(), vec!(0, 1, 2)); - /// ``` - pub struct SeekableMemWriter { - buf: Vec, - pos: uint, - } - - impl SeekableMemWriter { - /// Create a new `SeekableMemWriter`. - #[inline] - pub fn new() -> SeekableMemWriter { - SeekableMemWriter::with_capacity(BUF_CAPACITY) - } - /// Create a new `SeekableMemWriter`, allocating at least `n` bytes for - /// the internal buffer. - #[inline] - pub fn with_capacity(n: uint) -> SeekableMemWriter { - SeekableMemWriter { buf: Vec::with_capacity(n), pos: 0 } - } - - /// Acquires an immutable reference to the underlying buffer of this - /// `SeekableMemWriter`. - /// - /// No method is exposed for acquiring a mutable reference to the buffer - /// because it could corrupt the state of this `MemWriter`. - #[inline] - pub fn get_ref<'a>(&'a self) -> &'a [u8] { self.buf.as_slice() } - - /// Unwraps this `SeekableMemWriter`, returning the underlying buffer - #[inline] - pub fn unwrap(self) -> Vec { self.buf } - } - - impl Writer for SeekableMemWriter { - #[inline] - fn write(&mut self, buf: &[u8]) -> IoResult<()> { - if self.pos == self.buf.len() { - self.buf.push_all(buf) - } else { - // Make sure the internal buffer is as least as big as where we - // currently are - let difference = self.pos as i64 - self.buf.len() as i64; - if difference > 0 { - self.buf.grow(difference as uint, &0); - } - - // Figure out what bytes will be used to overwrite what's currently - // there (left), and what will be appended on the end (right) - let cap = self.buf.len() - self.pos; - let (left, right) = if cap <= buf.len() { - (buf.slice_to(cap), buf.slice_from(cap)) - } else { - (buf, &[]) - }; - - // Do the necessary writes - if left.len() > 0 { - slice::bytes::copy_memory(self.buf.mut_slice_from(self.pos), left); - } - if right.len() > 0 { - self.buf.push_all(right); - } - } - - // Bump us forward - self.pos += buf.len(); - Ok(()) - } - } - - impl Seek for SeekableMemWriter { - #[inline] - fn tell(&self) -> IoResult { Ok(self.pos as u64) } - - #[inline] - fn seek(&mut self, pos: i64, style: SeekStyle) -> IoResult<()> { - let new = try!(combine(style, self.pos, self.buf.len(), pos)); - self.pos = new as uint; - Ok(()) - } - } - #[test] fn test_vuint_at() { let data = [ @@ -1196,11 +1101,11 @@ fn test_v(v: Option) { debug!("v == {}", v); let mut wr = SeekableMemWriter::new(); { - let mut ebml_w = writer::Encoder::new(&mut wr); - let _ = v.encode(&mut ebml_w); + let mut rbml_w = writer::Encoder::new(&mut wr); + let _ = v.encode(&mut rbml_w); } - let ebml_doc = Doc::new(wr.get_ref()); - let mut deser = reader::Decoder::new(ebml_doc); + let rbml_doc = Doc::new(wr.get_ref()); + let mut deser = reader::Decoder::new(rbml_doc); let v1 = Decodable::decode(&mut deser).unwrap(); debug!("v1 == {}", v1); assert_eq!(v, v1); @@ -1215,9 +1120,8 @@ fn test_v(v: Option) { #[cfg(test)] mod bench { #![allow(non_snake_case_functions)] - extern crate test; - use self::test::Bencher; - use ebml::reader; + use test::Bencher; + use super::reader; #[bench] pub fn vuint_at_A_aligned(b: &mut Bencher) { diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 82040f141593e7575a1ed9224a5f5757e8835903..f9774e83e8a1c19c905db648c59db95d49374333 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -44,6 +44,7 @@ extern crate llvm = "rustc_llvm"; extern crate rustc_back = "rustc_back"; extern crate serialize; +extern crate rbml; extern crate time; #[phase(plugin, link)] extern crate log; #[phase(plugin, link)] extern crate syntax; @@ -132,7 +133,6 @@ pub mod util { pub mod common; pub mod ppaux; - pub mod io; pub mod nodemap; } diff --git a/src/librustc/metadata/csearch.rs b/src/librustc/metadata/csearch.rs index b1b366ec03090de4526f3ab2626956c4056b8a53..252d19bbb237b838cab6db360de0bcc8b1e3c018 100644 --- a/src/librustc/metadata/csearch.rs +++ b/src/librustc/metadata/csearch.rs @@ -20,8 +20,8 @@ use middle::typeck; use middle::subst::VecPerParamSpace; -use serialize::ebml; -use serialize::ebml::reader; +use rbml; +use rbml::reader; use std::rc::Rc; use syntax::ast; use syntax::ast_map; @@ -218,7 +218,7 @@ pub fn get_field_type(tcx: &ty::ctxt, class_id: ast::DefId, def: ast::DefId) -> ty::Polytype { let cstore = &tcx.sess.cstore; let cdata = cstore.get_crate_data(class_id.krate); - let all_items = reader::get_doc(ebml::Doc::new(cdata.data()), tag_items); + let all_items = reader::get_doc(rbml::Doc::new(cdata.data()), tag_items); let class_doc = expect(tcx.sess.diagnostic(), decoder::maybe_find_item(class_id.node, all_items), || { diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index f7576ffb4818bb4af32eb603fd101428f58f92a5..c9807a18383e8ef5bc932222cfb55f306e44b121 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -37,8 +37,8 @@ use std::collections::hashmap::HashMap; use std::rc::Rc; use std::u64; -use serialize::ebml::reader; -use serialize::ebml; +use rbml::reader; +use rbml; use serialize::Decodable; use syntax::ast_map; use syntax::attr; @@ -56,8 +56,8 @@ // what crate that's in and give us a def_id that makes sense for the current // build. -fn lookup_hash<'a>(d: ebml::Doc<'a>, eq_fn: |&[u8]| -> bool, - hash: u64) -> Option> { +fn lookup_hash<'a>(d: rbml::Doc<'a>, eq_fn: |&[u8]| -> bool, + hash: u64) -> Option> { let index = reader::get_doc(d, tag_index); let table = reader::get_doc(index, tag_index_table); let hash_pos = table.start + (hash % 256 * 4) as uint; @@ -80,7 +80,7 @@ fn lookup_hash<'a>(d: ebml::Doc<'a>, eq_fn: |&[u8]| -> bool, } pub fn maybe_find_item<'a>(item_id: ast::NodeId, - items: ebml::Doc<'a>) -> Option> { + items: rbml::Doc<'a>) -> Option> { fn eq_item(bytes: &[u8], item_id: ast::NodeId) -> bool { return u64_from_be_bytes( bytes.slice(0u, 4u), 0u, 4u) as ast::NodeId @@ -91,17 +91,17 @@ fn eq_item(bytes: &[u8], item_id: ast::NodeId) -> bool { hash::hash(&(item_id as i64))) } -fn find_item<'a>(item_id: ast::NodeId, items: ebml::Doc<'a>) -> ebml::Doc<'a> { +fn find_item<'a>(item_id: ast::NodeId, items: rbml::Doc<'a>) -> rbml::Doc<'a> { match maybe_find_item(item_id, items) { None => fail!("lookup_item: id not found: {}", item_id), Some(d) => d } } -// Looks up an item in the given metadata and returns an ebml doc pointing +// Looks up an item in the given metadata and returns an rbml doc pointing // to the item data. -fn lookup_item<'a>(item_id: ast::NodeId, data: &'a [u8]) -> ebml::Doc<'a> { - let items = reader::get_doc(ebml::Doc::new(data), tag_items); +fn lookup_item<'a>(item_id: ast::NodeId, data: &'a [u8]) -> rbml::Doc<'a> { + let items = reader::get_doc(rbml::Doc::new(data), tag_items); find_item(item_id, items) } @@ -127,7 +127,7 @@ enum Family { InheritedField // N } -fn item_family(item: ebml::Doc) -> Family { +fn item_family(item: rbml::Doc) -> Family { let fam = reader::get_doc(item, tag_items_data_item_family); match reader::doc_as_u8(fam) as char { 'c' => ImmStatic, @@ -152,7 +152,7 @@ fn item_family(item: ebml::Doc) -> Family { } } -fn item_visibility(item: ebml::Doc) -> ast::Visibility { +fn item_visibility(item: rbml::Doc) -> ast::Visibility { match reader::maybe_get_doc(item, tag_items_data_item_visibility) { None => ast::Public, Some(visibility_doc) => { @@ -165,7 +165,7 @@ fn item_visibility(item: ebml::Doc) -> ast::Visibility { } } -fn item_method_sort(item: ebml::Doc) -> char { +fn item_method_sort(item: rbml::Doc) -> char { let mut ret = 'r'; reader::tagged_docs(item, tag_item_trait_method_sort, |doc| { ret = doc.as_str_slice().as_bytes()[0] as char; @@ -174,11 +174,11 @@ fn item_method_sort(item: ebml::Doc) -> char { ret } -fn item_symbol(item: ebml::Doc) -> String { +fn item_symbol(item: rbml::Doc) -> String { reader::get_doc(item, tag_items_data_item_symbol).as_str().to_string() } -fn item_parent_item(d: ebml::Doc) -> Option { +fn item_parent_item(d: rbml::Doc) -> Option { let mut ret = None; reader::tagged_docs(d, tag_items_data_parent_item, |did| { ret = Some(reader::with_doc_data(did, parse_def_id)); @@ -188,60 +188,60 @@ fn item_parent_item(d: ebml::Doc) -> Option { } fn item_reqd_and_translated_parent_item(cnum: ast::CrateNum, - d: ebml::Doc) -> ast::DefId { + d: rbml::Doc) -> ast::DefId { let trait_did = item_parent_item(d).expect("item without parent"); ast::DefId { krate: cnum, node: trait_did.node } } -fn item_def_id(d: ebml::Doc, cdata: Cmd) -> ast::DefId { +fn item_def_id(d: rbml::Doc, cdata: Cmd) -> ast::DefId { let tagdoc = reader::get_doc(d, tag_def_id); return translate_def_id(cdata, reader::with_doc_data(tagdoc, parse_def_id)); } -fn get_provided_source(d: ebml::Doc, cdata: Cmd) -> Option { +fn get_provided_source(d: rbml::Doc, cdata: Cmd) -> Option { reader::maybe_get_doc(d, tag_item_method_provided_source).map(|doc| { translate_def_id(cdata, reader::with_doc_data(doc, parse_def_id)) }) } -fn each_reexport(d: ebml::Doc, f: |ebml::Doc| -> bool) -> bool { +fn each_reexport(d: rbml::Doc, f: |rbml::Doc| -> bool) -> bool { reader::tagged_docs(d, tag_items_data_item_reexport, f) } -fn variant_disr_val(d: ebml::Doc) -> Option { +fn variant_disr_val(d: rbml::Doc) -> Option { reader::maybe_get_doc(d, tag_disr_val).and_then(|val_doc| { reader::with_doc_data(val_doc, |data| u64::parse_bytes(data, 10u)) }) } -fn doc_type(doc: ebml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::t { +fn doc_type(doc: rbml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::t { let tp = reader::get_doc(doc, tag_items_data_item_type); parse_ty_data(tp.data, cdata.cnum, tp.start, tcx, |_, did| translate_def_id(cdata, did)) } -fn doc_method_fty(doc: ebml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::BareFnTy { +fn doc_method_fty(doc: rbml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::BareFnTy { let tp = reader::get_doc(doc, tag_item_method_fty); parse_bare_fn_ty_data(tp.data, cdata.cnum, tp.start, tcx, |_, did| translate_def_id(cdata, did)) } -pub fn item_type(_item_id: ast::DefId, item: ebml::Doc, +pub fn item_type(_item_id: ast::DefId, item: rbml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::t { doc_type(item, tcx, cdata) } -fn doc_trait_ref(doc: ebml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::TraitRef { +fn doc_trait_ref(doc: rbml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::TraitRef { parse_trait_ref_data(doc.data, cdata.cnum, doc.start, tcx, |_, did| translate_def_id(cdata, did)) } -fn item_trait_ref(doc: ebml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::TraitRef { +fn item_trait_ref(doc: rbml::Doc, tcx: &ty::ctxt, cdata: Cmd) -> ty::TraitRef { let tp = reader::get_doc(doc, tag_item_trait_ref); doc_trait_ref(tp, tcx, cdata) } -fn item_ty_param_defs(item: ebml::Doc, +fn item_ty_param_defs(item: rbml::Doc, tcx: &ty::ctxt, cdata: Cmd, tag: uint) @@ -257,7 +257,7 @@ fn item_ty_param_defs(item: ebml::Doc, bounds } -fn item_region_param_defs(item_doc: ebml::Doc, cdata: Cmd) +fn item_region_param_defs(item_doc: rbml::Doc, cdata: Cmd) -> subst::VecPerParamSpace { let mut v = subst::VecPerParamSpace::empty(); @@ -285,7 +285,7 @@ fn item_region_param_defs(item_doc: ebml::Doc, cdata: Cmd) v } -fn enum_variant_ids(item: ebml::Doc, cdata: Cmd) -> Vec { +fn enum_variant_ids(item: rbml::Doc, cdata: Cmd) -> Vec { let mut ids: Vec = Vec::new(); let v = tag_items_data_item_variant; reader::tagged_docs(item, v, |p| { @@ -296,7 +296,7 @@ fn enum_variant_ids(item: ebml::Doc, cdata: Cmd) -> Vec { return ids; } -fn item_path(item_doc: ebml::Doc) -> Vec { +fn item_path(item_doc: rbml::Doc) -> Vec { let path_doc = reader::get_doc(item_doc, tag_path); let len_doc = reader::get_doc(path_doc, tag_path_len); @@ -319,7 +319,7 @@ fn item_path(item_doc: ebml::Doc) -> Vec { result } -fn item_name(intr: &IdentInterner, item: ebml::Doc) -> ast::Ident { +fn item_name(intr: &IdentInterner, item: rbml::Doc) -> ast::Ident { let name = reader::get_doc(item, tag_paths_data_name); let string = name.as_str_slice(); match intr.find_equiv(&string) { @@ -328,7 +328,7 @@ fn item_name(intr: &IdentInterner, item: ebml::Doc) -> ast::Ident { } } -fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum) +fn item_to_def_like(item: rbml::Doc, did: ast::DefId, cnum: ast::CrateNum) -> DefLike { let fam = item_family(item); match fam { @@ -463,7 +463,7 @@ pub enum DefLike { /// Iterates over the language items in the given crate. pub fn each_lang_item(cdata: Cmd, f: |ast::NodeId, uint| -> bool) -> bool { - let root = ebml::Doc::new(cdata.data()); + let root = rbml::Doc::new(cdata.data()); let lang_items = reader::get_doc(root, tag_lang_items); reader::tagged_docs(lang_items, tag_lang_items_item, |item_doc| { let id_doc = reader::get_doc(item_doc, tag_lang_items_item_id); @@ -480,7 +480,7 @@ pub fn each_lang_item(cdata: Cmd, f: |ast::NodeId, uint| -> bool) -> bool { fn each_child_of_item_or_crate(intr: Rc, cdata: Cmd, - item_doc: ebml::Doc, + item_doc: rbml::Doc, get_crate_data: GetCrateDataCb, callback: |DefLike, ast::Ident, @@ -503,7 +503,7 @@ fn each_child_of_item_or_crate(intr: Rc, None => cdata }; - let other_crates_items = reader::get_doc(ebml::Doc::new(crate_data.data()), tag_items); + let other_crates_items = reader::get_doc(rbml::Doc::new(crate_data.data()), tag_items); // Get the item. match maybe_find_item(child_def_id.node, other_crates_items) { @@ -531,7 +531,7 @@ fn each_child_of_item_or_crate(intr: Rc, |inherent_impl_def_id_doc| { let inherent_impl_def_id = item_def_id(inherent_impl_def_id_doc, cdata); - let items = reader::get_doc(ebml::Doc::new(cdata.data()), tag_items); + let items = reader::get_doc(rbml::Doc::new(cdata.data()), tag_items); match maybe_find_item(inherent_impl_def_id.node, items) { None => {} Some(inherent_impl_doc) => { @@ -596,7 +596,7 @@ fn each_child_of_item_or_crate(intr: Rc, None => cdata }; - let other_crates_items = reader::get_doc(ebml::Doc::new(crate_data.data()), tag_items); + let other_crates_items = reader::get_doc(rbml::Doc::new(crate_data.data()), tag_items); // Get the item. match maybe_find_item(child_def_id.node, other_crates_items) { @@ -623,7 +623,7 @@ pub fn each_child_of_item(intr: Rc, get_crate_data: GetCrateDataCb, callback: |DefLike, ast::Ident, ast::Visibility|) { // Find the item. - let root_doc = ebml::Doc::new(cdata.data()); + let root_doc = rbml::Doc::new(cdata.data()); let items = reader::get_doc(root_doc, tag_items); let item_doc = match maybe_find_item(id, items) { None => return, @@ -644,7 +644,7 @@ pub fn each_top_level_item_of_crate(intr: Rc, callback: |DefLike, ast::Ident, ast::Visibility|) { - let root_doc = ebml::Doc::new(cdata.data()); + let root_doc = rbml::Doc::new(cdata.data()); let misc_info_doc = reader::get_doc(root_doc, tag_misc_info); let crate_items_doc = reader::get_doc(misc_info_doc, tag_misc_info_crate_items); @@ -663,7 +663,7 @@ pub fn get_item_path(cdata: Cmd, id: ast::NodeId) -> Vec { pub type DecodeInlinedItem<'a> = |cdata: Cmd, tcx: &ty::ctxt, path: Vec, - par_doc: ebml::Doc|: 'a + par_doc: rbml::Doc|: 'a -> Result >; pub fn maybe_get_item_ast(cdata: Cmd, tcx: &ty::ctxt, id: ast::NodeId, @@ -693,7 +693,7 @@ pub fn maybe_get_item_ast(cdata: Cmd, tcx: &ty::ctxt, id: ast::NodeId, pub fn get_enum_variants(intr: Rc, cdata: Cmd, id: ast::NodeId, tcx: &ty::ctxt) -> Vec> { let data = cdata.data(); - let items = reader::get_doc(ebml::Doc::new(data), tag_items); + let items = reader::get_doc(rbml::Doc::new(data), tag_items); let item = find_item(id, items); let mut disr_val = 0; enum_variant_ids(item, cdata).iter().map(|did| { @@ -725,7 +725,7 @@ pub fn get_enum_variants(intr: Rc, cdata: Cmd, id: ast::NodeId, }).collect() } -fn get_explicit_self(item: ebml::Doc) -> ty::ExplicitSelfCategory { +fn get_explicit_self(item: rbml::Doc) -> ty::ExplicitSelfCategory { fn get_mutability(ch: u8) -> ast::Mutability { match ch as char { 'i' => ast::MutImmutable, @@ -965,7 +965,7 @@ pub fn get_item_attrs(cdata: Cmd, } pub fn get_struct_field_attrs(cdata: Cmd) -> HashMap> { - let data = ebml::Doc::new(cdata.data()); + let data = rbml::Doc::new(cdata.data()); let fields = reader::get_doc(data, tag_struct_fields); let mut map = HashMap::new(); reader::tagged_docs(fields, tag_struct_field, |field| { @@ -1023,7 +1023,7 @@ pub fn get_struct_fields(intr: Rc, cdata: Cmd, id: ast::NodeId) result } -fn get_meta_items(md: ebml::Doc) -> Vec> { +fn get_meta_items(md: rbml::Doc) -> Vec> { let mut items: Vec> = Vec::new(); reader::tagged_docs(md, tag_meta_item_word, |meta_item_doc| { let nd = reader::get_doc(meta_item_doc, tag_meta_item_name); @@ -1051,7 +1051,7 @@ fn get_meta_items(md: ebml::Doc) -> Vec> { return items; } -fn get_attributes(md: ebml::Doc) -> Vec { +fn get_attributes(md: rbml::Doc) -> Vec { let mut attrs: Vec = Vec::new(); match reader::maybe_get_doc(md, tag_attributes) { Some(attrs_d) => { @@ -1082,7 +1082,7 @@ fn get_attributes(md: ebml::Doc) -> Vec { return attrs; } -fn list_crate_attributes(md: ebml::Doc, hash: &Svh, +fn list_crate_attributes(md: rbml::Doc, hash: &Svh, out: &mut io::Writer) -> io::IoResult<()> { try!(write!(out, "=Crate Attributes ({})=\n", *hash)); @@ -1095,7 +1095,7 @@ fn list_crate_attributes(md: ebml::Doc, hash: &Svh, } pub fn get_crate_attributes(data: &[u8]) -> Vec { - get_attributes(ebml::Doc::new(data)) + get_attributes(rbml::Doc::new(data)) } #[deriving(Clone)] @@ -1107,10 +1107,10 @@ pub struct CrateDep { pub fn get_crate_deps(data: &[u8]) -> Vec { let mut deps: Vec = Vec::new(); - let cratedoc = ebml::Doc::new(data); + let cratedoc = rbml::Doc::new(data); let depsdoc = reader::get_doc(cratedoc, tag_crate_deps); let mut crate_num = 1; - fn docstr(doc: ebml::Doc, tag_: uint) -> String { + fn docstr(doc: rbml::Doc, tag_: uint) -> String { let d = reader::get_doc(doc, tag_); d.as_str_slice().to_string() } @@ -1138,27 +1138,27 @@ fn list_crate_deps(data: &[u8], out: &mut io::Writer) -> io::IoResult<()> { } pub fn maybe_get_crate_hash(data: &[u8]) -> Option { - let cratedoc = ebml::Doc::new(data); + let cratedoc = rbml::Doc::new(data); reader::maybe_get_doc(cratedoc, tag_crate_hash).map(|doc| { Svh::new(doc.as_str_slice()) }) } pub fn get_crate_hash(data: &[u8]) -> Svh { - let cratedoc = ebml::Doc::new(data); + let cratedoc = rbml::Doc::new(data); let hashdoc = reader::get_doc(cratedoc, tag_crate_hash); Svh::new(hashdoc.as_str_slice()) } pub fn maybe_get_crate_name(data: &[u8]) -> Option { - let cratedoc = ebml::Doc::new(data); + let cratedoc = rbml::Doc::new(data); reader::maybe_get_doc(cratedoc, tag_crate_crate_name).map(|doc| { doc.as_str_slice().to_string() }) } pub fn get_crate_triple(data: &[u8]) -> Option { - let cratedoc = ebml::Doc::new(data); + let cratedoc = rbml::Doc::new(data); let triple_doc = reader::maybe_get_doc(cratedoc, tag_crate_triple); triple_doc.map(|s| s.as_str().to_string()) } @@ -1169,7 +1169,7 @@ pub fn get_crate_name(data: &[u8]) -> String { pub fn list_crate_metadata(bytes: &[u8], out: &mut io::Writer) -> io::IoResult<()> { let hash = get_crate_hash(bytes); - let md = ebml::Doc::new(bytes); + let md = rbml::Doc::new(bytes); try!(list_crate_attributes(md, &hash, out)); list_crate_deps(bytes, out) } @@ -1196,7 +1196,7 @@ pub fn translate_def_id(cdata: Cmd, did: ast::DefId) -> ast::DefId { } pub fn each_impl(cdata: Cmd, callback: |ast::DefId|) { - let impls_doc = reader::get_doc(ebml::Doc::new(cdata.data()), tag_impls); + let impls_doc = reader::get_doc(rbml::Doc::new(cdata.data()), tag_impls); let _ = reader::tagged_docs(impls_doc, tag_impls_impl, |impl_doc| { callback(item_def_id(impl_doc, cdata)); true @@ -1252,7 +1252,7 @@ pub fn get_trait_of_method(cdata: Cmd, id: ast::NodeId, tcx: &ty::ctxt) pub fn get_native_libraries(cdata: Cmd) -> Vec<(cstore::NativeLibaryKind, String)> { - let libraries = reader::get_doc(ebml::Doc::new(cdata.data()), + let libraries = reader::get_doc(rbml::Doc::new(cdata.data()), tag_native_libraries); let mut result = Vec::new(); reader::tagged_docs(libraries, tag_native_libraries_lib, |lib_doc| { @@ -1268,12 +1268,12 @@ pub fn get_native_libraries(cdata: Cmd) } pub fn get_plugin_registrar_fn(data: &[u8]) -> Option { - reader::maybe_get_doc(ebml::Doc::new(data), tag_plugin_registrar_fn) + reader::maybe_get_doc(rbml::Doc::new(data), tag_plugin_registrar_fn) .map(|doc| FromPrimitive::from_u32(reader::doc_as_u32(doc)).unwrap()) } pub fn get_exported_macros(data: &[u8]) -> Vec { - let macros = reader::get_doc(ebml::Doc::new(data), + let macros = reader::get_doc(rbml::Doc::new(data), tag_exported_macros); let mut result = Vec::new(); reader::tagged_docs(macros, tag_macro_def, |macro_doc| { @@ -1286,7 +1286,7 @@ pub fn get_exported_macros(data: &[u8]) -> Vec { pub fn get_dylib_dependency_formats(cdata: Cmd) -> Vec<(ast::CrateNum, cstore::LinkagePreference)> { - let formats = reader::get_doc(ebml::Doc::new(cdata.data()), + let formats = reader::get_doc(rbml::Doc::new(cdata.data()), tag_dylib_dependency_formats); let mut result = Vec::new(); @@ -1312,7 +1312,7 @@ pub fn get_dylib_dependency_formats(cdata: Cmd) pub fn get_missing_lang_items(cdata: Cmd) -> Vec { - let items = reader::get_doc(ebml::Doc::new(cdata.data()), tag_lang_items); + let items = reader::get_doc(rbml::Doc::new(cdata.data()), tag_lang_items); let mut result = Vec::new(); reader::tagged_docs(items, tag_lang_items_missing, |missing_doc| { let item: lang_items::LangItem = @@ -1340,7 +1340,7 @@ pub fn get_method_arg_names(cdata: Cmd, id: ast::NodeId) -> Vec { pub fn get_reachable_extern_fns(cdata: Cmd) -> Vec { let mut ret = Vec::new(); - let items = reader::get_doc(ebml::Doc::new(cdata.data()), + let items = reader::get_doc(rbml::Doc::new(cdata.data()), tag_reachable_extern_fns); reader::tagged_docs(items, tag_reachable_extern_fn_id, |doc| { ret.push(ast::DefId { diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index dbda4f58d960f91fc721e205ccdc5431acf6dc87..6ede414e83758b5f7b801716619e7e46c4df739e 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -26,7 +26,6 @@ use middle::typeck; use middle::stability; use middle; -use util::io::SeekableMemWriter; use util::nodemap::{NodeMap, NodeSet}; use serialize::Encodable; @@ -52,7 +51,8 @@ use syntax::visit::Visitor; use syntax::visit; use syntax; -use writer = serialize::ebml::writer; +use rbml::writer; +use rbml::io::SeekableMemWriter; /// A borrowed version of ast::InlinedItem. pub enum InlinedItemRef<'a> { @@ -64,7 +64,7 @@ pub enum InlinedItemRef<'a> { pub type Encoder<'a> = writer::Encoder<'a, SeekableMemWriter>; pub type EncodeInlinedItem<'a> = |ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, ii: InlinedItemRef|: 'a; pub struct EncodeParams<'a> { @@ -92,16 +92,16 @@ pub struct EncodeContext<'a> { pub reachable: &'a NodeSet, } -fn encode_name(ebml_w: &mut Encoder, name: Name) { - ebml_w.wr_tagged_str(tag_paths_data_name, token::get_name(name).get()); +fn encode_name(rbml_w: &mut Encoder, name: Name) { + rbml_w.wr_tagged_str(tag_paths_data_name, token::get_name(name).get()); } -fn encode_impl_type_basename(ebml_w: &mut Encoder, name: Ident) { - ebml_w.wr_tagged_str(tag_item_impl_type_basename, token::get_ident(name).get()); +fn encode_impl_type_basename(rbml_w: &mut Encoder, name: Ident) { + rbml_w.wr_tagged_str(tag_item_impl_type_basename, token::get_ident(name).get()); } -pub fn encode_def_id(ebml_w: &mut Encoder, id: DefId) { - ebml_w.wr_tagged_str(tag_def_id, def_to_string(id).as_slice()); +pub fn encode_def_id(rbml_w: &mut Encoder, id: DefId) { + rbml_w.wr_tagged_str(tag_def_id, def_to_string(id).as_slice()); } #[deriving(Clone)] @@ -110,7 +110,7 @@ struct entry { pos: u64 } -fn encode_trait_ref(ebml_w: &mut Encoder, +fn encode_trait_ref(rbml_w: &mut Encoder, ecx: &EncodeContext, trait_ref: &ty::TraitRef, tag: uint) { @@ -121,31 +121,31 @@ fn encode_trait_ref(ebml_w: &mut Encoder, abbrevs: &ecx.type_abbrevs }; - ebml_w.start_tag(tag); - tyencode::enc_trait_ref(ebml_w.writer, ty_str_ctxt, trait_ref); - ebml_w.end_tag(); + rbml_w.start_tag(tag); + tyencode::enc_trait_ref(rbml_w.writer, ty_str_ctxt, trait_ref); + rbml_w.end_tag(); } -fn encode_impl_vtables(ebml_w: &mut Encoder, +fn encode_impl_vtables(rbml_w: &mut Encoder, ecx: &EncodeContext, vtables: &typeck::vtable_res) { - ebml_w.start_tag(tag_item_impl_vtables); - astencode::encode_vtable_res(ecx, ebml_w, vtables); - ebml_w.end_tag(); + rbml_w.start_tag(tag_item_impl_vtables); + astencode::encode_vtable_res(ecx, rbml_w, vtables); + rbml_w.end_tag(); } // Item info table encoding -fn encode_family(ebml_w: &mut Encoder, c: char) { - ebml_w.start_tag(tag_items_data_item_family); - ebml_w.writer.write(&[c as u8]); - ebml_w.end_tag(); +fn encode_family(rbml_w: &mut Encoder, c: char) { + rbml_w.start_tag(tag_items_data_item_family); + rbml_w.writer.write(&[c as u8]); + rbml_w.end_tag(); } pub fn def_to_string(did: DefId) -> String { format!("{}:{}", did.krate, did.node) } -fn encode_ty_type_param_defs(ebml_w: &mut Encoder, +fn encode_ty_type_param_defs(rbml_w: &mut Encoder, ecx: &EncodeContext, params: &VecPerParamSpace, tag: uint) { @@ -156,61 +156,61 @@ fn encode_ty_type_param_defs(ebml_w: &mut Encoder, abbrevs: &ecx.type_abbrevs }; for param in params.iter() { - ebml_w.start_tag(tag); - tyencode::enc_type_param_def(ebml_w.writer, ty_str_ctxt, param); - ebml_w.end_tag(); + rbml_w.start_tag(tag); + tyencode::enc_type_param_def(rbml_w.writer, ty_str_ctxt, param); + rbml_w.end_tag(); } } -fn encode_region_param_defs(ebml_w: &mut Encoder, +fn encode_region_param_defs(rbml_w: &mut Encoder, params: &VecPerParamSpace) { for param in params.iter() { - ebml_w.start_tag(tag_region_param_def); + rbml_w.start_tag(tag_region_param_def); - ebml_w.start_tag(tag_region_param_def_ident); - encode_name(ebml_w, param.name); - ebml_w.end_tag(); + rbml_w.start_tag(tag_region_param_def_ident); + encode_name(rbml_w, param.name); + rbml_w.end_tag(); - ebml_w.wr_tagged_str(tag_region_param_def_def_id, + rbml_w.wr_tagged_str(tag_region_param_def_def_id, def_to_string(param.def_id).as_slice()); - ebml_w.wr_tagged_u64(tag_region_param_def_space, + rbml_w.wr_tagged_u64(tag_region_param_def_space, param.space.to_uint() as u64); - ebml_w.wr_tagged_u64(tag_region_param_def_index, + rbml_w.wr_tagged_u64(tag_region_param_def_index, param.index as u64); - ebml_w.end_tag(); + rbml_w.end_tag(); } } -fn encode_item_variances(ebml_w: &mut Encoder, +fn encode_item_variances(rbml_w: &mut Encoder, ecx: &EncodeContext, id: ast::NodeId) { let v = ty::item_variances(ecx.tcx, ast_util::local_def(id)); - ebml_w.start_tag(tag_item_variances); - v.encode(ebml_w); - ebml_w.end_tag(); + rbml_w.start_tag(tag_item_variances); + v.encode(rbml_w); + rbml_w.end_tag(); } -fn encode_bounds_and_type(ebml_w: &mut Encoder, +fn encode_bounds_and_type(rbml_w: &mut Encoder, ecx: &EncodeContext, pty: &ty::Polytype) { - encode_ty_type_param_defs(ebml_w, ecx, &pty.generics.types, + encode_ty_type_param_defs(rbml_w, ecx, &pty.generics.types, tag_items_data_item_ty_param_bounds); - encode_region_param_defs(ebml_w, &pty.generics.regions); - encode_type(ecx, ebml_w, pty.ty); + encode_region_param_defs(rbml_w, &pty.generics.regions); + encode_type(ecx, rbml_w, pty.ty); } -fn encode_variant_id(ebml_w: &mut Encoder, vid: DefId) { - ebml_w.start_tag(tag_items_data_item_variant); +fn encode_variant_id(rbml_w: &mut Encoder, vid: DefId) { + rbml_w.start_tag(tag_items_data_item_variant); let s = def_to_string(vid); - ebml_w.writer.write(s.as_bytes()); - ebml_w.end_tag(); + rbml_w.writer.write(s.as_bytes()); + rbml_w.end_tag(); } pub fn write_closure_type(ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, closure_type: &ty::ClosureTy) { let ty_str_ctxt = &tyencode::ctxt { diag: ecx.diag, @@ -218,11 +218,11 @@ pub fn write_closure_type(ecx: &EncodeContext, tcx: ecx.tcx, abbrevs: &ecx.type_abbrevs }; - tyencode::enc_closure_ty(ebml_w.writer, ty_str_ctxt, closure_type); + tyencode::enc_closure_ty(rbml_w.writer, ty_str_ctxt, closure_type); } pub fn write_type(ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, typ: ty::t) { let ty_str_ctxt = &tyencode::ctxt { diag: ecx.diag, @@ -230,21 +230,21 @@ pub fn write_type(ecx: &EncodeContext, tcx: ecx.tcx, abbrevs: &ecx.type_abbrevs }; - tyencode::enc_ty(ebml_w.writer, ty_str_ctxt, typ); + tyencode::enc_ty(rbml_w.writer, ty_str_ctxt, typ); } fn encode_type(ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, typ: ty::t) { - ebml_w.start_tag(tag_items_data_item_type); - write_type(ecx, ebml_w, typ); - ebml_w.end_tag(); + rbml_w.start_tag(tag_items_data_item_type); + write_type(ecx, rbml_w, typ); + rbml_w.end_tag(); } fn encode_method_fty(ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, typ: &ty::BareFnTy) { - ebml_w.start_tag(tag_item_method_fty); + rbml_w.start_tag(tag_item_method_fty); let ty_str_ctxt = &tyencode::ctxt { diag: ecx.diag, @@ -252,66 +252,66 @@ fn encode_method_fty(ecx: &EncodeContext, tcx: ecx.tcx, abbrevs: &ecx.type_abbrevs }; - tyencode::enc_bare_fn_ty(ebml_w.writer, ty_str_ctxt, typ); + tyencode::enc_bare_fn_ty(rbml_w.writer, ty_str_ctxt, typ); - ebml_w.end_tag(); + rbml_w.end_tag(); } fn encode_symbol(ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, id: NodeId) { - ebml_w.start_tag(tag_items_data_item_symbol); + rbml_w.start_tag(tag_items_data_item_symbol); match ecx.item_symbols.borrow().find(&id) { Some(x) => { debug!("encode_symbol(id={:?}, str={})", id, *x); - ebml_w.writer.write(x.as_bytes()); + rbml_w.writer.write(x.as_bytes()); } None => { ecx.diag.handler().bug( format!("encode_symbol: id not found {}", id).as_slice()); } } - ebml_w.end_tag(); + rbml_w.end_tag(); } fn encode_disr_val(_: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, disr_val: ty::Disr) { - ebml_w.start_tag(tag_disr_val); + rbml_w.start_tag(tag_disr_val); let s = disr_val.to_string(); - ebml_w.writer.write(s.as_bytes()); - ebml_w.end_tag(); + rbml_w.writer.write(s.as_bytes()); + rbml_w.end_tag(); } -fn encode_parent_item(ebml_w: &mut Encoder, id: DefId) { - ebml_w.start_tag(tag_items_data_parent_item); +fn encode_parent_item(rbml_w: &mut Encoder, id: DefId) { + rbml_w.start_tag(tag_items_data_parent_item); let s = def_to_string(id); - ebml_w.writer.write(s.as_bytes()); - ebml_w.end_tag(); + rbml_w.writer.write(s.as_bytes()); + rbml_w.end_tag(); } -fn encode_struct_fields(ebml_w: &mut Encoder, +fn encode_struct_fields(rbml_w: &mut Encoder, fields: &[ty::field_ty], origin: DefId) { for f in fields.iter() { if f.name == special_idents::unnamed_field.name { - ebml_w.start_tag(tag_item_unnamed_field); + rbml_w.start_tag(tag_item_unnamed_field); } else { - ebml_w.start_tag(tag_item_field); - encode_name(ebml_w, f.name); + rbml_w.start_tag(tag_item_field); + encode_name(rbml_w, f.name); } - encode_struct_field_family(ebml_w, f.vis); - encode_def_id(ebml_w, f.id); - ebml_w.start_tag(tag_item_field_origin); + encode_struct_field_family(rbml_w, f.vis); + encode_def_id(rbml_w, f.id); + rbml_w.start_tag(tag_item_field_origin); let s = def_to_string(origin); - ebml_w.writer.write(s.as_bytes()); - ebml_w.end_tag(); - ebml_w.end_tag(); + rbml_w.writer.write(s.as_bytes()); + rbml_w.end_tag(); + rbml_w.end_tag(); } } fn encode_enum_variant_info(ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, id: NodeId, variants: &[P], index: &mut Vec>) { @@ -325,82 +325,82 @@ fn encode_enum_variant_info(ecx: &EncodeContext, let def_id = local_def(variant.node.id); index.push(entry { val: variant.node.id as i64, - pos: ebml_w.writer.tell().unwrap(), + pos: rbml_w.writer.tell().unwrap(), }); - ebml_w.start_tag(tag_items_data_item); - encode_def_id(ebml_w, def_id); + rbml_w.start_tag(tag_items_data_item); + encode_def_id(rbml_w, def_id); match variant.node.kind { - ast::TupleVariantKind(_) => encode_family(ebml_w, 'v'), - ast::StructVariantKind(_) => encode_family(ebml_w, 'V') + ast::TupleVariantKind(_) => encode_family(rbml_w, 'v'), + ast::StructVariantKind(_) => encode_family(rbml_w, 'V') } - encode_name(ebml_w, variant.node.name.name); - encode_parent_item(ebml_w, local_def(id)); - encode_visibility(ebml_w, variant.node.vis); - encode_attributes(ebml_w, variant.node.attrs.as_slice()); + encode_name(rbml_w, variant.node.name.name); + encode_parent_item(rbml_w, local_def(id)); + encode_visibility(rbml_w, variant.node.vis); + encode_attributes(rbml_w, variant.node.attrs.as_slice()); let stab = stability::lookup(ecx.tcx, ast_util::local_def(variant.node.id)); - encode_stability(ebml_w, stab); + encode_stability(rbml_w, stab); match variant.node.kind { ast::TupleVariantKind(_) => {}, ast::StructVariantKind(_) => { let fields = ty::lookup_struct_fields(ecx.tcx, def_id); let idx = encode_info_for_struct(ecx, - ebml_w, + rbml_w, fields.as_slice(), index); - encode_struct_fields(ebml_w, fields.as_slice(), def_id); - encode_index(ebml_w, idx, write_i64); + encode_struct_fields(rbml_w, fields.as_slice(), def_id); + encode_index(rbml_w, idx, write_i64); } } if vi.get(i).disr_val != disr_val { - encode_disr_val(ecx, ebml_w, vi.get(i).disr_val); + encode_disr_val(ecx, rbml_w, vi.get(i).disr_val); disr_val = vi.get(i).disr_val; } - encode_bounds_and_type(ebml_w, ecx, + encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(ecx.tcx, def_id)); - ecx.tcx.map.with_path(variant.node.id, |path| encode_path(ebml_w, path)); - ebml_w.end_tag(); + ecx.tcx.map.with_path(variant.node.id, |path| encode_path(rbml_w, path)); + rbml_w.end_tag(); disr_val += 1; i += 1; } } -fn encode_path + Clone>(ebml_w: &mut Encoder, +fn encode_path + Clone>(rbml_w: &mut Encoder, mut path: PI) { - ebml_w.start_tag(tag_path); - ebml_w.wr_tagged_u32(tag_path_len, path.clone().count() as u32); + rbml_w.start_tag(tag_path); + rbml_w.wr_tagged_u32(tag_path_len, path.clone().count() as u32); for pe in path { let tag = match pe { ast_map::PathMod(_) => tag_path_elem_mod, ast_map::PathName(_) => tag_path_elem_name }; - ebml_w.wr_tagged_str(tag, token::get_name(pe.name()).get()); + rbml_w.wr_tagged_str(tag, token::get_name(pe.name()).get()); } - ebml_w.end_tag(); + rbml_w.end_tag(); } -fn encode_reexported_static_method(ebml_w: &mut Encoder, +fn encode_reexported_static_method(rbml_w: &mut Encoder, exp: &middle::resolve::Export2, method_def_id: DefId, method_ident: Ident) { debug!("(encode reexported static method) {}::{}", exp.name, token::get_ident(method_ident)); - ebml_w.start_tag(tag_items_data_item_reexport); - ebml_w.start_tag(tag_items_data_item_reexport_def_id); - ebml_w.wr_str(def_to_string(method_def_id).as_slice()); - ebml_w.end_tag(); - ebml_w.start_tag(tag_items_data_item_reexport_name); - ebml_w.wr_str(format!("{}::{}", + rbml_w.start_tag(tag_items_data_item_reexport); + rbml_w.start_tag(tag_items_data_item_reexport_def_id); + rbml_w.wr_str(def_to_string(method_def_id).as_slice()); + rbml_w.end_tag(); + rbml_w.start_tag(tag_items_data_item_reexport_name); + rbml_w.wr_str(format!("{}::{}", exp.name, token::get_ident(method_ident)).as_slice()); - ebml_w.end_tag(); - ebml_w.end_tag(); + rbml_w.end_tag(); + rbml_w.end_tag(); } fn encode_reexported_static_base_methods(ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, exp: &middle::resolve::Export2) -> bool { let impl_methods = ecx.tcx.impl_methods.borrow(); @@ -410,7 +410,7 @@ fn encode_reexported_static_base_methods(ecx: &EncodeContext, for &method_did in impl_methods.get(base_impl_did).iter() { let m = ty::method(ecx.tcx, method_did); if m.explicit_self == ty::StaticExplicitSelfCategory { - encode_reexported_static_method(ebml_w, exp, m.def_id, m.ident); + encode_reexported_static_method(rbml_w, exp, m.def_id, m.ident); } } } @@ -422,14 +422,14 @@ fn encode_reexported_static_base_methods(ecx: &EncodeContext, } fn encode_reexported_static_trait_methods(ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, exp: &middle::resolve::Export2) -> bool { match ecx.tcx.trait_methods_cache.borrow().find(&exp.def_id) { Some(methods) => { for m in methods.iter() { if m.explicit_self == ty::StaticExplicitSelfCategory { - encode_reexported_static_method(ebml_w, exp, m.def_id, m.ident); + encode_reexported_static_method(rbml_w, exp, m.def_id, m.ident); } } @@ -440,7 +440,7 @@ fn encode_reexported_static_trait_methods(ecx: &EncodeContext, } fn encode_reexported_static_methods(ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, mod_path: PathElems, exp: &middle::resolve::Export2) { match ecx.tcx.map.find(exp.def_id.node) { @@ -469,8 +469,8 @@ fn encode_reexported_static_methods(ecx: &EncodeContext, // but not yet for Foo. // if path_differs || original_name.get() != exp.name.as_slice() { - if !encode_reexported_static_base_methods(ecx, ebml_w, exp) { - if encode_reexported_static_trait_methods(ecx, ebml_w, exp) { + if !encode_reexported_static_base_methods(ecx, rbml_w, exp) { + if encode_reexported_static_trait_methods(ecx, rbml_w, exp) { debug!("(encode reexported static methods) {} \ [trait]", original_name); @@ -520,7 +520,7 @@ fn each_auxiliary_node_id(item: Gc, callback: |NodeId| -> bool) -> bool { } fn encode_reexports(ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, id: NodeId, path: PathElems) { debug!("(encoding info for module) encoding reexports for {}", id); @@ -534,15 +534,15 @@ fn encode_reexports(ecx: &EncodeContext, exp.def_id.krate, exp.def_id.node, id); - ebml_w.start_tag(tag_items_data_item_reexport); - ebml_w.start_tag(tag_items_data_item_reexport_def_id); - ebml_w.wr_str(def_to_string(exp.def_id).as_slice()); - ebml_w.end_tag(); - ebml_w.start_tag(tag_items_data_item_reexport_name); - ebml_w.wr_str(exp.name.as_slice()); - ebml_w.end_tag(); - ebml_w.end_tag(); - encode_reexported_static_methods(ecx, ebml_w, path.clone(), exp); + rbml_w.start_tag(tag_items_data_item_reexport); + rbml_w.start_tag(tag_items_data_item_reexport_def_id); + rbml_w.wr_str(def_to_string(exp.def_id).as_slice()); + rbml_w.end_tag(); + rbml_w.start_tag(tag_items_data_item_reexport_name); + rbml_w.wr_str(exp.name.as_slice()); + rbml_w.end_tag(); + rbml_w.end_tag(); + encode_reexported_static_methods(ecx, rbml_w, path.clone(), exp); } } None => { @@ -553,30 +553,30 @@ fn encode_reexports(ecx: &EncodeContext, } fn encode_info_for_mod(ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, md: &Mod, attrs: &[Attribute], id: NodeId, path: PathElems, name: Ident, vis: Visibility) { - ebml_w.start_tag(tag_items_data_item); - encode_def_id(ebml_w, local_def(id)); - encode_family(ebml_w, 'm'); - encode_name(ebml_w, name.name); + rbml_w.start_tag(tag_items_data_item); + encode_def_id(rbml_w, local_def(id)); + encode_family(rbml_w, 'm'); + encode_name(rbml_w, name.name); debug!("(encoding info for module) encoding info for module ID {}", id); // Encode info about all the module children. for item in md.items.iter() { - ebml_w.start_tag(tag_mod_child); - ebml_w.wr_str(def_to_string(local_def(item.id)).as_slice()); - ebml_w.end_tag(); + rbml_w.start_tag(tag_mod_child); + rbml_w.wr_str(def_to_string(local_def(item.id)).as_slice()); + rbml_w.end_tag(); each_auxiliary_node_id(*item, |auxiliary_node_id| { - ebml_w.start_tag(tag_mod_child); - ebml_w.wr_str(def_to_string(local_def( + rbml_w.start_tag(tag_mod_child); + rbml_w.wr_str(def_to_string(local_def( auxiliary_node_id)).as_slice()); - ebml_w.end_tag(); + rbml_w.end_tag(); true }); @@ -588,100 +588,100 @@ fn encode_info_for_mod(ecx: &EncodeContext, token::get_ident(ident), did, ecx.tcx.map.node_to_string(did)); - ebml_w.start_tag(tag_mod_impl); - ebml_w.wr_str(def_to_string(local_def(did)).as_slice()); - ebml_w.end_tag(); + rbml_w.start_tag(tag_mod_impl); + rbml_w.wr_str(def_to_string(local_def(did)).as_slice()); + rbml_w.end_tag(); } _ => {} } } - encode_path(ebml_w, path.clone()); - encode_visibility(ebml_w, vis); + encode_path(rbml_w, path.clone()); + encode_visibility(rbml_w, vis); let stab = stability::lookup(ecx.tcx, ast_util::local_def(id)); - encode_stability(ebml_w, stab); + encode_stability(rbml_w, stab); // Encode the reexports of this module, if this module is public. if vis == Public { debug!("(encoding info for module) encoding reexports for {}", id); - encode_reexports(ecx, ebml_w, id, path); + encode_reexports(ecx, rbml_w, id, path); } - encode_attributes(ebml_w, attrs); + encode_attributes(rbml_w, attrs); - ebml_w.end_tag(); + rbml_w.end_tag(); } -fn encode_struct_field_family(ebml_w: &mut Encoder, +fn encode_struct_field_family(rbml_w: &mut Encoder, visibility: Visibility) { - encode_family(ebml_w, match visibility { + encode_family(rbml_w, match visibility { Public => 'g', Inherited => 'N' }); } -fn encode_visibility(ebml_w: &mut Encoder, visibility: Visibility) { - ebml_w.start_tag(tag_items_data_item_visibility); +fn encode_visibility(rbml_w: &mut Encoder, visibility: Visibility) { + rbml_w.start_tag(tag_items_data_item_visibility); let ch = match visibility { Public => 'y', Inherited => 'i', }; - ebml_w.wr_str(ch.to_string().as_slice()); - ebml_w.end_tag(); + rbml_w.wr_str(ch.to_string().as_slice()); + rbml_w.end_tag(); } -fn encode_explicit_self(ebml_w: &mut Encoder, +fn encode_explicit_self(rbml_w: &mut Encoder, explicit_self: &ty::ExplicitSelfCategory) { - ebml_w.start_tag(tag_item_trait_method_explicit_self); + rbml_w.start_tag(tag_item_trait_method_explicit_self); // Encode the base self type. match *explicit_self { ty::StaticExplicitSelfCategory => { - ebml_w.writer.write(&[ 's' as u8 ]); + rbml_w.writer.write(&[ 's' as u8 ]); } ty::ByValueExplicitSelfCategory => { - ebml_w.writer.write(&[ 'v' as u8 ]); + rbml_w.writer.write(&[ 'v' as u8 ]); } ty::ByBoxExplicitSelfCategory => { - ebml_w.writer.write(&[ '~' as u8 ]); + rbml_w.writer.write(&[ '~' as u8 ]); } ty::ByReferenceExplicitSelfCategory(_, m) => { // FIXME(#4846) encode custom lifetime - ebml_w.writer.write(&['&' as u8]); - encode_mutability(ebml_w, m); + rbml_w.writer.write(&['&' as u8]); + encode_mutability(rbml_w, m); } } - ebml_w.end_tag(); + rbml_w.end_tag(); - fn encode_mutability(ebml_w: &mut Encoder, + fn encode_mutability(rbml_w: &mut Encoder, m: ast::Mutability) { match m { - MutImmutable => { ebml_w.writer.write(&[ 'i' as u8 ]); } - MutMutable => { ebml_w.writer.write(&[ 'm' as u8 ]); } + MutImmutable => { rbml_w.writer.write(&[ 'i' as u8 ]); } + MutMutable => { rbml_w.writer.write(&[ 'm' as u8 ]); } } } } -fn encode_method_sort(ebml_w: &mut Encoder, sort: char) { - ebml_w.start_tag(tag_item_trait_method_sort); - ebml_w.writer.write(&[ sort as u8 ]); - ebml_w.end_tag(); +fn encode_method_sort(rbml_w: &mut Encoder, sort: char) { + rbml_w.start_tag(tag_item_trait_method_sort); + rbml_w.writer.write(&[ sort as u8 ]); + rbml_w.end_tag(); } -fn encode_provided_source(ebml_w: &mut Encoder, +fn encode_provided_source(rbml_w: &mut Encoder, source_opt: Option) { for source in source_opt.iter() { - ebml_w.start_tag(tag_item_method_provided_source); + rbml_w.start_tag(tag_item_method_provided_source); let s = def_to_string(*source); - ebml_w.writer.write(s.as_bytes()); - ebml_w.end_tag(); + rbml_w.writer.write(s.as_bytes()); + rbml_w.end_tag(); } } /* Returns an index of items in this class */ fn encode_info_for_struct(ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, fields: &[ty::field_ty], global_index: &mut Vec>) -> Vec> { @@ -695,86 +695,86 @@ fn encode_info_for_struct(ecx: &EncodeContext, let nm = field.name; let id = field.id.node; - index.push(entry {val: id as i64, pos: ebml_w.writer.tell().unwrap()}); + index.push(entry {val: id as i64, pos: rbml_w.writer.tell().unwrap()}); global_index.push(entry { val: id as i64, - pos: ebml_w.writer.tell().unwrap(), + pos: rbml_w.writer.tell().unwrap(), }); - ebml_w.start_tag(tag_items_data_item); + rbml_w.start_tag(tag_items_data_item); debug!("encode_info_for_struct: doing {} {}", token::get_name(nm), id); - encode_struct_field_family(ebml_w, field.vis); - encode_name(ebml_w, nm); - encode_type(ecx, ebml_w, node_id_to_type(tcx, id)); - encode_def_id(ebml_w, local_def(id)); + encode_struct_field_family(rbml_w, field.vis); + encode_name(rbml_w, nm); + encode_type(ecx, rbml_w, node_id_to_type(tcx, id)); + encode_def_id(rbml_w, local_def(id)); let stab = stability::lookup(ecx.tcx, field.id); - encode_stability(ebml_w, stab); + encode_stability(rbml_w, stab); - ebml_w.end_tag(); + rbml_w.end_tag(); } index } fn encode_info_for_struct_ctor(ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, name: ast::Ident, ctor_id: NodeId, index: &mut Vec>, struct_id: NodeId) { index.push(entry { val: ctor_id as i64, - pos: ebml_w.writer.tell().unwrap(), + pos: rbml_w.writer.tell().unwrap(), }); - ebml_w.start_tag(tag_items_data_item); - encode_def_id(ebml_w, local_def(ctor_id)); - encode_family(ebml_w, 'f'); - encode_bounds_and_type(ebml_w, ecx, + rbml_w.start_tag(tag_items_data_item); + encode_def_id(rbml_w, local_def(ctor_id)); + encode_family(rbml_w, 'f'); + encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(ecx.tcx, local_def(ctor_id))); - encode_name(ebml_w, name.name); - encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, ctor_id)); - ecx.tcx.map.with_path(ctor_id, |path| encode_path(ebml_w, path)); - encode_parent_item(ebml_w, local_def(struct_id)); + encode_name(rbml_w, name.name); + encode_type(ecx, rbml_w, node_id_to_type(ecx.tcx, ctor_id)); + ecx.tcx.map.with_path(ctor_id, |path| encode_path(rbml_w, path)); + encode_parent_item(rbml_w, local_def(struct_id)); if ecx.item_symbols.borrow().contains_key(&ctor_id) { - encode_symbol(ecx, ebml_w, ctor_id); + encode_symbol(ecx, rbml_w, ctor_id); } let stab = stability::lookup(ecx.tcx, ast_util::local_def(ctor_id)); - encode_stability(ebml_w, stab); + encode_stability(rbml_w, stab); // indicate that this is a tuple struct ctor, because downstream users will normally want // the tuple struct definition, but without this there is no way for them to tell that // they actually have a ctor rather than a normal function - ebml_w.start_tag(tag_items_data_item_is_tuple_struct_ctor); - ebml_w.end_tag(); + rbml_w.start_tag(tag_items_data_item_is_tuple_struct_ctor); + rbml_w.end_tag(); - ebml_w.end_tag(); + rbml_w.end_tag(); } fn encode_method_ty_fields(ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, method_ty: &ty::Method) { - encode_def_id(ebml_w, method_ty.def_id); - encode_name(ebml_w, method_ty.ident.name); - encode_ty_type_param_defs(ebml_w, ecx, &method_ty.generics.types, + encode_def_id(rbml_w, method_ty.def_id); + encode_name(rbml_w, method_ty.ident.name); + encode_ty_type_param_defs(rbml_w, ecx, &method_ty.generics.types, tag_item_method_tps); - encode_method_fty(ecx, ebml_w, &method_ty.fty); - encode_visibility(ebml_w, method_ty.vis); - encode_explicit_self(ebml_w, &method_ty.explicit_self); + encode_method_fty(ecx, rbml_w, &method_ty.fty); + encode_visibility(rbml_w, method_ty.vis); + encode_explicit_self(rbml_w, &method_ty.explicit_self); let fn_style = method_ty.fty.fn_style; match method_ty.explicit_self { ty::StaticExplicitSelfCategory => { - encode_family(ebml_w, fn_style_static_method_family(fn_style)); + encode_family(rbml_w, fn_style_static_method_family(fn_style)); } - _ => encode_family(ebml_w, style_fn_family(fn_style)) + _ => encode_family(rbml_w, style_fn_family(fn_style)) } - encode_provided_source(ebml_w, method_ty.provided_source); + encode_provided_source(rbml_w, method_ty.provided_source); } fn encode_info_for_method(ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, m: &ty::Method, impl_path: PathElems, is_default_impl: bool, @@ -783,23 +783,23 @@ fn encode_info_for_method(ecx: &EncodeContext, debug!("encode_info_for_method: {:?} {}", m.def_id, token::get_ident(m.ident)); - ebml_w.start_tag(tag_items_data_item); + rbml_w.start_tag(tag_items_data_item); - encode_method_ty_fields(ecx, ebml_w, m); - encode_parent_item(ebml_w, local_def(parent_id)); + encode_method_ty_fields(ecx, rbml_w, m); + encode_parent_item(rbml_w, local_def(parent_id)); let stab = stability::lookup(ecx.tcx, m.def_id); - encode_stability(ebml_w, stab); + encode_stability(rbml_w, stab); // The type for methods gets encoded twice, which is unfortunate. let pty = lookup_item_type(ecx.tcx, m.def_id); - encode_bounds_and_type(ebml_w, ecx, &pty); + encode_bounds_and_type(rbml_w, ecx, &pty); let elem = ast_map::PathName(m.ident.name); - encode_path(ebml_w, impl_path.chain(Some(elem).move_iter())); + encode_path(rbml_w, impl_path.chain(Some(elem).move_iter())); match ast_method_opt { Some(ast_method) => { - encode_attributes(ebml_w, ast_method.attrs.as_slice()) + encode_attributes(rbml_w, ast_method.attrs.as_slice()) } None => () } @@ -807,41 +807,41 @@ fn encode_info_for_method(ecx: &EncodeContext, for &ast_method in ast_method_opt.iter() { let any_types = !pty.generics.types.is_empty(); if any_types || is_default_impl || should_inline(ast_method.attrs.as_slice()) { - encode_inlined_item(ecx, ebml_w, + encode_inlined_item(ecx, rbml_w, IIMethodRef(local_def(parent_id), false, &*ast_method)); } else { - encode_symbol(ecx, ebml_w, m.def_id.node); + encode_symbol(ecx, rbml_w, m.def_id.node); } - encode_method_argument_names(ebml_w, &*ast_method.pe_fn_decl()); + encode_method_argument_names(rbml_w, &*ast_method.pe_fn_decl()); } - ebml_w.end_tag(); + rbml_w.end_tag(); } -fn encode_method_argument_names(ebml_w: &mut Encoder, +fn encode_method_argument_names(rbml_w: &mut Encoder, decl: &ast::FnDecl) { - ebml_w.start_tag(tag_method_argument_names); + rbml_w.start_tag(tag_method_argument_names); for arg in decl.inputs.iter() { - ebml_w.start_tag(tag_method_argument_name); + rbml_w.start_tag(tag_method_argument_name); match arg.pat.node { ast::PatIdent(_, ref path1, _) => { let name = token::get_ident(path1.node); - ebml_w.writer.write(name.get().as_bytes()); + rbml_w.writer.write(name.get().as_bytes()); } _ => {} } - ebml_w.end_tag(); + rbml_w.end_tag(); } - ebml_w.end_tag(); + rbml_w.end_tag(); } fn encode_inlined_item(ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, ii: InlinedItemRef) { let mut eii = ecx.encode_inlined_item.borrow_mut(); let eii: &mut EncodeInlinedItem = &mut *eii; - (*eii)(ecx, ebml_w, ii) + (*eii)(ecx, rbml_w, ii) } fn style_fn_family(s: FnStyle) -> char { @@ -869,15 +869,15 @@ fn should_inline(attrs: &[Attribute]) -> bool { // Encodes the inherent implementations of a structure, enumeration, or trait. fn encode_inherent_implementations(ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, def_id: DefId) { match ecx.tcx.inherent_impls.borrow().find(&def_id) { None => {} Some(implementations) => { for &impl_def_id in implementations.borrow().iter() { - ebml_w.start_tag(tag_items_data_item_inherent_impl); - encode_def_id(ebml_w, impl_def_id); - ebml_w.end_tag(); + rbml_w.start_tag(tag_items_data_item_inherent_impl); + encode_def_id(rbml_w, impl_def_id); + rbml_w.end_tag(); } } } @@ -885,41 +885,41 @@ fn encode_inherent_implementations(ecx: &EncodeContext, // Encodes the implementations of a trait defined in this crate. fn encode_extension_implementations(ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, trait_def_id: DefId) { match ecx.tcx.trait_impls.borrow().find(&trait_def_id) { None => {} Some(implementations) => { for &impl_def_id in implementations.borrow().iter() { - ebml_w.start_tag(tag_items_data_item_extension_impl); - encode_def_id(ebml_w, impl_def_id); - ebml_w.end_tag(); + rbml_w.start_tag(tag_items_data_item_extension_impl); + encode_def_id(rbml_w, impl_def_id); + rbml_w.end_tag(); } } } } -fn encode_stability(ebml_w: &mut Encoder, stab_opt: Option) { +fn encode_stability(rbml_w: &mut Encoder, stab_opt: Option) { stab_opt.map(|stab| { - ebml_w.start_tag(tag_items_data_item_stability); - stab.encode(ebml_w).unwrap(); - ebml_w.end_tag(); + rbml_w.start_tag(tag_items_data_item_stability); + stab.encode(rbml_w).unwrap(); + rbml_w.end_tag(); }); } fn encode_info_for_item(ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, item: &Item, index: &mut Vec>, path: PathElems, vis: ast::Visibility) { let tcx = ecx.tcx; - fn add_to_index(item: &Item, ebml_w: &Encoder, + fn add_to_index(item: &Item, rbml_w: &Encoder, index: &mut Vec>) { index.push(entry { val: item.id as i64, - pos: ebml_w.writer.tell().unwrap(), + pos: rbml_w.writer.tell().unwrap(), }); } @@ -931,52 +931,52 @@ fn add_to_index(item: &Item, ebml_w: &Encoder, match item.node { ItemStatic(_, m, _) => { - add_to_index(item, ebml_w, index); - ebml_w.start_tag(tag_items_data_item); - encode_def_id(ebml_w, def_id); + add_to_index(item, rbml_w, index); + rbml_w.start_tag(tag_items_data_item); + encode_def_id(rbml_w, def_id); if m == ast::MutMutable { - encode_family(ebml_w, 'b'); + encode_family(rbml_w, 'b'); } else { - encode_family(ebml_w, 'c'); + encode_family(rbml_w, 'c'); } - encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id)); - encode_symbol(ecx, ebml_w, item.id); - encode_name(ebml_w, item.ident.name); - encode_path(ebml_w, path); + encode_type(ecx, rbml_w, node_id_to_type(tcx, item.id)); + encode_symbol(ecx, rbml_w, item.id); + encode_name(rbml_w, item.ident.name); + encode_path(rbml_w, path); let inlineable = !ecx.non_inlineable_statics.borrow().contains(&item.id); if inlineable { - encode_inlined_item(ecx, ebml_w, IIItemRef(item)); + encode_inlined_item(ecx, rbml_w, IIItemRef(item)); } - encode_visibility(ebml_w, vis); - encode_stability(ebml_w, stab); - ebml_w.end_tag(); + encode_visibility(rbml_w, vis); + encode_stability(rbml_w, stab); + rbml_w.end_tag(); } ItemFn(ref decl, fn_style, _, ref generics, _) => { - add_to_index(item, ebml_w, index); - ebml_w.start_tag(tag_items_data_item); - encode_def_id(ebml_w, def_id); - encode_family(ebml_w, style_fn_family(fn_style)); + add_to_index(item, rbml_w, index); + rbml_w.start_tag(tag_items_data_item); + encode_def_id(rbml_w, def_id); + encode_family(rbml_w, style_fn_family(fn_style)); let tps_len = generics.ty_params.len(); - encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id)); - encode_name(ebml_w, item.ident.name); - encode_path(ebml_w, path); - encode_attributes(ebml_w, item.attrs.as_slice()); + encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(tcx, def_id)); + encode_name(rbml_w, item.ident.name); + encode_path(rbml_w, path); + encode_attributes(rbml_w, item.attrs.as_slice()); if tps_len > 0u || should_inline(item.attrs.as_slice()) { - encode_inlined_item(ecx, ebml_w, IIItemRef(item)); + encode_inlined_item(ecx, rbml_w, IIItemRef(item)); } else { - encode_symbol(ecx, ebml_w, item.id); + encode_symbol(ecx, rbml_w, item.id); } - encode_visibility(ebml_w, vis); - encode_stability(ebml_w, stab); - encode_method_argument_names(ebml_w, &**decl); - ebml_w.end_tag(); + encode_visibility(rbml_w, vis); + encode_stability(rbml_w, stab); + encode_method_argument_names(rbml_w, &**decl); + rbml_w.end_tag(); } ItemMod(ref m) => { - add_to_index(item, ebml_w, index); + add_to_index(item, rbml_w, index); encode_info_for_mod(ecx, - ebml_w, + rbml_w, m, item.attrs.as_slice(), item.id, @@ -985,60 +985,60 @@ fn add_to_index(item: &Item, ebml_w: &Encoder, item.vis); } ItemForeignMod(ref fm) => { - add_to_index(item, ebml_w, index); - ebml_w.start_tag(tag_items_data_item); - encode_def_id(ebml_w, def_id); - encode_family(ebml_w, 'n'); - encode_name(ebml_w, item.ident.name); - encode_path(ebml_w, path); + add_to_index(item, rbml_w, index); + rbml_w.start_tag(tag_items_data_item); + encode_def_id(rbml_w, def_id); + encode_family(rbml_w, 'n'); + encode_name(rbml_w, item.ident.name); + encode_path(rbml_w, path); // Encode all the items in this module. for foreign_item in fm.items.iter() { - ebml_w.start_tag(tag_mod_child); - ebml_w.wr_str(def_to_string(local_def(foreign_item.id)).as_slice()); - ebml_w.end_tag(); + rbml_w.start_tag(tag_mod_child); + rbml_w.wr_str(def_to_string(local_def(foreign_item.id)).as_slice()); + rbml_w.end_tag(); } - encode_visibility(ebml_w, vis); - encode_stability(ebml_w, stab); - ebml_w.end_tag(); + encode_visibility(rbml_w, vis); + encode_stability(rbml_w, stab); + rbml_w.end_tag(); } ItemTy(..) => { - add_to_index(item, ebml_w, index); - ebml_w.start_tag(tag_items_data_item); - encode_def_id(ebml_w, def_id); - encode_family(ebml_w, 'y'); - encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id)); - encode_name(ebml_w, item.ident.name); - encode_path(ebml_w, path); - encode_visibility(ebml_w, vis); - encode_stability(ebml_w, stab); - ebml_w.end_tag(); + add_to_index(item, rbml_w, index); + rbml_w.start_tag(tag_items_data_item); + encode_def_id(rbml_w, def_id); + encode_family(rbml_w, 'y'); + encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(tcx, def_id)); + encode_name(rbml_w, item.ident.name); + encode_path(rbml_w, path); + encode_visibility(rbml_w, vis); + encode_stability(rbml_w, stab); + rbml_w.end_tag(); } ItemEnum(ref enum_definition, _) => { - add_to_index(item, ebml_w, index); - - ebml_w.start_tag(tag_items_data_item); - encode_def_id(ebml_w, def_id); - encode_family(ebml_w, 't'); - encode_item_variances(ebml_w, ecx, item.id); - encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id)); - encode_name(ebml_w, item.ident.name); - encode_attributes(ebml_w, item.attrs.as_slice()); + add_to_index(item, rbml_w, index); + + rbml_w.start_tag(tag_items_data_item); + encode_def_id(rbml_w, def_id); + encode_family(rbml_w, 't'); + encode_item_variances(rbml_w, ecx, item.id); + encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(tcx, def_id)); + encode_name(rbml_w, item.ident.name); + encode_attributes(rbml_w, item.attrs.as_slice()); for v in (*enum_definition).variants.iter() { - encode_variant_id(ebml_w, local_def(v.node.id)); + encode_variant_id(rbml_w, local_def(v.node.id)); } - encode_inlined_item(ecx, ebml_w, IIItemRef(item)); - encode_path(ebml_w, path); + encode_inlined_item(ecx, rbml_w, IIItemRef(item)); + encode_path(rbml_w, path); // Encode inherent implementations for this enumeration. - encode_inherent_implementations(ecx, ebml_w, def_id); + encode_inherent_implementations(ecx, rbml_w, def_id); - encode_visibility(ebml_w, vis); - encode_stability(ebml_w, stab); - ebml_w.end_tag(); + encode_visibility(rbml_w, vis); + encode_stability(rbml_w, stab); + rbml_w.end_tag(); encode_enum_variant_info(ecx, - ebml_w, + rbml_w, item.id, (*enum_definition).variants.as_slice(), index); @@ -1051,44 +1051,44 @@ fn add_to_index(item: &Item, ebml_w: &Encoder, the index, and the index needs to be in the item for the class itself */ let idx = encode_info_for_struct(ecx, - ebml_w, + rbml_w, fields.as_slice(), index); /* Index the class*/ - add_to_index(item, ebml_w, index); + add_to_index(item, rbml_w, index); /* Now, make an item for the class itself */ - ebml_w.start_tag(tag_items_data_item); - encode_def_id(ebml_w, def_id); - encode_family(ebml_w, 'S'); - encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id)); - - encode_item_variances(ebml_w, ecx, item.id); - encode_name(ebml_w, item.ident.name); - encode_attributes(ebml_w, item.attrs.as_slice()); - encode_path(ebml_w, path.clone()); - encode_stability(ebml_w, stab); - encode_visibility(ebml_w, vis); + rbml_w.start_tag(tag_items_data_item); + encode_def_id(rbml_w, def_id); + encode_family(rbml_w, 'S'); + encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(tcx, def_id)); + + encode_item_variances(rbml_w, ecx, item.id); + encode_name(rbml_w, item.ident.name); + encode_attributes(rbml_w, item.attrs.as_slice()); + encode_path(rbml_w, path.clone()); + encode_stability(rbml_w, stab); + encode_visibility(rbml_w, vis); /* Encode def_ids for each field and method for methods, write all the stuff get_trait_method needs to know*/ - encode_struct_fields(ebml_w, fields.as_slice(), def_id); + encode_struct_fields(rbml_w, fields.as_slice(), def_id); - encode_inlined_item(ecx, ebml_w, IIItemRef(item)); + encode_inlined_item(ecx, rbml_w, IIItemRef(item)); // Encode inherent implementations for this structure. - encode_inherent_implementations(ecx, ebml_w, def_id); + encode_inherent_implementations(ecx, rbml_w, def_id); /* Each class has its own index -- encode it */ - encode_index(ebml_w, idx, write_i64); - ebml_w.end_tag(); + encode_index(rbml_w, idx, write_i64); + rbml_w.end_tag(); // If this is a tuple-like struct, encode the type of the constructor. match struct_def.ctor_id { Some(ctor_id) => { - encode_info_for_struct_ctor(ecx, ebml_w, item.ident, + encode_info_for_struct_ctor(ecx, rbml_w, item.ident, ctor_id, index, def_id.node); } None => {} @@ -1100,38 +1100,38 @@ fn add_to_index(item: &Item, ebml_w: &Encoder, let impl_methods = tcx.impl_methods.borrow(); let methods = impl_methods.get(&def_id); - add_to_index(item, ebml_w, index); - ebml_w.start_tag(tag_items_data_item); - encode_def_id(ebml_w, def_id); - encode_family(ebml_w, 'i'); - encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id)); - encode_name(ebml_w, item.ident.name); - encode_attributes(ebml_w, item.attrs.as_slice()); + add_to_index(item, rbml_w, index); + rbml_w.start_tag(tag_items_data_item); + encode_def_id(rbml_w, def_id); + encode_family(rbml_w, 'i'); + encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(tcx, def_id)); + encode_name(rbml_w, item.ident.name); + encode_attributes(rbml_w, item.attrs.as_slice()); match ty.node { ast::TyPath(ref path, ref bounds, _) if path.segments .len() == 1 => { let ident = path.segments.last().unwrap().identifier; assert!(bounds.is_none()); - encode_impl_type_basename(ebml_w, ident); + encode_impl_type_basename(rbml_w, ident); } _ => {} } for &method_def_id in methods.iter() { - ebml_w.start_tag(tag_item_impl_method); + rbml_w.start_tag(tag_item_impl_method); let s = def_to_string(method_def_id); - ebml_w.writer.write(s.as_bytes()); - ebml_w.end_tag(); + rbml_w.writer.write(s.as_bytes()); + rbml_w.end_tag(); } for ast_trait_ref in opt_trait.iter() { let trait_ref = ty::node_id_to_trait_ref( tcx, ast_trait_ref.ref_id); - encode_trait_ref(ebml_w, ecx, &*trait_ref, tag_item_trait_ref); + encode_trait_ref(rbml_w, ecx, &*trait_ref, tag_item_trait_ref); let impl_vtables = ty::lookup_impl_vtables(tcx, def_id); - encode_impl_vtables(ebml_w, ecx, &impl_vtables); + encode_impl_vtables(rbml_w, ecx, &impl_vtables); } - encode_path(ebml_w, path.clone()); - encode_stability(ebml_w, stab); - ebml_w.end_tag(); + encode_path(rbml_w, path.clone()); + encode_stability(rbml_w, stab); + rbml_w.end_tag(); // Iterate down the methods, emitting them. We rely on the // assumption that all of the actually implemented methods @@ -1145,10 +1145,10 @@ fn add_to_index(item: &Item, ebml_w: &Encoder, index.push(entry { val: method_def_id.node as i64, - pos: ebml_w.writer.tell().unwrap(), + pos: rbml_w.writer.tell().unwrap(), }); encode_info_for_method(ecx, - ebml_w, + rbml_w, &*ty::method(tcx, method_def_id), path.clone(), false, @@ -1157,43 +1157,43 @@ fn add_to_index(item: &Item, ebml_w: &Encoder, } } ItemTrait(_, _, ref super_traits, ref ms) => { - add_to_index(item, ebml_w, index); - ebml_w.start_tag(tag_items_data_item); - encode_def_id(ebml_w, def_id); - encode_family(ebml_w, 'I'); - encode_item_variances(ebml_w, ecx, item.id); + add_to_index(item, rbml_w, index); + rbml_w.start_tag(tag_items_data_item); + encode_def_id(rbml_w, def_id); + encode_family(rbml_w, 'I'); + encode_item_variances(rbml_w, ecx, item.id); let trait_def = ty::lookup_trait_def(tcx, def_id); - encode_ty_type_param_defs(ebml_w, ecx, + encode_ty_type_param_defs(rbml_w, ecx, &trait_def.generics.types, tag_items_data_item_ty_param_bounds); - encode_region_param_defs(ebml_w, &trait_def.generics.regions); - encode_trait_ref(ebml_w, ecx, &*trait_def.trait_ref, tag_item_trait_ref); - encode_name(ebml_w, item.ident.name); - encode_attributes(ebml_w, item.attrs.as_slice()); - encode_visibility(ebml_w, vis); - encode_stability(ebml_w, stab); + encode_region_param_defs(rbml_w, &trait_def.generics.regions); + encode_trait_ref(rbml_w, ecx, &*trait_def.trait_ref, tag_item_trait_ref); + encode_name(rbml_w, item.ident.name); + encode_attributes(rbml_w, item.attrs.as_slice()); + encode_visibility(rbml_w, vis); + encode_stability(rbml_w, stab); for &method_def_id in ty::trait_method_def_ids(tcx, def_id).iter() { - ebml_w.start_tag(tag_item_trait_method); - encode_def_id(ebml_w, method_def_id); - ebml_w.end_tag(); + rbml_w.start_tag(tag_item_trait_method); + encode_def_id(rbml_w, method_def_id); + rbml_w.end_tag(); - ebml_w.start_tag(tag_mod_child); - ebml_w.wr_str(def_to_string(method_def_id).as_slice()); - ebml_w.end_tag(); + rbml_w.start_tag(tag_mod_child); + rbml_w.wr_str(def_to_string(method_def_id).as_slice()); + rbml_w.end_tag(); } - encode_path(ebml_w, path.clone()); + encode_path(rbml_w, path.clone()); // FIXME(#8559): This should use the tcx's supertrait cache instead of // reading the AST's list, because the former has already filtered out // the builtin-kinds-as-supertraits. See corresponding fixme in decoder. for ast_trait_ref in super_traits.iter() { let trait_ref = ty::node_id_to_trait_ref(ecx.tcx, ast_trait_ref.ref_id); - encode_trait_ref(ebml_w, ecx, &*trait_ref, tag_item_super_trait_ref); + encode_trait_ref(rbml_w, ecx, &*trait_ref, tag_item_super_trait_ref); } // Encode the implementations of this trait. - encode_extension_implementations(ecx, ebml_w, def_id); + encode_extension_implementations(ecx, rbml_w, def_id); - ebml_w.end_tag(); + rbml_w.end_tag(); // Now output the method info for each method. let r = ty::trait_method_def_ids(tcx, def_id); @@ -1204,32 +1204,32 @@ fn add_to_index(item: &Item, ebml_w: &Encoder, index.push(entry { val: method_def_id.node as i64, - pos: ebml_w.writer.tell().unwrap(), + pos: rbml_w.writer.tell().unwrap(), }); - ebml_w.start_tag(tag_items_data_item); + rbml_w.start_tag(tag_items_data_item); - encode_method_ty_fields(ecx, ebml_w, &*method_ty); - encode_parent_item(ebml_w, def_id); + encode_method_ty_fields(ecx, rbml_w, &*method_ty); + encode_parent_item(rbml_w, def_id); let stab = stability::lookup(tcx, method_def_id); - encode_stability(ebml_w, stab); + encode_stability(rbml_w, stab); let elem = ast_map::PathName(method_ty.ident.name); - encode_path(ebml_w, path.clone().chain(Some(elem).move_iter())); + encode_path(rbml_w, path.clone().chain(Some(elem).move_iter())); match method_ty.explicit_self { ty::StaticExplicitSelfCategory => { - encode_family(ebml_w, + encode_family(rbml_w, fn_style_static_method_family( method_ty.fty.fn_style)); let pty = ty::lookup_item_type(tcx, method_def_id); - encode_bounds_and_type(ebml_w, ecx, &pty); + encode_bounds_and_type(rbml_w, ecx, &pty); } _ => { - encode_family(ebml_w, + encode_family(rbml_w, style_fn_family( method_ty.fty.fn_style)); } @@ -1237,32 +1237,32 @@ fn add_to_index(item: &Item, ebml_w: &Encoder, match ms.get(i) { &Required(ref tm) => { - encode_attributes(ebml_w, tm.attrs.as_slice()); - encode_method_sort(ebml_w, 'r'); - encode_method_argument_names(ebml_w, &*tm.decl); + encode_attributes(rbml_w, tm.attrs.as_slice()); + encode_method_sort(rbml_w, 'r'); + encode_method_argument_names(rbml_w, &*tm.decl); } &Provided(m) => { - encode_attributes(ebml_w, m.attrs.as_slice()); + encode_attributes(rbml_w, m.attrs.as_slice()); // If this is a static method, we've already encoded // this. if method_ty.explicit_self != ty::StaticExplicitSelfCategory { // FIXME: I feel like there is something funny going on. let pty = ty::lookup_item_type(tcx, method_def_id); - encode_bounds_and_type(ebml_w, ecx, &pty); + encode_bounds_and_type(rbml_w, ecx, &pty); } - encode_method_sort(ebml_w, 'p'); - encode_inlined_item(ecx, ebml_w, + encode_method_sort(rbml_w, 'p'); + encode_inlined_item(ecx, rbml_w, IIMethodRef(def_id, true, &*m)); - encode_method_argument_names(ebml_w, &*m.pe_fn_decl()); + encode_method_argument_names(rbml_w, &*m.pe_fn_decl()); } } - ebml_w.end_tag(); + rbml_w.end_tag(); } // Encode inherent implementations for this trait. - encode_inherent_implementations(ecx, ebml_w, def_id); + encode_inherent_implementations(ecx, rbml_w, def_id); } ItemMac(..) => { // macros are encoded separately @@ -1271,61 +1271,61 @@ fn add_to_index(item: &Item, ebml_w: &Encoder, } fn encode_info_for_foreign_item(ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, nitem: &ForeignItem, index: &mut Vec>, path: PathElems, abi: abi::Abi) { index.push(entry { val: nitem.id as i64, - pos: ebml_w.writer.tell().unwrap(), + pos: rbml_w.writer.tell().unwrap(), }); - ebml_w.start_tag(tag_items_data_item); - encode_def_id(ebml_w, local_def(nitem.id)); + rbml_w.start_tag(tag_items_data_item); + encode_def_id(rbml_w, local_def(nitem.id)); match nitem.node { ForeignItemFn(..) => { - encode_family(ebml_w, style_fn_family(NormalFn)); - encode_bounds_and_type(ebml_w, ecx, + encode_family(rbml_w, style_fn_family(NormalFn)); + encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(ecx.tcx,local_def(nitem.id))); - encode_name(ebml_w, nitem.ident.name); + encode_name(rbml_w, nitem.ident.name); if abi == abi::RustIntrinsic { - encode_inlined_item(ecx, ebml_w, IIForeignRef(nitem)); + encode_inlined_item(ecx, rbml_w, IIForeignRef(nitem)); } else { - encode_symbol(ecx, ebml_w, nitem.id); + encode_symbol(ecx, rbml_w, nitem.id); } } ForeignItemStatic(_, mutbl) => { if mutbl { - encode_family(ebml_w, 'b'); + encode_family(rbml_w, 'b'); } else { - encode_family(ebml_w, 'c'); + encode_family(rbml_w, 'c'); } - encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, nitem.id)); - encode_symbol(ecx, ebml_w, nitem.id); - encode_name(ebml_w, nitem.ident.name); + encode_type(ecx, rbml_w, node_id_to_type(ecx.tcx, nitem.id)); + encode_symbol(ecx, rbml_w, nitem.id); + encode_name(rbml_w, nitem.ident.name); } } - encode_path(ebml_w, path); - ebml_w.end_tag(); + encode_path(rbml_w, path); + rbml_w.end_tag(); } fn my_visit_expr(_e: &Expr) { } fn my_visit_item(i: &Item, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, ecx_ptr: *const int, index: &mut Vec>) { - let mut ebml_w = unsafe { ebml_w.unsafe_clone() }; + let mut rbml_w = unsafe { rbml_w.unsafe_clone() }; // See above let ecx: &EncodeContext = unsafe { mem::transmute(ecx_ptr) }; ecx.tcx.map.with_path(i.id, |path| { - encode_info_for_item(ecx, &mut ebml_w, i, index, path, i.vis); + encode_info_for_item(ecx, &mut rbml_w, i, index, path, i.vis); }); } fn my_visit_foreign_item(ni: &ForeignItem, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, ecx_ptr:*const int, index: &mut Vec>) { // See above @@ -1334,19 +1334,19 @@ fn my_visit_foreign_item(ni: &ForeignItem, ecx.tcx.map.path_to_string(ni.id), token::get_ident(ni.ident)); - let mut ebml_w = unsafe { - ebml_w.unsafe_clone() + let mut rbml_w = unsafe { + rbml_w.unsafe_clone() }; let abi = ecx.tcx.map.get_foreign_abi(ni.id); ecx.tcx.map.with_path(ni.id, |path| { - encode_info_for_foreign_item(ecx, &mut ebml_w, + encode_info_for_foreign_item(ecx, &mut rbml_w, ni, index, path, abi); }); } struct EncodeVisitor<'a,'b> { - ebml_w_for_visit_item: &'a mut Encoder<'b>, + rbml_w_for_visit_item: &'a mut Encoder<'b>, ecx_ptr:*const int, index: &'a mut Vec>, } @@ -1359,31 +1359,31 @@ fn visit_expr(&mut self, ex: &Expr, _: ()) { fn visit_item(&mut self, i: &Item, _: ()) { visit::walk_item(self, i, ()); my_visit_item(i, - self.ebml_w_for_visit_item, + self.rbml_w_for_visit_item, self.ecx_ptr, self.index); } fn visit_foreign_item(&mut self, ni: &ForeignItem, _: ()) { visit::walk_foreign_item(self, ni, ()); my_visit_foreign_item(ni, - self.ebml_w_for_visit_item, + self.rbml_w_for_visit_item, self.ecx_ptr, self.index); } } fn encode_info_for_items(ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, krate: &Crate) -> Vec> { let mut index = Vec::new(); - ebml_w.start_tag(tag_items_data); + rbml_w.start_tag(tag_items_data); index.push(entry { val: CRATE_NODE_ID as i64, - pos: ebml_w.writer.tell().unwrap(), + pos: rbml_w.writer.tell().unwrap(), }); encode_info_for_mod(ecx, - ebml_w, + rbml_w, &krate.module, &[], CRATE_NODE_ID, @@ -1396,17 +1396,17 @@ fn encode_info_for_items(ecx: &EncodeContext, visit::walk_crate(&mut EncodeVisitor { index: &mut index, ecx_ptr: ecx_ptr, - ebml_w_for_visit_item: &mut *ebml_w, + rbml_w_for_visit_item: &mut *rbml_w, }, krate, ()); - ebml_w.end_tag(); + rbml_w.end_tag(); index } // Path and definition ID indexing -fn encode_index(ebml_w: &mut Encoder, index: Vec>, +fn encode_index(rbml_w: &mut Encoder, index: Vec>, write_fn: |&mut SeekableMemWriter, &T|) { let mut buckets: Vec>> = Vec::from_fn(256, |_| Vec::new()); for elt in index.move_iter() { @@ -1414,33 +1414,33 @@ fn encode_index(ebml_w: &mut Encoder, index: Vec>, buckets.get_mut(h % 256).push(elt); } - ebml_w.start_tag(tag_index); + rbml_w.start_tag(tag_index); let mut bucket_locs = Vec::new(); - ebml_w.start_tag(tag_index_buckets); + rbml_w.start_tag(tag_index_buckets); for bucket in buckets.iter() { - bucket_locs.push(ebml_w.writer.tell().unwrap()); - ebml_w.start_tag(tag_index_buckets_bucket); + bucket_locs.push(rbml_w.writer.tell().unwrap()); + rbml_w.start_tag(tag_index_buckets_bucket); for elt in bucket.iter() { - ebml_w.start_tag(tag_index_buckets_bucket_elt); + rbml_w.start_tag(tag_index_buckets_bucket_elt); assert!(elt.pos < 0xffff_ffff); { - let wr: &mut SeekableMemWriter = ebml_w.writer; + let wr: &mut SeekableMemWriter = rbml_w.writer; wr.write_be_u32(elt.pos as u32); } - write_fn(ebml_w.writer, &elt.val); - ebml_w.end_tag(); + write_fn(rbml_w.writer, &elt.val); + rbml_w.end_tag(); } - ebml_w.end_tag(); + rbml_w.end_tag(); } - ebml_w.end_tag(); - ebml_w.start_tag(tag_index_table); + rbml_w.end_tag(); + rbml_w.start_tag(tag_index_table); for pos in bucket_locs.iter() { assert!(*pos < 0xffff_ffff); - let wr: &mut SeekableMemWriter = ebml_w.writer; + let wr: &mut SeekableMemWriter = rbml_w.writer; wr.write_be_u32(*pos as u32); } - ebml_w.end_tag(); - ebml_w.end_tag(); + rbml_w.end_tag(); + rbml_w.end_tag(); } fn write_i64(writer: &mut SeekableMemWriter, &n: &i64) { @@ -1449,55 +1449,55 @@ fn write_i64(writer: &mut SeekableMemWriter, &n: &i64) { wr.write_be_u32(n as u32); } -fn encode_meta_item(ebml_w: &mut Encoder, mi: Gc) { +fn encode_meta_item(rbml_w: &mut Encoder, mi: Gc) { match mi.node { MetaWord(ref name) => { - ebml_w.start_tag(tag_meta_item_word); - ebml_w.start_tag(tag_meta_item_name); - ebml_w.writer.write(name.get().as_bytes()); - ebml_w.end_tag(); - ebml_w.end_tag(); + rbml_w.start_tag(tag_meta_item_word); + rbml_w.start_tag(tag_meta_item_name); + rbml_w.writer.write(name.get().as_bytes()); + rbml_w.end_tag(); + rbml_w.end_tag(); } MetaNameValue(ref name, ref value) => { match value.node { LitStr(ref value, _) => { - ebml_w.start_tag(tag_meta_item_name_value); - ebml_w.start_tag(tag_meta_item_name); - ebml_w.writer.write(name.get().as_bytes()); - ebml_w.end_tag(); - ebml_w.start_tag(tag_meta_item_value); - ebml_w.writer.write(value.get().as_bytes()); - ebml_w.end_tag(); - ebml_w.end_tag(); + rbml_w.start_tag(tag_meta_item_name_value); + rbml_w.start_tag(tag_meta_item_name); + rbml_w.writer.write(name.get().as_bytes()); + rbml_w.end_tag(); + rbml_w.start_tag(tag_meta_item_value); + rbml_w.writer.write(value.get().as_bytes()); + rbml_w.end_tag(); + rbml_w.end_tag(); } _ => {/* FIXME (#623): encode other variants */ } } } MetaList(ref name, ref items) => { - ebml_w.start_tag(tag_meta_item_list); - ebml_w.start_tag(tag_meta_item_name); - ebml_w.writer.write(name.get().as_bytes()); - ebml_w.end_tag(); + rbml_w.start_tag(tag_meta_item_list); + rbml_w.start_tag(tag_meta_item_name); + rbml_w.writer.write(name.get().as_bytes()); + rbml_w.end_tag(); for inner_item in items.iter() { - encode_meta_item(ebml_w, *inner_item); + encode_meta_item(rbml_w, *inner_item); } - ebml_w.end_tag(); + rbml_w.end_tag(); } } } -fn encode_attributes(ebml_w: &mut Encoder, attrs: &[Attribute]) { - ebml_w.start_tag(tag_attributes); +fn encode_attributes(rbml_w: &mut Encoder, attrs: &[Attribute]) { + rbml_w.start_tag(tag_attributes); for attr in attrs.iter() { - ebml_w.start_tag(tag_attribute); - ebml_w.wr_tagged_u8(tag_attribute_is_sugared_doc, attr.node.is_sugared_doc as u8); - encode_meta_item(ebml_w, attr.node.value); - ebml_w.end_tag(); + rbml_w.start_tag(tag_attribute); + rbml_w.wr_tagged_u8(tag_attribute_is_sugared_doc, attr.node.is_sugared_doc as u8); + encode_meta_item(rbml_w, attr.node.value); + rbml_w.end_tag(); } - ebml_w.end_tag(); + rbml_w.end_tag(); } -fn encode_crate_deps(ebml_w: &mut Encoder, cstore: &cstore::CStore) { +fn encode_crate_deps(rbml_w: &mut Encoder, cstore: &cstore::CStore) { fn get_ordered_deps(cstore: &cstore::CStore) -> Vec { // Pull the cnums and name,vers,hash out of cstore let mut deps = Vec::new(); @@ -1527,77 +1527,77 @@ fn get_ordered_deps(cstore: &cstore::CStore) -> Vec { // the assumption that they are numbered 1 to n. // FIXME (#2166): This is not nearly enough to support correct versioning // but is enough to get transitive crate dependencies working. - ebml_w.start_tag(tag_crate_deps); + rbml_w.start_tag(tag_crate_deps); let r = get_ordered_deps(cstore); for dep in r.iter() { - encode_crate_dep(ebml_w, (*dep).clone()); + encode_crate_dep(rbml_w, (*dep).clone()); } - ebml_w.end_tag(); + rbml_w.end_tag(); } -fn encode_lang_items(ecx: &EncodeContext, ebml_w: &mut Encoder) { - ebml_w.start_tag(tag_lang_items); +fn encode_lang_items(ecx: &EncodeContext, rbml_w: &mut Encoder) { + rbml_w.start_tag(tag_lang_items); for (i, def_id) in ecx.tcx.lang_items.items() { for id in def_id.iter() { if id.krate == LOCAL_CRATE { - ebml_w.start_tag(tag_lang_items_item); + rbml_w.start_tag(tag_lang_items_item); - ebml_w.start_tag(tag_lang_items_item_id); + rbml_w.start_tag(tag_lang_items_item_id); { - let wr: &mut SeekableMemWriter = ebml_w.writer; + let wr: &mut SeekableMemWriter = rbml_w.writer; wr.write_be_u32(i as u32); } - ebml_w.end_tag(); // tag_lang_items_item_id + rbml_w.end_tag(); // tag_lang_items_item_id - ebml_w.start_tag(tag_lang_items_item_node_id); + rbml_w.start_tag(tag_lang_items_item_node_id); { - let wr: &mut SeekableMemWriter = ebml_w.writer; + let wr: &mut SeekableMemWriter = rbml_w.writer; wr.write_be_u32(id.node as u32); } - ebml_w.end_tag(); // tag_lang_items_item_node_id + rbml_w.end_tag(); // tag_lang_items_item_node_id - ebml_w.end_tag(); // tag_lang_items_item + rbml_w.end_tag(); // tag_lang_items_item } } } for i in ecx.tcx.lang_items.missing.iter() { - ebml_w.wr_tagged_u32(tag_lang_items_missing, *i as u32); + rbml_w.wr_tagged_u32(tag_lang_items_missing, *i as u32); } - ebml_w.end_tag(); // tag_lang_items + rbml_w.end_tag(); // tag_lang_items } -fn encode_native_libraries(ecx: &EncodeContext, ebml_w: &mut Encoder) { - ebml_w.start_tag(tag_native_libraries); +fn encode_native_libraries(ecx: &EncodeContext, rbml_w: &mut Encoder) { + rbml_w.start_tag(tag_native_libraries); for &(ref lib, kind) in ecx.tcx.sess.cstore.get_used_libraries() .borrow().iter() { match kind { cstore::NativeStatic => {} // these libraries are not propagated cstore::NativeFramework | cstore::NativeUnknown => { - ebml_w.start_tag(tag_native_libraries_lib); + rbml_w.start_tag(tag_native_libraries_lib); - ebml_w.start_tag(tag_native_libraries_kind); - ebml_w.writer.write_be_u32(kind as u32); - ebml_w.end_tag(); + rbml_w.start_tag(tag_native_libraries_kind); + rbml_w.writer.write_be_u32(kind as u32); + rbml_w.end_tag(); - ebml_w.start_tag(tag_native_libraries_name); - ebml_w.writer.write(lib.as_bytes()); - ebml_w.end_tag(); + rbml_w.start_tag(tag_native_libraries_name); + rbml_w.writer.write(lib.as_bytes()); + rbml_w.end_tag(); - ebml_w.end_tag(); + rbml_w.end_tag(); } } } - ebml_w.end_tag(); + rbml_w.end_tag(); } -fn encode_plugin_registrar_fn(ecx: &EncodeContext, ebml_w: &mut Encoder) { +fn encode_plugin_registrar_fn(ecx: &EncodeContext, rbml_w: &mut Encoder) { match ecx.tcx.sess.plugin_registrar_fn.get() { - Some(id) => { ebml_w.wr_tagged_u32(tag_plugin_registrar_fn, id); } + Some(id) => { rbml_w.wr_tagged_u32(tag_plugin_registrar_fn, id); } None => {} } } @@ -1605,72 +1605,72 @@ fn encode_plugin_registrar_fn(ecx: &EncodeContext, ebml_w: &mut Encoder) { /// Given a span, write the text of that span into the output stream /// as an exported macro fn encode_macro_def(ecx: &EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, span: &syntax::codemap::Span) { let def = ecx.tcx.sess.codemap().span_to_snippet(*span) .expect("Unable to find source for macro"); - ebml_w.start_tag(tag_macro_def); - ebml_w.wr_str(def.as_slice()); - ebml_w.end_tag(); + rbml_w.start_tag(tag_macro_def); + rbml_w.wr_str(def.as_slice()); + rbml_w.end_tag(); } /// Serialize the text of the exported macros fn encode_macro_defs(ecx: &EncodeContext, krate: &Crate, - ebml_w: &mut Encoder) { - ebml_w.start_tag(tag_exported_macros); + rbml_w: &mut Encoder) { + rbml_w.start_tag(tag_exported_macros); for item in krate.exported_macros.iter() { - encode_macro_def(ecx, ebml_w, &item.span); + encode_macro_def(ecx, rbml_w, &item.span); } - ebml_w.end_tag(); + rbml_w.end_tag(); } fn encode_unboxed_closures<'a>( ecx: &'a EncodeContext, - ebml_w: &'a mut Encoder) { - ebml_w.start_tag(tag_unboxed_closures); + rbml_w: &'a mut Encoder) { + rbml_w.start_tag(tag_unboxed_closures); for (unboxed_closure_id, unboxed_closure_type) in ecx.tcx.unboxed_closure_types.borrow().iter() { if unboxed_closure_id.krate != LOCAL_CRATE { continue } - ebml_w.start_tag(tag_unboxed_closure); - encode_def_id(ebml_w, *unboxed_closure_id); - ebml_w.start_tag(tag_unboxed_closure_type); - write_closure_type(ecx, ebml_w, unboxed_closure_type); - ebml_w.end_tag(); - ebml_w.end_tag(); + rbml_w.start_tag(tag_unboxed_closure); + encode_def_id(rbml_w, *unboxed_closure_id); + rbml_w.start_tag(tag_unboxed_closure_type); + write_closure_type(ecx, rbml_w, unboxed_closure_type); + rbml_w.end_tag(); + rbml_w.end_tag(); } - ebml_w.end_tag(); + rbml_w.end_tag(); } -fn encode_struct_field_attrs(ebml_w: &mut Encoder, krate: &Crate) { +fn encode_struct_field_attrs(rbml_w: &mut Encoder, krate: &Crate) { struct StructFieldVisitor<'a, 'b> { - ebml_w: &'a mut Encoder<'b>, + rbml_w: &'a mut Encoder<'b>, } impl<'a, 'b> Visitor<()> for StructFieldVisitor<'a, 'b> { fn visit_struct_field(&mut self, field: &ast::StructField, _: ()) { - self.ebml_w.start_tag(tag_struct_field); - self.ebml_w.wr_tagged_u32(tag_struct_field_id, field.node.id); - encode_attributes(self.ebml_w, field.node.attrs.as_slice()); - self.ebml_w.end_tag(); + self.rbml_w.start_tag(tag_struct_field); + self.rbml_w.wr_tagged_u32(tag_struct_field_id, field.node.id); + encode_attributes(self.rbml_w, field.node.attrs.as_slice()); + self.rbml_w.end_tag(); } } - ebml_w.start_tag(tag_struct_fields); + rbml_w.start_tag(tag_struct_fields); visit::walk_crate(&mut StructFieldVisitor { - ebml_w: ebml_w + rbml_w: rbml_w }, krate, ()); - ebml_w.end_tag(); + rbml_w.end_tag(); } struct ImplVisitor<'a,'b,'c> { ecx: &'a EncodeContext<'b>, - ebml_w: &'a mut Encoder<'c>, + rbml_w: &'a mut Encoder<'c>, } impl<'a,'b,'c> Visitor<()> for ImplVisitor<'a,'b,'c> { @@ -1685,9 +1685,9 @@ fn visit_item(&mut self, item: &Item, _: ()) { // or if the trait is not defined in this crate. if Some(def_id) == self.ecx.tcx.lang_items.drop_trait() || def_id.krate != LOCAL_CRATE { - self.ebml_w.start_tag(tag_impls_impl); - encode_def_id(self.ebml_w, local_def(item.id)); - self.ebml_w.end_tag(); + self.rbml_w.start_tag(tag_impls_impl); + encode_def_id(self.rbml_w, local_def(item.id)); + self.rbml_w.end_tag(); } } _ => {} @@ -1708,55 +1708,55 @@ fn visit_item(&mut self, item: &Item, _: ()) { /// * Implementations of traits not defined in this crate. fn encode_impls<'a>(ecx: &'a EncodeContext, krate: &Crate, - ebml_w: &'a mut Encoder) { - ebml_w.start_tag(tag_impls); + rbml_w: &'a mut Encoder) { + rbml_w.start_tag(tag_impls); { let mut visitor = ImplVisitor { ecx: ecx, - ebml_w: ebml_w, + rbml_w: rbml_w, }; visit::walk_crate(&mut visitor, krate, ()); } - ebml_w.end_tag(); + rbml_w.end_tag(); } fn encode_misc_info(ecx: &EncodeContext, krate: &Crate, - ebml_w: &mut Encoder) { - ebml_w.start_tag(tag_misc_info); - ebml_w.start_tag(tag_misc_info_crate_items); + rbml_w: &mut Encoder) { + rbml_w.start_tag(tag_misc_info); + rbml_w.start_tag(tag_misc_info_crate_items); for &item in krate.module.items.iter() { - ebml_w.start_tag(tag_mod_child); - ebml_w.wr_str(def_to_string(local_def(item.id)).as_slice()); - ebml_w.end_tag(); + rbml_w.start_tag(tag_mod_child); + rbml_w.wr_str(def_to_string(local_def(item.id)).as_slice()); + rbml_w.end_tag(); each_auxiliary_node_id(item, |auxiliary_node_id| { - ebml_w.start_tag(tag_mod_child); - ebml_w.wr_str(def_to_string(local_def( + rbml_w.start_tag(tag_mod_child); + rbml_w.wr_str(def_to_string(local_def( auxiliary_node_id)).as_slice()); - ebml_w.end_tag(); + rbml_w.end_tag(); true }); } // Encode reexports for the root module. - encode_reexports(ecx, ebml_w, 0, ast_map::Values([].iter()).chain(None)); + encode_reexports(ecx, rbml_w, 0, ast_map::Values([].iter()).chain(None)); - ebml_w.end_tag(); - ebml_w.end_tag(); + rbml_w.end_tag(); + rbml_w.end_tag(); } -fn encode_reachable_extern_fns(ecx: &EncodeContext, ebml_w: &mut Encoder) { - ebml_w.start_tag(tag_reachable_extern_fns); +fn encode_reachable_extern_fns(ecx: &EncodeContext, rbml_w: &mut Encoder) { + rbml_w.start_tag(tag_reachable_extern_fns); for id in ecx.reachable.iter() { match ecx.tcx.map.find(*id) { Some(ast_map::NodeItem(i)) => { match i.node { ast::ItemFn(_, _, abi, _, _) if abi != abi::Rust => { - ebml_w.wr_tagged_u32(tag_reachable_extern_fn_id, *id); + rbml_w.wr_tagged_u32(tag_reachable_extern_fn_id, *id); } _ => {} } @@ -1765,41 +1765,41 @@ fn encode_reachable_extern_fns(ecx: &EncodeContext, ebml_w: &mut Encoder) { } } - ebml_w.end_tag(); + rbml_w.end_tag(); } -fn encode_crate_dep(ebml_w: &mut Encoder, +fn encode_crate_dep(rbml_w: &mut Encoder, dep: decoder::CrateDep) { - ebml_w.start_tag(tag_crate_dep); - ebml_w.start_tag(tag_crate_dep_crate_name); - ebml_w.writer.write(dep.name.as_bytes()); - ebml_w.end_tag(); - ebml_w.start_tag(tag_crate_dep_hash); - ebml_w.writer.write(dep.hash.as_str().as_bytes()); - ebml_w.end_tag(); - ebml_w.end_tag(); + rbml_w.start_tag(tag_crate_dep); + rbml_w.start_tag(tag_crate_dep_crate_name); + rbml_w.writer.write(dep.name.as_bytes()); + rbml_w.end_tag(); + rbml_w.start_tag(tag_crate_dep_hash); + rbml_w.writer.write(dep.hash.as_str().as_bytes()); + rbml_w.end_tag(); + rbml_w.end_tag(); } -fn encode_hash(ebml_w: &mut Encoder, hash: &Svh) { - ebml_w.start_tag(tag_crate_hash); - ebml_w.writer.write(hash.as_str().as_bytes()); - ebml_w.end_tag(); +fn encode_hash(rbml_w: &mut Encoder, hash: &Svh) { + rbml_w.start_tag(tag_crate_hash); + rbml_w.writer.write(hash.as_str().as_bytes()); + rbml_w.end_tag(); } -fn encode_crate_name(ebml_w: &mut Encoder, crate_name: &str) { - ebml_w.start_tag(tag_crate_crate_name); - ebml_w.writer.write(crate_name.as_bytes()); - ebml_w.end_tag(); +fn encode_crate_name(rbml_w: &mut Encoder, crate_name: &str) { + rbml_w.start_tag(tag_crate_crate_name); + rbml_w.writer.write(crate_name.as_bytes()); + rbml_w.end_tag(); } -fn encode_crate_triple(ebml_w: &mut Encoder, triple: &str) { - ebml_w.start_tag(tag_crate_triple); - ebml_w.writer.write(triple.as_bytes()); - ebml_w.end_tag(); +fn encode_crate_triple(rbml_w: &mut Encoder, triple: &str) { + rbml_w.start_tag(tag_crate_triple); + rbml_w.writer.write(triple.as_bytes()); + rbml_w.end_tag(); } -fn encode_dylib_dependency_formats(ebml_w: &mut Encoder, ecx: &EncodeContext) { - ebml_w.start_tag(tag_dylib_dependency_formats); +fn encode_dylib_dependency_formats(rbml_w: &mut Encoder, ecx: &EncodeContext) { + rbml_w.start_tag(tag_dylib_dependency_formats); match ecx.tcx.dependency_formats.borrow().find(&config::CrateTypeDylib) { Some(arr) => { let s = arr.iter().enumerate().filter_map(|(i, slot)| { @@ -1808,20 +1808,15 @@ fn encode_dylib_dependency_formats(ebml_w: &mut Encoder, ecx: &EncodeContext) { cstore::RequireStatic => "s", })).to_string()) }).collect::>(); - ebml_w.writer.write(s.connect(",").as_bytes()); + rbml_w.writer.write(s.connect(",").as_bytes()); } None => {} } - ebml_w.end_tag(); + rbml_w.end_tag(); } // NB: Increment this as you change the metadata encoding version. -pub static metadata_encoding_version : &'static [u8] = - &[0x72, //'r' as u8, - 0x75, //'u' as u8, - 0x73, //'s' as u8, - 0x74, //'t' as u8, - 0, 0, 0, 1 ]; +pub static metadata_encoding_version : &'static [u8] = &[b'r', b'u', b's', b't', 0, 0, 0, 1 ]; pub fn encode_metadata(parms: EncodeParams, krate: &Crate) -> Vec { let mut wr = SeekableMemWriter::new(); @@ -1885,79 +1880,79 @@ struct Stats { reachable: reachable, }; - let mut ebml_w = writer::Encoder::new(wr); + let mut rbml_w = writer::Encoder::new(wr); - encode_crate_name(&mut ebml_w, ecx.link_meta.crate_name.as_slice()); - encode_crate_triple(&mut ebml_w, + encode_crate_name(&mut rbml_w, ecx.link_meta.crate_name.as_slice()); + encode_crate_triple(&mut rbml_w, tcx.sess .targ_cfg .target_strs .target_triple .as_slice()); - encode_hash(&mut ebml_w, &ecx.link_meta.crate_hash); - encode_dylib_dependency_formats(&mut ebml_w, &ecx); + encode_hash(&mut rbml_w, &ecx.link_meta.crate_hash); + encode_dylib_dependency_formats(&mut rbml_w, &ecx); - let mut i = ebml_w.writer.tell().unwrap(); - encode_attributes(&mut ebml_w, krate.attrs.as_slice()); - stats.attr_bytes = ebml_w.writer.tell().unwrap() - i; + let mut i = rbml_w.writer.tell().unwrap(); + encode_attributes(&mut rbml_w, krate.attrs.as_slice()); + stats.attr_bytes = rbml_w.writer.tell().unwrap() - i; - i = ebml_w.writer.tell().unwrap(); - encode_crate_deps(&mut ebml_w, ecx.cstore); - stats.dep_bytes = ebml_w.writer.tell().unwrap() - i; + i = rbml_w.writer.tell().unwrap(); + encode_crate_deps(&mut rbml_w, ecx.cstore); + stats.dep_bytes = rbml_w.writer.tell().unwrap() - i; // Encode the language items. - i = ebml_w.writer.tell().unwrap(); - encode_lang_items(&ecx, &mut ebml_w); - stats.lang_item_bytes = ebml_w.writer.tell().unwrap() - i; + i = rbml_w.writer.tell().unwrap(); + encode_lang_items(&ecx, &mut rbml_w); + stats.lang_item_bytes = rbml_w.writer.tell().unwrap() - i; // Encode the native libraries used - i = ebml_w.writer.tell().unwrap(); - encode_native_libraries(&ecx, &mut ebml_w); - stats.native_lib_bytes = ebml_w.writer.tell().unwrap() - i; + i = rbml_w.writer.tell().unwrap(); + encode_native_libraries(&ecx, &mut rbml_w); + stats.native_lib_bytes = rbml_w.writer.tell().unwrap() - i; // Encode the plugin registrar function - i = ebml_w.writer.tell().unwrap(); - encode_plugin_registrar_fn(&ecx, &mut ebml_w); - stats.plugin_registrar_fn_bytes = ebml_w.writer.tell().unwrap() - i; + i = rbml_w.writer.tell().unwrap(); + encode_plugin_registrar_fn(&ecx, &mut rbml_w); + stats.plugin_registrar_fn_bytes = rbml_w.writer.tell().unwrap() - i; // Encode macro definitions - i = ebml_w.writer.tell().unwrap(); - encode_macro_defs(&ecx, krate, &mut ebml_w); - stats.macro_defs_bytes = ebml_w.writer.tell().unwrap() - i; + i = rbml_w.writer.tell().unwrap(); + encode_macro_defs(&ecx, krate, &mut rbml_w); + stats.macro_defs_bytes = rbml_w.writer.tell().unwrap() - i; // Encode the types of all unboxed closures in this crate. - i = ebml_w.writer.tell().unwrap(); - encode_unboxed_closures(&ecx, &mut ebml_w); - stats.unboxed_closure_bytes = ebml_w.writer.tell().unwrap() - i; + i = rbml_w.writer.tell().unwrap(); + encode_unboxed_closures(&ecx, &mut rbml_w); + stats.unboxed_closure_bytes = rbml_w.writer.tell().unwrap() - i; // Encode the def IDs of impls, for coherence checking. - i = ebml_w.writer.tell().unwrap(); - encode_impls(&ecx, krate, &mut ebml_w); - stats.impl_bytes = ebml_w.writer.tell().unwrap() - i; + i = rbml_w.writer.tell().unwrap(); + encode_impls(&ecx, krate, &mut rbml_w); + stats.impl_bytes = rbml_w.writer.tell().unwrap() - i; // Encode miscellaneous info. - i = ebml_w.writer.tell().unwrap(); - encode_misc_info(&ecx, krate, &mut ebml_w); - encode_reachable_extern_fns(&ecx, &mut ebml_w); - stats.misc_bytes = ebml_w.writer.tell().unwrap() - i; + i = rbml_w.writer.tell().unwrap(); + encode_misc_info(&ecx, krate, &mut rbml_w); + encode_reachable_extern_fns(&ecx, &mut rbml_w); + stats.misc_bytes = rbml_w.writer.tell().unwrap() - i; // Encode and index the items. - ebml_w.start_tag(tag_items); - i = ebml_w.writer.tell().unwrap(); - let items_index = encode_info_for_items(&ecx, &mut ebml_w, krate); - stats.item_bytes = ebml_w.writer.tell().unwrap() - i; + rbml_w.start_tag(tag_items); + i = rbml_w.writer.tell().unwrap(); + let items_index = encode_info_for_items(&ecx, &mut rbml_w, krate); + stats.item_bytes = rbml_w.writer.tell().unwrap() - i; - i = ebml_w.writer.tell().unwrap(); - encode_index(&mut ebml_w, items_index, write_i64); - stats.index_bytes = ebml_w.writer.tell().unwrap() - i; - ebml_w.end_tag(); + i = rbml_w.writer.tell().unwrap(); + encode_index(&mut rbml_w, items_index, write_i64); + stats.index_bytes = rbml_w.writer.tell().unwrap() - i; + rbml_w.end_tag(); - encode_struct_field_attrs(&mut ebml_w, krate); + encode_struct_field_attrs(&mut rbml_w, krate); - stats.total_bytes = ebml_w.writer.tell().unwrap(); + stats.total_bytes = rbml_w.writer.tell().unwrap(); if tcx.sess.meta_stats() { - for e in ebml_w.writer.get_ref().iter() { + for e in rbml_w.writer.get_ref().iter() { if *e == 0 { stats.zero_bytes += 1; } diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index f301dc3760db60200a76df86f24de4b34f83cbef..f16a46ed72933e6ef8bf8b6373571618f678c57e 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -27,7 +27,7 @@ use syntax::diagnostic::SpanHandler; use syntax::parse::token; -use util::io::SeekableMemWriter; +use rbml::io::SeekableMemWriter; macro_rules! mywrite( ($($arg:tt)*) => ({ write!($($arg)*); }) ) diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 9a587dd77418259b7000b976386c77c0cbdfdd23..f68501bbb9143e3acedfcc683f95073ee144ceae 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -28,7 +28,6 @@ use middle::subst::VecPerParamSpace; use middle::typeck::{MethodCall, MethodCallee, MethodOrigin}; use middle::{ty, typeck}; -use util::io::SeekableMemWriter; use util::ppaux::ty_to_string; use syntax::{ast, ast_map, ast_util, codemap, fold}; @@ -43,12 +42,12 @@ use std::mem; use std::gc::GC; -use serialize::ebml::reader; -use serialize::ebml; +use rbml::io::SeekableMemWriter; +use rbml::{reader, writer}; +use rbml; use serialize; use serialize::{Encoder, Encodable, EncoderHelpers, DecoderHelpers}; use serialize::{Decoder, Decodable}; -use writer = serialize::ebml::writer; #[cfg(test)] use syntax::parse; #[cfg(test)] use syntax::print::pprust; @@ -79,7 +78,7 @@ trait tr_intern { // Top-level methods. pub fn encode_inlined_item(ecx: &e::EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, ii: e::InlinedItemRef) { let id = match ii { e::IIItemRef(i) => i.id, @@ -88,26 +87,26 @@ pub fn encode_inlined_item(ecx: &e::EncodeContext, }; debug!("> Encoding inlined item: {} ({})", ecx.tcx.map.path_to_string(id), - ebml_w.writer.tell()); + rbml_w.writer.tell()); let ii = simplify_ast(ii); let id_range = ast_util::compute_id_range_for_inlined_item(&ii); - ebml_w.start_tag(c::tag_ast as uint); - id_range.encode(ebml_w); - encode_ast(ebml_w, ii); - encode_side_tables_for_ii(ecx, ebml_w, &ii); - ebml_w.end_tag(); + rbml_w.start_tag(c::tag_ast as uint); + id_range.encode(rbml_w); + encode_ast(rbml_w, ii); + encode_side_tables_for_ii(ecx, rbml_w, &ii); + rbml_w.end_tag(); debug!("< Encoded inlined fn: {} ({})", ecx.tcx.map.path_to_string(id), - ebml_w.writer.tell()); + rbml_w.writer.tell()); } pub fn decode_inlined_item(cdata: &cstore::crate_metadata, tcx: &ty::ctxt, path: Vec, - par_doc: ebml::Doc) + par_doc: rbml::Doc) -> Result> { let dcx = &DecodeContext { cdata: cdata, @@ -294,10 +293,10 @@ fn read_def_id_noxcx(&mut self, // We also have to adjust the spans: for now we just insert a dummy span, // but eventually we should add entries to the local codemap as required. -fn encode_ast(ebml_w: &mut Encoder, item: ast::InlinedItem) { - ebml_w.start_tag(c::tag_tree as uint); - item.encode(ebml_w); - ebml_w.end_tag(); +fn encode_ast(rbml_w: &mut Encoder, item: ast::InlinedItem) { + rbml_w.start_tag(c::tag_tree as uint); + item.encode(rbml_w); + rbml_w.end_tag(); } struct NestedItemsDropper; @@ -353,7 +352,7 @@ fn simplify_ast(ii: e::InlinedItemRef) -> ast::InlinedItem { } } -fn decode_ast(par_doc: ebml::Doc) -> ast::InlinedItem { +fn decode_ast(par_doc: rbml::Doc) -> ast::InlinedItem { let chi_doc = par_doc.get(c::tag_tree as uint); let mut d = reader::Decoder::new(chi_doc); Decodable::decode(&mut d).unwrap() @@ -401,7 +400,7 @@ fn renumber_and_map_ast(xcx: &ExtendedDecodeContext, // ______________________________________________________________________ // Encoding and decoding of ast::def -fn decode_def(xcx: &ExtendedDecodeContext, doc: ebml::Doc) -> def::Def { +fn decode_def(xcx: &ExtendedDecodeContext, doc: rbml::Doc) -> def::Def { let mut dsr = reader::Decoder::new(doc); let def: def::Def = Decodable::decode(&mut dsr).unwrap(); def.tr(xcx) @@ -526,16 +525,16 @@ fn tr(&self, xcx: &ExtendedDecodeContext) -> ty::TraitStore { // ______________________________________________________________________ // Encoding and decoding of freevar information -fn encode_freevar_entry(ebml_w: &mut Encoder, fv: &freevar_entry) { - (*fv).encode(ebml_w).unwrap(); +fn encode_freevar_entry(rbml_w: &mut Encoder, fv: &freevar_entry) { + (*fv).encode(rbml_w).unwrap(); } -trait ebml_decoder_helper { +trait rbml_decoder_helper { fn read_freevar_entry(&mut self, xcx: &ExtendedDecodeContext) -> freevar_entry; } -impl<'a> ebml_decoder_helper for reader::Decoder<'a> { +impl<'a> rbml_decoder_helper for reader::Decoder<'a> { fn read_freevar_entry(&mut self, xcx: &ExtendedDecodeContext) -> freevar_entry { let fv: freevar_entry = Decodable::decode(self).unwrap(); @@ -561,21 +560,21 @@ fn read_method_callee(&mut self, xcx: &ExtendedDecodeContext) } fn encode_method_callee(ecx: &e::EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, adjustment: typeck::ExprAdjustment, method: &MethodCallee) { - ebml_w.emit_struct("MethodCallee", 4, |ebml_w| { - ebml_w.emit_struct_field("adjustment", 0u, |ebml_w| { - adjustment.encode(ebml_w) + rbml_w.emit_struct("MethodCallee", 4, |rbml_w| { + rbml_w.emit_struct_field("adjustment", 0u, |rbml_w| { + adjustment.encode(rbml_w) }); - ebml_w.emit_struct_field("origin", 1u, |ebml_w| { - method.origin.encode(ebml_w) + rbml_w.emit_struct_field("origin", 1u, |rbml_w| { + method.origin.encode(rbml_w) }); - ebml_w.emit_struct_field("ty", 2u, |ebml_w| { - Ok(ebml_w.emit_ty(ecx, method.ty)) + rbml_w.emit_struct_field("ty", 2u, |rbml_w| { + Ok(rbml_w.emit_ty(ecx, method.ty)) }); - ebml_w.emit_struct_field("substs", 3u, |ebml_w| { - Ok(ebml_w.emit_substs(ecx, &method.substs)) + rbml_w.emit_struct_field("substs", 3u, |rbml_w| { + Ok(rbml_w.emit_substs(ecx, &method.substs)) }) }).unwrap(); } @@ -636,81 +635,81 @@ fn tr(&self, xcx: &ExtendedDecodeContext) -> MethodOrigin { // Encoding and decoding vtable_res fn encode_vtable_res_with_key(ecx: &e::EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, adjustment: typeck::ExprAdjustment, dr: &typeck::vtable_res) { - ebml_w.emit_struct("VtableWithKey", 2, |ebml_w| { - ebml_w.emit_struct_field("adjustment", 0u, |ebml_w| { - adjustment.encode(ebml_w) + rbml_w.emit_struct("VtableWithKey", 2, |rbml_w| { + rbml_w.emit_struct_field("adjustment", 0u, |rbml_w| { + adjustment.encode(rbml_w) }); - ebml_w.emit_struct_field("vtable_res", 1u, |ebml_w| { - Ok(encode_vtable_res(ecx, ebml_w, dr)) + rbml_w.emit_struct_field("vtable_res", 1u, |rbml_w| { + Ok(encode_vtable_res(ecx, rbml_w, dr)) }) }).unwrap() } pub fn encode_vtable_res(ecx: &e::EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, dr: &typeck::vtable_res) { // can't autogenerate this code because automatic code of // ty::t doesn't work, and there is no way (atm) to have // hand-written encoding routines combine with auto-generated // ones. perhaps we should fix this. encode_vec_per_param_space( - ebml_w, dr, - |ebml_w, param_tables| encode_vtable_param_res(ecx, ebml_w, + rbml_w, dr, + |rbml_w, param_tables| encode_vtable_param_res(ecx, rbml_w, param_tables)) } pub fn encode_vtable_param_res(ecx: &e::EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, param_tables: &typeck::vtable_param_res) { - ebml_w.emit_from_vec(param_tables.as_slice(), |ebml_w, vtable_origin| { - Ok(encode_vtable_origin(ecx, ebml_w, vtable_origin)) + rbml_w.emit_from_vec(param_tables.as_slice(), |rbml_w, vtable_origin| { + Ok(encode_vtable_origin(ecx, rbml_w, vtable_origin)) }).unwrap() } pub fn encode_vtable_origin(ecx: &e::EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, vtable_origin: &typeck::vtable_origin) { - ebml_w.emit_enum("vtable_origin", |ebml_w| { + rbml_w.emit_enum("vtable_origin", |rbml_w| { match *vtable_origin { typeck::vtable_static(def_id, ref substs, ref vtable_res) => { - ebml_w.emit_enum_variant("vtable_static", 0u, 3u, |ebml_w| { - ebml_w.emit_enum_variant_arg(0u, |ebml_w| { - Ok(ebml_w.emit_def_id(def_id)) + rbml_w.emit_enum_variant("vtable_static", 0u, 3u, |rbml_w| { + rbml_w.emit_enum_variant_arg(0u, |rbml_w| { + Ok(rbml_w.emit_def_id(def_id)) }); - ebml_w.emit_enum_variant_arg(1u, |ebml_w| { - Ok(ebml_w.emit_substs(ecx, substs)) + rbml_w.emit_enum_variant_arg(1u, |rbml_w| { + Ok(rbml_w.emit_substs(ecx, substs)) }); - ebml_w.emit_enum_variant_arg(2u, |ebml_w| { - Ok(encode_vtable_res(ecx, ebml_w, vtable_res)) + rbml_w.emit_enum_variant_arg(2u, |rbml_w| { + Ok(encode_vtable_res(ecx, rbml_w, vtable_res)) }) }) } typeck::vtable_param(pn, bn) => { - ebml_w.emit_enum_variant("vtable_param", 1u, 3u, |ebml_w| { - ebml_w.emit_enum_variant_arg(0u, |ebml_w| { - pn.encode(ebml_w) + rbml_w.emit_enum_variant("vtable_param", 1u, 3u, |rbml_w| { + rbml_w.emit_enum_variant_arg(0u, |rbml_w| { + pn.encode(rbml_w) }); - ebml_w.emit_enum_variant_arg(1u, |ebml_w| { - ebml_w.emit_uint(bn) + rbml_w.emit_enum_variant_arg(1u, |rbml_w| { + rbml_w.emit_uint(bn) }) }) } typeck::vtable_unboxed_closure(def_id) => { - ebml_w.emit_enum_variant("vtable_unboxed_closure", + rbml_w.emit_enum_variant("vtable_unboxed_closure", 2u, 1u, - |ebml_w| { - ebml_w.emit_enum_variant_arg(0u, |ebml_w| { - Ok(ebml_w.emit_def_id(def_id)) + |rbml_w| { + rbml_w.emit_enum_variant_arg(0u, |rbml_w| { + Ok(rbml_w.emit_def_id(def_id)) }) }) } typeck::vtable_error => { - ebml_w.emit_enum_variant("vtable_error", 3u, 3u, |_ebml_w| { + rbml_w.emit_enum_variant("vtable_error", 3u, 3u, |_rbml_w| { Ok(()) }) } @@ -831,12 +830,12 @@ fn read_vtable_origin(&mut self, // ___________________________________________________________________________ // -fn encode_vec_per_param_space(ebml_w: &mut Encoder, +fn encode_vec_per_param_space(rbml_w: &mut Encoder, v: &subst::VecPerParamSpace, f: |&mut Encoder, &T|) { for &space in subst::ParamSpace::all().iter() { - ebml_w.emit_from_vec(v.get_slice(space), - |ebml_w, n| Ok(f(ebml_w, n))).unwrap(); + rbml_w.emit_from_vec(v.get_slice(space), + |rbml_w, n| Ok(f(rbml_w, n))).unwrap(); } } @@ -858,7 +857,7 @@ fn ty_str_ctxt<'a>(&'a self) -> tyencode::ctxt<'a> { } } -trait ebml_writer_helpers { +trait rbml_writer_helpers { fn emit_closure_type(&mut self, ecx: &e::EncodeContext, closure_type: &ty::ClosureTy); @@ -874,7 +873,7 @@ fn emit_polytype(&mut self, fn emit_auto_adjustment(&mut self, ecx: &e::EncodeContext, adj: &ty::AutoAdjustment); } -impl<'a> ebml_writer_helpers for Encoder<'a> { +impl<'a> rbml_writer_helpers for Encoder<'a> { fn emit_closure_type(&mut self, ecx: &e::EncodeContext, closure_type: &ty::ClosureTy) { @@ -980,34 +979,34 @@ fn id(&mut self, id: ast::NodeId) { struct SideTableEncodingIdVisitor<'a,'b> { ecx_ptr: *const libc::c_void, - new_ebml_w: &'a mut Encoder<'b>, + new_rbml_w: &'a mut Encoder<'b>, } impl<'a,'b> ast_util::IdVisitingOperation for SideTableEncodingIdVisitor<'a,'b> { fn visit_id(&self, id: ast::NodeId) { - // Note: this will cause a copy of ebml_w, which is bad as + // Note: this will cause a copy of rbml_w, which is bad as // it is mutable. But I believe it's harmless since we generate // balanced EBML. // // FIXME(pcwalton): Don't copy this way. - let mut new_ebml_w = unsafe { - self.new_ebml_w.unsafe_clone() + let mut new_rbml_w = unsafe { + self.new_rbml_w.unsafe_clone() }; // See above let ecx: &e::EncodeContext = unsafe { mem::transmute(self.ecx_ptr) }; - encode_side_tables_for_id(ecx, &mut new_ebml_w, id) + encode_side_tables_for_id(ecx, &mut new_rbml_w, id) } } fn encode_side_tables_for_ii(ecx: &e::EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, ii: &ast::InlinedItem) { - ebml_w.start_tag(c::tag_table as uint); - let mut new_ebml_w = unsafe { - ebml_w.unsafe_clone() + rbml_w.start_tag(c::tag_table as uint); + let mut new_rbml_w = unsafe { + rbml_w.unsafe_clone() }; // Because the ast visitor uses @IdVisitingOperation, I can't pass in @@ -1017,49 +1016,49 @@ fn encode_side_tables_for_ii(ecx: &e::EncodeContext, ecx_ptr: unsafe { mem::transmute(ecx) }, - new_ebml_w: &mut new_ebml_w, + new_rbml_w: &mut new_rbml_w, }); - ebml_w.end_tag(); + rbml_w.end_tag(); } fn encode_side_tables_for_id(ecx: &e::EncodeContext, - ebml_w: &mut Encoder, + rbml_w: &mut Encoder, id: ast::NodeId) { let tcx = ecx.tcx; debug!("Encoding side tables for id {}", id); for def in tcx.def_map.borrow().find(&id).iter() { - ebml_w.tag(c::tag_table_def, |ebml_w| { - ebml_w.id(id); - ebml_w.tag(c::tag_table_val, |ebml_w| (*def).encode(ebml_w).unwrap()); + rbml_w.tag(c::tag_table_def, |rbml_w| { + rbml_w.id(id); + rbml_w.tag(c::tag_table_val, |rbml_w| (*def).encode(rbml_w).unwrap()); }) } for &ty in tcx.node_types.borrow().find(&(id as uint)).iter() { - ebml_w.tag(c::tag_table_node_type, |ebml_w| { - ebml_w.id(id); - ebml_w.tag(c::tag_table_val, |ebml_w| { - ebml_w.emit_ty(ecx, *ty); + rbml_w.tag(c::tag_table_node_type, |rbml_w| { + rbml_w.id(id); + rbml_w.tag(c::tag_table_val, |rbml_w| { + rbml_w.emit_ty(ecx, *ty); }) }) } for &item_substs in tcx.item_substs.borrow().find(&id).iter() { - ebml_w.tag(c::tag_table_item_subst, |ebml_w| { - ebml_w.id(id); - ebml_w.tag(c::tag_table_val, |ebml_w| { - ebml_w.emit_substs(ecx, &item_substs.substs); + rbml_w.tag(c::tag_table_item_subst, |rbml_w| { + rbml_w.id(id); + rbml_w.tag(c::tag_table_val, |rbml_w| { + rbml_w.emit_substs(ecx, &item_substs.substs); }) }) } for &fv in tcx.freevars.borrow().find(&id).iter() { - ebml_w.tag(c::tag_table_freevars, |ebml_w| { - ebml_w.id(id); - ebml_w.tag(c::tag_table_val, |ebml_w| { - ebml_w.emit_from_vec(fv.as_slice(), |ebml_w, fv_entry| { - Ok(encode_freevar_entry(ebml_w, fv_entry)) + rbml_w.tag(c::tag_table_freevars, |rbml_w| { + rbml_w.id(id); + rbml_w.tag(c::tag_table_val, |rbml_w| { + rbml_w.emit_from_vec(fv.as_slice(), |rbml_w, fv_entry| { + Ok(encode_freevar_entry(rbml_w, fv_entry)) }); }) }) @@ -1067,38 +1066,38 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id }; for &pty in tcx.tcache.borrow().find(&lid).iter() { - ebml_w.tag(c::tag_table_tcache, |ebml_w| { - ebml_w.id(id); - ebml_w.tag(c::tag_table_val, |ebml_w| { - ebml_w.emit_polytype(ecx, pty.clone()); + rbml_w.tag(c::tag_table_tcache, |rbml_w| { + rbml_w.id(id); + rbml_w.tag(c::tag_table_val, |rbml_w| { + rbml_w.emit_polytype(ecx, pty.clone()); }) }) } for &type_param_def in tcx.ty_param_defs.borrow().find(&id).iter() { - ebml_w.tag(c::tag_table_param_defs, |ebml_w| { - ebml_w.id(id); - ebml_w.tag(c::tag_table_val, |ebml_w| { - ebml_w.emit_type_param_def(ecx, type_param_def) + rbml_w.tag(c::tag_table_param_defs, |rbml_w| { + rbml_w.id(id); + rbml_w.tag(c::tag_table_val, |rbml_w| { + rbml_w.emit_type_param_def(ecx, type_param_def) }) }) } let method_call = MethodCall::expr(id); for &method in tcx.method_map.borrow().find(&method_call).iter() { - ebml_w.tag(c::tag_table_method_map, |ebml_w| { - ebml_w.id(id); - ebml_w.tag(c::tag_table_val, |ebml_w| { - encode_method_callee(ecx, ebml_w, method_call.adjustment, method) + rbml_w.tag(c::tag_table_method_map, |rbml_w| { + rbml_w.id(id); + rbml_w.tag(c::tag_table_val, |rbml_w| { + encode_method_callee(ecx, rbml_w, method_call.adjustment, method) }) }) } for &dr in tcx.vtable_map.borrow().find(&method_call).iter() { - ebml_w.tag(c::tag_table_vtable_map, |ebml_w| { - ebml_w.id(id); - ebml_w.tag(c::tag_table_val, |ebml_w| { - encode_vtable_res_with_key(ecx, ebml_w, method_call.adjustment, dr); + rbml_w.tag(c::tag_table_vtable_map, |rbml_w| { + rbml_w.id(id); + rbml_w.tag(c::tag_table_val, |rbml_w| { + encode_vtable_res_with_key(ecx, rbml_w, method_call.adjustment, dr); }) }) } @@ -1109,20 +1108,20 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, for autoderef in range(0, adj.autoderefs) { let method_call = MethodCall::autoderef(id, autoderef); for &method in tcx.method_map.borrow().find(&method_call).iter() { - ebml_w.tag(c::tag_table_method_map, |ebml_w| { - ebml_w.id(id); - ebml_w.tag(c::tag_table_val, |ebml_w| { - encode_method_callee(ecx, ebml_w, + rbml_w.tag(c::tag_table_method_map, |rbml_w| { + rbml_w.id(id); + rbml_w.tag(c::tag_table_val, |rbml_w| { + encode_method_callee(ecx, rbml_w, method_call.adjustment, method) }) }) } for &dr in tcx.vtable_map.borrow().find(&method_call).iter() { - ebml_w.tag(c::tag_table_vtable_map, |ebml_w| { - ebml_w.id(id); - ebml_w.tag(c::tag_table_val, |ebml_w| { - encode_vtable_res_with_key(ecx, ebml_w, + rbml_w.tag(c::tag_table_vtable_map, |rbml_w| { + rbml_w.id(id); + rbml_w.tag(c::tag_table_val, |rbml_w| { + encode_vtable_res_with_key(ecx, rbml_w, method_call.adjustment, dr); }) }) @@ -1132,19 +1131,19 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, ty::AutoObject(..) => { let method_call = MethodCall::autoobject(id); for &method in tcx.method_map.borrow().find(&method_call).iter() { - ebml_w.tag(c::tag_table_method_map, |ebml_w| { - ebml_w.id(id); - ebml_w.tag(c::tag_table_val, |ebml_w| { - encode_method_callee(ecx, ebml_w, method_call.adjustment, method) + rbml_w.tag(c::tag_table_method_map, |rbml_w| { + rbml_w.id(id); + rbml_w.tag(c::tag_table_val, |rbml_w| { + encode_method_callee(ecx, rbml_w, method_call.adjustment, method) }) }) } for &dr in tcx.vtable_map.borrow().find(&method_call).iter() { - ebml_w.tag(c::tag_table_vtable_map, |ebml_w| { - ebml_w.id(id); - ebml_w.tag(c::tag_table_val, |ebml_w| { - encode_vtable_res_with_key(ecx, ebml_w, method_call.adjustment, dr); + rbml_w.tag(c::tag_table_vtable_map, |rbml_w| { + rbml_w.id(id); + rbml_w.tag(c::tag_table_val, |rbml_w| { + encode_vtable_res_with_key(ecx, rbml_w, method_call.adjustment, dr); }) }) } @@ -1152,10 +1151,10 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, _ => {} } - ebml_w.tag(c::tag_table_adjustments, |ebml_w| { - ebml_w.id(id); - ebml_w.tag(c::tag_table_val, |ebml_w| { - ebml_w.emit_auto_adjustment(ecx, adj); + rbml_w.tag(c::tag_table_adjustments, |rbml_w| { + rbml_w.id(id); + rbml_w.tag(c::tag_table_val, |rbml_w| { + rbml_w.emit_auto_adjustment(ecx, adj); }) }) } @@ -1164,10 +1163,10 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, .borrow() .find(&ast_util::local_def(id)) .iter() { - ebml_w.tag(c::tag_table_unboxed_closure_type, |ebml_w| { - ebml_w.id(id); - ebml_w.tag(c::tag_table_val, |ebml_w| { - ebml_w.emit_closure_type(ecx, *unboxed_closure_type) + rbml_w.tag(c::tag_table_unboxed_closure_type, |rbml_w| { + rbml_w.id(id); + rbml_w.tag(c::tag_table_val, |rbml_w| { + rbml_w.emit_closure_type(ecx, *unboxed_closure_type) }) }) } @@ -1178,14 +1177,14 @@ trait doc_decoder_helpers { fn opt_child(&self, tag: c::astencode_tag) -> Option; } -impl<'a> doc_decoder_helpers for ebml::Doc<'a> { +impl<'a> doc_decoder_helpers for rbml::Doc<'a> { fn as_int(&self) -> int { reader::doc_as_u64(*self) as int } - fn opt_child(&self, tag: c::astencode_tag) -> Option> { + fn opt_child(&self, tag: c::astencode_tag) -> Option> { reader::maybe_get_doc(*self, tag as uint) } } -trait ebml_decoder_decoder_helpers { +trait rbml_decoder_decoder_helpers { fn read_ty(&mut self, xcx: &ExtendedDecodeContext) -> ty::t; fn read_tys(&mut self, xcx: &ExtendedDecodeContext) -> Vec; fn read_type_param_def(&mut self, xcx: &ExtendedDecodeContext) @@ -1214,7 +1213,7 @@ fn read_substs_noxcx(&mut self, tcx: &ty::ctxt, -> subst::Substs; } -impl<'a> ebml_decoder_decoder_helpers for reader::Decoder<'a> { +impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> { fn read_ty_noxcx(&mut self, tcx: &ty::ctxt, cdata: &cstore::crate_metadata) -> ty::t { self.read_opaque(|_, doc| { @@ -1270,7 +1269,7 @@ fn read_ty(&mut self, xcx: &ExtendedDecodeContext) -> ty::t { Ok(ty) }).unwrap(); - fn type_string(doc: ebml::Doc) -> String { + fn type_string(doc: rbml::Doc) -> String { let mut str = String::new(); for i in range(doc.start, doc.end) { str.push_char(doc.data[i] as char); @@ -1423,7 +1422,7 @@ fn convert_def_id(&mut self, } fn decode_side_tables(xcx: &ExtendedDecodeContext, - ast_doc: ebml::Doc) { + ast_doc: rbml::Doc) { let dcx = xcx.dcx; let tbl_doc = ast_doc.get(c::tag_table as uint); reader::docs(tbl_doc, |tag, entry_doc| { @@ -1527,14 +1526,14 @@ fn decode_side_tables(xcx: &ExtendedDecodeContext, // Testing of astencode_gen #[cfg(test)] -fn encode_item_ast(ebml_w: &mut Encoder, item: Gc) { - ebml_w.start_tag(c::tag_tree as uint); - (*item).encode(ebml_w); - ebml_w.end_tag(); +fn encode_item_ast(rbml_w: &mut Encoder, item: Gc) { + rbml_w.start_tag(c::tag_tree as uint); + (*item).encode(rbml_w); + rbml_w.end_tag(); } #[cfg(test)] -fn decode_item_ast(par_doc: ebml::Doc) -> Gc { +fn decode_item_ast(par_doc: rbml::Doc) -> Gc { let chi_doc = par_doc.get(c::tag_tree as uint); let mut d = reader::Decoder::new(chi_doc); box(GC) Decodable::decode(&mut d).unwrap() @@ -1576,11 +1575,11 @@ fn roundtrip(in_item: Option>) { let in_item = in_item.unwrap(); let mut wr = SeekableMemWriter::new(); { - let mut ebml_w = writer::Encoder::new(&mut wr); - encode_item_ast(&mut ebml_w, in_item); + let mut rbml_w = writer::Encoder::new(&mut wr); + encode_item_ast(&mut rbml_w, in_item); } - let ebml_doc = ebml::Doc::new(wr.get_ref()); - let out_item = decode_item_ast(ebml_doc); + let rbml_doc = rbml::Doc::new(wr.get_ref()); + let out_item = decode_item_ast(rbml_doc); assert!(in_item == out_item); } diff --git a/src/librustc/middle/subst.rs b/src/librustc/middle/subst.rs index ef0709316f0af43c880808dc45b4e89c6296ae41..673872103af60977c3ea6dfa76ed81201f03a21a 100644 --- a/src/librustc/middle/subst.rs +++ b/src/librustc/middle/subst.rs @@ -584,9 +584,11 @@ fn fold_region(&mut self, r: ty::Region) -> ty::Region { self.tcx().sess.span_bug( span, format!("Type parameter out of range \ - when substituting in region {} (root type={})", + when substituting in region {} (root type={}) \ + (space={}, index={})", region_name.as_str(), - self.root_ty.repr(self.tcx())).as_slice()); + self.root_ty.repr(self.tcx()), + space, i).as_slice()); } } } diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index ea301784c930e0966412a5ae13b8c2bad6d1ac16..f1e84b8da8105b17a008586050efb6d898a173ee 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -485,6 +485,9 @@ pub fn get_res_dtor(ccx: &CrateContext, if !substs.types.is_empty() { assert_eq!(did.krate, ast::LOCAL_CRATE); + // Since we're in trans we don't care for any region parameters + let ref substs = subst::Substs::erased(substs.types.clone()); + let vtables = typeck::check::vtable::trans_resolve_method(ccx.tcx(), did.node, substs); let (val, _) = monomorphize::monomorphic_fn(ccx, did, substs, vtables, None); @@ -2593,7 +2596,7 @@ pub fn write_metadata(cx: &CrateContext, krate: &ast::Crate) -> Vec { } let encode_inlined_item: encoder::EncodeInlinedItem = - |ecx, ebml_w, ii| astencode::encode_inlined_item(ecx, ebml_w, ii); + |ecx, rbml_w, ii| astencode::encode_inlined_item(ecx, rbml_w, ii); let encode_parms = crate_ctxt_to_encode_parms(cx, encode_inlined_item); let metadata = encoder::encode_metadata(encode_parms, krate); diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index 2fd468d8fda8fbe248c90b694fa146dc60fe4244..7d546aac0cbaed28eecce64105d3c2760be91b80 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -109,7 +109,7 @@ fn const_vec(cx: &CrateContext, e: &ast::Expr, (v, llunitty, inlineable.iter().fold(true, |a, &b| a && b)) } -fn const_addr_of(cx: &CrateContext, cv: ValueRef) -> ValueRef { +pub fn const_addr_of(cx: &CrateContext, cv: ValueRef) -> ValueRef { unsafe { let gv = "const".with_c_str(|name| { llvm::LLVMAddGlobal(cx.llmod, val_ty(cv).to_ref(), name) diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs index dd8fe5e9303a56145601274cdb087f4af69652d1..2fd2e69cfc3bcbf31ec72682b5deb2e07a36e56d 100644 --- a/src/librustc/middle/trans/controlflow.rs +++ b/src/librustc/middle/trans/controlflow.rs @@ -20,6 +20,7 @@ use middle::trans::cleanup::CleanupMethods; use middle::trans::cleanup; use middle::trans::common::*; +use middle::trans::consts; use middle::trans::datum; use middle::trans::debuginfo; use middle::trans::expr; @@ -477,14 +478,6 @@ pub fn trans_ret<'a>(bcx: &'a Block<'a>, return bcx; } -fn str_slice_arg<'a>(bcx: &'a Block<'a>, s: InternedString) -> ValueRef { - let ccx = bcx.ccx(); - let s = C_str_slice(ccx, s); - let slot = alloca(bcx, val_ty(s), "__temp"); - Store(bcx, s, slot); - slot -} - pub fn trans_fail<'a>( bcx: &'a Block<'a>, sp: Span, @@ -493,12 +486,14 @@ pub fn trans_fail<'a>( let ccx = bcx.ccx(); let _icx = push_ctxt("trans_fail_value"); - let v_str = str_slice_arg(bcx, fail_str); + let v_str = C_str_slice(ccx, fail_str); let loc = bcx.sess().codemap().lookup_char_pos(sp.lo); let filename = token::intern_and_get_ident(loc.file.name.as_slice()); - let v_filename = str_slice_arg(bcx, filename); - let v_line = loc.line as int; - let args = vec!(v_str, v_filename, C_int(ccx, v_line)); + let filename = C_str_slice(ccx, filename); + let line = C_int(ccx, loc.line as int); + let expr_file_line_const = C_struct(ccx, &[v_str, filename, line], false); + let expr_file_line = consts::const_addr_of(ccx, expr_file_line_const); + let args = vec!(expr_file_line); let did = langcall(bcx, Some(sp), "", FailFnLangItem); let bcx = callee::trans_lang_call(bcx, did, @@ -514,6 +509,7 @@ pub fn trans_fail_bounds_check<'a>( index: ValueRef, len: ValueRef) -> &'a Block<'a> { + let ccx = bcx.ccx(); let _icx = push_ctxt("trans_fail_bounds_check"); // Extract the file/line from the span @@ -521,9 +517,11 @@ pub fn trans_fail_bounds_check<'a>( let filename = token::intern_and_get_ident(loc.file.name.as_slice()); // Invoke the lang item - let filename = str_slice_arg(bcx, filename); - let line = C_int(bcx.ccx(), loc.line as int); - let args = vec!(filename, line, index, len); + let filename = C_str_slice(ccx, filename); + let line = C_int(ccx, loc.line as int); + let file_line_const = C_struct(ccx, &[filename, line], false); + let file_line = consts::const_addr_of(ccx, file_line_const); + let args = vec!(file_line, index, len); let did = langcall(bcx, Some(sp), "", FailBoundsCheckFnLangItem); let bcx = callee::trans_lang_call(bcx, did, diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index bbb6e162ecb992e9ff7ebabbbe9976dc074f047d..fd2ccc539e2ad24620417c9d512a38387df1364d 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -3547,6 +3547,17 @@ fn check_fn_for_vec_elements_expected(fcx: &FnCtxt, span_err!(tcx.sess, path.span, E0071, "`{}` does not name a structure", pprust::path_to_string(path)); + + // Make sure to still write the types + // otherwise we might ICE + fcx.write_error(id); + for field in fields.iter() { + check_expr(fcx, &*field.expr); + } + match base_expr { + Some(ref base) => check_expr(fcx, &**base), + None => {} + } } } diff --git a/src/librustrt/at_exit_imp.rs b/src/librustrt/at_exit_imp.rs index c9188e81975c614f9bcd93f384012d9841b03299..9e4c42296769e56b5bb615aa08e397a413b02f7c 100644 --- a/src/librustrt/at_exit_imp.rs +++ b/src/librustrt/at_exit_imp.rs @@ -31,7 +31,7 @@ pub fn init() { let state: Box = box Exclusive::new(Vec::new()); unsafe { rtassert!(!RUNNING.load(atomics::SeqCst)); - rtassert!(QUEUE.swap(mem::transmute(state), atomics::SeqCst) == 0); + assert!(QUEUE.swap(mem::transmute(state), atomics::SeqCst) == 0); } } diff --git a/src/librustrt/task.rs b/src/librustrt/task.rs index e3d9b7d136ec2e05b6b16816e89dbb29d35418d9..5873c8273e790f16a47f15c94e2cca9ce9d0d80c 100644 --- a/src/librustrt/task.rs +++ b/src/librustrt/task.rs @@ -649,7 +649,7 @@ struct List { #[should_fail] fn test_begin_unwind() { use std::rt::unwind::begin_unwind; - begin_unwind("cause", file!(), line!()) + begin_unwind("cause", &(file!(), line!())) } #[test] diff --git a/src/librustrt/unwind.rs b/src/librustrt/unwind.rs index 5dfeb15afb84ad013f46c60562479d3e5ed5272b..344d3a0f103d3138eec1d743676f0821c1df19d0 100644 --- a/src/librustrt/unwind.rs +++ b/src/librustrt/unwind.rs @@ -417,8 +417,8 @@ fn write(&mut self, buf: &[u8]) -> fmt::Result { begin_unwind_inner(box String::from_utf8(v).unwrap(), file_line) } -// FIXME: Need to change expr_fail in AstBuilder to change this to &(str, uint) /// This is the entry point of unwinding for fail!() and assert!(). +#[cfg(stage0)] #[inline(never)] #[cold] // avoid code bloat at the call sites as much as possible pub fn begin_unwind(msg: M, file: &'static str, line: uint) -> ! { // Note that this should be the only allocation performed in this code path. @@ -432,6 +432,21 @@ pub fn begin_unwind(msg: M, file: &'static str, line: uint) -> ! begin_unwind_inner(box msg, &(file, line)) } +/// This is the entry point of unwinding for fail!() and assert!(). +#[cfg(not(stage0))] +#[inline(never)] #[cold] // avoid code bloat at the call sites as much as possible +pub fn begin_unwind(msg: M, file_line: &(&'static str, uint)) -> ! { + // Note that this should be the only allocation performed in this code path. + // Currently this means that fail!() on OOM will invoke this code path, + // but then again we're not really ready for failing on OOM anyway. If + // we do start doing this, then we should propagate this allocation to + // be performed in the parent of this task instead of the task that's + // failing. + + // see below for why we do the `Any` coercion here. + begin_unwind_inner(box msg, file_line) +} + /// The core of the unwinding. /// /// This is non-generic to avoid instantiation bloat in other crates diff --git a/src/libsemver/lib.rs b/src/libsemver/lib.rs index 41f7aa5012d49bab88d1e4bb3808a808f59e57b6..3cc5189c024db7b4a5dcd15f09c6928866bbcfb0 100644 --- a/src/libsemver/lib.rs +++ b/src/libsemver/lib.rs @@ -29,7 +29,8 @@ //! `0.8.1-rc.3.0+20130922.linux`. #![crate_name = "semver"] -#![experimental] +#![deprecated = "This is now a cargo package located at: \ + https://github.com/rust-lang/semver"] #![crate_type = "rlib"] #![crate_type = "dylib"] #![license = "MIT/ASL2"] diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index 5cb272a19eb886fff9edac35180c253c8dae5088..5c35ad8523382cef363099662becabdac6c3a677 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -39,6 +39,5 @@ mod collection_impls; pub mod base64; -pub mod ebml; pub mod hex; pub mod json; diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs index a7d697c8665ef639132dac200953b41e65d885c1..80fe05fcea5cdf99f1cdc14179c4af21dfd3324d 100644 --- a/src/libstd/c_vec.rs +++ b/src/libstd/c_vec.rs @@ -43,6 +43,7 @@ use ptr::RawPtr; use ptr; use raw; +use slice::Vector; /// The type representing a foreign chunk of memory pub struct CVec { @@ -101,13 +102,6 @@ pub unsafe fn new_with_dtor(base: *mut T, len: uint, } } - /// View the stored data as a slice. - pub fn as_slice<'a>(&'a self) -> &'a [T] { - unsafe { - mem::transmute(raw::Slice { data: self.base as *const T, len: self.len }) - } - } - /// View the stored data as a mutable slice. pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] { unsafe { @@ -151,6 +145,15 @@ pub unsafe fn unwrap(mut self) -> *mut T { } } +impl Vector for CVec { + /// View the stored data as a slice. + fn as_slice<'a>(&'a self) -> &'a [T] { + unsafe { + mem::transmute(raw::Slice { data: self.base as *const T, len: self.len }) + } + } +} + impl Collection for CVec { fn len(&self) -> uint { self.len } } diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index f0732c7d508e82a6b99d8f4cd4530c126ea2bee7..e67329df7aec4beae2b8af3baadaa192aabda700 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -37,6 +37,39 @@ /// fail!("this is a {} {message}", "fancy", message = "message"); /// ``` #[macro_export] +#[cfg(not(stage0))] +macro_rules! fail( + () => ({ + fail!("explicit failure") + }); + ($msg:expr) => ({ + // static requires less code at runtime, more constant data + static FILE_LINE: (&'static str, uint) = (file!(), line!()); + ::std::rt::begin_unwind($msg, &FILE_LINE) + }); + ($fmt:expr, $($arg:tt)*) => ({ + // a closure can't have return type !, so we need a full + // function to pass to format_args!, *and* we need the + // file and line numbers right here; so an inner bare fn + // is our only choice. + // + // LLVM doesn't tend to inline this, presumably because begin_unwind_fmt + // is #[cold] and #[inline(never)] and because this is flagged as cold + // as returning !. We really do want this to be inlined, however, + // because it's just a tiny wrapper. Small wins (156K to 149K in size) + // were seen when forcing this to be inlined, and that number just goes + // up with the number of calls to fail!() + #[inline(always)] + fn run_fmt(fmt: &::std::fmt::Arguments) -> ! { + static FILE_LINE: (&'static str, uint) = (file!(), line!()); + ::std::rt::begin_unwind_fmt(fmt, &FILE_LINE) + } + format_args!(run_fmt, $fmt, $($arg)*) + }); +) + +#[macro_export] +#[cfg(stage0)] macro_rules! fail( () => ({ fail!("explicit failure") diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 1e9ec32d759435baebbc3122097421f182676728..a22db7292fa087ce7231afac9b09f5bcee72c189 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -142,6 +142,16 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// Creates a new Path from a byte vector or string. /// The resulting Path will always be normalized. /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let path = Path::new("foo/bar"); + /// # } + /// ``` + /// /// # Failure /// /// Fails the task if the path contains a NUL. @@ -155,6 +165,17 @@ fn new(path: T) -> Self { /// Creates a new Path from a byte vector or string, if possible. /// The resulting Path will always be normalized. + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let x: &[u8] = b"foo\0"; + /// assert!(Path::new_opt(x).is_none()); + /// # } + /// ``` #[inline] fn new_opt(path: T) -> Option { if contains_nul(&path) { @@ -166,18 +187,63 @@ fn new_opt(path: T) -> Option { /// Returns the path as a string, if possible. /// If the path is not representable in utf-8, this returns None. + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let p = Path::new("/abc/def"); + /// assert_eq!(p.as_str(), Some("/abc/def")); + /// # } + /// ``` #[inline] fn as_str<'a>(&'a self) -> Option<&'a str> { str::from_utf8(self.as_vec()) } /// Returns the path as a byte vector + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let p = Path::new("abc/def"); + /// assert_eq!(p.as_vec(), b"abc/def"); + /// # } + /// ``` fn as_vec<'a>(&'a self) -> &'a [u8]; /// Converts the Path into an owned byte vector + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let p = Path::new("abc/def"); + /// assert_eq!(p.into_vec(), b"abc/def".to_vec()); + /// // attempting to use p now results in "error: use of moved value" + /// # } + /// ``` fn into_vec(self) -> Vec; /// Returns an object that implements `Show` for printing paths + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let p = Path::new("abc/def"); + /// println!("{}", p.display()); // prints "abc/def" + /// # } + /// ``` fn display<'a>(&'a self) -> Display<'a, Self> { Display{ path: self, filename: false } } @@ -185,32 +251,102 @@ fn display<'a>(&'a self) -> Display<'a, Self> { /// Returns an object that implements `Show` for printing filenames /// /// If there is no filename, nothing will be printed. + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let p = Path::new("abc/def"); + /// println!("{}", p.filename_display()); // prints "def" + /// # } + /// ``` fn filename_display<'a>(&'a self) -> Display<'a, Self> { Display{ path: self, filename: true } } /// Returns the directory component of `self`, as a byte vector (with no trailing separator). /// If `self` has no directory component, returns ['.']. + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let p = Path::new("abc/def/ghi"); + /// assert_eq!(p.dirname(), b"abc/def"); + /// # } + /// ``` fn dirname<'a>(&'a self) -> &'a [u8]; + /// Returns the directory component of `self`, as a string, if possible. /// See `dirname` for details. + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let p = Path::new("abc/def/ghi"); + /// assert_eq!(p.dirname_str(), Some("abc/def")); + /// # } + /// ``` #[inline] fn dirname_str<'a>(&'a self) -> Option<&'a str> { str::from_utf8(self.dirname()) } + /// Returns the file component of `self`, as a byte vector. /// If `self` represents the root of the file hierarchy, returns None. /// If `self` is "." or "..", returns None. + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let p = Path::new("abc/def/ghi"); + /// assert_eq!(p.filename(), Some(b"ghi")); + /// # } + /// ``` fn filename<'a>(&'a self) -> Option<&'a [u8]>; + /// Returns the file component of `self`, as a string, if possible. /// See `filename` for details. + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let p = Path::new("abc/def/ghi"); + /// assert_eq!(p.filename_str(), Some("ghi")); + /// # } + /// ``` #[inline] fn filename_str<'a>(&'a self) -> Option<&'a str> { self.filename().and_then(str::from_utf8) } + /// Returns the stem of the filename of `self`, as a byte vector. /// The stem is the portion of the filename just before the last '.'. /// If there is no '.', the entire filename is returned. + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let p = Path::new("/abc/def.txt"); + /// assert_eq!(p.filestem(), Some(b"def")); + /// # } + /// ``` fn filestem<'a>(&'a self) -> Option<&'a [u8]> { match self.filename() { None => None, @@ -224,16 +360,40 @@ fn filestem<'a>(&'a self) -> Option<&'a [u8]> { }) } } + /// Returns the stem of the filename of `self`, as a string, if possible. /// See `filestem` for details. + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let p = Path::new("/abc/def.txt"); + /// assert_eq!(p.filestem_str(), Some("def")); + /// # } + /// ``` #[inline] fn filestem_str<'a>(&'a self) -> Option<&'a str> { self.filestem().and_then(str::from_utf8) } + /// Returns the extension of the filename of `self`, as an optional byte vector. /// The extension is the portion of the filename just after the last '.'. /// If there is no extension, None is returned. /// If the filename ends in '.', the empty vector is returned. + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let p = Path::new("abc/def.txt"); + /// assert_eq!(p.extension(), Some(b"txt")); + /// # } + /// ``` fn extension<'a>(&'a self) -> Option<&'a [u8]> { match self.filename() { None => None, @@ -247,8 +407,20 @@ fn extension<'a>(&'a self) -> Option<&'a [u8]> { } } } + /// Returns the extension of the filename of `self`, as a string, if possible. /// See `extension` for details. + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let p = Path::new("abc/def.txt"); + /// assert_eq!(p.extension_str(), Some("txt")); + /// # } + /// ``` #[inline] fn extension_str<'a>(&'a self) -> Option<&'a str> { self.extension().and_then(str::from_utf8) @@ -257,6 +429,18 @@ fn extension_str<'a>(&'a self) -> Option<&'a str> { /// Replaces the filename portion of the path with the given byte vector or string. /// If the replacement name is [], this is equivalent to popping the path. /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let mut p = Path::new("abc/def.txt"); + /// p.set_filename("foo.dat"); + /// assert!(p == Path::new("abc/foo.dat")); + /// # } + /// ``` + /// /// # Failure /// /// Fails the task if the filename contains a NUL. @@ -265,11 +449,24 @@ fn set_filename(&mut self, filename: T) { assert!(!contains_nul(&filename)); unsafe { self.set_filename_unchecked(filename) } } + /// Replaces the extension with the given byte vector or string. /// If there is no extension in `self`, this adds one. /// If the argument is [] or "", this removes the extension. /// If `self` has no filename, this is a no-op. /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let mut p = Path::new("abc/def.txt"); + /// p.set_extension("csv"); + /// assert!(p == Path::new("abc/def.csv")); + /// # } + /// ``` + /// /// # Failure /// /// Fails the task if the extension contains a NUL. @@ -308,6 +505,17 @@ fn set_extension(&mut self, extension: T) { /// byte vector or string. /// See `set_filename` for details. /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let mut p = Path::new("abc/def.txt"); + /// assert!(p.with_filename("foo.dat") == Path::new("abc/foo.dat")); + /// # } + /// ``` + /// /// # Failure /// /// Fails the task if the filename contains a NUL. @@ -317,10 +525,22 @@ fn with_filename(&self, filename: T) -> Self { p.set_filename(filename); p } + /// Returns a new Path constructed by setting the extension to the given /// byte vector or string. /// See `set_extension` for details. /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let mut p = Path::new("abc/def.txt"); + /// assert!(p.with_extension("csv") == Path::new("abc/def.csv")); + /// # } + /// ``` + /// /// # Failure /// /// Fails the task if the extension contains a NUL. @@ -333,6 +553,17 @@ fn with_extension(&self, extension: T) -> Self { /// Returns the directory component of `self`, as a Path. /// If `self` represents the root of the filesystem hierarchy, returns `self`. + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let p = Path::new("abc/def/ghi"); + /// assert!(p.dir_path() == Path::new("abc/def")); + /// # } + /// ``` fn dir_path(&self) -> Self { // self.dirname() returns a NUL-free vector unsafe { GenericPathUnsafe::new_unchecked(self.dirname()) } @@ -341,11 +572,34 @@ fn dir_path(&self) -> Self { /// Returns a Path that represents the filesystem root that `self` is rooted in. /// /// If `self` is not absolute, or vol/cwd-relative in the case of Windows, this returns None. + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// assert!(Path::new("abc/def").root_path() == None); + /// assert!(Path::new("/abc/def").root_path() == Some(Path::new("/"))); + /// # } + /// ``` fn root_path(&self) -> Option; /// Pushes a path (as a byte vector or string) onto `self`. /// If the argument represents an absolute path, it replaces `self`. /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let mut p = Path::new("foo/bar"); + /// p.push("baz.txt"); + /// assert!(p == Path::new("foo/bar/baz.txt")); + /// # } + /// ``` + /// /// # Failure /// /// Fails the task if the path contains a NUL. @@ -354,8 +608,21 @@ fn push(&mut self, path: T) { assert!(!contains_nul(&path)); unsafe { self.push_unchecked(path) } } + /// Pushes multiple paths (as byte vectors or strings) onto `self`. /// See `push` for details. + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let mut p = Path::new("foo"); + /// p.push_many(&["bar", "baz.txt"]); + /// assert!(p == Path::new("foo/bar/baz.txt")); + /// # } + /// ``` #[inline] fn push_many(&mut self, paths: &[T]) { let t: Option = None; @@ -369,15 +636,39 @@ fn push_many(&mut self, paths: &[T]) { } } } + /// Removes the last path component from the receiver. /// Returns `true` if the receiver was modified, or `false` if it already /// represented the root of the file hierarchy. + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let mut p = Path::new("foo/bar/baz.txt"); + /// p.pop(); + /// assert!(p == Path::new("foo/bar")); + /// # } + /// ``` fn pop(&mut self) -> bool; /// Returns a new Path constructed by joining `self` with the given path /// (as a byte vector or string). /// If the given path is absolute, the new Path will represent just that. /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let p = Path::new("/foo"); + /// assert!(p.join("bar.txt") == Path::new("/foo/bar.txt")); + /// # } + /// ``` + /// /// # Failure /// /// Fails the task if the path contains a NUL. @@ -387,9 +678,22 @@ fn join(&self, path: T) -> Self { p.push(path); p } + /// Returns a new Path constructed by joining `self` with the given paths /// (as byte vectors or strings). /// See `join` for details. + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let p = Path::new("foo"); + /// let fbbq = Path::new("foo/bar/baz/quux.txt"); + /// assert!(p.join_many(&["bar", "baz", "quux.txt"]) == fbbq); + /// # } + /// ``` #[inline] fn join_many(&self, paths: &[T]) -> Self { let mut p = self.clone(); @@ -400,12 +704,34 @@ fn join_many(&self, paths: &[T]) -> Self { /// Returns whether `self` represents an absolute path. /// An absolute path is defined as one that, when joined to another path, will /// yield back the same absolute path. + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let p = Path::new("/abc/def"); + /// assert!(p.is_absolute()); + /// # } + /// ``` fn is_absolute(&self) -> bool; /// Returns whether `self` represents a relative path. /// Typically this is the inverse of `is_absolute`. /// But for Windows paths, it also means the path is not volume-relative or /// relative to the current working directory. + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let p = Path::new("abc/def"); + /// assert!(p.is_relative()); + /// # } + /// ``` fn is_relative(&self) -> bool { !self.is_absolute() } @@ -413,15 +739,53 @@ fn is_relative(&self) -> bool { /// Returns whether `self` is equal to, or is an ancestor of, the given path. /// If both paths are relative, they are compared as though they are relative /// to the same parent path. + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let p = Path::new("foo/bar/baz/quux.txt"); + /// let fb = Path::new("foo/bar"); + /// let bq = Path::new("baz/quux.txt"); + /// assert!(fb.is_ancestor_of(&p)); + /// # } + /// ``` fn is_ancestor_of(&self, other: &Self) -> bool; /// Returns the Path that, were it joined to `base`, would yield `self`. /// If no such path exists, None is returned. /// If `self` is absolute and `base` is relative, or on Windows if both /// paths refer to separate drives, an absolute path is returned. + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let p = Path::new("foo/bar/baz/quux.txt"); + /// let fb = Path::new("foo/bar"); + /// let bq = Path::new("baz/quux.txt"); + /// assert!(p.path_relative_from(&fb) == Some(bq)); + /// # } + /// ``` fn path_relative_from(&self, base: &Self) -> Option; /// Returns whether the relative path `child` is a suffix of `self`. + /// + /// # Example + /// + /// ``` + /// # foo(); + /// # #[cfg(windows)] fn foo() {} + /// # #[cfg(unix)] fn foo() { + /// let p = Path::new("foo/bar/baz/quux.txt"); + /// let bq = Path::new("baz/quux.txt"); + /// assert!(p.ends_with_path(&bq)); + /// # } + /// ``` fn ends_with_path(&self, child: &Self) -> bool; } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 6c9e113f41a4c5f2514cfe671b5df77353fe65a9..33daefa3e06b1a516cde3f069171c75d1763eed5 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -690,6 +690,13 @@ fn expr_tuple(&self, sp: Span, exprs: Vec>) -> Gc { fn expr_fail(&self, span: Span, msg: InternedString) -> Gc { let loc = self.codemap().lookup_char_pos(span.lo); + let expr_file = self.expr_str(span, + token::intern_and_get_ident(loc.file + .name + .as_slice())); + let expr_line = self.expr_uint(span, loc.line); + let expr_file_line_tuple = self.expr_tuple(span, vec!(expr_file, expr_line)); + let expr_file_line_ptr = self.expr_addr_of(span, expr_file_line_tuple); self.expr_call_global( span, vec!( @@ -698,11 +705,7 @@ fn expr_fail(&self, span: Span, msg: InternedString) -> Gc { self.ident_of("begin_unwind")), vec!( self.expr_str(span, msg), - self.expr_str(span, - token::intern_and_get_ident(loc.file - .name - .as_slice())), - self.expr_uint(span, loc.line))) + expr_file_line_ptr)) } fn expr_unreachable(&self, span: Span) -> Gc { diff --git a/src/libtest/stats.rs b/src/libtest/stats.rs index d8f628e2196f5780197e445dea9d45ac852c0420..9af28e771e1fbd17ec095ecaa050bae91724a636 100644 --- a/src/libtest/stats.rs +++ b/src/libtest/stats.rs @@ -164,7 +164,7 @@ pub fn new(samples: &[T]) -> Summary { } } -impl<'a,T: FloatMath + FromPrimitive> Stats for &'a [T] { +impl<'a, T: FloatMath + FromPrimitive> Stats for &'a [T] { // FIXME #11059 handle NaN, inf and overflow fn sum(self) -> T { diff --git a/src/liburl/lib.rs b/src/liburl/lib.rs index c7e27c0083612f100085b995cd144411207717c4..0221b95b40434b23c721bdebd3a8df0b6e7cecb9 100644 --- a/src/liburl/lib.rs +++ b/src/liburl/lib.rs @@ -394,7 +394,7 @@ fn maybe_push_value(map: &mut HashMap>, } } -fn split_char_first<'a>(s: &'a str, c: char) -> (&'a str, &'a str) { +fn split_char_first(s: &str, c: char) -> (&str, &str) { let mut iter = s.splitn(c, 1); match (iter.next(), iter.next()) { @@ -466,7 +466,7 @@ pub fn query_to_str(query: &Query) -> String { /// }; /// println!("Scheme in use: {}.", scheme); // Scheme in use: https. /// ``` -pub fn get_scheme<'a>(rawurl: &'a str) -> DecodeResult<(&'a str, &'a str)> { +pub fn get_scheme(rawurl: &str) -> DecodeResult<(&str, &str)> { for (i,c) in rawurl.chars().enumerate() { let result = match c { 'A' .. 'Z' @@ -493,8 +493,8 @@ pub fn get_scheme<'a>(rawurl: &'a str) -> DecodeResult<(&'a str, &'a str)> { } // returns userinfo, host, port, and unparsed part, or an error -fn get_authority<'a>(rawurl: &'a str) -> - DecodeResult<(Option, &'a str, Option, &'a str)> { +fn get_authority(rawurl: &str) -> + DecodeResult<(Option, &str, Option, &str)> { enum State { Start, // starting state PassHostPort, // could be in user or port @@ -662,8 +662,7 @@ enum Input { // returns the path and unparsed part of url, or an error -fn get_path<'a>(rawurl: &'a str, is_authority: bool) - -> DecodeResult<(String, &'a str)> { +fn get_path(rawurl: &str, is_authority: bool) -> DecodeResult<(String, &str)> { let len = rawurl.len(); let mut end = len; for (i,c) in rawurl.chars().enumerate() { diff --git a/src/libuuid/lib.rs b/src/libuuid/lib.rs index 037afce9b167a7c5a404ff3906af076d7ffa8bca..2ffed792abd4683dbb379920a7877a0d29c13fcf 100644 --- a/src/libuuid/lib.rs +++ b/src/libuuid/lib.rs @@ -29,6 +29,8 @@ To create a new random (V4) UUID and print it out in hexadecimal form: ```rust +# #![allow(deprecated)] +# extern crate uuid; use uuid::Uuid; fn main() { @@ -55,7 +57,8 @@ fn main() { */ #![crate_name = "uuid"] -#![experimental] +#![deprecated = "This is now a cargo package located at: \ + https://github.com/rust-lang/uuid"] #![crate_type = "rlib"] #![crate_type = "dylib"] #![license = "MIT/ASL2"] @@ -312,7 +315,7 @@ pub fn get_version(&self) -> Option { } /// Return an array of 16 octets containing the UUID data - pub fn as_bytes<'a>(&'a self) -> &'a [u8] { + pub fn as_bytes(&self) -> &[u8] { self.bytes.as_slice() } diff --git a/src/test/auxiliary/lang-item-public.rs b/src/test/auxiliary/lang-item-public.rs index 7b84e11ef31f020b9d1db86cd3fb1a91cbdd4a8d..5723b59a60b95c3bb3b89184c37f73fd9562229e 100644 --- a/src/test/auxiliary/lang-item-public.rs +++ b/src/test/auxiliary/lang-item-public.rs @@ -12,7 +12,7 @@ #![feature(lang_items)] #[lang="fail_"] -fn fail(_: &'static str, _: &'static str, _: uint) -> ! { loop {} } +fn fail(_: &(&'static str, &'static str, uint)) -> ! { loop {} } #[lang = "stack_exhausted"] extern fn stack_exhausted() {} diff --git a/src/test/compile-fail/issue-16058.rs b/src/test/compile-fail/issue-16058.rs new file mode 100644 index 0000000000000000000000000000000000000000..4637512216c40b15d3e72110ff0dbcb4ad54e1e9 --- /dev/null +++ b/src/test/compile-fail/issue-16058.rs @@ -0,0 +1,26 @@ +// Copyright 2012-2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + + +pub struct GslResult { + pub val: f64, + pub err: f64 +} + +impl GslResult { + pub fn new() -> GslResult { + Result { //~ ERROR: `Result` does not name a structure + val: 0f64, + err: 0f64 + } + } +} + +fn main() {} diff --git a/src/test/run-pass/auto-encode.rs b/src/test/run-pass/auto-encode.rs index d01cda79e22d4de4cb3d360ebb4ab53f62f3871d..b03feb8fc224b050c2e822a23fcad972ad6bc618 100644 --- a/src/test/run-pass/auto-encode.rs +++ b/src/test/run-pass/auto-encode.rs @@ -10,33 +10,33 @@ // ignore-test FIXME(#5121) - -extern crate time; +extern crate rbml; extern crate serialize; +extern crate time; // These tests used to be separate files, but I wanted to refactor all // the common code. use std::hashmap::{HashMap, HashSet}; -use EBReader = serialize::ebml::reader; -use EBWriter = serialize::ebml::writer; +use EBReader = rbml::reader; +use EBWriter = rbml::writer; use std::cmp::Eq; use std::cmp; use std::io; use serialize::{Decodable, Encodable}; -fn test_ebml<'a, 'b, A: +fn test_rbml<'a, 'b, A: Eq + Encodable> + Decodable> >(a1: &A) { let mut wr = std::io::MemWriter::new(); - let mut ebml_w = EBwriter::Encoder::new(&mut wr); - a1.encode(&mut ebml_w); + let mut rbml_w = EBwriter::Encoder::new(&mut wr); + a1.encode(&mut rbml_w); let bytes = wr.get_ref(); - let d: serialize::ebml::Doc<'a> = EBDoc::new(bytes); + let d: serialize::rbml::Doc<'a> = EBDoc::new(bytes); let mut decoder: EBReader::Decoder<'a> = EBreader::Decoder::new(d); let a2: A = Decodable::decode(&mut decoder); assert!(*a1 == a2); @@ -133,40 +133,40 @@ enum CLike { A, B, C } pub fn main() { let a = &Plus(@Minus(@Val(3u), @Val(10u)), @Plus(@Val(22u), @Val(5u))); - test_ebml(a); + test_rbml(a); let a = &Spanned {lo: 0u, hi: 5u, node: 22u}; - test_ebml(a); + test_rbml(a); let a = &Point {x: 3u, y: 5u}; - test_ebml(a); + test_rbml(a); let a = &Top(22u); - test_ebml(a); + test_rbml(a); let a = &Bottom(222u); - test_ebml(a); + test_rbml(a); let a = &A; - test_ebml(a); + test_rbml(a); let a = &B; - test_ebml(a); + test_rbml(a); let a = &time::now(); - test_ebml(a); + test_rbml(a); - test_ebml(&1.0f32); - test_ebml(&1.0f64); - test_ebml(&'a'); + test_rbml(&1.0f32); + test_rbml(&1.0f64); + test_rbml(&'a'); let mut a = HashMap::new(); - test_ebml(&a); + test_rbml(&a); a.insert(1, 2); - test_ebml(&a); + test_rbml(&a); let mut a = HashSet::new(); - test_ebml(&a); + test_rbml(&a); a.insert(1); - test_ebml(&a); + test_rbml(&a); } diff --git a/src/test/run-pass/backtrace.rs b/src/test/run-pass/backtrace.rs index c2a1c01b919ab05f3a29bb9b63f5acde3778424a..0e4be12aa456d581f093b6e783cedfee35d36380 100644 --- a/src/test/run-pass/backtrace.rs +++ b/src/test/run-pass/backtrace.rs @@ -24,7 +24,10 @@ fn start(argc: int, argv: *const *const u8) -> int { #[inline(never)] fn foo() { - fail!() + let _v = vec![1i, 2, 3]; + if os::getenv("IS_TEST").is_some() { + fail!() + } } #[inline(never)] @@ -37,8 +40,11 @@ fn double() { } fn runtest(me: &str) { + let mut template = Command::new(me); + template.env("IS_TEST", "1"); + // Make sure that the stack trace is printed - let mut p = Command::new(me).arg("fail").env("RUST_BACKTRACE", "1").spawn().unwrap(); + let p = template.clone().arg("fail").env("RUST_BACKTRACE", "1").spawn().unwrap(); let out = p.wait_with_output().unwrap(); assert!(!out.status.success()); let s = str::from_utf8(out.error.as_slice()).unwrap(); @@ -46,7 +52,7 @@ fn runtest(me: &str) { "bad output: {}", s); // Make sure the stack trace is *not* printed - let mut p = Command::new(me).arg("fail").spawn().unwrap(); + let p = template.clone().arg("fail").spawn().unwrap(); let out = p.wait_with_output().unwrap(); assert!(!out.status.success()); let s = str::from_utf8(out.error.as_slice()).unwrap(); @@ -54,7 +60,7 @@ fn runtest(me: &str) { "bad output2: {}", s); // Make sure a stack trace is printed - let mut p = Command::new(me).arg("double-fail").spawn().unwrap(); + let p = template.clone().arg("double-fail").spawn().unwrap(); let out = p.wait_with_output().unwrap(); assert!(!out.status.success()); let s = str::from_utf8(out.error.as_slice()).unwrap(); @@ -62,7 +68,7 @@ fn runtest(me: &str) { "bad output3: {}", s); // Make sure a stack trace isn't printed too many times - let mut p = Command::new(me).arg("double-fail") + let p = template.clone().arg("double-fail") .env("RUST_BACKTRACE", "1").spawn().unwrap(); let out = p.wait_with_output().unwrap(); assert!(!out.status.success()); diff --git a/src/test/run-pass/deriving-encodable-decodable.rs b/src/test/run-pass/deriving-encodable-decodable.rs index bf519056130874f277e86e9483910ad4c7b834c7..573b57fb44a46d772b18a6ac031cbc43882c109d 100644 --- a/src/test/run-pass/deriving-encodable-decodable.rs +++ b/src/test/run-pass/deriving-encodable-decodable.rs @@ -16,15 +16,16 @@ #![feature(struct_variant)] extern crate rand; +extern crate rbml; extern crate serialize; use std::io::MemWriter; use rand::{random, Rand}; +use rbml; +use rbml::Doc; +use rbml::writer::Encoder; +use rbml::reader::Decoder; use serialize::{Encodable, Decodable}; -use serialize::ebml; -use serialize::ebml::Doc; -use serialize::ebml::writer::Encoder; -use serialize::ebml::reader::Decoder; #[deriving(Encodable, Decodable, Eq, Rand)] struct A; @@ -61,7 +62,7 @@ fn roundtrip<'a, T: Rand + Eq + Encodable> + let mut w = MemWriter::new(); let mut e = Encoder::new(&mut w); obj.encode(&mut e); - let doc = ebml::Doc::new(@w.get_ref()); + let doc = rbml::Doc::new(@w.get_ref()); let mut dec = Decoder::new(doc); let obj2 = Decodable::decode(&mut dec); assert!(obj == obj2); diff --git a/src/test/run-pass/for-loop-does-not-borrow-iterators.rs b/src/test/run-pass/for-loop-does-not-borrow-iterators.rs new file mode 100644 index 0000000000000000000000000000000000000000..206ab0dfeb2d06074568c2fde5c1150e2e7e08c3 --- /dev/null +++ b/src/test/run-pass/for-loop-does-not-borrow-iterators.rs @@ -0,0 +1,30 @@ +// Copyright 2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + + +// The `for` loop use to keep a mutable borrow when executing its body, +// making it impossible to re-use the iterator as follows. +// https://github.com/rust-lang/rust/issues/8372 +// +// This was fixed in https://github.com/rust-lang/rust/pull/15809 + +pub fn main() { + let mut for_loop_values = Vec::new(); + let mut explicit_next_call_values = Vec::new(); + + let mut iter = range(1i, 10); + for i in iter { + for_loop_values.push(i); + explicit_next_call_values.push(iter.next()); + } + + assert_eq!(for_loop_values, vec![1, 3, 5, 7, 9]); + assert_eq!(explicit_next_call_values, vec![Some(2), Some(4), Some(6), Some(8), None]); +} diff --git a/src/test/run-pass/issue-11881.rs b/src/test/run-pass/issue-11881.rs index d7f487b629b5eb05817ad3f93631d0606eb1fba8..28fc4ce192e187cc84d532b35b6a5f1df1342f99 100644 --- a/src/test/run-pass/issue-11881.rs +++ b/src/test/run-pass/issue-11881.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +extern crate rbml; extern crate serialize; use std::io; @@ -16,121 +17,9 @@ use serialize::{Encodable, Encoder}; use serialize::json; -use serialize::ebml::writer; -static BUF_CAPACITY: uint = 128; - -fn combine(seek: SeekStyle, cur: uint, end: uint, offset: i64) -> IoResult { - // compute offset as signed and clamp to prevent overflow - let pos = match seek { - io::SeekSet => 0, - io::SeekEnd => end, - io::SeekCur => cur, - } as i64; - - if offset + pos < 0 { - Err(IoError { - kind: io::InvalidInput, - desc: "invalid seek to a negative offset", - detail: None - }) - } else { - Ok((offset + pos) as u64) - } -} - -/// Writes to an owned, growable byte vector that supports seeking. -/// -/// # Example -/// -/// ```rust -/// # #![allow(unused_must_use)] -/// use std::io::SeekableMemWriter; -/// -/// let mut w = SeekableMemWriter::new(); -/// w.write([0, 1, 2]); -/// -/// assert_eq!(w.unwrap(), vec!(0, 1, 2)); -/// ``` -pub struct SeekableMemWriter { - buf: Vec, - pos: uint, -} - -impl SeekableMemWriter { - /// Create a new `SeekableMemWriter`. - #[inline] - pub fn new() -> SeekableMemWriter { - SeekableMemWriter::with_capacity(BUF_CAPACITY) - } - /// Create a new `SeekableMemWriter`, allocating at least `n` bytes for - /// the internal buffer. - #[inline] - pub fn with_capacity(n: uint) -> SeekableMemWriter { - SeekableMemWriter { buf: Vec::with_capacity(n), pos: 0 } - } - - /// Acquires an immutable reference to the underlying buffer of this - /// `SeekableMemWriter`. - /// - /// No method is exposed for acquiring a mutable reference to the buffer - /// because it could corrupt the state of this `MemWriter`. - #[inline] - pub fn get_ref<'a>(&'a self) -> &'a [u8] { self.buf.as_slice() } - - /// Unwraps this `SeekableMemWriter`, returning the underlying buffer - #[inline] - pub fn unwrap(self) -> Vec { self.buf } -} - -impl Writer for SeekableMemWriter { - #[inline] - fn write(&mut self, buf: &[u8]) -> IoResult<()> { - if self.pos == self.buf.len() { - self.buf.push_all(buf) - } else { - // Make sure the internal buffer is as least as big as where we - // currently are - let difference = self.pos as i64 - self.buf.len() as i64; - if difference > 0 { - self.buf.grow(difference as uint, &0); - } - - // Figure out what bytes will be used to overwrite what's currently - // there (left), and what will be appended on the end (right) - let cap = self.buf.len() - self.pos; - let (left, right) = if cap <= buf.len() { - (buf.slice_to(cap), buf.slice_from(cap)) - } else { - (buf, &[]) - }; - - // Do the necessary writes - if left.len() > 0 { - slice::bytes::copy_memory(self.buf.mut_slice_from(self.pos), left); - } - if right.len() > 0 { - self.buf.push_all(right); - } - } - - // Bump us forward - self.pos += buf.len(); - Ok(()) - } -} - -impl Seek for SeekableMemWriter { - #[inline] - fn tell(&self) -> IoResult { Ok(self.pos as u64) } - - #[inline] - fn seek(&mut self, pos: i64, style: SeekStyle) -> IoResult<()> { - let new = try!(combine(style, self.pos, self.buf.len(), pos)); - self.pos = new as uint; - Ok(()) - } -} +use rbml::writer; +use rbml::io::SeekableMemWriter; #[deriving(Encodable)] struct Foo { @@ -144,7 +33,7 @@ struct Bar { enum WireProtocol { JSON, - EBML, + RBML, // ... } @@ -155,7 +44,7 @@ fn encode_json<'a, let mut encoder = json::Encoder::new(wr); val.encode(&mut encoder); } -fn encode_ebml<'a, +fn encode_rbml<'a, T: Encodable, std::io::IoError>>(val: &T, wr: &'a mut SeekableMemWriter) { @@ -169,6 +58,6 @@ pub fn main() { let proto = JSON; match proto { JSON => encode_json(&target, &mut wr), - EBML => encode_ebml(&target, &mut wr) + RBML => encode_rbml(&target, &mut wr) } } diff --git a/src/test/run-pass/issue-15858.rs b/src/test/run-pass/issue-15858.rs new file mode 100644 index 0000000000000000000000000000000000000000..c75c672546125bbbbef280a344252e4cb2d45b7f --- /dev/null +++ b/src/test/run-pass/issue-15858.rs @@ -0,0 +1,45 @@ +// Copyright 2012-2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(unsafe_destructor)] + +static mut DROP_RAN: bool = false; + +trait Bar<'b> { + fn do_something(&mut self); +} + +struct BarImpl<'b>; + +impl<'b> Bar<'b> for BarImpl<'b> { + fn do_something(&mut self) {} +} + + +struct Foo; + +#[unsafe_destructor] +impl<'b, B: Bar<'b>> Drop for Foo { + fn drop(&mut self) { + unsafe { + DROP_RAN = true; + } + } +} + + +fn main() { + { + let _x: Foo = Foo; + } + unsafe { + assert_eq!(DROP_RAN, true); + } +}