]> git.lizzy.rs Git - rust.git/commitdiff
Purge @-boxes from the reading half of EBML
authorAlex Crichton <alex@alexcrichton.com>
Wed, 18 Dec 2013 22:10:28 +0000 (14:10 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 20 Dec 2013 01:08:05 +0000 (17:08 -0800)
Now that the metadata is an owned value with a lifetime of a borrowed byte
slice, it's possible to have future optimizations where the metadata doesn't
need to be copied around (very expensive operation).

12 files changed:
src/libextra/ebml.rs
src/libextra/uuid.rs
src/librustc/metadata/creader.rs
src/librustc/metadata/csearch.rs
src/librustc/metadata/cstore.rs
src/librustc/metadata/decoder.rs
src/librustc/metadata/encoder.rs
src/librustc/metadata/loader.rs
src/librustc/middle/astencode.rs
src/librustdoc/clean.rs
src/test/run-pass/auto-encode.rs
src/test/run-pass/deriving-encodable-decodable.rs

index 5014c42f8d8e0ede438be12d95a92d8f672ed391..16a43276401142455ae062543bc49ad68b80f7ab 100644 (file)
 
 // Common data structures
 #[deriving(Clone)]
-pub struct Doc {
-    data: @~[u8],
+pub struct Doc<'a> {
+    data: &'a [u8],
     start: uint,
     end: uint,
 }
 
-impl Doc {
-    pub fn get(&self, tag: uint) -> Doc {
+impl<'doc> Doc<'doc> {
+    pub fn get<'a>(&'a self, tag: uint) -> Doc<'a> {
         reader::get_doc(*self, tag)
     }
 
@@ -38,9 +38,9 @@ pub fn as_str(&self) -> ~str {
     }
 }
 
-pub struct TaggedDoc {
+pub struct TaggedDoc<'a> {
     priv tag: uint,
-    doc: Doc,
+    doc: Doc<'a>,
 }
 
 pub enum EbmlEncoderTag {
@@ -167,13 +167,13 @@ pub fn vuint_at(data: &[u8], start: uint) -> Res {
         vuint_at_slow(data, start)
     }
 
-    pub fn Doc(data: @~[u8]) -> Doc {
+    pub fn Doc<'a>(data: &'a [u8]) -> Doc<'a> {
         Doc { data: data, start: 0u, end: data.len() }
     }
 
-    pub fn doc_at(data: @~[u8], start: uint) -> TaggedDoc {
-        let elt_tag = vuint_at(*data, start);
-        let elt_size = vuint_at(*data, elt_tag.next);
+    pub fn doc_at<'a>(data: &'a [u8], start: uint) -> TaggedDoc<'a> {
+        let elt_tag = vuint_at(data, start);
+        let elt_size = vuint_at(data, elt_tag.next);
         let end = elt_size.next + elt_size.val;
         TaggedDoc {
             tag: elt_tag.val,
@@ -181,11 +181,11 @@ pub fn doc_at(data: @~[u8], start: uint) -> TaggedDoc {
         }
     }
 
-    pub fn maybe_get_doc(d: Doc, tg: uint) -> Option<Doc> {
+    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 = vuint_at(*d.data, pos);
-            let elt_size = vuint_at(*d.data, elt_tag.next);
+            let elt_tag = vuint_at(d.data, pos);
+            let elt_size = vuint_at(d.data, elt_tag.next);
             pos = elt_size.next + elt_size.val;
             if elt_tag.val == tg {
                 return Some(Doc { data: d.data, start: elt_size.next,
@@ -195,7 +195,7 @@ pub fn maybe_get_doc(d: Doc, tg: uint) -> Option<Doc> {
         None
     }
 
-    pub fn get_doc(d: Doc, tg: uint) -> Doc {
+    pub fn get_doc<'a>(d: Doc<'a>, tg: uint) -> Doc<'a> {
         match maybe_get_doc(d, tg) {
             Some(d) => d,
             None => {
@@ -205,11 +205,11 @@ pub fn get_doc(d: Doc, tg: uint) -> Doc {
         }
     }
 
-    pub fn docs(d: Doc, it: |uint, Doc| -> bool) -> bool {
+    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 = vuint_at(*d.data, pos);
-            let elt_size = vuint_at(*d.data, elt_tag.next);
+            let elt_tag = vuint_at(d.data, pos);
+            let elt_size = vuint_at(d.data, elt_tag.next);
             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) {
@@ -219,11 +219,11 @@ pub fn docs(d: Doc, it: |uint, Doc| -> bool) -> bool {
         return true;
     }
 
-    pub fn tagged_docs(d: Doc, tg: uint, it: |Doc| -> bool) -> bool {
+    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 = vuint_at(*d.data, pos);
-            let elt_size = vuint_at(*d.data, elt_tag.next);
+            let elt_tag = vuint_at(d.data, pos);
+            let elt_size = vuint_at(d.data, elt_tag.next);
             pos = elt_size.next + elt_size.val;
             if elt_tag.val == tg {
                 let doc = Doc { data: d.data, start: elt_size.next,
@@ -236,29 +236,29 @@ pub fn tagged_docs(d: Doc, tg: uint, it: |Doc| -> bool) -> bool {
         return true;
     }
 
-    pub fn with_doc_data<T>(d: Doc, f: |x: &[u8]| -> T) -> T {
+    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]
+        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
+        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
+        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)
+        u64_from_be_bytes(d.data, d.start, 8u)
     }
 
     pub fn doc_as_i8(d: Doc) -> i8 { doc_as_u8(d) as i8 }
@@ -266,19 +266,19 @@ 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 {
-        priv parent: Doc,
+    pub struct Decoder<'a> {
+        priv parent: Doc<'a>,
         priv pos: uint,
     }
 
-    pub fn Decoder(d: Doc) -> Decoder {
+    pub fn Decoder<'a>(d: Doc<'a>) -> Decoder<'a> {
         Decoder {
             parent: d,
             pos: d.start
         }
     }
 
-    impl Decoder {
+    impl<'doc> Decoder<'doc> {
         fn _check_label(&mut self, lbl: &str) {
             if self.pos < self.parent.end {
                 let TaggedDoc { tag: r_tag, doc: r_doc } =
@@ -294,7 +294,7 @@ fn _check_label(&mut self, lbl: &str) {
             }
         }
 
-        fn next_doc(&mut self, exp_tag: EbmlEncoderTag) -> Doc {
+        fn next_doc(&mut self, exp_tag: EbmlEncoderTag) -> Doc<'doc> {
             debug!(". next_doc(exp_tag={:?})", exp_tag);
             if self.pos >= self.parent.end {
                 fail!("no more documents in current node!");
@@ -321,7 +321,7 @@ fn next_doc(&mut self, exp_tag: EbmlEncoderTag) -> Doc {
         }
 
         fn push_doc<T>(&mut self, exp_tag: EbmlEncoderTag,
-                       f: |&mut Decoder| -> T) -> T {
+                       f: |&mut Decoder<'doc>| -> T) -> T {
             let d = self.next_doc(exp_tag);
             let old_parent = self.parent;
             let old_pos = self.pos;
@@ -338,10 +338,8 @@ fn _next_uint(&mut self, exp_tag: EbmlEncoderTag) -> uint {
             debug!("_next_uint exp_tag={:?} result={}", exp_tag, r);
             r as uint
         }
-    }
 
-    impl Decoder {
-        pub fn read_opaque<R>(&mut self, op: |&mut Decoder, Doc| -> R) -> R {
+        pub fn read_opaque<R>(&mut self, op: |&mut Decoder<'doc>, Doc| -> R) -> R {
             let doc = self.next_doc(EsOpaque);
 
             let (old_parent, old_pos) = (self.parent, self.pos);
@@ -356,7 +354,7 @@ pub fn read_opaque<R>(&mut self, op: |&mut Decoder, Doc| -> R) -> R {
         }
     }
 
-    impl serialize::Decoder for Decoder {
+    impl<'doc> serialize::Decoder for Decoder<'doc> {
         fn read_nil(&mut self) -> () { () }
 
         fn read_u64(&mut self) -> u64 { doc_as_u64(self.next_doc(EsU64)) }
@@ -412,7 +410,7 @@ fn read_str(&mut self) -> ~str {
         }
 
         // Compound types:
-        fn read_enum<T>(&mut self, name: &str, f: |&mut Decoder| -> T) -> T {
+        fn read_enum<T>(&mut self, name: &str, f: |&mut Decoder<'doc>| -> T) -> T {
             debug!("read_enum({})", name);
             self._check_label(name);
 
@@ -431,7 +429,7 @@ fn read_enum<T>(&mut self, name: &str, f: |&mut Decoder| -> T) -> T {
 
         fn read_enum_variant<T>(&mut self,
                                 _: &[&str],
-                                f: |&mut Decoder, uint| -> T)
+                                f: |&mut Decoder<'doc>, uint| -> T)
                                 -> T {
             debug!("read_enum_variant()");
             let idx = self._next_uint(EsEnumVid);
@@ -452,14 +450,14 @@ fn read_enum_variant<T>(&mut self,
 
         fn read_enum_variant_arg<T>(&mut self,
                                     idx: uint,
-                                    f: |&mut Decoder| -> T) -> T {
+                                    f: |&mut Decoder<'doc>| -> T) -> T {
             debug!("read_enum_variant_arg(idx={})", idx);
             f(self)
         }
 
         fn read_enum_struct_variant<T>(&mut self,
                                        _: &[&str],
-                                       f: |&mut Decoder, uint| -> T)
+                                       f: |&mut Decoder<'doc>, uint| -> T)
                                        -> T {
             debug!("read_enum_struct_variant()");
             let idx = self._next_uint(EsEnumVid);
@@ -481,7 +479,7 @@ fn read_enum_struct_variant<T>(&mut self,
         fn read_enum_struct_variant_field<T>(&mut self,
                                              name: &str,
                                              idx: uint,
-                                             f: |&mut Decoder| -> T)
+                                             f: |&mut Decoder<'doc>| -> T)
                                              -> T {
             debug!("read_enum_struct_variant_arg(name={}, idx={})", name, idx);
             f(self)
@@ -490,7 +488,7 @@ fn read_enum_struct_variant_field<T>(&mut self,
         fn read_struct<T>(&mut self,
                           name: &str,
                           _: uint,
-                          f: |&mut Decoder| -> T)
+                          f: |&mut Decoder<'doc>| -> T)
                           -> T {
             debug!("read_struct(name={})", name);
             f(self)
@@ -499,19 +497,19 @@ fn read_struct<T>(&mut self,
         fn read_struct_field<T>(&mut self,
                                 name: &str,
                                 idx: uint,
-                                f: |&mut Decoder| -> T)
+                                f: |&mut Decoder<'doc>| -> T)
                                 -> T {
             debug!("read_struct_field(name={}, idx={})", name, idx);
             self._check_label(name);
             f(self)
         }
 
-        fn read_tuple<T>(&mut self, f: |&mut Decoder, uint| -> T) -> T {
+        fn read_tuple<T>(&mut self, f: |&mut Decoder<'doc>, uint| -> T) -> T {
             debug!("read_tuple()");
             self.read_seq(f)
         }
 
-        fn read_tuple_arg<T>(&mut self, idx: uint, f: |&mut Decoder| -> T)
+        fn read_tuple_arg<T>(&mut self, idx: uint, f: |&mut Decoder<'doc>| -> T)
                              -> T {
             debug!("read_tuple_arg(idx={})", idx);
             self.read_seq_elt(idx, f)
@@ -519,7 +517,7 @@ fn read_tuple_arg<T>(&mut self, idx: uint, f: |&mut Decoder| -> T)
 
         fn read_tuple_struct<T>(&mut self,
                                 name: &str,
-                                f: |&mut Decoder, uint| -> T)
+                                f: |&mut Decoder<'doc>, uint| -> T)
                                 -> T {
             debug!("read_tuple_struct(name={})", name);
             self.read_tuple(f)
@@ -527,13 +525,13 @@ fn read_tuple_struct<T>(&mut self,
 
         fn read_tuple_struct_arg<T>(&mut self,
                                     idx: uint,
-                                    f: |&mut Decoder| -> T)
+                                    f: |&mut Decoder<'doc>| -> T)
                                     -> T {
             debug!("read_tuple_struct_arg(idx={})", idx);
             self.read_tuple_arg(idx, f)
         }
 
-        fn read_option<T>(&mut self, f: |&mut Decoder, bool| -> T) -> T {
+        fn read_option<T>(&mut self, f: |&mut Decoder<'doc>, bool| -> T) -> T {
             debug!("read_option()");
             self.read_enum("Option", |this| {
                 this.read_enum_variant(["None", "Some"], |this, idx| {
@@ -546,7 +544,7 @@ fn read_option<T>(&mut self, f: |&mut Decoder, bool| -> T) -> T {
             })
         }
 
-        fn read_seq<T>(&mut self, f: |&mut Decoder, uint| -> T) -> T {
+        fn read_seq<T>(&mut self, f: |&mut Decoder<'doc>, uint| -> T) -> T {
             debug!("read_seq()");
             self.push_doc(EsVec, |d| {
                 let len = d._next_uint(EsVecLen);
@@ -555,13 +553,13 @@ fn read_seq<T>(&mut self, f: |&mut Decoder, uint| -> T) -> T {
             })
         }
 
-        fn read_seq_elt<T>(&mut self, idx: uint, f: |&mut Decoder| -> T)
+        fn read_seq_elt<T>(&mut self, idx: uint, f: |&mut Decoder<'doc>| -> T)
                            -> T {
             debug!("read_seq_elt(idx={})", idx);
             self.push_doc(EsVecElt, f)
         }
 
-        fn read_map<T>(&mut self, f: |&mut Decoder, uint| -> T) -> T {
+        fn read_map<T>(&mut self, f: |&mut Decoder<'doc>, uint| -> T) -> T {
             debug!("read_map()");
             self.push_doc(EsMap, |d| {
                 let len = d._next_uint(EsMapLen);
@@ -570,13 +568,13 @@ fn read_map<T>(&mut self, f: |&mut Decoder, uint| -> T) -> T {
             })
         }
 
-        fn read_map_elt_key<T>(&mut self, idx: uint, f: |&mut Decoder| -> T)
+        fn read_map_elt_key<T>(&mut self, idx: uint, f: |&mut Decoder<'doc>| -> T)
                                -> 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| -> T)
+        fn read_map_elt_val<T>(&mut self, idx: uint, f: |&mut Decoder<'doc>| -> T)
                                -> T {
             debug!("read_map_elt_val(idx={})", idx);
             self.push_doc(EsMapVal, f)
@@ -953,7 +951,7 @@ fn test_v(v: Option<int>) {
             let wr = @mut MemWriter::new();
             let mut ebml_w = writer::Encoder(wr);
             v.encode(&mut ebml_w);
-            let ebml_doc = reader::Doc(@wr.inner_ref().to_owned());
+            let ebml_doc = reader::Doc(*wr.inner_ref());
             let mut deser = reader::Decoder(ebml_doc);
             let v1 = serialize::Decodable::decode(&mut deser);
             debug!("v1 == {:?}", v1);
index 38a1394d339c4b7d64a7324a289a70cc2d958da8..9e48c3e7a73ed7207415d77a44be9632d011f535 100644 (file)
@@ -792,7 +792,7 @@ fn test_serialize_round_trip() {
         let u = Uuid::new_v4();
         let wr = @mut MemWriter::new();
         u.encode(&mut ebml::writer::Encoder(wr));
-        let doc = ebml::reader::Doc(@wr.inner_ref().to_owned());
+        let doc = ebml::reader::Doc(wr.inner_ref().as_slice());
         let u2 = Decodable::decode(&mut ebml::reader::Decoder(doc));
         assert_eq!(u, u2);
     }
index 955ba54a404fd93e0efc8c625ec50f8e800ada4e..4741281e6c28b1863b196f5c2b727191d80927cf 100644 (file)
@@ -267,9 +267,9 @@ fn resolve_crate(e: @mut Env,
             dylib, rlib, metadata
         } = load_ctxt.load_library_crate();
 
-        let attrs = decoder::get_crate_attributes(metadata);
+        let attrs = decoder::get_crate_attributes(metadata.as_slice());
         let pkgid = attr::find_pkgid(attrs).unwrap();
-        let hash = decoder::get_crate_hash(metadata);
+        let hash = decoder::get_crate_hash(metadata.as_slice());
 
         // Claim this crate number and cache it
         let cnum = e.next_crate_num;
@@ -282,7 +282,7 @@ fn resolve_crate(e: @mut Env,
         e.next_crate_num += 1;
 
         // Now resolve the crates referenced by this crate
-        let cnum_map = resolve_crate_deps(e, metadata);
+        let cnum_map = resolve_crate_deps(e, metadata.as_slice());
 
         let cmeta = @cstore::crate_metadata {
             name: name,
@@ -307,7 +307,7 @@ fn resolve_crate(e: @mut Env,
 }
 
 // Go through the crate metadata and load any crates that it references
-fn resolve_crate_deps(e: @mut Env, cdata: @~[u8]) -> cstore::cnum_map {
+fn resolve_crate_deps(e: @mut Env, cdata: &[u8]) -> cstore::cnum_map {
     debug!("resolving deps of external crate");
     // The map from crate numbers in the crate we're resolving to local crate
     // numbers
index c1c56e94f27e70de6da0b8a04fbac614d1a80e21..3a63a6fa201436278f8057ebca46b253210dd901 100644 (file)
@@ -31,13 +31,13 @@ pub struct StaticMethodInfo {
 }
 
 pub fn get_symbol(cstore: @mut cstore::CStore, def: ast::DefId) -> ~str {
-    let cdata = cstore::get_crate_data(cstore, def.crate).data;
+    let cdata = cstore::get_crate_data(cstore, def.crate).data();
     return decoder::get_symbol(cdata, def.node);
 }
 
 pub fn get_type_param_count(cstore: @mut cstore::CStore, def: ast::DefId)
                          -> uint {
-    let cdata = cstore::get_crate_data(cstore, def.crate).data;
+    let cdata = cstore::get_crate_data(cstore, def.crate).data();
     return decoder::get_type_param_count(cdata, def.node);
 }
 
@@ -210,7 +210,7 @@ pub fn get_field_type(tcx: ty::ctxt, class_id: ast::DefId,
                       def: ast::DefId) -> ty::ty_param_bounds_and_ty {
     let cstore = tcx.cstore;
     let cdata = cstore::get_crate_data(cstore, class_id.crate);
-    let all_items = reader::get_doc(reader::Doc(cdata.data), tag_items);
+    let all_items = reader::get_doc(reader::Doc(cdata.data()), tag_items);
     debug!("Looking up {:?}", class_id);
     let class_doc = expect(tcx.diag,
                            decoder::maybe_find_item(class_id.node, all_items),
index c2f6443ed5401b5aaf492453103d82b01d7355c5..e236c4e38e6bae04c4318785cb7001292a98d9b7 100644 (file)
 // own crate numbers.
 pub type cnum_map = @mut HashMap<ast::CrateNum, ast::CrateNum>;
 
+pub enum MetadataBlob {
+    MetadataVec(~[u8]),
+}
+
 pub struct crate_metadata {
     name: @str,
-    data: @~[u8],
+    data: MetadataBlob,
     cnum_map: cnum_map,
     cnum: ast::CrateNum
 }
@@ -86,12 +90,12 @@ pub fn get_crate_data(cstore: &CStore, cnum: ast::CrateNum)
 
 pub fn get_crate_hash(cstore: &CStore, cnum: ast::CrateNum) -> @str {
     let cdata = get_crate_data(cstore, cnum);
-    decoder::get_crate_hash(cdata.data)
+    decoder::get_crate_hash(cdata.data())
 }
 
 pub fn get_crate_vers(cstore: &CStore, cnum: ast::CrateNum) -> @str {
     let cdata = get_crate_data(cstore, cnum);
-    decoder::get_crate_vers(cdata.data)
+    decoder::get_crate_vers(cdata.data())
 }
 
 pub fn set_crate_data(cstore: &mut CStore,
@@ -182,8 +186,8 @@ pub fn get_dep_hashes(cstore: &CStore) -> ~[@str] {
 
     for (_, &cnum) in cstore.extern_mod_crate_map.iter() {
         let cdata = cstore::get_crate_data(cstore, cnum);
-        let hash = decoder::get_crate_hash(cdata.data);
-        let vers = decoder::get_crate_vers(cdata.data);
+        let hash = decoder::get_crate_hash(cdata.data());
+        let vers = decoder::get_crate_vers(cdata.data());
         debug!("Add hash[{}]: {} {}", cdata.name, vers, hash);
         result.push(crate_hash {
             name: cdata.name,
@@ -203,3 +207,15 @@ pub fn get_dep_hashes(cstore: &CStore) -> ~[@str] {
 
     sorted.map(|ch| ch.hash)
 }
+
+impl crate_metadata {
+    pub fn data<'a>(&'a self) -> &'a [u8] { self.data.as_slice() }
+}
+
+impl MetadataBlob {
+    pub fn as_slice<'a>(&'a self) -> &'a [u8] {
+        match *self {
+            MetadataVec(ref vec) => vec.as_slice(),
+        }
+    }
+}
index 70d65bc54702f3235b199175c9411e79ba9714ff..e21a41d9ba25c2ac79666957ccf469041d45e97b 100644 (file)
 // what crate that's in and give us a def_id that makes sense for the current
 // build.
 
-fn lookup_hash(d: ebml::Doc, eq_fn: |&[u8]| -> bool, hash: u64) ->
-   Option<ebml::Doc> {
+fn lookup_hash<'a>(d: ebml::Doc<'a>, eq_fn: |&[u8]| -> bool,
+                   hash: u64) -> Option<ebml::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;
-    let pos = u64_from_be_bytes(*d.data, hash_pos, 4) as uint;
+    let pos = u64_from_be_bytes(d.data, hash_pos, 4) as uint;
     let tagged_doc = reader::doc_at(d.data, pos);
 
     let belt = tag_index_buckets_bucket_elt;
 
     let mut ret = None;
     reader::tagged_docs(tagged_doc.doc, belt, |elt| {
-        let pos = u64_from_be_bytes(*elt.data, elt.start, 4) as uint;
+        let pos = u64_from_be_bytes(elt.data, elt.start, 4) as uint;
         if eq_fn(elt.data.slice(elt.start + 4, elt.end)) {
             ret = Some(reader::doc_at(d.data, pos).doc);
             false
@@ -75,7 +75,8 @@ fn lookup_hash(d: ebml::Doc, eq_fn: |&[u8]| -> bool, hash: u64) ->
 
 pub type GetCrateDataCb<'a> = 'a |ast::CrateNum| -> Cmd;
 
-pub fn maybe_find_item(item_id: ast::NodeId, items: ebml::Doc) -> Option<ebml::Doc> {
+pub fn maybe_find_item<'a>(item_id: ast::NodeId,
+                           items: ebml::Doc<'a>) -> Option<ebml::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
@@ -86,7 +87,7 @@ fn eq_item(bytes: &[u8], item_id: ast::NodeId) -> bool {
                 (item_id as i64).hash())
 }
 
-fn find_item(item_id: ast::NodeId, items: ebml::Doc) -> ebml::Doc {
+fn find_item<'a>(item_id: ast::NodeId, items: ebml::Doc<'a>) -> ebml::Doc<'a> {
     match maybe_find_item(item_id, items) {
        None => fail!("lookup_item: id not found: {}", item_id),
        Some(d) => d
@@ -95,7 +96,7 @@ fn find_item(item_id: ast::NodeId, items: ebml::Doc) -> ebml::Doc {
 
 // Looks up an item in the given metadata and returns an ebml doc pointing
 // to the item data.
-pub fn lookup_item(item_id: ast::NodeId, data: @~[u8]) -> ebml::Doc {
+pub fn lookup_item<'a>(item_id: ast::NodeId, data: &'a [u8]) -> ebml::Doc<'a> {
     let items = reader::get_doc(reader::Doc(data), tag_items);
     find_item(item_id, items)
 }
@@ -216,13 +217,13 @@ fn variant_disr_val(d: ebml::Doc) -> Option<ty::Disr> {
 
 fn doc_type(doc: ebml::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,
+    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 {
     let tp = reader::get_doc(doc, tag_item_method_fty);
-    parse_bare_fn_ty_data(*tp.data, cdata.cnum, tp.start, tcx,
+    parse_bare_fn_ty_data(tp.data, cdata.cnum, tp.start, tcx,
                           |_, did| translate_def_id(cdata, did))
 }
 
@@ -231,7 +232,7 @@ fn doc_transformed_self_ty(doc: ebml::Doc,
                            cdata: Cmd) -> Option<ty::t>
 {
     reader::maybe_get_doc(doc, tag_item_method_transformed_self_ty).map(|tp| {
-        parse_ty_data(*tp.data, cdata.cnum, tp.start, tcx,
+        parse_ty_data(tp.data, cdata.cnum, tp.start, tcx,
                       |_, did| translate_def_id(cdata, did))
     })
 }
@@ -242,7 +243,7 @@ pub fn item_type(_item_id: ast::DefId, item: ebml::Doc,
 }
 
 fn doc_trait_ref(doc: ebml::Doc, tcx: ty::ctxt, cdata: Cmd) -> ty::TraitRef {
-    parse_trait_ref_data(*doc.data, cdata.cnum, doc.start, tcx,
+    parse_trait_ref_data(doc.data, cdata.cnum, doc.start, tcx,
                          |_, did| translate_def_id(cdata, did))
 }
 
@@ -259,7 +260,7 @@ fn item_ty_param_defs(item: ebml::Doc,
     let mut bounds = ~[];
     reader::tagged_docs(item, tag, |p| {
         let bd = parse_type_param_def_data(
-            *p.data, p.start, cdata.cnum, tcx,
+            p.data, p.start, cdata.cnum, tcx,
             |_, did| translate_def_id(cdata, did));
         bounds.push(bd);
         true
@@ -392,7 +393,7 @@ pub fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum)
     }
 }
 
-pub fn lookup_def(cnum: ast::CrateNum, data: @~[u8], did_: ast::DefId) ->
+pub fn lookup_def(cnum: ast::CrateNum, data: &[u8], did_: ast::DefId) ->
    ast::Def {
     let item = lookup_item(did_.node, data);
     let did = ast::DefId { crate: cnum, node: did_.node };
@@ -404,7 +405,7 @@ pub fn get_trait_def(cdata: Cmd,
                      item_id: ast::NodeId,
                      tcx: ty::ctxt) -> ty::TraitDef
 {
-    let item_doc = lookup_item(item_id, cdata.data);
+    let item_doc = lookup_item(item_id, cdata.data());
     let tp_defs = item_ty_param_defs(item_doc, tcx, cdata,
                                      tag_items_data_item_ty_param_bounds);
     let rp_defs = item_region_param_defs(item_doc, tcx, cdata);
@@ -430,7 +431,7 @@ pub fn get_trait_def(cdata: Cmd,
 pub fn get_type(cdata: Cmd, id: ast::NodeId, tcx: ty::ctxt)
     -> ty::ty_param_bounds_and_ty {
 
-    let item = lookup_item(id, cdata.data);
+    let item = lookup_item(id, cdata.data());
 
     let t = item_type(ast::DefId { crate: cdata.cnum, node: id }, item, tcx,
                       cdata);
@@ -445,7 +446,7 @@ pub fn get_type(cdata: Cmd, id: ast::NodeId, tcx: ty::ctxt)
     }
 }
 
-pub fn get_type_param_count(data: @~[u8], id: ast::NodeId) -> uint {
+pub fn get_type_param_count(data: &[u8], id: ast::NodeId) -> uint {
     item_ty_param_count(lookup_item(id, data))
 }
 
@@ -453,7 +454,7 @@ pub fn get_impl_trait(cdata: Cmd,
                       id: ast::NodeId,
                       tcx: ty::ctxt) -> Option<@ty::TraitRef>
 {
-    let item_doc = lookup_item(id, cdata.data);
+    let item_doc = lookup_item(id, cdata.data());
     reader::maybe_get_doc(item_doc, tag_item_trait_ref).map(|tp| {
         @doc_trait_ref(tp, tcx, cdata)
     })
@@ -463,7 +464,7 @@ pub fn get_impl_vtables(cdata: Cmd,
                         id: ast::NodeId,
                         tcx: ty::ctxt) -> typeck::impl_res
 {
-    let item_doc = lookup_item(id, cdata.data);
+    let item_doc = lookup_item(id, cdata.data());
     let vtables_doc = reader::get_doc(item_doc, tag_item_impl_vtables);
     let mut decoder = reader::Decoder(vtables_doc);
 
@@ -476,7 +477,7 @@ pub fn get_impl_vtables(cdata: Cmd,
 
 pub fn get_impl_method(intr: @ident_interner, cdata: Cmd, id: ast::NodeId,
                        name: ast::Ident) -> Option<ast::DefId> {
-    let items = reader::get_doc(reader::Doc(cdata.data), tag_items);
+    let items = reader::get_doc(reader::Doc(cdata.data()), tag_items);
     let mut found = None;
     reader::tagged_docs(find_item(id, items), tag_item_impl_method, |mid| {
         let m_did = reader::with_doc_data(mid, parse_def_id);
@@ -488,7 +489,7 @@ pub fn get_impl_method(intr: @ident_interner, cdata: Cmd, id: ast::NodeId,
     found
 }
 
-pub fn get_symbol(data: @~[u8], id: ast::NodeId) -> ~str {
+pub fn get_symbol(data: &[u8], id: ast::NodeId) -> ~str {
     return item_symbol(lookup_item(id, data));
 }
 
@@ -509,7 +510,7 @@ pub fn def_like_to_def(def_like: DefLike) -> ast::Def {
 
 /// Iterates over the language items in the given crate.
 pub fn each_lang_item(cdata: Cmd, f: |ast::NodeId, uint| -> bool) -> bool {
-    let root = reader::Doc(cdata.data);
+    let root = reader::Doc(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);
@@ -538,10 +539,10 @@ fn each_child_of_item_or_crate(intr: @ident_interner,
         // This item may be in yet another crate if it was the child of a
         // reexport.
         let other_crates_items = if child_def_id.crate == cdata.cnum {
-            reader::get_doc(reader::Doc(cdata.data), tag_items)
+            reader::get_doc(reader::Doc(cdata.data()), tag_items)
         } else {
             let crate_data = get_crate_data(child_def_id.crate);
-            reader::get_doc(reader::Doc(crate_data.data), tag_items)
+            reader::get_doc(reader::Doc(crate_data.data()), tag_items)
         };
 
         // Get the item.
@@ -570,7 +571,7 @@ fn each_child_of_item_or_crate(intr: @ident_interner,
                                 |inherent_impl_def_id_doc| {
         let inherent_impl_def_id = item_def_id(inherent_impl_def_id_doc,
                                                cdata);
-        let items = reader::get_doc(reader::Doc(cdata.data), tag_items);
+        let items = reader::get_doc(reader::Doc(cdata.data()), tag_items);
         match maybe_find_item(inherent_impl_def_id.node, items) {
             None => {}
             Some(inherent_impl_doc) => {
@@ -626,10 +627,10 @@ fn each_child_of_item_or_crate(intr: @ident_interner,
 
         // This reexport may be in yet another crate.
         let other_crates_items = if child_def_id.crate == cdata.cnum {
-            reader::get_doc(reader::Doc(cdata.data), tag_items)
+            reader::get_doc(reader::Doc(cdata.data()), tag_items)
         } else {
             let crate_data = get_crate_data(child_def_id.crate);
-            reader::get_doc(reader::Doc(crate_data.data), tag_items)
+            reader::get_doc(reader::Doc(crate_data.data()), tag_items)
         };
 
         // Get the item.
@@ -657,7 +658,7 @@ pub fn each_child_of_item(intr: @ident_interner,
                           get_crate_data: GetCrateDataCb,
                           callback: |DefLike, ast::Ident, ast::visibility|) {
     // Find the item.
-    let root_doc = reader::Doc(cdata.data);
+    let root_doc = reader::Doc(cdata.data());
     let items = reader::get_doc(root_doc, tag_items);
     let item_doc = match maybe_find_item(id, items) {
         None => return,
@@ -678,7 +679,7 @@ pub fn each_top_level_item_of_crate(intr: @ident_interner,
                                     callback: |DefLike,
                                                ast::Ident,
                                                ast::visibility|) {
-    let root_doc = reader::Doc(cdata.data);
+    let root_doc = reader::Doc(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);
@@ -691,7 +692,7 @@ pub fn each_top_level_item_of_crate(intr: @ident_interner,
 }
 
 pub fn get_item_path(cdata: Cmd, id: ast::NodeId) -> ast_map::path {
-    item_path(lookup_item(id, cdata.data))
+    item_path(lookup_item(id, cdata.data()))
 }
 
 pub type decode_inlined_item<'a> = 'a |cdata: @cstore::crate_metadata,
@@ -705,7 +706,7 @@ pub fn maybe_get_item_ast(cdata: Cmd, tcx: ty::ctxt,
                           decode_inlined_item: decode_inlined_item)
                        -> csearch::found_ast {
     debug!("Looking up item: {}", id);
-    let item_doc = lookup_item(id, cdata.data);
+    let item_doc = lookup_item(id, cdata.data());
     let path = {
         let item_path = item_path(item_doc);
         item_path.init().to_owned()
@@ -716,7 +717,7 @@ pub fn maybe_get_item_ast(cdata: Cmd, tcx: ty::ctxt,
         match item_parent_item(item_doc) {
           Some(did) => {
             let did = translate_def_id(cdata, did);
-            let parent_item = lookup_item(did.node, cdata.data);
+            let parent_item = lookup_item(did.node, cdata.data());
             match decode_inlined_item(cdata, tcx, path, parent_item) {
               Some(ref ii) => csearch::found_parent(did, *ii),
               None => csearch::not_found
@@ -730,7 +731,7 @@ pub fn maybe_get_item_ast(cdata: Cmd, tcx: ty::ctxt,
 
 pub fn get_enum_variants(intr: @ident_interner, cdata: Cmd, id: ast::NodeId,
                      tcx: ty::ctxt) -> ~[@ty::VariantInfo] {
-    let data = cdata.data;
+    let data = cdata.data();
     let items = reader::get_doc(reader::Doc(data), tag_items);
     let item = find_item(id, items);
     let mut infos: ~[@ty::VariantInfo] = ~[];
@@ -808,7 +809,7 @@ fn item_impl_methods(intr: @ident_interner, cdata: Cmd, item: ebml::Doc,
 pub fn get_impl(intr: @ident_interner, cdata: Cmd, impl_id: ast::NodeId,
                tcx: ty::ctxt)
                 -> ty::Impl {
-    let data = cdata.data;
+    let data = cdata.data();
     let impl_item = lookup_item(impl_id, data);
     ty::Impl {
         did: ast::DefId {
@@ -825,7 +826,7 @@ pub fn get_method_name_and_explicit_self(
     cdata: Cmd,
     id: ast::NodeId) -> (ast::Ident, ast::explicit_self_)
 {
-    let method_doc = lookup_item(id, cdata.data);
+    let method_doc = lookup_item(id, cdata.data());
     let name = item_name(intr, method_doc);
     let explicit_self = get_explicit_self(method_doc);
     (name, explicit_self)
@@ -834,12 +835,12 @@ pub fn get_method_name_and_explicit_self(
 pub fn get_method(intr: @ident_interner, cdata: Cmd, id: ast::NodeId,
                   tcx: ty::ctxt) -> ty::Method
 {
-    let method_doc = lookup_item(id, cdata.data);
+    let method_doc = lookup_item(id, cdata.data());
     let def_id = item_def_id(method_doc, cdata);
 
     let container_id = item_reqd_and_translated_parent_item(cdata.cnum,
                                                             method_doc);
-    let container_doc = lookup_item(container_id.node, cdata.data);
+    let container_doc = lookup_item(container_id.node, cdata.data());
     let container = match item_family(container_doc) {
         Trait => TraitContainer(container_id),
         _ => ImplContainer(container_id),
@@ -873,7 +874,7 @@ pub fn get_method(intr: @ident_interner, cdata: Cmd, id: ast::NodeId,
 
 pub fn get_trait_method_def_ids(cdata: Cmd,
                                 id: ast::NodeId) -> ~[ast::DefId] {
-    let data = cdata.data;
+    let data = cdata.data();
     let item = lookup_item(id, data);
     let mut result = ~[];
     reader::tagged_docs(item, tag_item_trait_method, |mth| {
@@ -884,7 +885,7 @@ pub fn get_trait_method_def_ids(cdata: Cmd,
 }
 
 pub fn get_item_variances(cdata: Cmd, id: ast::NodeId) -> ty::ItemVariances {
-    let data = cdata.data;
+    let data = cdata.data();
     let item_doc = lookup_item(id, data);
     let variance_doc = reader::get_doc(item_doc, tag_item_variances);
     let mut decoder = reader::Decoder(variance_doc);
@@ -894,7 +895,7 @@ pub fn get_item_variances(cdata: Cmd, id: ast::NodeId) -> ty::ItemVariances {
 pub fn get_provided_trait_methods(intr: @ident_interner, cdata: Cmd,
                                   id: ast::NodeId, tcx: ty::ctxt) ->
         ~[@ty::Method] {
-    let data = cdata.data;
+    let data = cdata.data();
     let item = lookup_item(id, data);
     let mut result = ~[];
 
@@ -915,7 +916,7 @@ pub fn get_provided_trait_methods(intr: @ident_interner, cdata: Cmd,
 pub fn get_supertraits(cdata: Cmd, id: ast::NodeId, tcx: ty::ctxt)
                     -> ~[@ty::TraitRef] {
     let mut results = ~[];
-    let item_doc = lookup_item(id, cdata.data);
+    let item_doc = lookup_item(id, cdata.data());
     reader::tagged_docs(item_doc, tag_item_super_trait_ref, |trait_doc| {
         // NB. Only reads the ones that *aren't* builtin-bounds. See also
         // get_trait_def() for collecting the builtin bounds.
@@ -931,7 +932,7 @@ pub fn get_supertraits(cdata: Cmd, id: ast::NodeId, tcx: ty::ctxt)
 
 pub fn get_type_name_if_impl(cdata: Cmd,
                              node_id: ast::NodeId) -> Option<ast::Ident> {
-    let item = lookup_item(node_id, cdata.data);
+    let item = lookup_item(node_id, cdata.data());
     if item_family(item) != Impl {
         return None;
     }
@@ -949,7 +950,7 @@ pub fn get_static_methods_if_impl(intr: @ident_interner,
                                   cdata: Cmd,
                                   node_id: ast::NodeId)
                                -> Option<~[StaticMethodInfo]> {
-    let item = lookup_item(node_id, cdata.data);
+    let item = lookup_item(node_id, cdata.data());
     if item_family(item) != Impl {
         return None;
     }
@@ -969,7 +970,7 @@ pub fn get_static_methods_if_impl(intr: @ident_interner,
 
     let mut static_impl_methods = ~[];
     for impl_method_id in impl_method_ids.iter() {
-        let impl_method_doc = lookup_item(impl_method_id.node, cdata.data);
+        let impl_method_doc = lookup_item(impl_method_id.node, cdata.data());
         let family = item_family(impl_method_doc);
         match family {
             StaticMethod | UnsafeStaticMethod => {
@@ -997,7 +998,7 @@ pub fn get_static_methods_if_impl(intr: @ident_interner,
 pub fn get_item_attrs(cdata: Cmd,
                       node_id: ast::NodeId,
                       f: |~[@ast::MetaItem]|) {
-    let item = lookup_item(node_id, cdata.data);
+    let item = lookup_item(node_id, cdata.data());
     reader::tagged_docs(item, tag_attributes, |attributes| {
         reader::tagged_docs(attributes, tag_attribute, |attribute| {
             f(get_meta_items(attribute));
@@ -1018,7 +1019,7 @@ fn struct_field_family_to_visibility(family: Family) -> ast::visibility {
 
 pub fn get_struct_fields(intr: @ident_interner, cdata: Cmd, id: ast::NodeId)
     -> ~[ty::field_ty] {
-    let data = cdata.data;
+    let data = cdata.data();
     let item = lookup_item(id, data);
     let mut result = ~[];
     reader::tagged_docs(item, tag_item_field, |an_item| {
@@ -1049,7 +1050,7 @@ pub fn get_struct_fields(intr: @ident_interner, cdata: Cmd, id: ast::NodeId)
 
 pub fn get_item_visibility(cdata: Cmd, id: ast::NodeId)
                         -> ast::visibility {
-    item_visibility(lookup_item(id, cdata.data))
+    item_visibility(lookup_item(id, cdata.data()))
 }
 
 fn get_meta_items(md: ebml::Doc) -> ~[@ast::MetaItem] {
@@ -1119,7 +1120,7 @@ fn list_crate_attributes(intr: @ident_interner, md: ebml::Doc, hash: &str,
     write!(out, "\n\n");
 }
 
-pub fn get_crate_attributes(data: @~[u8]) -> ~[ast::Attribute] {
+pub fn get_crate_attributes(data: &[u8]) -> ~[ast::Attribute] {
     return get_attributes(reader::Doc(data));
 }
 
@@ -1131,7 +1132,7 @@ pub struct CrateDep {
     hash: @str
 }
 
-pub fn get_crate_deps(data: @~[u8]) -> ~[CrateDep] {
+pub fn get_crate_deps(data: &[u8]) -> ~[CrateDep] {
     let mut deps: ~[CrateDep] = ~[];
     let cratedoc = reader::Doc(data);
     let depsdoc = reader::get_doc(cratedoc, tag_crate_deps);
@@ -1151,7 +1152,7 @@ fn docstr(doc: ebml::Doc, tag_: uint) -> @str {
     return deps;
 }
 
-fn list_crate_deps(data: @~[u8], out: @mut io::Writer) {
+fn list_crate_deps(data: &[u8], out: @mut io::Writer) {
     write!(out, "=External Dependencies=\n");
 
     let r = get_crate_deps(data);
@@ -1163,13 +1164,13 @@ fn list_crate_deps(data: @~[u8], out: @mut io::Writer) {
     write!(out, "\n");
 }
 
-pub fn get_crate_hash(data: @~[u8]) -> @str {
+pub fn get_crate_hash(data: &[u8]) -> @str {
     let cratedoc = reader::Doc(data);
     let hashdoc = reader::get_doc(cratedoc, tag_crate_hash);
     hashdoc.as_str_slice().to_managed()
 }
 
-pub fn get_crate_vers(data: @~[u8]) -> @str {
+pub fn get_crate_vers(data: &[u8]) -> @str {
     let attrs = decoder::get_crate_attributes(data);
     match attr::find_pkgid(attrs) {
         None => @"0.0",
@@ -1177,7 +1178,7 @@ pub fn get_crate_vers(data: @~[u8]) -> @str {
     }
 }
 
-pub fn list_crate_metadata(intr: @ident_interner, bytes: @~[u8],
+pub fn list_crate_metadata(intr: @ident_interner, bytes: &[u8],
                            out: @mut io::Writer) {
     let hash = get_crate_hash(bytes);
     let md = reader::Doc(bytes);
@@ -1202,7 +1203,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(reader::Doc(cdata.data), tag_impls);
+    let impls_doc = reader::get_doc(reader::Doc(cdata.data()), tag_impls);
     let _ = reader::tagged_docs(impls_doc, tag_impls_impl, |impl_doc| {
         callback(item_def_id(impl_doc, cdata));
         true
@@ -1212,7 +1213,7 @@ pub fn each_impl(cdata: Cmd, callback: |ast::DefId|) {
 pub fn each_implementation_for_type(cdata: Cmd,
                                     id: ast::NodeId,
                                     callback: |ast::DefId|) {
-    let item_doc = lookup_item(id, cdata.data);
+    let item_doc = lookup_item(id, cdata.data());
     reader::tagged_docs(item_doc,
                         tag_items_data_item_inherent_impl,
                         |impl_doc| {
@@ -1225,7 +1226,7 @@ pub fn each_implementation_for_type(cdata: Cmd,
 pub fn each_implementation_for_trait(cdata: Cmd,
                                      id: ast::NodeId,
                                      callback: |ast::DefId|) {
-    let item_doc = lookup_item(id, cdata.data);
+    let item_doc = lookup_item(id, cdata.data());
 
     let _ = reader::tagged_docs(item_doc,
                                 tag_items_data_item_extension_impl,
@@ -1238,13 +1239,13 @@ pub fn each_implementation_for_trait(cdata: Cmd,
 
 pub fn get_trait_of_method(cdata: Cmd, id: ast::NodeId, tcx: ty::ctxt)
                            -> Option<ast::DefId> {
-    let item_doc = lookup_item(id, cdata.data);
+    let item_doc = lookup_item(id, cdata.data());
     let parent_item_id = match item_parent_item(item_doc) {
         None => return None,
         Some(item_id) => item_id,
     };
     let parent_item_id = translate_def_id(cdata, parent_item_id);
-    let parent_item_doc = lookup_item(parent_item_id.node, cdata.data);
+    let parent_item_doc = lookup_item(parent_item_id.node, cdata.data());
     match item_family(parent_item_doc) {
         Trait => Some(item_def_id(parent_item_doc, cdata)),
         Impl => {
@@ -1257,7 +1258,8 @@ pub fn get_trait_of_method(cdata: Cmd, id: ast::NodeId, tcx: ty::ctxt)
 
 
 pub fn get_native_libraries(cdata: Cmd) -> ~[(cstore::NativeLibaryKind, ~str)] {
-    let libraries = reader::get_doc(reader::Doc(cdata.data), tag_native_libraries);
+    let libraries = reader::get_doc(reader::Doc(cdata.data()),
+                                    tag_native_libraries);
     let mut result = ~[];
     reader::tagged_docs(libraries, tag_native_libraries_lib, |lib_doc| {
         let kind_doc = reader::get_doc(lib_doc, tag_native_libraries_kind);
index b27aa11651d4a1400f27cce9e43dc9f1e4e5417b..482b641cf2acf971d79b7d6c7da7eff0ce189950 100644 (file)
@@ -1526,8 +1526,8 @@ fn get_ordered_deps(ecx: &EncodeContext, cstore: &cstore::CStore)
         cstore::iter_crate_data(cstore, |key, val| {
             let dep = decoder::CrateDep {cnum: key,
                        name: ecx.tcx.sess.ident_of(val.name),
-                       vers: decoder::get_crate_vers(val.data),
-                       hash: decoder::get_crate_hash(val.data)};
+                       vers: decoder::get_crate_vers(val.data()),
+                       hash: decoder::get_crate_hash(val.data())};
             deps.push(dep);
         });
 
index dd5d082ddb7c8941d7f489e2187deadeaaba9efb..ae851a7377dc6bba3a4d726995b6a8867b2e1789 100644 (file)
@@ -13,6 +13,7 @@
 use back::archive::{Archive, METADATA_FILENAME};
 use driver::session::Session;
 use lib::llvm::{False, llvm, ObjectFile, mk_section_iter};
+use metadata::cstore::{MetadataBlob, MetadataVec};
 use metadata::decoder;
 use metadata::encoder;
 use metadata::filesearch::{FileMatches, FileDoesntMatch};
@@ -57,7 +58,7 @@ pub struct Context {
 pub struct Library {
     dylib: Option<Path>,
     rlib: Option<Path>,
-    metadata: @~[u8],
+    metadata: MetadataBlob,
 }
 
 impl Context {
@@ -103,8 +104,10 @@ fn find_library_crate(&self) -> Option<Library> {
                     } else if candidate {
                         match get_metadata_section(self.sess, self.os, path) {
                             Some(cvec) =>
-                                if crate_matches(cvec, self.name, self.version, self.hash) {
-                                    debug!("found {} with matching pkgid", path.display());
+                                if crate_matches(cvec.as_slice(), self.name,
+                                                 self.version, self.hash) {
+                                    debug!("found {} with matching pkgid",
+                                           path.display());
                                     let (rlib, dylib) = if file.ends_with(".rlib") {
                                         (Some(path.clone()), None)
                                     } else {
@@ -154,7 +157,8 @@ fn find_library_crate(&self) -> Option<Library> {
                         }
                         None => {}
                     }
-                    let attrs = decoder::get_crate_attributes(lib.metadata);
+                    let data = lib.metadata.as_slice();
+                    let attrs = decoder::get_crate_attributes(data);
                     match attr::find_pkgid(attrs) {
                         None => {}
                         Some(pkgid) => {
@@ -226,7 +230,7 @@ pub fn note_pkgid_attr(diag: @mut span_handler,
     diag.handler().note(format!("pkgid: {}", pkgid.to_str()));
 }
 
-fn crate_matches(crate_data: @~[u8],
+fn crate_matches(crate_data: &[u8],
                  name: @str,
                  version: @str,
                  hash: @str) -> bool {
@@ -244,10 +248,11 @@ fn crate_matches(crate_data: @~[u8],
     }
 }
 
-fn get_metadata_section(sess: Session, os: Os, filename: &Path) -> Option<@~[u8]> {
+fn get_metadata_section(sess: Session, os: Os,
+                        filename: &Path) -> Option<MetadataBlob> {
     if filename.filename_str().unwrap().ends_with(".rlib") {
         let archive = Archive::open(sess, filename.clone());
-        return Some(@archive.read(METADATA_FILENAME));
+        return Some(MetadataVec(archive.read(METADATA_FILENAME)));
     }
     unsafe {
         let mb = filename.with_c_str(|buf| {
@@ -284,15 +289,15 @@ fn get_metadata_section(sess: Session, os: Os, filename: &Path) -> Option<@~[u8]
                        csz - vlen);
                 vec::raw::buf_as_slice(cvbuf1, csz-vlen, |bytes| {
                     let inflated = flate::inflate_bytes(bytes);
-                    found = Some(@(inflated));
+                    found = Some(MetadataVec(inflated));
                 });
-                if found != None {
+                if found.is_some() {
                     return found;
                 }
             }
             llvm::LLVMMoveToNextSection(si.llsi);
         }
-        return option::None::<@~[u8]>;
+        return None;
     }
 }
 
@@ -323,7 +328,8 @@ pub fn list_file_metadata(sess: Session,
                           path: &Path,
                           out: @mut io::Writer) {
     match get_metadata_section(sess, os, path) {
-      option::Some(bytes) => decoder::list_crate_metadata(intr, bytes, out),
+      option::Some(bytes) => decoder::list_crate_metadata(intr, bytes.as_slice(),
+                                                          out),
       option::None => {
         write!(out, "could not find metadata in {}.\n", path.display())
       }
index b5dec466a089653bcf1ee24661de113885b3fcb8..93302739178bdfeac7dd568637def2d06983590d 100644 (file)
@@ -511,7 +511,7 @@ fn read_freevar_entry(&mut self, xcx: @ExtendedDecodeContext)
                           -> freevar_entry;
 }
 
-impl ebml_decoder_helper for reader::Decoder {
+impl<'a> ebml_decoder_helper for reader::Decoder<'a> {
     fn read_freevar_entry(&mut self, xcx: @ExtendedDecodeContext)
                           -> freevar_entry {
         let fv: freevar_entry = Decodable::decode(self);
@@ -536,7 +536,7 @@ fn read_capture_var(&mut self, xcx: @ExtendedDecodeContext)
                         -> moves::CaptureVar;
 }
 
-impl capture_var_helper for reader::Decoder {
+impl<'a> capture_var_helper for reader::Decoder<'a> {
     fn read_capture_var(&mut self, xcx: @ExtendedDecodeContext)
                         -> moves::CaptureVar {
         let cvar: moves::CaptureVar = Decodable::decode(self);
@@ -581,7 +581,7 @@ fn encode_method_map_entry(ecx: &e::EncodeContext,
     })
 }
 
-impl read_method_map_entry_helper for reader::Decoder {
+impl<'a> read_method_map_entry_helper for reader::Decoder<'a> {
     fn read_method_map_entry(&mut self, xcx: @ExtendedDecodeContext)
                              -> method_map_entry {
         self.read_struct("method_map_entry", 3, |this| {
@@ -703,7 +703,7 @@ fn read_vtable_origin(&mut self,
                           -> typeck::vtable_origin;
 }
 
-impl vtable_decoder_helpers for reader::Decoder {
+impl<'a> vtable_decoder_helpers for reader::Decoder<'a> {
     fn read_vtable_res(&mut self,
                        tcx: ty::ctxt, cdata: @cstore::crate_metadata)
                       -> typeck::vtable_res {
@@ -1026,12 +1026,12 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
 
 trait doc_decoder_helpers {
     fn as_int(&self) -> int;
-    fn opt_child(&self, tag: c::astencode_tag) -> Option<ebml::Doc>;
+    fn opt_child(&self, tag: c::astencode_tag) -> Option<Self>;
 }
 
-impl doc_decoder_helpers for ebml::Doc {
+impl<'a> doc_decoder_helpers for ebml::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> {
+    fn opt_child(&self, tag: c::astencode_tag) -> Option<ebml::Doc<'a>> {
         reader::maybe_get_doc(*self, tag as uint)
     }
 }
@@ -1058,12 +1058,12 @@ fn read_tys_noxcx(&mut self,
                       cdata: @cstore::crate_metadata) -> ~[ty::t];
 }
 
-impl ebml_decoder_decoder_helpers for reader::Decoder {
+impl<'a> ebml_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| {
             tydecode::parse_ty_data(
-                *doc.data,
+                doc.data,
                 cdata.cnum,
                 doc.start,
                 tcx,
@@ -1087,7 +1087,7 @@ fn read_ty(&mut self, xcx: @ExtendedDecodeContext) -> ty::t {
             debug!("read_ty({})", type_string(doc));
 
             let ty = tydecode::parse_ty_data(
-                *doc.data,
+                doc.data,
                 xcx.dcx.cdata.cnum,
                 doc.start,
                 xcx.dcx.tcx,
@@ -1113,7 +1113,7 @@ fn read_type_param_def(&mut self, xcx: @ExtendedDecodeContext)
                            -> ty::TypeParameterDef {
         self.read_opaque(|this, doc| {
             tydecode::parse_type_param_def_data(
-                *doc.data,
+                doc.data,
                 doc.start,
                 xcx.dcx.cdata.cnum,
                 xcx.dcx.tcx,
@@ -1338,7 +1338,7 @@ fn roundtrip(in_item: Option<@ast::item>) {
     let wr = @mut MemWriter::new();
     let mut ebml_w = writer::Encoder(wr);
     encode_item_ast(&mut ebml_w, in_item);
-    let ebml_doc = reader::Doc(@wr.inner_ref().to_owned());
+    let ebml_doc = reader::Doc(wr.inner_ref().as_slice());
     let out_item = decode_item_ast(ebml_doc);
 
     assert_eq!(in_item, out_item);
index 443293818af7c1cd63f0bd3f4bd567595a09b5df..1862b505f79913a174ae6d90a77bfd356ddd4561 100644 (file)
@@ -102,7 +102,7 @@ impl Clean<ExternalCrate> for cstore::crate_metadata {
     fn clean(&self) -> ExternalCrate {
         ExternalCrate {
             name: self.name.to_owned(),
-            attrs: decoder::get_crate_attributes(self.data).clean()
+            attrs: decoder::get_crate_attributes(self.data()).clean()
         }
     }
 }
index 86af60e736000b02318e171129c6a300df2ff2fe..1810f33eadbd9c8af1c5707dc17c9b48f33bcd3d 100644 (file)
@@ -10,6 +10,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// xfail-test FIXME(#5121)
+
 #[feature(managed_boxes)];
 
 extern mod extra;
 use extra::serialize::{Decodable, Encodable};
 use extra::time;
 
-fn test_ebml<A:
+fn test_ebml<'a, A:
     Eq +
     Encodable<EBWriter::Encoder> +
-    Decodable<EBReader::Decoder>
+    Decodable<EBReader::Decoder<'a>>
 >(a1: &A) {
     let mut wr = @mut std::io::mem::MemWriter::new();
     let mut ebml_w = EBWriter::Encoder(wr);
     a1.encode(&mut ebml_w);
-    let bytes = wr.inner_ref().to_owned();
+    let bytes = wr.inner_ref().as_slice();
 
-    let d = EBReader::Doc(@bytes);
-    let mut decoder = EBReader::Decoder(d);
+    let d: extra::ebml::Doc<'a> = EBReader::Doc(bytes);
+    let mut decoder: EBReader::Decoder<'a> = EBReader::Decoder(d);
     let a2: A = Decodable::decode(&mut decoder);
     assert!(*a1 == a2);
 }
index e9620d4dea4201f0eedb6f00b64602f7494346d0..4f4e9c9ce00b7e9f7f20015171365ed474b5018b 100644 (file)
@@ -12,6 +12,7 @@
 // job done at least
 
 // xfail-fast
+// xfail-test FIXME(#5121)
 
 #[feature(struct_variant, managed_boxes)];
 
@@ -54,7 +55,8 @@ struct G<T> {
     t: T
 }
 
-fn roundtrip<T: Rand + Eq + Encodable<Encoder> + Decodable<Decoder>>() {
+fn roundtrip<'a, T: Rand + Eq + Encodable<Encoder> +
+                    Decodable<Decoder<'a>>>() {
     let obj: T = random();
     let w = @mut MemWriter::new();
     let mut e = Encoder(w);