]> git.lizzy.rs Git - rust.git/commitdiff
remove serialize::ebml, add librbml
authorErick Tryzelaar <erick.tryzelaar@gmail.com>
Wed, 30 Jul 2014 00:06:37 +0000 (17:06 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 31 Jul 2014 14:30:49 +0000 (07:30 -0700)
Our implementation of ebml has diverged from the standard in order
to better serve the needs of the compiler, so it doesn't make much
sense to call what we have ebml anyore. Furthermore, our implementation
is pretty crufty, and should eventually be rewritten into a format
that better suits the needs of the compiler. This patch factors out
serialize::ebml into librbml, otherwise known as the Really Bad
Markup Language. This is a stopgap library that shouldn't be used
by end users, and will eventually be replaced by something better.

[breaking-change]

13 files changed:
mk/crates.mk
src/librbml/lib.rs [new file with mode: 0644]
src/librustc/lib.rs
src/librustc/metadata/csearch.rs
src/librustc/metadata/decoder.rs
src/librustc/metadata/encoder.rs
src/librustc/middle/astencode.rs
src/librustc/middle/trans/base.rs
src/libserialize/ebml.rs [deleted file]
src/libserialize/lib.rs
src/test/run-pass/auto-encode.rs
src/test/run-pass/deriving-encodable-decodable.rs
src/test/run-pass/issue-11881.rs

index c95576f6252aa3feca7b16ef2c458ec7de17f04e..5bc4505fb05c742bf92f22bf21d65320820112d2 100644 (file)
@@ -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/librbml/lib.rs b/src/librbml/lib.rs
new file mode 100644 (file)
index 0000000..e54410b
--- /dev/null
@@ -0,0 +1,1311 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! 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)]
+
+extern crate serialize;
+
+#[phase(plugin, link)] extern crate log;
+#[cfg(test)] extern crate test;
+
+use std::io;
+use std::str;
+
+
+/// Common data structures
+#[deriving(Clone)]
+pub struct Doc<'a> {
+    pub data: &'a [u8],
+    pub start: uint,
+    pub end: uint,
+}
+
+impl<'doc> Doc<'doc> {
+    pub fn new(data: &'doc [u8]) -> Doc<'doc> {
+        Doc { data: data, start: 0u, end: data.len() }
+    }
+
+    pub fn get<'a>(&'a self, tag: uint) -> Doc<'a> {
+        reader::get_doc(*self, tag)
+    }
+
+    pub fn as_str_slice<'a>(&'a self) -> &'a str {
+        str::from_utf8(self.data.slice(self.start, self.end)).unwrap()
+    }
+
+    pub fn as_str(&self) -> String {
+        self.as_str_slice().to_string()
+    }
+}
+
+pub struct TaggedDoc<'a> {
+    tag: uint,
+    pub doc: Doc<'a>,
+}
+
+#[deriving(Show)]
+pub enum EbmlEncoderTag {
+    EsUint,     // 0
+    EsU64,      // 1
+    EsU32,      // 2
+    EsU16,      // 3
+    EsU8,       // 4
+    EsInt,      // 5
+    EsI64,      // 6
+    EsI32,      // 7
+    EsI16,      // 8
+    EsI8,       // 9
+    EsBool,     // 10
+    EsChar,     // 11
+    EsStr,      // 12
+    EsF64,      // 13
+    EsF32,      // 14
+    EsFloat,    // 15
+    EsEnum,     // 16
+    EsEnumVid,  // 17
+    EsEnumBody, // 18
+    EsVec,      // 19
+    EsVecLen,   // 20
+    EsVecElt,   // 21
+    EsMap,      // 22
+    EsMapLen,   // 23
+    EsMapKey,   // 24
+    EsMapVal,   // 25
+
+    EsOpaque,
+
+    EsLabel, // Used only when debugging
+}
+
+#[deriving(Show)]
+pub enum Error {
+    IntTooBig(uint),
+    Expected(String),
+    IoError(io::IoError)
+}
+// --------------------------------------
+
+pub mod reader {
+    use std::char;
+
+    use std::mem::transmute;
+    use std::int;
+    use std::option::{None, Option, Some};
+    use std::io::extensions::u64_from_be_bytes;
+
+    use serialize;
+
+    use super::{ EsVec, EsMap, EsEnum, EsVecLen, EsVecElt, EsMapLen, EsMapKey,
+        EsEnumVid, EsU64, EsU32, EsU16, EsU8, EsInt, EsI64, EsI32, EsI16, EsI8,
+        EsBool, EsF64, EsF32, EsChar, EsStr, EsMapVal, EsEnumBody, EsUint,
+        EsOpaque, EsLabel, EbmlEncoderTag, Doc, TaggedDoc, Error, IntTooBig,
+        Expected };
+
+    pub type DecodeResult<T> = Result<T, Error>;
+    // rbml reading
+
+    macro_rules! try_or(
+        ($e:expr, $r:expr) => (
+            match $e {
+                Ok(e) => e,
+                Err(e) => {
+                    debug!("ignored error: {}", e);
+                    return $r
+                }
+            }
+        )
+    )
+
+    pub struct Res {
+        pub val: uint,
+        pub next: uint
+    }
+
+    #[inline(never)]
+    fn vuint_at_slow(data: &[u8], start: uint) -> DecodeResult<Res> {
+        let a = data[start];
+        if a & 0x80u8 != 0u8 {
+            return Ok(Res {val: (a & 0x7fu8) as uint, next: start + 1u});
+        }
+        if a & 0x40u8 != 0u8 {
+            return Ok(Res {val: ((a & 0x3fu8) as uint) << 8u |
+                        (data[start + 1u] as uint),
+                    next: start + 2u});
+        }
+        if a & 0x20u8 != 0u8 {
+            return Ok(Res {val: ((a & 0x1fu8) as uint) << 16u |
+                        (data[start + 1u] as uint) << 8u |
+                        (data[start + 2u] as uint),
+                    next: start + 3u});
+        }
+        if a & 0x10u8 != 0u8 {
+            return Ok(Res {val: ((a & 0x0fu8) as uint) << 24u |
+                        (data[start + 1u] as uint) << 16u |
+                        (data[start + 2u] as uint) << 8u |
+                        (data[start + 3u] as uint),
+                    next: start + 4u});
+        }
+        Err(IntTooBig(a as uint))
+    }
+
+    pub fn vuint_at(data: &[u8], start: uint) -> DecodeResult<Res> {
+        if data.len() - start < 4 {
+            return vuint_at_slow(data, start);
+        }
+
+        // Lookup table for parsing EBML Element IDs as per http://ebml.sourceforge.net/specs/
+        // The Element IDs are parsed by reading a big endian u32 positioned at data[start].
+        // Using the four most significant bits of the u32 we lookup in the table below how the
+        // element ID should be derived from it.
+        //
+        // The table stores tuples (shift, mask) where shift is the number the u32 should be right
+        // shifted with and mask is the value the right shifted value should be masked with.
+        // If for example the most significant bit is set this means it's a class A ID and the u32
+        // should be right shifted with 24 and masked with 0x7f. Therefore we store (24, 0x7f) at
+        // index 0x8 - 0xF (four bit numbers where the most significant bit is set).
+        //
+        // By storing the number of shifts and masks in a table instead of checking in order if
+        // the most significant bit is set, the second most significant bit is set etc. we can
+        // replace up to three "and+branch" with a single table lookup which gives us a measured
+        // speedup of around 2x on x86_64.
+        static SHIFT_MASK_TABLE: [(uint, u32), ..16] = [
+            (0, 0x0), (0, 0x0fffffff),
+            (8, 0x1fffff), (8, 0x1fffff),
+            (16, 0x3fff), (16, 0x3fff), (16, 0x3fff), (16, 0x3fff),
+            (24, 0x7f), (24, 0x7f), (24, 0x7f), (24, 0x7f),
+            (24, 0x7f), (24, 0x7f), (24, 0x7f), (24, 0x7f)
+        ];
+
+        unsafe {
+            let ptr = data.as_ptr().offset(start as int) as *const u32;
+            let val = Int::from_be(*ptr);
+
+            let i = (val >> 28u) as uint;
+            let (shift, mask) = SHIFT_MASK_TABLE[i];
+            Ok(Res {
+                val: ((val >> shift) & mask) as uint,
+                next: start + (((32 - shift) >> 3) as uint)
+            })
+        }
+    }
+
+    pub fn doc_at<'a>(data: &'a [u8], start: uint) -> DecodeResult<TaggedDoc<'a>> {
+        let elt_tag = try!(vuint_at(data, start));
+        let elt_size = try!(vuint_at(data, elt_tag.next));
+        let end = elt_size.next + elt_size.val;
+        Ok(TaggedDoc {
+            tag: elt_tag.val,
+            doc: Doc { data: data, start: elt_size.next, end: end }
+        })
+    }
+
+    pub fn maybe_get_doc<'a>(d: Doc<'a>, tg: uint) -> Option<Doc<'a>> {
+        let mut pos = d.start;
+        while pos < d.end {
+            let elt_tag = try_or!(vuint_at(d.data, pos), None);
+            let elt_size = try_or!(vuint_at(d.data, elt_tag.next), None);
+            pos = elt_size.next + elt_size.val;
+            if elt_tag.val == tg {
+                return Some(Doc { data: d.data, start: elt_size.next,
+                                  end: pos });
+            }
+        }
+        None
+    }
+
+    pub fn get_doc<'a>(d: Doc<'a>, tg: uint) -> Doc<'a> {
+        match maybe_get_doc(d, tg) {
+            Some(d) => d,
+            None => {
+                error!("failed to find block with tag {}", tg);
+                fail!();
+            }
+        }
+    }
+
+    pub fn docs<'a>(d: Doc<'a>, it: |uint, Doc<'a>| -> bool) -> bool {
+        let mut pos = d.start;
+        while pos < d.end {
+            let elt_tag = try_or!(vuint_at(d.data, pos), false);
+            let elt_size = try_or!(vuint_at(d.data, elt_tag.next), false);
+            pos = elt_size.next + elt_size.val;
+            let doc = Doc { data: d.data, start: elt_size.next, end: pos };
+            if !it(elt_tag.val, doc) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    pub fn tagged_docs<'a>(d: Doc<'a>, tg: uint, it: |Doc<'a>| -> bool) -> bool {
+        let mut pos = d.start;
+        while pos < d.end {
+            let elt_tag = try_or!(vuint_at(d.data, pos), false);
+            let elt_size = try_or!(vuint_at(d.data, elt_tag.next), false);
+            pos = elt_size.next + elt_size.val;
+            if elt_tag.val == tg {
+                let doc = Doc { data: d.data, start: elt_size.next,
+                                end: pos };
+                if !it(doc) {
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+    pub fn with_doc_data<'a, T>(d: Doc<'a>, f: |x: &'a [u8]| -> T) -> T {
+        f(d.data.slice(d.start, d.end))
+    }
+
+
+    pub fn doc_as_u8(d: Doc) -> u8 {
+        assert_eq!(d.end, d.start + 1u);
+        d.data[d.start]
+    }
+
+    pub fn doc_as_u16(d: Doc) -> u16 {
+        assert_eq!(d.end, d.start + 2u);
+        u64_from_be_bytes(d.data, d.start, 2u) as u16
+    }
+
+    pub fn doc_as_u32(d: Doc) -> u32 {
+        assert_eq!(d.end, d.start + 4u);
+        u64_from_be_bytes(d.data, d.start, 4u) as u32
+    }
+
+    pub fn doc_as_u64(d: Doc) -> u64 {
+        assert_eq!(d.end, d.start + 8u);
+        u64_from_be_bytes(d.data, d.start, 8u)
+    }
+
+    pub fn doc_as_i8(d: Doc) -> i8 { doc_as_u8(d) as i8 }
+    pub fn doc_as_i16(d: Doc) -> i16 { doc_as_u16(d) as i16 }
+    pub fn doc_as_i32(d: Doc) -> i32 { doc_as_u32(d) as i32 }
+    pub fn doc_as_i64(d: Doc) -> i64 { doc_as_u64(d) as i64 }
+
+    pub struct Decoder<'a> {
+        parent: Doc<'a>,
+        pos: uint,
+    }
+
+    impl<'doc> Decoder<'doc> {
+        pub fn new(d: Doc<'doc>) -> Decoder<'doc> {
+            Decoder {
+                parent: d,
+                pos: d.start
+            }
+        }
+
+        fn _check_label(&mut self, lbl: &str) -> DecodeResult<()> {
+            if self.pos < self.parent.end {
+                let TaggedDoc { tag: r_tag, doc: r_doc } =
+                    try!(doc_at(self.parent.data, self.pos));
+
+                if r_tag == (EsLabel as uint) {
+                    self.pos = r_doc.end;
+                    let str = r_doc.as_str_slice();
+                    if lbl != str {
+                        return Err(Expected(format!("Expected label {} but \
+                                                     found {}", lbl, str)));
+                    }
+                }
+            }
+            Ok(())
+        }
+
+        fn next_doc(&mut self, exp_tag: EbmlEncoderTag) -> DecodeResult<Doc<'doc>> {
+            debug!(". next_doc(exp_tag={})", exp_tag);
+            if self.pos >= self.parent.end {
+                return Err(Expected(format!("no more documents in \
+                                             current node!")));
+            }
+            let TaggedDoc { tag: r_tag, doc: r_doc } =
+                try!(doc_at(self.parent.data, self.pos));
+            debug!("self.parent={}-{} self.pos={} r_tag={} r_doc={}-{}",
+                   self.parent.start,
+                   self.parent.end,
+                   self.pos,
+                   r_tag,
+                   r_doc.start,
+                   r_doc.end);
+            if r_tag != (exp_tag as uint) {
+                return Err(Expected(format!("expected EBML doc with tag {} but \
+                                             found tag {}", exp_tag, r_tag)));
+            }
+            if r_doc.end > self.parent.end {
+                return Err(Expected(format!("invalid EBML, child extends to \
+                                             {:#x}, parent to {:#x}",
+                                            r_doc.end, self.parent.end)));
+            }
+            self.pos = r_doc.end;
+            Ok(r_doc)
+        }
+
+        fn push_doc<T>(&mut self, exp_tag: EbmlEncoderTag,
+                       f: |&mut Decoder<'doc>| -> DecodeResult<T>) -> DecodeResult<T> {
+            let d = try!(self.next_doc(exp_tag));
+            let old_parent = self.parent;
+            let old_pos = self.pos;
+            self.parent = d;
+            self.pos = d.start;
+            let r = try!(f(self));
+            self.parent = old_parent;
+            self.pos = old_pos;
+            Ok(r)
+        }
+
+        fn _next_uint(&mut self, exp_tag: EbmlEncoderTag) -> DecodeResult<uint> {
+            let r = doc_as_u32(try!(self.next_doc(exp_tag)));
+            debug!("_next_uint exp_tag={} result={}", exp_tag, r);
+            Ok(r as uint)
+        }
+
+        pub fn read_opaque<R>(&mut self,
+                              op: |&mut Decoder<'doc>, Doc| -> DecodeResult<R>) -> DecodeResult<R> {
+            let doc = try!(self.next_doc(EsOpaque));
+
+            let (old_parent, old_pos) = (self.parent, self.pos);
+            self.parent = doc;
+            self.pos = doc.start;
+
+            let result = try!(op(self, doc));
+
+            self.parent = old_parent;
+            self.pos = old_pos;
+            Ok(result)
+        }
+    }
+
+    impl<'doc> serialize::Decoder<Error> for Decoder<'doc> {
+        fn read_nil(&mut self) -> DecodeResult<()> { Ok(()) }
+
+        fn read_u64(&mut self) -> DecodeResult<u64> { Ok(doc_as_u64(try!(self.next_doc(EsU64)))) }
+        fn read_u32(&mut self) -> DecodeResult<u32> { Ok(doc_as_u32(try!(self.next_doc(EsU32)))) }
+        fn read_u16(&mut self) -> DecodeResult<u16> { Ok(doc_as_u16(try!(self.next_doc(EsU16)))) }
+        fn read_u8 (&mut self) -> DecodeResult<u8 > { Ok(doc_as_u8 (try!(self.next_doc(EsU8 )))) }
+        fn read_uint(&mut self) -> DecodeResult<uint> {
+            let v = doc_as_u64(try!(self.next_doc(EsUint)));
+            if v > (::std::uint::MAX as u64) {
+                Err(IntTooBig(v as uint))
+            } else {
+                Ok(v as uint)
+            }
+        }
+
+        fn read_i64(&mut self) -> DecodeResult<i64> {
+            Ok(doc_as_u64(try!(self.next_doc(EsI64))) as i64)
+        }
+        fn read_i32(&mut self) -> DecodeResult<i32> {
+            Ok(doc_as_u32(try!(self.next_doc(EsI32))) as i32)
+        }
+        fn read_i16(&mut self) -> DecodeResult<i16> {
+            Ok(doc_as_u16(try!(self.next_doc(EsI16))) as i16)
+        }
+        fn read_i8 (&mut self) -> DecodeResult<i8> {
+            Ok(doc_as_u8(try!(self.next_doc(EsI8 ))) as i8)
+        }
+        fn read_int(&mut self) -> DecodeResult<int> {
+            let v = doc_as_u64(try!(self.next_doc(EsInt))) as i64;
+            if v > (int::MAX as i64) || v < (int::MIN as i64) {
+                debug!("FIXME \\#6122: Removing this makes this function miscompile");
+                Err(IntTooBig(v as uint))
+            } else {
+                Ok(v as int)
+            }
+        }
+
+        fn read_bool(&mut self) -> DecodeResult<bool> {
+            Ok(doc_as_u8(try!(self.next_doc(EsBool))) != 0)
+        }
+
+        fn read_f64(&mut self) -> DecodeResult<f64> {
+            let bits = doc_as_u64(try!(self.next_doc(EsF64)));
+            Ok(unsafe { transmute(bits) })
+        }
+        fn read_f32(&mut self) -> DecodeResult<f32> {
+            let bits = doc_as_u32(try!(self.next_doc(EsF32)));
+            Ok(unsafe { transmute(bits) })
+        }
+        fn read_char(&mut self) -> DecodeResult<char> {
+            Ok(char::from_u32(doc_as_u32(try!(self.next_doc(EsChar)))).unwrap())
+        }
+        fn read_str(&mut self) -> DecodeResult<String> {
+            Ok(try!(self.next_doc(EsStr)).as_str())
+        }
+
+        // Compound types:
+        fn read_enum<T>(&mut self,
+                        name: &str,
+                        f: |&mut Decoder<'doc>| -> DecodeResult<T>) -> DecodeResult<T> {
+            debug!("read_enum({})", name);
+            try!(self._check_label(name));
+
+            let doc = try!(self.next_doc(EsEnum));
+
+            let (old_parent, old_pos) = (self.parent, self.pos);
+            self.parent = doc;
+            self.pos = self.parent.start;
+
+            let result = try!(f(self));
+
+            self.parent = old_parent;
+            self.pos = old_pos;
+            Ok(result)
+        }
+
+        fn read_enum_variant<T>(&mut self,
+                                _: &[&str],
+                                f: |&mut Decoder<'doc>, uint| -> DecodeResult<T>)
+                                -> DecodeResult<T> {
+            debug!("read_enum_variant()");
+            let idx = try!(self._next_uint(EsEnumVid));
+            debug!("  idx={}", idx);
+
+            let doc = try!(self.next_doc(EsEnumBody));
+
+            let (old_parent, old_pos) = (self.parent, self.pos);
+            self.parent = doc;
+            self.pos = self.parent.start;
+
+            let result = try!(f(self, idx));
+
+            self.parent = old_parent;
+            self.pos = old_pos;
+            Ok(result)
+        }
+
+        fn read_enum_variant_arg<T>(&mut self,
+                                    idx: uint,
+                                    f: |&mut Decoder<'doc>| -> DecodeResult<T>) -> DecodeResult<T> {
+            debug!("read_enum_variant_arg(idx={})", idx);
+            f(self)
+        }
+
+        fn read_enum_struct_variant<T>(&mut self,
+                                       _: &[&str],
+                                       f: |&mut Decoder<'doc>, uint| -> DecodeResult<T>)
+                                       -> DecodeResult<T> {
+            debug!("read_enum_struct_variant()");
+            let idx = try!(self._next_uint(EsEnumVid));
+            debug!("  idx={}", idx);
+
+            let doc = try!(self.next_doc(EsEnumBody));
+
+            let (old_parent, old_pos) = (self.parent, self.pos);
+            self.parent = doc;
+            self.pos = self.parent.start;
+
+            let result = try!(f(self, idx));
+
+            self.parent = old_parent;
+            self.pos = old_pos;
+            Ok(result)
+        }
+
+        fn read_enum_struct_variant_field<T>(&mut self,
+                                             name: &str,
+                                             idx: uint,
+                                             f: |&mut Decoder<'doc>| -> DecodeResult<T>)
+                                             -> DecodeResult<T> {
+            debug!("read_enum_struct_variant_arg(name={}, idx={})", name, idx);
+            f(self)
+        }
+
+        fn read_struct<T>(&mut self,
+                          name: &str,
+                          _: uint,
+                          f: |&mut Decoder<'doc>| -> DecodeResult<T>)
+                          -> DecodeResult<T> {
+            debug!("read_struct(name={})", name);
+            f(self)
+        }
+
+        fn read_struct_field<T>(&mut self,
+                                name: &str,
+                                idx: uint,
+                                f: |&mut Decoder<'doc>| -> DecodeResult<T>)
+                                -> DecodeResult<T> {
+            debug!("read_struct_field(name={}, idx={})", name, idx);
+            try!(self._check_label(name));
+            f(self)
+        }
+
+        fn read_tuple<T>(&mut self,
+                         f: |&mut Decoder<'doc>, uint| -> DecodeResult<T>) -> DecodeResult<T> {
+            debug!("read_tuple()");
+            self.read_seq(f)
+        }
+
+        fn read_tuple_arg<T>(&mut self, idx: uint, f: |&mut Decoder<'doc>| -> DecodeResult<T>)
+                             -> DecodeResult<T> {
+            debug!("read_tuple_arg(idx={})", idx);
+            self.read_seq_elt(idx, f)
+        }
+
+        fn read_tuple_struct<T>(&mut self,
+                                name: &str,
+                                f: |&mut Decoder<'doc>, uint| -> DecodeResult<T>)
+                                -> DecodeResult<T> {
+            debug!("read_tuple_struct(name={})", name);
+            self.read_tuple(f)
+        }
+
+        fn read_tuple_struct_arg<T>(&mut self,
+                                    idx: uint,
+                                    f: |&mut Decoder<'doc>| -> DecodeResult<T>)
+                                    -> DecodeResult<T> {
+            debug!("read_tuple_struct_arg(idx={})", idx);
+            self.read_tuple_arg(idx, f)
+        }
+
+        fn read_option<T>(&mut self,
+                          f: |&mut Decoder<'doc>, bool| -> DecodeResult<T>) -> DecodeResult<T> {
+            debug!("read_option()");
+            self.read_enum("Option", |this| {
+                this.read_enum_variant(["None", "Some"], |this, idx| {
+                    match idx {
+                        0 => f(this, false),
+                        1 => f(this, true),
+                        _ => {
+                            Err(Expected(format!("Expected None or Some")))
+                        }
+                    }
+                })
+            })
+        }
+
+        fn read_seq<T>(&mut self,
+                       f: |&mut Decoder<'doc>, uint| -> DecodeResult<T>) -> DecodeResult<T> {
+            debug!("read_seq()");
+            self.push_doc(EsVec, |d| {
+                let len = try!(d._next_uint(EsVecLen));
+                debug!("  len={}", len);
+                f(d, len)
+            })
+        }
+
+        fn read_seq_elt<T>(&mut self, idx: uint, f: |&mut Decoder<'doc>| -> DecodeResult<T>)
+                           -> DecodeResult<T> {
+            debug!("read_seq_elt(idx={})", idx);
+            self.push_doc(EsVecElt, f)
+        }
+
+        fn read_map<T>(&mut self,
+                       f: |&mut Decoder<'doc>, uint| -> DecodeResult<T>) -> DecodeResult<T> {
+            debug!("read_map()");
+            self.push_doc(EsMap, |d| {
+                let len = try!(d._next_uint(EsMapLen));
+                debug!("  len={}", len);
+                f(d, len)
+            })
+        }
+
+        fn read_map_elt_key<T>(&mut self, idx: uint, f: |&mut Decoder<'doc>| -> DecodeResult<T>)
+                               -> DecodeResult<T> {
+            debug!("read_map_elt_key(idx={})", idx);
+            self.push_doc(EsMapKey, f)
+        }
+
+        fn read_map_elt_val<T>(&mut self, idx: uint, f: |&mut Decoder<'doc>| -> DecodeResult<T>)
+                               -> DecodeResult<T> {
+            debug!("read_map_elt_val(idx={})", idx);
+            self.push_doc(EsMapVal, f)
+        }
+    }
+}
+
+pub mod writer {
+    use std::clone::Clone;
+    use std::io::extensions::u64_to_be_bytes;
+    use std::io::{Writer, Seek};
+    use std::io;
+    use std::mem;
+
+    use super::{ EsVec, EsMap, EsEnum, EsVecLen, EsVecElt, EsMapLen, EsMapKey,
+        EsEnumVid, EsU64, EsU32, EsU16, EsU8, EsInt, EsI64, EsI32, EsI16, EsI8,
+        EsBool, EsF64, EsF32, EsChar, EsStr, EsMapVal, EsEnumBody, EsUint,
+        EsOpaque, EsLabel, EbmlEncoderTag };
+
+    use serialize;
+
+
+    pub type EncodeResult = io::IoResult<()>;
+
+    // rbml writing
+    pub struct Encoder<'a, W> {
+        pub writer: &'a mut W,
+        size_positions: Vec<uint>,
+    }
+
+    fn write_sized_vuint<W: Writer>(w: &mut W, n: uint, size: uint) -> EncodeResult {
+        match size {
+            1u => w.write(&[0x80u8 | (n as u8)]),
+            2u => w.write(&[0x40u8 | ((n >> 8_u) as u8), n as u8]),
+            3u => w.write(&[0x20u8 | ((n >> 16_u) as u8), (n >> 8_u) as u8,
+                            n as u8]),
+            4u => w.write(&[0x10u8 | ((n >> 24_u) as u8), (n >> 16_u) as u8,
+                            (n >> 8_u) as u8, n as u8]),
+            _ => Err(io::IoError {
+                kind: io::OtherIoError,
+                desc: "int too big",
+                detail: Some(format!("{}", n))
+            })
+        }
+    }
+
+    fn write_vuint<W: Writer>(w: &mut W, n: uint) -> EncodeResult {
+        if n < 0x7f_u { return write_sized_vuint(w, n, 1u); }
+        if n < 0x4000_u { return write_sized_vuint(w, n, 2u); }
+        if n < 0x200000_u { return write_sized_vuint(w, n, 3u); }
+        if n < 0x10000000_u { return write_sized_vuint(w, n, 4u); }
+        Err(io::IoError {
+            kind: io::OtherIoError,
+            desc: "int too big",
+            detail: Some(format!("{}", n))
+        })
+    }
+
+    // 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 {
+                writer: w,
+                size_positions: vec!(),
+            }
+        }
+
+        /// FIXME(pcwalton): Workaround for badness in trans. DO NOT USE ME.
+        pub unsafe fn unsafe_clone(&self) -> Encoder<'a, W> {
+            Encoder {
+                writer: mem::transmute_copy(&self.writer),
+                size_positions: self.size_positions.clone(),
+            }
+        }
+
+        pub fn start_tag(&mut self, tag_id: uint) -> EncodeResult {
+            debug!("Start tag {}", tag_id);
+
+            // Write the enum ID:
+            try!(write_vuint(self.writer, tag_id));
+
+            // Write a placeholder four-byte size.
+            self.size_positions.push(try!(self.writer.tell()) as uint);
+            let zeroes: &[u8] = &[0u8, 0u8, 0u8, 0u8];
+            self.writer.write(zeroes)
+        }
+
+        pub fn end_tag(&mut self) -> EncodeResult {
+            let last_size_pos = self.size_positions.pop().unwrap();
+            let cur_pos = try!(self.writer.tell());
+            try!(self.writer.seek(last_size_pos as i64, io::SeekSet));
+            let size = cur_pos as uint - last_size_pos - 4;
+            try!(write_sized_vuint(self.writer, size, 4u));
+            let r = try!(self.writer.seek(cur_pos as i64, io::SeekSet));
+
+            debug!("End tag (size = {})", size);
+            Ok(r)
+        }
+
+        pub fn wr_tag(&mut self, tag_id: uint, blk: || -> EncodeResult) -> EncodeResult {
+            try!(self.start_tag(tag_id));
+            try!(blk());
+            self.end_tag()
+        }
+
+        pub fn wr_tagged_bytes(&mut self, tag_id: uint, b: &[u8]) -> EncodeResult {
+            try!(write_vuint(self.writer, tag_id));
+            try!(write_vuint(self.writer, b.len()));
+            self.writer.write(b)
+        }
+
+        pub fn wr_tagged_u64(&mut self, tag_id: uint, v: u64) -> EncodeResult {
+            u64_to_be_bytes(v, 8u, |v| {
+                self.wr_tagged_bytes(tag_id, v)
+            })
+        }
+
+        pub fn wr_tagged_u32(&mut self, tag_id: uint, v: u32)  -> EncodeResult{
+            u64_to_be_bytes(v as u64, 4u, |v| {
+                self.wr_tagged_bytes(tag_id, v)
+            })
+        }
+
+        pub fn wr_tagged_u16(&mut self, tag_id: uint, v: u16) -> EncodeResult {
+            u64_to_be_bytes(v as u64, 2u, |v| {
+                self.wr_tagged_bytes(tag_id, v)
+            })
+        }
+
+        pub fn wr_tagged_u8(&mut self, tag_id: uint, v: u8) -> EncodeResult {
+            self.wr_tagged_bytes(tag_id, &[v])
+        }
+
+        pub fn wr_tagged_i64(&mut self, tag_id: uint, v: i64) -> EncodeResult {
+            u64_to_be_bytes(v as u64, 8u, |v| {
+                self.wr_tagged_bytes(tag_id, v)
+            })
+        }
+
+        pub fn wr_tagged_i32(&mut self, tag_id: uint, v: i32) -> EncodeResult {
+            u64_to_be_bytes(v as u64, 4u, |v| {
+                self.wr_tagged_bytes(tag_id, v)
+            })
+        }
+
+        pub fn wr_tagged_i16(&mut self, tag_id: uint, v: i16) -> EncodeResult {
+            u64_to_be_bytes(v as u64, 2u, |v| {
+                self.wr_tagged_bytes(tag_id, v)
+            })
+        }
+
+        pub fn wr_tagged_i8(&mut self, tag_id: uint, v: i8) -> EncodeResult {
+            self.wr_tagged_bytes(tag_id, &[v as u8])
+        }
+
+        pub fn wr_tagged_str(&mut self, tag_id: uint, v: &str) -> EncodeResult {
+            self.wr_tagged_bytes(tag_id, v.as_bytes())
+        }
+
+        pub fn wr_bytes(&mut self, b: &[u8]) -> EncodeResult {
+            debug!("Write {} bytes", b.len());
+            self.writer.write(b)
+        }
+
+        pub fn wr_str(&mut self, s: &str) -> EncodeResult {
+            debug!("Write str: {}", s);
+            self.writer.write(s.as_bytes())
+        }
+    }
+
+    // FIXME (#2743): optionally perform "relaxations" on end_tag to more
+    // efficiently encode sizes; this is a fixed point iteration
+
+    // Set to true to generate more debugging in EBML code.
+    // Totally lame approach.
+    static DEBUG: bool = true;
+
+    impl<'a, W: Writer + Seek> Encoder<'a, W> {
+        // used internally to emit things like the vector length and so on
+        fn _emit_tagged_uint(&mut self, t: EbmlEncoderTag, v: uint) -> EncodeResult {
+            assert!(v <= 0xFFFF_FFFF_u);
+            self.wr_tagged_u32(t as uint, v as u32)
+        }
+
+        fn _emit_label(&mut self, label: &str) -> EncodeResult {
+            // There are various strings that we have access to, such as
+            // the name of a record field, which do not actually appear in
+            // the encoded EBML (normally).  This is just for
+            // efficiency.  When debugging, though, we can emit such
+            // labels and then they will be checked by decoder to
+            // try and check failures more quickly.
+            if DEBUG { self.wr_tagged_str(EsLabel as uint, label) }
+            else { Ok(()) }
+        }
+
+        pub fn emit_opaque(&mut self, f: |&mut Encoder<W>| -> EncodeResult) -> EncodeResult {
+            try!(self.start_tag(EsOpaque as uint));
+            try!(f(self));
+            self.end_tag()
+        }
+    }
+
+    impl<'a, W: Writer + Seek> serialize::Encoder<io::IoError> for Encoder<'a, W> {
+        fn emit_nil(&mut self) -> EncodeResult {
+            Ok(())
+        }
+
+        fn emit_uint(&mut self, v: uint) -> EncodeResult {
+            self.wr_tagged_u64(EsUint as uint, v as u64)
+        }
+        fn emit_u64(&mut self, v: u64) -> EncodeResult {
+            self.wr_tagged_u64(EsU64 as uint, v)
+        }
+        fn emit_u32(&mut self, v: u32) -> EncodeResult {
+            self.wr_tagged_u32(EsU32 as uint, v)
+        }
+        fn emit_u16(&mut self, v: u16) -> EncodeResult {
+            self.wr_tagged_u16(EsU16 as uint, v)
+        }
+        fn emit_u8(&mut self, v: u8) -> EncodeResult {
+            self.wr_tagged_u8(EsU8 as uint, v)
+        }
+
+        fn emit_int(&mut self, v: int) -> EncodeResult {
+            self.wr_tagged_i64(EsInt as uint, v as i64)
+        }
+        fn emit_i64(&mut self, v: i64) -> EncodeResult {
+            self.wr_tagged_i64(EsI64 as uint, v)
+        }
+        fn emit_i32(&mut self, v: i32) -> EncodeResult {
+            self.wr_tagged_i32(EsI32 as uint, v)
+        }
+        fn emit_i16(&mut self, v: i16) -> EncodeResult {
+            self.wr_tagged_i16(EsI16 as uint, v)
+        }
+        fn emit_i8(&mut self, v: i8) -> EncodeResult {
+            self.wr_tagged_i8(EsI8 as uint, v)
+        }
+
+        fn emit_bool(&mut self, v: bool) -> EncodeResult {
+            self.wr_tagged_u8(EsBool as uint, v as u8)
+        }
+
+        fn emit_f64(&mut self, v: f64) -> EncodeResult {
+            let bits = unsafe { mem::transmute(v) };
+            self.wr_tagged_u64(EsF64 as uint, bits)
+        }
+        fn emit_f32(&mut self, v: f32) -> EncodeResult {
+            let bits = unsafe { mem::transmute(v) };
+            self.wr_tagged_u32(EsF32 as uint, bits)
+        }
+        fn emit_char(&mut self, v: char) -> EncodeResult {
+            self.wr_tagged_u32(EsChar as uint, v as u32)
+        }
+
+        fn emit_str(&mut self, v: &str) -> EncodeResult {
+            self.wr_tagged_str(EsStr as uint, v)
+        }
+
+        fn emit_enum(&mut self,
+                     name: &str,
+                     f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
+            try!(self._emit_label(name));
+            try!(self.start_tag(EsEnum as uint));
+            try!(f(self));
+            self.end_tag()
+        }
+
+        fn emit_enum_variant(&mut self,
+                             _: &str,
+                             v_id: uint,
+                             _: uint,
+                             f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
+            try!(self._emit_tagged_uint(EsEnumVid, v_id));
+            try!(self.start_tag(EsEnumBody as uint));
+            try!(f(self));
+            self.end_tag()
+        }
+
+        fn emit_enum_variant_arg(&mut self,
+                                 _: uint,
+                                 f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
+            f(self)
+        }
+
+        fn emit_enum_struct_variant(&mut self,
+                                    v_name: &str,
+                                    v_id: uint,
+                                    cnt: uint,
+                                    f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
+            self.emit_enum_variant(v_name, v_id, cnt, f)
+        }
+
+        fn emit_enum_struct_variant_field(&mut self,
+                                          _: &str,
+                                          idx: uint,
+                                          f: |&mut Encoder<'a, W>| -> EncodeResult)
+            -> EncodeResult {
+            self.emit_enum_variant_arg(idx, f)
+        }
+
+        fn emit_struct(&mut self,
+                       _: &str,
+                       _len: uint,
+                       f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
+            f(self)
+        }
+
+        fn emit_struct_field(&mut self,
+                             name: &str,
+                             _: uint,
+                             f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
+            try!(self._emit_label(name));
+            f(self)
+        }
+
+        fn emit_tuple(&mut self,
+                      len: uint,
+                      f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
+            self.emit_seq(len, f)
+        }
+        fn emit_tuple_arg(&mut self,
+                          idx: uint,
+                          f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
+            self.emit_seq_elt(idx, f)
+        }
+
+        fn emit_tuple_struct(&mut self,
+                             _: &str,
+                             len: uint,
+                             f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
+            self.emit_seq(len, f)
+        }
+        fn emit_tuple_struct_arg(&mut self,
+                                 idx: uint,
+                                 f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
+            self.emit_seq_elt(idx, f)
+        }
+
+        fn emit_option(&mut self,
+                       f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
+            self.emit_enum("Option", f)
+        }
+        fn emit_option_none(&mut self) -> EncodeResult {
+            self.emit_enum_variant("None", 0, 0, |_| Ok(()))
+        }
+        fn emit_option_some(&mut self,
+                            f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
+
+            self.emit_enum_variant("Some", 1, 1, f)
+        }
+
+        fn emit_seq(&mut self,
+                    len: uint,
+                    f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
+
+            try!(self.start_tag(EsVec as uint));
+            try!(self._emit_tagged_uint(EsVecLen, len));
+            try!(f(self));
+            self.end_tag()
+        }
+
+        fn emit_seq_elt(&mut self,
+                        _idx: uint,
+                        f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
+
+            try!(self.start_tag(EsVecElt as uint));
+            try!(f(self));
+            self.end_tag()
+        }
+
+        fn emit_map(&mut self,
+                    len: uint,
+                    f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
+
+            try!(self.start_tag(EsMap as uint));
+            try!(self._emit_tagged_uint(EsMapLen, len));
+            try!(f(self));
+            self.end_tag()
+        }
+
+        fn emit_map_elt_key(&mut self,
+                            _idx: uint,
+                            f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
+
+            try!(self.start_tag(EsMapKey as uint));
+            try!(f(self));
+            self.end_tag()
+        }
+
+        fn emit_map_elt_val(&mut self,
+                            _idx: uint,
+                            f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
+            try!(self.start_tag(EsMapVal as uint));
+            try!(f(self));
+            self.end_tag()
+        }
+    }
+}
+
+// ___________________________________________________________________________
+// Testing
+
+#[cfg(test)]
+mod tests {
+    use super::{Doc, reader, writer};
+    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<u64> {
+        // 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<u8>,
+        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<u8> { 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<u64> { 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 = [
+            0x80,
+            0xff,
+            0x40, 0x00,
+            0x7f, 0xff,
+            0x20, 0x00, 0x00,
+            0x3f, 0xff, 0xff,
+            0x10, 0x00, 0x00, 0x00,
+            0x1f, 0xff, 0xff, 0xff
+        ];
+
+        let mut res: reader::Res;
+
+        // Class A
+        res = reader::vuint_at(data, 0).unwrap();
+        assert_eq!(res.val, 0);
+        assert_eq!(res.next, 1);
+        res = reader::vuint_at(data, res.next).unwrap();
+        assert_eq!(res.val, (1 << 7) - 1);
+        assert_eq!(res.next, 2);
+
+        // Class B
+        res = reader::vuint_at(data, res.next).unwrap();
+        assert_eq!(res.val, 0);
+        assert_eq!(res.next, 4);
+        res = reader::vuint_at(data, res.next).unwrap();
+        assert_eq!(res.val, (1 << 14) - 1);
+        assert_eq!(res.next, 6);
+
+        // Class C
+        res = reader::vuint_at(data, res.next).unwrap();
+        assert_eq!(res.val, 0);
+        assert_eq!(res.next, 9);
+        res = reader::vuint_at(data, res.next).unwrap();
+        assert_eq!(res.val, (1 << 21) - 1);
+        assert_eq!(res.next, 12);
+
+        // Class D
+        res = reader::vuint_at(data, res.next).unwrap();
+        assert_eq!(res.val, 0);
+        assert_eq!(res.next, 16);
+        res = reader::vuint_at(data, res.next).unwrap();
+        assert_eq!(res.val, (1 << 28) - 1);
+        assert_eq!(res.next, 20);
+    }
+
+    #[test]
+    fn test_option_int() {
+        fn test_v(v: Option<int>) {
+            debug!("v == {}", v);
+            let mut wr = SeekableMemWriter::new();
+            {
+                let mut rbml_w = writer::Encoder::new(&mut wr);
+                let _ = v.encode(&mut rbml_w);
+            }
+            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);
+        }
+
+        test_v(Some(22));
+        test_v(None);
+        test_v(Some(3));
+    }
+}
+
+#[cfg(test)]
+mod bench {
+    #![allow(non_snake_case_functions)]
+    use test::Bencher;
+    use super::reader;
+
+    #[bench]
+    pub fn vuint_at_A_aligned(b: &mut Bencher) {
+        let data = Vec::from_fn(4*100, |i| {
+            match i % 2 {
+              0 => 0x80u8,
+              _ => i as u8,
+            }
+        });
+        let mut sum = 0u;
+        b.iter(|| {
+            let mut i = 0;
+            while i < data.len() {
+                sum += reader::vuint_at(data.as_slice(), i).unwrap().val;
+                i += 4;
+            }
+        });
+    }
+
+    #[bench]
+    pub fn vuint_at_A_unaligned(b: &mut Bencher) {
+        let data = Vec::from_fn(4*100+1, |i| {
+            match i % 2 {
+              1 => 0x80u8,
+              _ => i as u8
+            }
+        });
+        let mut sum = 0u;
+        b.iter(|| {
+            let mut i = 1;
+            while i < data.len() {
+                sum += reader::vuint_at(data.as_slice(), i).unwrap().val;
+                i += 4;
+            }
+        });
+    }
+
+    #[bench]
+    pub fn vuint_at_D_aligned(b: &mut Bencher) {
+        let data = Vec::from_fn(4*100, |i| {
+            match i % 4 {
+              0 => 0x10u8,
+              3 => i as u8,
+              _ => 0u8
+            }
+        });
+        let mut sum = 0u;
+        b.iter(|| {
+            let mut i = 0;
+            while i < data.len() {
+                sum += reader::vuint_at(data.as_slice(), i).unwrap().val;
+                i += 4;
+            }
+        });
+    }
+
+    #[bench]
+    pub fn vuint_at_D_unaligned(b: &mut Bencher) {
+        let data = Vec::from_fn(4*100+1, |i| {
+            match i % 4 {
+              1 => 0x10u8,
+              0 => i as u8,
+              _ => 0u8
+            }
+        });
+        let mut sum = 0u;
+        b.iter(|| {
+            let mut i = 1;
+            while i < data.len() {
+                sum += reader::vuint_at(data.as_slice(), i).unwrap().val;
+                i += 4;
+            }
+        });
+    }
+}
index 82040f141593e7575a1ed9224a5f5757e8835903..5385c610350787c39ad8744d3f6bd59ceedaeab4 100644 (file)
@@ -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;
index b1b366ec03090de4526f3ab2626956c4056b8a53..252d19bbb237b838cab6db360de0bcc8b1e3c018 100644 (file)
@@ -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),
                            || {
index f7576ffb4818bb4af32eb603fd101428f58f92a5..c9807a18383e8ef5bc932222cfb55f306e44b121 100644 (file)
@@ -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<ebml::Doc<'a>> {
+fn lookup_hash<'a>(d: rbml::Doc<'a>, eq_fn: |&[u8]| -> bool,
+                   hash: u64) -> Option<rbml::Doc<'a>> {
     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<ebml::Doc<'a>> {
+                           items: rbml::Doc<'a>) -> Option<rbml::Doc<'a>> {
     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<ast::DefId> {
+fn item_parent_item(d: rbml::Doc) -> Option<ast::DefId> {
     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<ast::DefId> {
 }
 
 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<ast::DefId> {
+fn get_provided_source(d: rbml::Doc, cdata: Cmd) -> Option<ast::DefId> {
     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<ty::Disr> {
+fn variant_disr_val(d: rbml::Doc) -> Option<ty::Disr> {
     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<ty::RegionParameterDef>
 {
     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<ast::DefId> {
+fn enum_variant_ids(item: rbml::Doc, cdata: Cmd) -> Vec<ast::DefId> {
     let mut ids: Vec<ast::DefId> = 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<ast::DefId> {
     return ids;
 }
 
-fn item_path(item_doc: ebml::Doc) -> Vec<ast_map::PathElem> {
+fn item_path(item_doc: rbml::Doc) -> Vec<ast_map::PathElem> {
     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<ast_map::PathElem> {
     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<IdentInterner>,
                                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<IdentInterner>,
             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<IdentInterner>,
                                 |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<IdentInterner>,
             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<IdentInterner>,
                           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<IdentInterner>,
                                     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<ast_map::PathElem> {
 pub type DecodeInlinedItem<'a> = |cdata: Cmd,
                                   tcx: &ty::ctxt,
                                   path: Vec<ast_map::PathElem>,
-                                  par_doc: ebml::Doc|: 'a
+                                  par_doc: rbml::Doc|: 'a
                                   -> Result<ast::InlinedItem, Vec<ast_map::PathElem> >;
 
 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<IdentInterner>, cdata: Cmd, id: ast::NodeId,
                      tcx: &ty::ctxt) -> Vec<Rc<ty::VariantInfo>> {
     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<IdentInterner>, 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<ast::NodeId, Vec<ast::Attribute>> {
-    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<IdentInterner>, cdata: Cmd, id: ast::NodeId)
     result
 }
 
-fn get_meta_items(md: ebml::Doc) -> Vec<Gc<ast::MetaItem>> {
+fn get_meta_items(md: rbml::Doc) -> Vec<Gc<ast::MetaItem>> {
     let mut items: Vec<Gc<ast::MetaItem>> = 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<Gc<ast::MetaItem>> {
     return items;
 }
 
-fn get_attributes(md: ebml::Doc) -> Vec<ast::Attribute> {
+fn get_attributes(md: rbml::Doc) -> Vec<ast::Attribute> {
     let mut attrs: Vec<ast::Attribute> = Vec::new();
     match reader::maybe_get_doc(md, tag_attributes) {
       Some(attrs_d) => {
@@ -1082,7 +1082,7 @@ fn get_attributes(md: ebml::Doc) -> Vec<ast::Attribute> {
     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<ast::Attribute> {
-    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<CrateDep> {
     let mut deps: Vec<CrateDep> = 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<Svh> {
-    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<String> {
-    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<String> {
-    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<ast::NodeId> {
-    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<String> {
-    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<String> {
 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<lang_items::LangItem>
 {
-    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<String> {
 
 pub fn get_reachable_extern_fns(cdata: Cmd) -> Vec<ast::DefId> {
     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 {
index dbda4f58d960f91fc721e205ccdc5431acf6dc87..40da534bfabaf70beef74d573ebadde6c129f591 100644 (file)
@@ -52,7 +52,7 @@
 use syntax::visit::Visitor;
 use syntax::visit;
 use syntax;
-use writer = serialize::ebml::writer;
+use rbml::writer;
 
 /// 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<T> {
     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<ty::TypeParameterDef>,
                              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<ty::RegionParameterDef>) {
     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<Variant>],
                             index: &mut Vec<entry<i64>>) {
@@ -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<PI: Iterator<PathElem> + Clone>(ebml_w: &mut Encoder,
+fn encode_path<PI: Iterator<PathElem> + 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<Item>, 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<DefId>) {
     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<entry<i64>>)
                           -> Vec<entry<i64>> {
@@ -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<entry<i64>>,
                                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<attr::Stability>) {
+fn encode_stability(rbml_w: &mut Encoder, stab_opt: Option<attr::Stability>) {
     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<entry<i64>>,
                         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<entry<i64>>) {
         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<entry<i64>>,
                                 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<entry<i64>>) {
-    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<entry<i64>>) {
     // 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<entry<i64>>,
 }
@@ -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<entry<i64>> {
     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<T: Hash>(ebml_w: &mut Encoder, index: Vec<entry<T>>,
+fn encode_index<T: Hash>(rbml_w: &mut Encoder, index: Vec<entry<T>>,
                          write_fn: |&mut SeekableMemWriter, &T|) {
     let mut buckets: Vec<Vec<entry<T>>> = Vec::from_fn(256, |_| Vec::new());
     for elt in index.move_iter() {
@@ -1414,33 +1414,33 @@ fn encode_index<T: Hash>(ebml_w: &mut Encoder, index: Vec<entry<T>>,
         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<MetaItem>) {
+fn encode_meta_item(rbml_w: &mut Encoder, mi: Gc<MetaItem>) {
     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<decoder::CrateDep> {
         // 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<decoder::CrateDep> {
     // 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,11 +1808,11 @@ fn encode_dylib_dependency_formats(ebml_w: &mut Encoder, ecx: &EncodeContext) {
                     cstore::RequireStatic => "s",
                 })).to_string())
             }).collect::<Vec<String>>();
-            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.
@@ -1885,79 +1885,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;
             }
index 9a587dd77418259b7000b976386c77c0cbdfdd23..98111c7c4cfd4759ed40f01ac852cd60b301f3b8 100644 (file)
 use std::mem;
 use std::gc::GC;
 
-use serialize::ebml::reader;
-use serialize::ebml;
+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<ast_map::PathElem>,
-                           par_doc: ebml::Doc)
+                           par_doc: rbml::Doc)
                            -> Result<ast::InlinedItem, Vec<ast_map::PathElem>> {
     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<T>(ebml_w: &mut Encoder,
+fn encode_vec_per_param_space<T>(rbml_w: &mut Encoder,
                                  v: &subst::VecPerParamSpace<T>,
                                  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<Self>;
 }
 
-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<ebml::Doc<'a>> {
+    fn opt_child(&self, tag: c::astencode_tag) -> Option<rbml::Doc<'a>> {
         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<ty::t>;
     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<ast::Item>) {
-    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<ast::Item>) {
+    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<ast::Item> {
+fn decode_item_ast(par_doc: rbml::Doc) -> Gc<ast::Item> {
     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<Gc<ast::Item>>) {
     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);
 }
index ea301784c930e0966412a5ae13b8c2bad6d1ac16..cbb337be838cb0c63745204f6a523f01c1e980e0 100644 (file)
@@ -2593,7 +2593,7 @@ pub fn write_metadata(cx: &CrateContext, krate: &ast::Crate) -> Vec<u8> {
     }
 
     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/libserialize/ebml.rs b/src/libserialize/ebml.rs
deleted file mode 100644 (file)
index c343446..0000000
+++ /dev/null
@@ -1,1295 +0,0 @@
-// 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![allow(missing_doc)]
-
-use std::io;
-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
-
-// Common data structures
-#[deriving(Clone)]
-pub struct Doc<'a> {
-    pub data: &'a [u8],
-    pub start: uint,
-    pub end: uint,
-}
-
-impl<'doc> Doc<'doc> {
-    pub fn new(data: &'doc [u8]) -> Doc<'doc> {
-        Doc { data: data, start: 0u, end: data.len() }
-    }
-
-    pub fn get<'a>(&'a self, tag: uint) -> Doc<'a> {
-        reader::get_doc(*self, tag)
-    }
-
-    pub fn as_str_slice<'a>(&'a self) -> &'a str {
-        str::from_utf8(self.data.slice(self.start, self.end)).unwrap()
-    }
-
-    pub fn as_str(&self) -> String {
-        self.as_str_slice().to_string()
-    }
-}
-
-pub struct TaggedDoc<'a> {
-    tag: uint,
-    pub doc: Doc<'a>,
-}
-
-#[deriving(Show)]
-pub enum EbmlEncoderTag {
-    EsUint,     // 0
-    EsU64,      // 1
-    EsU32,      // 2
-    EsU16,      // 3
-    EsU8,       // 4
-    EsInt,      // 5
-    EsI64,      // 6
-    EsI32,      // 7
-    EsI16,      // 8
-    EsI8,       // 9
-    EsBool,     // 10
-    EsChar,     // 11
-    EsStr,      // 12
-    EsF64,      // 13
-    EsF32,      // 14
-    EsFloat,    // 15
-    EsEnum,     // 16
-    EsEnumVid,  // 17
-    EsEnumBody, // 18
-    EsVec,      // 19
-    EsVecLen,   // 20
-    EsVecElt,   // 21
-    EsMap,      // 22
-    EsMapLen,   // 23
-    EsMapKey,   // 24
-    EsMapVal,   // 25
-
-    EsOpaque,
-
-    EsLabel, // Used only when debugging
-}
-
-#[deriving(Show)]
-pub enum Error {
-    IntTooBig(uint),
-    Expected(String),
-    IoError(io::IoError)
-}
-// --------------------------------------
-
-pub mod reader {
-    use std::char;
-
-    use std::mem::transmute;
-    use std::int;
-    use std::option::{None, Option, Some};
-    use std::io::extensions::u64_from_be_bytes;
-
-    use serialize;
-
-    use super::{ EsVec, EsMap, EsEnum, EsVecLen, EsVecElt, EsMapLen, EsMapKey,
-        EsEnumVid, EsU64, EsU32, EsU16, EsU8, EsInt, EsI64, EsI32, EsI16, EsI8,
-        EsBool, EsF64, EsF32, EsChar, EsStr, EsMapVal, EsEnumBody, EsUint,
-        EsOpaque, EsLabel, EbmlEncoderTag, Doc, TaggedDoc, Error, IntTooBig,
-        Expected };
-
-    pub type DecodeResult<T> = Result<T, Error>;
-    // ebml reading
-
-    macro_rules! try_or(
-        ($e:expr, $r:expr) => (
-            match $e {
-                Ok(e) => e,
-                Err(e) => {
-                    debug!("ignored error: {}", e);
-                    return $r
-                }
-            }
-        )
-    )
-
-    pub struct Res {
-        pub val: uint,
-        pub next: uint
-    }
-
-    #[inline(never)]
-    fn vuint_at_slow(data: &[u8], start: uint) -> DecodeResult<Res> {
-        let a = data[start];
-        if a & 0x80u8 != 0u8 {
-            return Ok(Res {val: (a & 0x7fu8) as uint, next: start + 1u});
-        }
-        if a & 0x40u8 != 0u8 {
-            return Ok(Res {val: ((a & 0x3fu8) as uint) << 8u |
-                        (data[start + 1u] as uint),
-                    next: start + 2u});
-        }
-        if a & 0x20u8 != 0u8 {
-            return Ok(Res {val: ((a & 0x1fu8) as uint) << 16u |
-                        (data[start + 1u] as uint) << 8u |
-                        (data[start + 2u] as uint),
-                    next: start + 3u});
-        }
-        if a & 0x10u8 != 0u8 {
-            return Ok(Res {val: ((a & 0x0fu8) as uint) << 24u |
-                        (data[start + 1u] as uint) << 16u |
-                        (data[start + 2u] as uint) << 8u |
-                        (data[start + 3u] as uint),
-                    next: start + 4u});
-        }
-        Err(IntTooBig(a as uint))
-    }
-
-    pub fn vuint_at(data: &[u8], start: uint) -> DecodeResult<Res> {
-        if data.len() - start < 4 {
-            return vuint_at_slow(data, start);
-        }
-
-        // Lookup table for parsing EBML Element IDs as per http://ebml.sourceforge.net/specs/
-        // The Element IDs are parsed by reading a big endian u32 positioned at data[start].
-        // Using the four most significant bits of the u32 we lookup in the table below how the
-        // element ID should be derived from it.
-        //
-        // The table stores tuples (shift, mask) where shift is the number the u32 should be right
-        // shifted with and mask is the value the right shifted value should be masked with.
-        // If for example the most significant bit is set this means it's a class A ID and the u32
-        // should be right shifted with 24 and masked with 0x7f. Therefore we store (24, 0x7f) at
-        // index 0x8 - 0xF (four bit numbers where the most significant bit is set).
-        //
-        // By storing the number of shifts and masks in a table instead of checking in order if
-        // the most significant bit is set, the second most significant bit is set etc. we can
-        // replace up to three "and+branch" with a single table lookup which gives us a measured
-        // speedup of around 2x on x86_64.
-        static SHIFT_MASK_TABLE: [(uint, u32), ..16] = [
-            (0, 0x0), (0, 0x0fffffff),
-            (8, 0x1fffff), (8, 0x1fffff),
-            (16, 0x3fff), (16, 0x3fff), (16, 0x3fff), (16, 0x3fff),
-            (24, 0x7f), (24, 0x7f), (24, 0x7f), (24, 0x7f),
-            (24, 0x7f), (24, 0x7f), (24, 0x7f), (24, 0x7f)
-        ];
-
-        unsafe {
-            let ptr = data.as_ptr().offset(start as int) as *const u32;
-            let val = Int::from_be(*ptr);
-
-            let i = (val >> 28u) as uint;
-            let (shift, mask) = SHIFT_MASK_TABLE[i];
-            Ok(Res {
-                val: ((val >> shift) & mask) as uint,
-                next: start + (((32 - shift) >> 3) as uint)
-            })
-        }
-    }
-
-    pub fn doc_at<'a>(data: &'a [u8], start: uint) -> DecodeResult<TaggedDoc<'a>> {
-        let elt_tag = try!(vuint_at(data, start));
-        let elt_size = try!(vuint_at(data, elt_tag.next));
-        let end = elt_size.next + elt_size.val;
-        Ok(TaggedDoc {
-            tag: elt_tag.val,
-            doc: Doc { data: data, start: elt_size.next, end: end }
-        })
-    }
-
-    pub fn maybe_get_doc<'a>(d: Doc<'a>, tg: uint) -> Option<Doc<'a>> {
-        let mut pos = d.start;
-        while pos < d.end {
-            let elt_tag = try_or!(vuint_at(d.data, pos), None);
-            let elt_size = try_or!(vuint_at(d.data, elt_tag.next), None);
-            pos = elt_size.next + elt_size.val;
-            if elt_tag.val == tg {
-                return Some(Doc { data: d.data, start: elt_size.next,
-                                  end: pos });
-            }
-        }
-        None
-    }
-
-    pub fn get_doc<'a>(d: Doc<'a>, tg: uint) -> Doc<'a> {
-        match maybe_get_doc(d, tg) {
-            Some(d) => d,
-            None => {
-                error!("failed to find block with tag {}", tg);
-                fail!();
-            }
-        }
-    }
-
-    pub fn docs<'a>(d: Doc<'a>, it: |uint, Doc<'a>| -> bool) -> bool {
-        let mut pos = d.start;
-        while pos < d.end {
-            let elt_tag = try_or!(vuint_at(d.data, pos), false);
-            let elt_size = try_or!(vuint_at(d.data, elt_tag.next), false);
-            pos = elt_size.next + elt_size.val;
-            let doc = Doc { data: d.data, start: elt_size.next, end: pos };
-            if !it(elt_tag.val, doc) {
-                return false;
-            }
-        }
-        return true;
-    }
-
-    pub fn tagged_docs<'a>(d: Doc<'a>, tg: uint, it: |Doc<'a>| -> bool) -> bool {
-        let mut pos = d.start;
-        while pos < d.end {
-            let elt_tag = try_or!(vuint_at(d.data, pos), false);
-            let elt_size = try_or!(vuint_at(d.data, elt_tag.next), false);
-            pos = elt_size.next + elt_size.val;
-            if elt_tag.val == tg {
-                let doc = Doc { data: d.data, start: elt_size.next,
-                                end: pos };
-                if !it(doc) {
-                    return false;
-                }
-            }
-        }
-        return true;
-    }
-
-    pub fn with_doc_data<'a, T>(d: Doc<'a>, f: |x: &'a [u8]| -> T) -> T {
-        f(d.data.slice(d.start, d.end))
-    }
-
-
-    pub fn doc_as_u8(d: Doc) -> u8 {
-        assert_eq!(d.end, d.start + 1u);
-        d.data[d.start]
-    }
-
-    pub fn doc_as_u16(d: Doc) -> u16 {
-        assert_eq!(d.end, d.start + 2u);
-        u64_from_be_bytes(d.data, d.start, 2u) as u16
-    }
-
-    pub fn doc_as_u32(d: Doc) -> u32 {
-        assert_eq!(d.end, d.start + 4u);
-        u64_from_be_bytes(d.data, d.start, 4u) as u32
-    }
-
-    pub fn doc_as_u64(d: Doc) -> u64 {
-        assert_eq!(d.end, d.start + 8u);
-        u64_from_be_bytes(d.data, d.start, 8u)
-    }
-
-    pub fn doc_as_i8(d: Doc) -> i8 { doc_as_u8(d) as i8 }
-    pub fn doc_as_i16(d: Doc) -> i16 { doc_as_u16(d) as i16 }
-    pub fn doc_as_i32(d: Doc) -> i32 { doc_as_u32(d) as i32 }
-    pub fn doc_as_i64(d: Doc) -> i64 { doc_as_u64(d) as i64 }
-
-    pub struct Decoder<'a> {
-        parent: Doc<'a>,
-        pos: uint,
-    }
-
-    impl<'doc> Decoder<'doc> {
-        pub fn new(d: Doc<'doc>) -> Decoder<'doc> {
-            Decoder {
-                parent: d,
-                pos: d.start
-            }
-        }
-
-        fn _check_label(&mut self, lbl: &str) -> DecodeResult<()> {
-            if self.pos < self.parent.end {
-                let TaggedDoc { tag: r_tag, doc: r_doc } =
-                    try!(doc_at(self.parent.data, self.pos));
-
-                if r_tag == (EsLabel as uint) {
-                    self.pos = r_doc.end;
-                    let str = r_doc.as_str_slice();
-                    if lbl != str {
-                        return Err(Expected(format!("Expected label {} but \
-                                                     found {}", lbl, str)));
-                    }
-                }
-            }
-            Ok(())
-        }
-
-        fn next_doc(&mut self, exp_tag: EbmlEncoderTag) -> DecodeResult<Doc<'doc>> {
-            debug!(". next_doc(exp_tag={})", exp_tag);
-            if self.pos >= self.parent.end {
-                return Err(Expected(format!("no more documents in \
-                                             current node!")));
-            }
-            let TaggedDoc { tag: r_tag, doc: r_doc } =
-                try!(doc_at(self.parent.data, self.pos));
-            debug!("self.parent={}-{} self.pos={} r_tag={} r_doc={}-{}",
-                   self.parent.start,
-                   self.parent.end,
-                   self.pos,
-                   r_tag,
-                   r_doc.start,
-                   r_doc.end);
-            if r_tag != (exp_tag as uint) {
-                return Err(Expected(format!("expected EBML doc with tag {} but \
-                                             found tag {}", exp_tag, r_tag)));
-            }
-            if r_doc.end > self.parent.end {
-                return Err(Expected(format!("invalid EBML, child extends to \
-                                             {:#x}, parent to {:#x}",
-                                            r_doc.end, self.parent.end)));
-            }
-            self.pos = r_doc.end;
-            Ok(r_doc)
-        }
-
-        fn push_doc<T>(&mut self, exp_tag: EbmlEncoderTag,
-                       f: |&mut Decoder<'doc>| -> DecodeResult<T>) -> DecodeResult<T> {
-            let d = try!(self.next_doc(exp_tag));
-            let old_parent = self.parent;
-            let old_pos = self.pos;
-            self.parent = d;
-            self.pos = d.start;
-            let r = try!(f(self));
-            self.parent = old_parent;
-            self.pos = old_pos;
-            Ok(r)
-        }
-
-        fn _next_uint(&mut self, exp_tag: EbmlEncoderTag) -> DecodeResult<uint> {
-            let r = doc_as_u32(try!(self.next_doc(exp_tag)));
-            debug!("_next_uint exp_tag={} result={}", exp_tag, r);
-            Ok(r as uint)
-        }
-
-        pub fn read_opaque<R>(&mut self,
-                              op: |&mut Decoder<'doc>, Doc| -> DecodeResult<R>) -> DecodeResult<R> {
-            let doc = try!(self.next_doc(EsOpaque));
-
-            let (old_parent, old_pos) = (self.parent, self.pos);
-            self.parent = doc;
-            self.pos = doc.start;
-
-            let result = try!(op(self, doc));
-
-            self.parent = old_parent;
-            self.pos = old_pos;
-            Ok(result)
-        }
-    }
-
-    impl<'doc> serialize::Decoder<Error> for Decoder<'doc> {
-        fn read_nil(&mut self) -> DecodeResult<()> { Ok(()) }
-
-        fn read_u64(&mut self) -> DecodeResult<u64> { Ok(doc_as_u64(try!(self.next_doc(EsU64)))) }
-        fn read_u32(&mut self) -> DecodeResult<u32> { Ok(doc_as_u32(try!(self.next_doc(EsU32)))) }
-        fn read_u16(&mut self) -> DecodeResult<u16> { Ok(doc_as_u16(try!(self.next_doc(EsU16)))) }
-        fn read_u8 (&mut self) -> DecodeResult<u8 > { Ok(doc_as_u8 (try!(self.next_doc(EsU8 )))) }
-        fn read_uint(&mut self) -> DecodeResult<uint> {
-            let v = doc_as_u64(try!(self.next_doc(EsUint)));
-            if v > (::std::uint::MAX as u64) {
-                Err(IntTooBig(v as uint))
-            } else {
-                Ok(v as uint)
-            }
-        }
-
-        fn read_i64(&mut self) -> DecodeResult<i64> {
-            Ok(doc_as_u64(try!(self.next_doc(EsI64))) as i64)
-        }
-        fn read_i32(&mut self) -> DecodeResult<i32> {
-            Ok(doc_as_u32(try!(self.next_doc(EsI32))) as i32)
-        }
-        fn read_i16(&mut self) -> DecodeResult<i16> {
-            Ok(doc_as_u16(try!(self.next_doc(EsI16))) as i16)
-        }
-        fn read_i8 (&mut self) -> DecodeResult<i8> {
-            Ok(doc_as_u8(try!(self.next_doc(EsI8 ))) as i8)
-        }
-        fn read_int(&mut self) -> DecodeResult<int> {
-            let v = doc_as_u64(try!(self.next_doc(EsInt))) as i64;
-            if v > (int::MAX as i64) || v < (int::MIN as i64) {
-                debug!("FIXME \\#6122: Removing this makes this function miscompile");
-                Err(IntTooBig(v as uint))
-            } else {
-                Ok(v as int)
-            }
-        }
-
-        fn read_bool(&mut self) -> DecodeResult<bool> {
-            Ok(doc_as_u8(try!(self.next_doc(EsBool))) != 0)
-        }
-
-        fn read_f64(&mut self) -> DecodeResult<f64> {
-            let bits = doc_as_u64(try!(self.next_doc(EsF64)));
-            Ok(unsafe { transmute(bits) })
-        }
-        fn read_f32(&mut self) -> DecodeResult<f32> {
-            let bits = doc_as_u32(try!(self.next_doc(EsF32)));
-            Ok(unsafe { transmute(bits) })
-        }
-        fn read_char(&mut self) -> DecodeResult<char> {
-            Ok(char::from_u32(doc_as_u32(try!(self.next_doc(EsChar)))).unwrap())
-        }
-        fn read_str(&mut self) -> DecodeResult<String> {
-            Ok(try!(self.next_doc(EsStr)).as_str())
-        }
-
-        // Compound types:
-        fn read_enum<T>(&mut self,
-                        name: &str,
-                        f: |&mut Decoder<'doc>| -> DecodeResult<T>) -> DecodeResult<T> {
-            debug!("read_enum({})", name);
-            try!(self._check_label(name));
-
-            let doc = try!(self.next_doc(EsEnum));
-
-            let (old_parent, old_pos) = (self.parent, self.pos);
-            self.parent = doc;
-            self.pos = self.parent.start;
-
-            let result = try!(f(self));
-
-            self.parent = old_parent;
-            self.pos = old_pos;
-            Ok(result)
-        }
-
-        fn read_enum_variant<T>(&mut self,
-                                _: &[&str],
-                                f: |&mut Decoder<'doc>, uint| -> DecodeResult<T>)
-                                -> DecodeResult<T> {
-            debug!("read_enum_variant()");
-            let idx = try!(self._next_uint(EsEnumVid));
-            debug!("  idx={}", idx);
-
-            let doc = try!(self.next_doc(EsEnumBody));
-
-            let (old_parent, old_pos) = (self.parent, self.pos);
-            self.parent = doc;
-            self.pos = self.parent.start;
-
-            let result = try!(f(self, idx));
-
-            self.parent = old_parent;
-            self.pos = old_pos;
-            Ok(result)
-        }
-
-        fn read_enum_variant_arg<T>(&mut self,
-                                    idx: uint,
-                                    f: |&mut Decoder<'doc>| -> DecodeResult<T>) -> DecodeResult<T> {
-            debug!("read_enum_variant_arg(idx={})", idx);
-            f(self)
-        }
-
-        fn read_enum_struct_variant<T>(&mut self,
-                                       _: &[&str],
-                                       f: |&mut Decoder<'doc>, uint| -> DecodeResult<T>)
-                                       -> DecodeResult<T> {
-            debug!("read_enum_struct_variant()");
-            let idx = try!(self._next_uint(EsEnumVid));
-            debug!("  idx={}", idx);
-
-            let doc = try!(self.next_doc(EsEnumBody));
-
-            let (old_parent, old_pos) = (self.parent, self.pos);
-            self.parent = doc;
-            self.pos = self.parent.start;
-
-            let result = try!(f(self, idx));
-
-            self.parent = old_parent;
-            self.pos = old_pos;
-            Ok(result)
-        }
-
-        fn read_enum_struct_variant_field<T>(&mut self,
-                                             name: &str,
-                                             idx: uint,
-                                             f: |&mut Decoder<'doc>| -> DecodeResult<T>)
-                                             -> DecodeResult<T> {
-            debug!("read_enum_struct_variant_arg(name={}, idx={})", name, idx);
-            f(self)
-        }
-
-        fn read_struct<T>(&mut self,
-                          name: &str,
-                          _: uint,
-                          f: |&mut Decoder<'doc>| -> DecodeResult<T>)
-                          -> DecodeResult<T> {
-            debug!("read_struct(name={})", name);
-            f(self)
-        }
-
-        fn read_struct_field<T>(&mut self,
-                                name: &str,
-                                idx: uint,
-                                f: |&mut Decoder<'doc>| -> DecodeResult<T>)
-                                -> DecodeResult<T> {
-            debug!("read_struct_field(name={}, idx={})", name, idx);
-            try!(self._check_label(name));
-            f(self)
-        }
-
-        fn read_tuple<T>(&mut self,
-                         f: |&mut Decoder<'doc>, uint| -> DecodeResult<T>) -> DecodeResult<T> {
-            debug!("read_tuple()");
-            self.read_seq(f)
-        }
-
-        fn read_tuple_arg<T>(&mut self, idx: uint, f: |&mut Decoder<'doc>| -> DecodeResult<T>)
-                             -> DecodeResult<T> {
-            debug!("read_tuple_arg(idx={})", idx);
-            self.read_seq_elt(idx, f)
-        }
-
-        fn read_tuple_struct<T>(&mut self,
-                                name: &str,
-                                f: |&mut Decoder<'doc>, uint| -> DecodeResult<T>)
-                                -> DecodeResult<T> {
-            debug!("read_tuple_struct(name={})", name);
-            self.read_tuple(f)
-        }
-
-        fn read_tuple_struct_arg<T>(&mut self,
-                                    idx: uint,
-                                    f: |&mut Decoder<'doc>| -> DecodeResult<T>)
-                                    -> DecodeResult<T> {
-            debug!("read_tuple_struct_arg(idx={})", idx);
-            self.read_tuple_arg(idx, f)
-        }
-
-        fn read_option<T>(&mut self,
-                          f: |&mut Decoder<'doc>, bool| -> DecodeResult<T>) -> DecodeResult<T> {
-            debug!("read_option()");
-            self.read_enum("Option", |this| {
-                this.read_enum_variant(["None", "Some"], |this, idx| {
-                    match idx {
-                        0 => f(this, false),
-                        1 => f(this, true),
-                        _ => {
-                            Err(Expected(format!("Expected None or Some")))
-                        }
-                    }
-                })
-            })
-        }
-
-        fn read_seq<T>(&mut self,
-                       f: |&mut Decoder<'doc>, uint| -> DecodeResult<T>) -> DecodeResult<T> {
-            debug!("read_seq()");
-            self.push_doc(EsVec, |d| {
-                let len = try!(d._next_uint(EsVecLen));
-                debug!("  len={}", len);
-                f(d, len)
-            })
-        }
-
-        fn read_seq_elt<T>(&mut self, idx: uint, f: |&mut Decoder<'doc>| -> DecodeResult<T>)
-                           -> DecodeResult<T> {
-            debug!("read_seq_elt(idx={})", idx);
-            self.push_doc(EsVecElt, f)
-        }
-
-        fn read_map<T>(&mut self,
-                       f: |&mut Decoder<'doc>, uint| -> DecodeResult<T>) -> DecodeResult<T> {
-            debug!("read_map()");
-            self.push_doc(EsMap, |d| {
-                let len = try!(d._next_uint(EsMapLen));
-                debug!("  len={}", len);
-                f(d, len)
-            })
-        }
-
-        fn read_map_elt_key<T>(&mut self, idx: uint, f: |&mut Decoder<'doc>| -> DecodeResult<T>)
-                               -> DecodeResult<T> {
-            debug!("read_map_elt_key(idx={})", idx);
-            self.push_doc(EsMapKey, f)
-        }
-
-        fn read_map_elt_val<T>(&mut self, idx: uint, f: |&mut Decoder<'doc>| -> DecodeResult<T>)
-                               -> DecodeResult<T> {
-            debug!("read_map_elt_val(idx={})", idx);
-            self.push_doc(EsMapVal, f)
-        }
-    }
-}
-
-pub mod writer {
-    use std::clone::Clone;
-    use std::io::extensions::u64_to_be_bytes;
-    use std::io::{Writer, Seek};
-    use std::io;
-    use std::mem;
-
-    use super::{ EsVec, EsMap, EsEnum, EsVecLen, EsVecElt, EsMapLen, EsMapKey,
-        EsEnumVid, EsU64, EsU32, EsU16, EsU8, EsInt, EsI64, EsI32, EsI16, EsI8,
-        EsBool, EsF64, EsF32, EsChar, EsStr, EsMapVal, EsEnumBody, EsUint,
-        EsOpaque, EsLabel, EbmlEncoderTag };
-
-    use serialize;
-
-
-    pub type EncodeResult = io::IoResult<()>;
-
-    // ebml writing
-    pub struct Encoder<'a, W> {
-        pub writer: &'a mut W,
-        size_positions: Vec<uint>,
-    }
-
-    fn write_sized_vuint<W: Writer>(w: &mut W, n: uint, size: uint) -> EncodeResult {
-        match size {
-            1u => w.write(&[0x80u8 | (n as u8)]),
-            2u => w.write(&[0x40u8 | ((n >> 8_u) as u8), n as u8]),
-            3u => w.write(&[0x20u8 | ((n >> 16_u) as u8), (n >> 8_u) as u8,
-                            n as u8]),
-            4u => w.write(&[0x10u8 | ((n >> 24_u) as u8), (n >> 16_u) as u8,
-                            (n >> 8_u) as u8, n as u8]),
-            _ => Err(io::IoError {
-                kind: io::OtherIoError,
-                desc: "int too big",
-                detail: Some(format!("{}", n))
-            })
-        }
-    }
-
-    fn write_vuint<W: Writer>(w: &mut W, n: uint) -> EncodeResult {
-        if n < 0x7f_u { return write_sized_vuint(w, n, 1u); }
-        if n < 0x4000_u { return write_sized_vuint(w, n, 2u); }
-        if n < 0x200000_u { return write_sized_vuint(w, n, 3u); }
-        if n < 0x10000000_u { return write_sized_vuint(w, n, 4u); }
-        Err(io::IoError {
-            kind: io::OtherIoError,
-            desc: "int too big",
-            detail: Some(format!("{}", n))
-        })
-    }
-
-    // FIXME (#2741): Provide a function to write the standard ebml header.
-    impl<'a, W: Writer + Seek> Encoder<'a, W> {
-        pub fn new(w: &'a mut W) -> Encoder<'a, W> {
-            Encoder {
-                writer: w,
-                size_positions: vec!(),
-            }
-        }
-
-        /// FIXME(pcwalton): Workaround for badness in trans. DO NOT USE ME.
-        pub unsafe fn unsafe_clone(&self) -> Encoder<'a, W> {
-            Encoder {
-                writer: mem::transmute_copy(&self.writer),
-                size_positions: self.size_positions.clone(),
-            }
-        }
-
-        pub fn start_tag(&mut self, tag_id: uint) -> EncodeResult {
-            debug!("Start tag {}", tag_id);
-
-            // Write the enum ID:
-            try!(write_vuint(self.writer, tag_id));
-
-            // Write a placeholder four-byte size.
-            self.size_positions.push(try!(self.writer.tell()) as uint);
-            let zeroes: &[u8] = &[0u8, 0u8, 0u8, 0u8];
-            self.writer.write(zeroes)
-        }
-
-        pub fn end_tag(&mut self) -> EncodeResult {
-            let last_size_pos = self.size_positions.pop().unwrap();
-            let cur_pos = try!(self.writer.tell());
-            try!(self.writer.seek(last_size_pos as i64, io::SeekSet));
-            let size = cur_pos as uint - last_size_pos - 4;
-            try!(write_sized_vuint(self.writer, size, 4u));
-            let r = try!(self.writer.seek(cur_pos as i64, io::SeekSet));
-
-            debug!("End tag (size = {})", size);
-            Ok(r)
-        }
-
-        pub fn wr_tag(&mut self, tag_id: uint, blk: || -> EncodeResult) -> EncodeResult {
-            try!(self.start_tag(tag_id));
-            try!(blk());
-            self.end_tag()
-        }
-
-        pub fn wr_tagged_bytes(&mut self, tag_id: uint, b: &[u8]) -> EncodeResult {
-            try!(write_vuint(self.writer, tag_id));
-            try!(write_vuint(self.writer, b.len()));
-            self.writer.write(b)
-        }
-
-        pub fn wr_tagged_u64(&mut self, tag_id: uint, v: u64) -> EncodeResult {
-            u64_to_be_bytes(v, 8u, |v| {
-                self.wr_tagged_bytes(tag_id, v)
-            })
-        }
-
-        pub fn wr_tagged_u32(&mut self, tag_id: uint, v: u32)  -> EncodeResult{
-            u64_to_be_bytes(v as u64, 4u, |v| {
-                self.wr_tagged_bytes(tag_id, v)
-            })
-        }
-
-        pub fn wr_tagged_u16(&mut self, tag_id: uint, v: u16) -> EncodeResult {
-            u64_to_be_bytes(v as u64, 2u, |v| {
-                self.wr_tagged_bytes(tag_id, v)
-            })
-        }
-
-        pub fn wr_tagged_u8(&mut self, tag_id: uint, v: u8) -> EncodeResult {
-            self.wr_tagged_bytes(tag_id, &[v])
-        }
-
-        pub fn wr_tagged_i64(&mut self, tag_id: uint, v: i64) -> EncodeResult {
-            u64_to_be_bytes(v as u64, 8u, |v| {
-                self.wr_tagged_bytes(tag_id, v)
-            })
-        }
-
-        pub fn wr_tagged_i32(&mut self, tag_id: uint, v: i32) -> EncodeResult {
-            u64_to_be_bytes(v as u64, 4u, |v| {
-                self.wr_tagged_bytes(tag_id, v)
-            })
-        }
-
-        pub fn wr_tagged_i16(&mut self, tag_id: uint, v: i16) -> EncodeResult {
-            u64_to_be_bytes(v as u64, 2u, |v| {
-                self.wr_tagged_bytes(tag_id, v)
-            })
-        }
-
-        pub fn wr_tagged_i8(&mut self, tag_id: uint, v: i8) -> EncodeResult {
-            self.wr_tagged_bytes(tag_id, &[v as u8])
-        }
-
-        pub fn wr_tagged_str(&mut self, tag_id: uint, v: &str) -> EncodeResult {
-            self.wr_tagged_bytes(tag_id, v.as_bytes())
-        }
-
-        pub fn wr_bytes(&mut self, b: &[u8]) -> EncodeResult {
-            debug!("Write {} bytes", b.len());
-            self.writer.write(b)
-        }
-
-        pub fn wr_str(&mut self, s: &str) -> EncodeResult {
-            debug!("Write str: {}", s);
-            self.writer.write(s.as_bytes())
-        }
-    }
-
-    // FIXME (#2743): optionally perform "relaxations" on end_tag to more
-    // efficiently encode sizes; this is a fixed point iteration
-
-    // Set to true to generate more debugging in EBML code.
-    // Totally lame approach.
-    static DEBUG: bool = true;
-
-    impl<'a, W: Writer + Seek> Encoder<'a, W> {
-        // used internally to emit things like the vector length and so on
-        fn _emit_tagged_uint(&mut self, t: EbmlEncoderTag, v: uint) -> EncodeResult {
-            assert!(v <= 0xFFFF_FFFF_u);
-            self.wr_tagged_u32(t as uint, v as u32)
-        }
-
-        fn _emit_label(&mut self, label: &str) -> EncodeResult {
-            // There are various strings that we have access to, such as
-            // the name of a record field, which do not actually appear in
-            // the encoded EBML (normally).  This is just for
-            // efficiency.  When debugging, though, we can emit such
-            // labels and then they will be checked by decoder to
-            // try and check failures more quickly.
-            if DEBUG { self.wr_tagged_str(EsLabel as uint, label) }
-            else { Ok(()) }
-        }
-
-        pub fn emit_opaque(&mut self, f: |&mut Encoder<W>| -> EncodeResult) -> EncodeResult {
-            try!(self.start_tag(EsOpaque as uint));
-            try!(f(self));
-            self.end_tag()
-        }
-    }
-
-    impl<'a, W: Writer + Seek> serialize::Encoder<io::IoError> for Encoder<'a, W> {
-        fn emit_nil(&mut self) -> EncodeResult {
-            Ok(())
-        }
-
-        fn emit_uint(&mut self, v: uint) -> EncodeResult {
-            self.wr_tagged_u64(EsUint as uint, v as u64)
-        }
-        fn emit_u64(&mut self, v: u64) -> EncodeResult {
-            self.wr_tagged_u64(EsU64 as uint, v)
-        }
-        fn emit_u32(&mut self, v: u32) -> EncodeResult {
-            self.wr_tagged_u32(EsU32 as uint, v)
-        }
-        fn emit_u16(&mut self, v: u16) -> EncodeResult {
-            self.wr_tagged_u16(EsU16 as uint, v)
-        }
-        fn emit_u8(&mut self, v: u8) -> EncodeResult {
-            self.wr_tagged_u8(EsU8 as uint, v)
-        }
-
-        fn emit_int(&mut self, v: int) -> EncodeResult {
-            self.wr_tagged_i64(EsInt as uint, v as i64)
-        }
-        fn emit_i64(&mut self, v: i64) -> EncodeResult {
-            self.wr_tagged_i64(EsI64 as uint, v)
-        }
-        fn emit_i32(&mut self, v: i32) -> EncodeResult {
-            self.wr_tagged_i32(EsI32 as uint, v)
-        }
-        fn emit_i16(&mut self, v: i16) -> EncodeResult {
-            self.wr_tagged_i16(EsI16 as uint, v)
-        }
-        fn emit_i8(&mut self, v: i8) -> EncodeResult {
-            self.wr_tagged_i8(EsI8 as uint, v)
-        }
-
-        fn emit_bool(&mut self, v: bool) -> EncodeResult {
-            self.wr_tagged_u8(EsBool as uint, v as u8)
-        }
-
-        fn emit_f64(&mut self, v: f64) -> EncodeResult {
-            let bits = unsafe { mem::transmute(v) };
-            self.wr_tagged_u64(EsF64 as uint, bits)
-        }
-        fn emit_f32(&mut self, v: f32) -> EncodeResult {
-            let bits = unsafe { mem::transmute(v) };
-            self.wr_tagged_u32(EsF32 as uint, bits)
-        }
-        fn emit_char(&mut self, v: char) -> EncodeResult {
-            self.wr_tagged_u32(EsChar as uint, v as u32)
-        }
-
-        fn emit_str(&mut self, v: &str) -> EncodeResult {
-            self.wr_tagged_str(EsStr as uint, v)
-        }
-
-        fn emit_enum(&mut self,
-                     name: &str,
-                     f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
-            try!(self._emit_label(name));
-            try!(self.start_tag(EsEnum as uint));
-            try!(f(self));
-            self.end_tag()
-        }
-
-        fn emit_enum_variant(&mut self,
-                             _: &str,
-                             v_id: uint,
-                             _: uint,
-                             f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
-            try!(self._emit_tagged_uint(EsEnumVid, v_id));
-            try!(self.start_tag(EsEnumBody as uint));
-            try!(f(self));
-            self.end_tag()
-        }
-
-        fn emit_enum_variant_arg(&mut self,
-                                 _: uint,
-                                 f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
-            f(self)
-        }
-
-        fn emit_enum_struct_variant(&mut self,
-                                    v_name: &str,
-                                    v_id: uint,
-                                    cnt: uint,
-                                    f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
-            self.emit_enum_variant(v_name, v_id, cnt, f)
-        }
-
-        fn emit_enum_struct_variant_field(&mut self,
-                                          _: &str,
-                                          idx: uint,
-                                          f: |&mut Encoder<'a, W>| -> EncodeResult)
-            -> EncodeResult {
-            self.emit_enum_variant_arg(idx, f)
-        }
-
-        fn emit_struct(&mut self,
-                       _: &str,
-                       _len: uint,
-                       f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
-            f(self)
-        }
-
-        fn emit_struct_field(&mut self,
-                             name: &str,
-                             _: uint,
-                             f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
-            try!(self._emit_label(name));
-            f(self)
-        }
-
-        fn emit_tuple(&mut self,
-                      len: uint,
-                      f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
-            self.emit_seq(len, f)
-        }
-        fn emit_tuple_arg(&mut self,
-                          idx: uint,
-                          f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
-            self.emit_seq_elt(idx, f)
-        }
-
-        fn emit_tuple_struct(&mut self,
-                             _: &str,
-                             len: uint,
-                             f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
-            self.emit_seq(len, f)
-        }
-        fn emit_tuple_struct_arg(&mut self,
-                                 idx: uint,
-                                 f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
-            self.emit_seq_elt(idx, f)
-        }
-
-        fn emit_option(&mut self,
-                       f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
-            self.emit_enum("Option", f)
-        }
-        fn emit_option_none(&mut self) -> EncodeResult {
-            self.emit_enum_variant("None", 0, 0, |_| Ok(()))
-        }
-        fn emit_option_some(&mut self,
-                            f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
-
-            self.emit_enum_variant("Some", 1, 1, f)
-        }
-
-        fn emit_seq(&mut self,
-                    len: uint,
-                    f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
-
-            try!(self.start_tag(EsVec as uint));
-            try!(self._emit_tagged_uint(EsVecLen, len));
-            try!(f(self));
-            self.end_tag()
-        }
-
-        fn emit_seq_elt(&mut self,
-                        _idx: uint,
-                        f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
-
-            try!(self.start_tag(EsVecElt as uint));
-            try!(f(self));
-            self.end_tag()
-        }
-
-        fn emit_map(&mut self,
-                    len: uint,
-                    f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
-
-            try!(self.start_tag(EsMap as uint));
-            try!(self._emit_tagged_uint(EsMapLen, len));
-            try!(f(self));
-            self.end_tag()
-        }
-
-        fn emit_map_elt_key(&mut self,
-                            _idx: uint,
-                            f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
-
-            try!(self.start_tag(EsMapKey as uint));
-            try!(f(self));
-            self.end_tag()
-        }
-
-        fn emit_map_elt_val(&mut self,
-                            _idx: uint,
-                            f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult {
-            try!(self.start_tag(EsMapVal as uint));
-            try!(f(self));
-            self.end_tag()
-        }
-    }
-}
-
-// ___________________________________________________________________________
-// Testing
-
-#[cfg(test)]
-mod tests {
-    use super::Doc;
-    use ebml::reader;
-    use ebml::writer;
-    use {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<u64> {
-        // 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<u8>,
-        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<u8> { 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<u64> { 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 = [
-            0x80,
-            0xff,
-            0x40, 0x00,
-            0x7f, 0xff,
-            0x20, 0x00, 0x00,
-            0x3f, 0xff, 0xff,
-            0x10, 0x00, 0x00, 0x00,
-            0x1f, 0xff, 0xff, 0xff
-        ];
-
-        let mut res: reader::Res;
-
-        // Class A
-        res = reader::vuint_at(data, 0).unwrap();
-        assert_eq!(res.val, 0);
-        assert_eq!(res.next, 1);
-        res = reader::vuint_at(data, res.next).unwrap();
-        assert_eq!(res.val, (1 << 7) - 1);
-        assert_eq!(res.next, 2);
-
-        // Class B
-        res = reader::vuint_at(data, res.next).unwrap();
-        assert_eq!(res.val, 0);
-        assert_eq!(res.next, 4);
-        res = reader::vuint_at(data, res.next).unwrap();
-        assert_eq!(res.val, (1 << 14) - 1);
-        assert_eq!(res.next, 6);
-
-        // Class C
-        res = reader::vuint_at(data, res.next).unwrap();
-        assert_eq!(res.val, 0);
-        assert_eq!(res.next, 9);
-        res = reader::vuint_at(data, res.next).unwrap();
-        assert_eq!(res.val, (1 << 21) - 1);
-        assert_eq!(res.next, 12);
-
-        // Class D
-        res = reader::vuint_at(data, res.next).unwrap();
-        assert_eq!(res.val, 0);
-        assert_eq!(res.next, 16);
-        res = reader::vuint_at(data, res.next).unwrap();
-        assert_eq!(res.val, (1 << 28) - 1);
-        assert_eq!(res.next, 20);
-    }
-
-    #[test]
-    fn test_option_int() {
-        fn test_v(v: Option<int>) {
-            debug!("v == {}", v);
-            let mut wr = SeekableMemWriter::new();
-            {
-                let mut ebml_w = writer::Encoder::new(&mut wr);
-                let _ = v.encode(&mut ebml_w);
-            }
-            let ebml_doc = Doc::new(wr.get_ref());
-            let mut deser = reader::Decoder::new(ebml_doc);
-            let v1 = Decodable::decode(&mut deser).unwrap();
-            debug!("v1 == {}", v1);
-            assert_eq!(v, v1);
-        }
-
-        test_v(Some(22));
-        test_v(None);
-        test_v(Some(3));
-    }
-}
-
-#[cfg(test)]
-mod bench {
-    #![allow(non_snake_case_functions)]
-    extern crate test;
-    use self::test::Bencher;
-    use ebml::reader;
-
-    #[bench]
-    pub fn vuint_at_A_aligned(b: &mut Bencher) {
-        let data = Vec::from_fn(4*100, |i| {
-            match i % 2 {
-              0 => 0x80u8,
-              _ => i as u8,
-            }
-        });
-        let mut sum = 0u;
-        b.iter(|| {
-            let mut i = 0;
-            while i < data.len() {
-                sum += reader::vuint_at(data.as_slice(), i).unwrap().val;
-                i += 4;
-            }
-        });
-    }
-
-    #[bench]
-    pub fn vuint_at_A_unaligned(b: &mut Bencher) {
-        let data = Vec::from_fn(4*100+1, |i| {
-            match i % 2 {
-              1 => 0x80u8,
-              _ => i as u8
-            }
-        });
-        let mut sum = 0u;
-        b.iter(|| {
-            let mut i = 1;
-            while i < data.len() {
-                sum += reader::vuint_at(data.as_slice(), i).unwrap().val;
-                i += 4;
-            }
-        });
-    }
-
-    #[bench]
-    pub fn vuint_at_D_aligned(b: &mut Bencher) {
-        let data = Vec::from_fn(4*100, |i| {
-            match i % 4 {
-              0 => 0x10u8,
-              3 => i as u8,
-              _ => 0u8
-            }
-        });
-        let mut sum = 0u;
-        b.iter(|| {
-            let mut i = 0;
-            while i < data.len() {
-                sum += reader::vuint_at(data.as_slice(), i).unwrap().val;
-                i += 4;
-            }
-        });
-    }
-
-    #[bench]
-    pub fn vuint_at_D_unaligned(b: &mut Bencher) {
-        let data = Vec::from_fn(4*100+1, |i| {
-            match i % 4 {
-              1 => 0x10u8,
-              0 => i as u8,
-              _ => 0u8
-            }
-        });
-        let mut sum = 0u;
-        b.iter(|| {
-            let mut i = 1;
-            while i < data.len() {
-                sum += reader::vuint_at(data.as_slice(), i).unwrap().val;
-                i += 4;
-            }
-        });
-    }
-}
index 5cb272a19eb886fff9edac35180c253c8dae5088..5c35ad8523382cef363099662becabdac6c3a677 100644 (file)
@@ -39,6 +39,5 @@
 mod collection_impls;
 
 pub mod base64;
-pub mod ebml;
 pub mod hex;
 pub mod json;
index d01cda79e22d4de4cb3d360ebb4ab53f62f3871d..b03feb8fc224b050c2e822a23fcad972ad6bc618 100644 (file)
 
 // 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<EBWriter::Encoder<'a>> +
     Decodable<EBReader::Decoder<'b>>
 >(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);
 }
index bf519056130874f277e86e9483910ad4c7b834c7..573b57fb44a46d772b18a6ac031cbc43882c109d 100644 (file)
 #![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<Encoder<'a>> +
     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);
index d7f487b629b5eb05817ad3f93631d0606eb1fba8..799cea865a331251eea5614231efd7bc5562d105 100644 (file)
@@ -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,7 +17,7 @@
 
 use serialize::{Encodable, Encoder};
 use serialize::json;
-use serialize::ebml::writer;
+use rbml::writer;
 
 static BUF_CAPACITY: uint = 128;
 
@@ -144,7 +145,7 @@ struct Bar {
 
 enum WireProtocol {
     JSON,
-    EBML,
+    RBML,
     // ...
 }
 
@@ -155,7 +156,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<writer::Encoder<'a, SeekableMemWriter>,
                             std::io::IoError>>(val: &T,
                                                wr: &'a mut SeekableMemWriter) {
@@ -169,6 +170,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)
     }
 }