提交 a9c6061c 编写于 作者: F Flavio Percoco

Register new snapshot

上级 cbfc0a5e
......@@ -168,17 +168,6 @@ fn filestem(&self) -> ~str {
}
}
// FIXME: remove unwrap_ after snapshot
#[cfg(stage0)]
fn unwrap_<T>(t: T) -> T {
t
}
#[cfg(not(stage0))]
fn unwrap_<T, E>(r: Result<T, E>) -> T {
r.unwrap()
}
pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
-> ast::Crate {
......@@ -200,7 +189,7 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
let mut stdout = io::BufferedWriter::new(io::stdout());
let mut json = json::PrettyEncoder::new(&mut stdout);
// unwrapping so IoError isn't ignored
unwrap_(krate.encode(&mut json));
krate.encode(&mut json).unwrap();
}
if sess.show_span() {
......@@ -276,7 +265,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
let mut stdout = io::BufferedWriter::new(io::stdout());
let mut json = json::PrettyEncoder::new(&mut stdout);
// unwrapping so IoError isn't ignored
unwrap_(krate.encode(&mut json));
krate.encode(&mut json).unwrap();
}
(krate, map)
......
......@@ -47,17 +47,6 @@
pub type Cmd = @crate_metadata;
// FIXME: remove unwrap_ after a snapshot
#[cfg(stage0)]
fn unwrap_<T>(t: T) -> T {
t
}
#[cfg(not(stage0))]
fn unwrap_<T, E>(r: Result<T, E>) -> T {
r.unwrap()
}
// A function that takes a def_id relative to the crate being searched and
// returns a def_id relative to the compilation environment, i.e. if we hit a
// def_id for an item defined in another crate, somebody needs to figure out
......@@ -70,7 +59,7 @@ fn lookup_hash<'a>(d: ebml::Doc<'a>, eq_fn: |&[u8]| -> bool,
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 tagged_doc = unwrap_(reader::doc_at(d.data, pos));
let tagged_doc = reader::doc_at(d.data, pos).unwrap();
let belt = tag_index_buckets_bucket_elt;
......@@ -78,7 +67,7 @@ fn lookup_hash<'a>(d: ebml::Doc<'a>, eq_fn: |&[u8]| -> bool,
reader::tagged_docs(tagged_doc.doc, belt, |elt| {
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(unwrap_(reader::doc_at(d.data, pos)).doc);
ret = Some(reader::doc_at(d.data, pos).unwrap().doc);
false
} else {
true
......@@ -864,7 +853,7 @@ pub fn get_item_variances(cdata: Cmd, id: ast::NodeId) -> ty::ItemVariances {
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);
unwrap_(Decodable::decode(&mut decoder))
Decodable::decode(&mut decoder).unwrap()
}
pub fn get_provided_trait_methods(intr: @IdentInterner, cdata: Cmd,
......
......@@ -62,11 +62,6 @@ pub enum InlinedItemRef<'a> {
IIForeignRef(&'a ast::ForeignItem)
}
// FIXME: remove this Encoder type after a snapshot
#[cfg(stage0)]
pub type Encoder<'a> = writer::Encoder<'a>;
#[cfg(not(stage0))]
pub type Encoder<'a> = writer::Encoder<'a, MemWriter>;
pub type EncodeInlinedItem<'a> = 'a |ecx: &EncodeContext,
......
此差异已折叠。
......@@ -327,17 +327,6 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
return pm.run_plugins(krate);
}
// FIXME: remove unwrap_ after snapshot
#[cfg(stage0)]
fn unwrap_<T>(t: T) -> T {
t
}
#[cfg(not(stage0))]
fn unwrap_<T, E>(r: Result<T, E>) -> T {
r.unwrap()
}
/// This input format purely deserializes the json output file. No passes are
/// run over the deserialized output.
fn json_input(input: &str) -> Result<Output, ~str> {
......@@ -363,7 +352,7 @@ fn json_input(input: &str) -> Result<Output, ~str> {
let krate = match obj.pop(&~"crate") {
Some(json) => {
let mut d = json::Decoder::new(json);
unwrap_(Decodable::decode(&mut d))
Decodable::decode(&mut d).unwrap()
}
None => return Err(~"malformed json"),
};
......@@ -395,7 +384,7 @@ fn json_output(krate: clean::Crate, res: Vec<plugins::PluginJson> ,
let mut w = MemWriter::new();
{
let mut encoder = json::Encoder::new(&mut w as &mut io::Writer);
unwrap_(krate.encode(&mut encoder));
krate.encode(&mut encoder).unwrap();
}
str::from_utf8_owned(w.unwrap()).unwrap()
};
......
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <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.
//! Implementations of serialization for structures found in libcollections
use std::uint;
use std::default::Default;
use std::hash::{Hash, Hasher};
use {Decodable, Encodable, Decoder, Encoder};
use collections::{DList, RingBuf, TreeMap, TreeSet, Deque, HashMap, HashSet,
TrieMap, TrieSet};
use collections::enum_set::{EnumSet, CLike};
impl<
S: Encoder,
T: Encodable<S>
> Encodable<S> for DList<T> {
fn encode(&self, s: &mut S) {
s.emit_seq(self.len(), |s| {
for (i, e) in self.iter().enumerate() {
s.emit_seq_elt(i, |s| e.encode(s));
}
})
}
}
impl<D:Decoder,T:Decodable<D>> Decodable<D> for DList<T> {
fn decode(d: &mut D) -> DList<T> {
let mut list = DList::new();
d.read_seq(|d, len| {
for i in range(0u, len) {
list.push_back(d.read_seq_elt(i, |d| Decodable::decode(d)));
}
});
list
}
}
impl<
S: Encoder,
T: Encodable<S>
> Encodable<S> for RingBuf<T> {
fn encode(&self, s: &mut S) {
s.emit_seq(self.len(), |s| {
for (i, e) in self.iter().enumerate() {
s.emit_seq_elt(i, |s| e.encode(s));
}
})
}
}
impl<D:Decoder,T:Decodable<D>> Decodable<D> for RingBuf<T> {
fn decode(d: &mut D) -> RingBuf<T> {
let mut deque = RingBuf::new();
d.read_seq(|d, len| {
for i in range(0u, len) {
deque.push_back(d.read_seq_elt(i, |d| Decodable::decode(d)));
}
});
deque
}
}
impl<
E: Encoder,
K: Encodable<E> + Eq + TotalOrd,
V: Encodable<E> + Eq
> Encodable<E> for TreeMap<K, V> {
fn encode(&self, e: &mut E) {
e.emit_map(self.len(), |e| {
let mut i = 0;
for (key, val) in self.iter() {
e.emit_map_elt_key(i, |e| key.encode(e));
e.emit_map_elt_val(i, |e| val.encode(e));
i += 1;
}
})
}
}
impl<
D: Decoder,
K: Decodable<D> + Eq + TotalOrd,
V: Decodable<D> + Eq
> Decodable<D> for TreeMap<K, V> {
fn decode(d: &mut D) -> TreeMap<K, V> {
d.read_map(|d, len| {
let mut map = TreeMap::new();
for i in range(0u, len) {
let key = d.read_map_elt_key(i, |d| Decodable::decode(d));
let val = d.read_map_elt_val(i, |d| Decodable::decode(d));
map.insert(key, val);
}
map
})
}
}
impl<
S: Encoder,
T: Encodable<S> + Eq + TotalOrd
> Encodable<S> for TreeSet<T> {
fn encode(&self, s: &mut S) {
s.emit_seq(self.len(), |s| {
let mut i = 0;
for e in self.iter() {
s.emit_seq_elt(i, |s| e.encode(s));
i += 1;
}
})
}
}
impl<
D: Decoder,
T: Decodable<D> + Eq + TotalOrd
> Decodable<D> for TreeSet<T> {
fn decode(d: &mut D) -> TreeSet<T> {
d.read_seq(|d, len| {
let mut set = TreeSet::new();
for i in range(0u, len) {
set.insert(d.read_seq_elt(i, |d| Decodable::decode(d)));
}
set
})
}
}
impl<
S: Encoder,
T: Encodable<S> + CLike
> Encodable<S> for EnumSet<T> {
fn encode(&self, s: &mut S) {
let mut bits = 0;
for item in self.iter() {
bits |= item.to_uint();
}
s.emit_uint(bits);
}
}
impl<
D: Decoder,
T: Decodable<D> + CLike
> Decodable<D> for EnumSet<T> {
fn decode(d: &mut D) -> EnumSet<T> {
let bits = d.read_uint();
let mut set = EnumSet::empty();
for bit in range(0, uint::BITS) {
if bits & (1 << bit) != 0 {
set.add(CLike::from_uint(1 << bit));
}
}
set
}
}
impl<
E: Encoder,
K: Encodable<E> + Hash<S> + TotalEq,
V: Encodable<E>,
S,
H: Hasher<S>
> Encodable<E> for HashMap<K, V, H> {
fn encode(&self, e: &mut E) {
e.emit_map(self.len(), |e| {
let mut i = 0;
for (key, val) in self.iter() {
e.emit_map_elt_key(i, |e| key.encode(e));
e.emit_map_elt_val(i, |e| val.encode(e));
i += 1;
}
})
}
}
impl<
D: Decoder,
K: Decodable<D> + Hash<S> + TotalEq,
V: Decodable<D>,
S,
H: Hasher<S> + Default
> Decodable<D> for HashMap<K, V, H> {
fn decode(d: &mut D) -> HashMap<K, V, H> {
d.read_map(|d, len| {
let hasher = Default::default();
let mut map = HashMap::with_capacity_and_hasher(len, hasher);
for i in range(0u, len) {
let key = d.read_map_elt_key(i, |d| Decodable::decode(d));
let val = d.read_map_elt_val(i, |d| Decodable::decode(d));
map.insert(key, val);
}
map
})
}
}
impl<
E: Encoder,
T: Encodable<E> + Hash<S> + TotalEq,
S,
H: Hasher<S>
> Encodable<E> for HashSet<T, H> {
fn encode(&self, s: &mut E) {
s.emit_seq(self.len(), |s| {
let mut i = 0;
for e in self.iter() {
s.emit_seq_elt(i, |s| e.encode(s));
i += 1;
}
})
}
}
impl<
D: Decoder,
T: Decodable<D> + Hash<S> + TotalEq,
S,
H: Hasher<S> + Default
> Decodable<D> for HashSet<T, H> {
fn decode(d: &mut D) -> HashSet<T, H> {
d.read_seq(|d, len| {
let mut set = HashSet::with_capacity_and_hasher(len, Default::default());
for i in range(0u, len) {
set.insert(d.read_seq_elt(i, |d| Decodable::decode(d)));
}
set
})
}
}
impl<
E: Encoder,
V: Encodable<E>
> Encodable<E> for TrieMap<V> {
fn encode(&self, e: &mut E) {
e.emit_map(self.len(), |e| {
for (i, (key, val)) in self.iter().enumerate() {
e.emit_map_elt_key(i, |e| key.encode(e));
e.emit_map_elt_val(i, |e| val.encode(e));
}
});
}
}
impl<
D: Decoder,
V: Decodable<D>
> Decodable<D> for TrieMap<V> {
fn decode(d: &mut D) -> TrieMap<V> {
d.read_map(|d, len| {
let mut map = TrieMap::new();
for i in range(0u, len) {
let key = d.read_map_elt_key(i, |d| Decodable::decode(d));
let val = d.read_map_elt_val(i, |d| Decodable::decode(d));
map.insert(key, val);
}
map
})
}
}
impl<S: Encoder> Encodable<S> for TrieSet {
fn encode(&self, s: &mut S) {
s.emit_seq(self.len(), |s| {
for (i, e) in self.iter().enumerate() {
s.emit_seq_elt(i, |s| e.encode(s));
}
})
}
}
impl<D: Decoder> Decodable<D> for TrieSet {
fn decode(d: &mut D) -> TrieSet {
d.read_seq(|d, len| {
let mut set = TrieSet::new();
for i in range(0u, len) {
set.insert(d.read_seq_elt(i, |d| Decodable::decode(d)));
}
set
})
}
}
此差异已折叠。
此差异已折叠。
......@@ -34,31 +34,10 @@
pub use self::serialize::{Decoder, Encoder, Decodable, Encodable,
DecoderHelpers, EncoderHelpers};
// FIXME: remove _old.rs files after snapshot
#[cfg(not(stage0))]
mod serialize;
#[cfg(not(stage0))]
mod collection_impls;
pub mod base64;
#[cfg(not(stage0))]
pub mod ebml;
pub mod hex;
#[cfg(not(stage0))]
pub mod json;
#[cfg(stage0)]
#[path="./serialize_old.rs"]
pub mod serialize;
#[cfg(stage0)]
#[path="./collection_impls_old.rs"]
mod collection_impls;
#[cfg(stage0)]
#[path="./ebml_old.rs"]
pub mod ebml;
#[cfg(stage0)]
#[path="./json_old.rs"]
pub mod json;
此差异已折叠。
......@@ -42,7 +42,6 @@ fn ne(&self, other: &Self) -> bool { !self.eq(other) }
}
/// Trait for equality comparisons where `a == b` and `a != b` are strict inverses.
#[cfg(not(stage0))]
pub trait TotalEq: Eq {
// FIXME #13101: this method is used solely by #[deriving] to
// assert that every component of a type implements #[deriving]
......@@ -56,15 +55,6 @@ pub trait TotalEq: Eq {
fn assert_receiver_is_total_eq(&self) {}
}
#[cfg(stage0)]
pub trait TotalEq: Eq {
/// This method must return the same value as `eq`. It exists to prevent
/// deriving `TotalEq` from fields not implementing the `TotalEq` trait.
fn equals(&self, other: &Self) -> bool {
self.eq(other)
}
}
macro_rules! totaleq_impl(
($t:ty) => {
impl TotalEq for $t {}
......
......@@ -33,14 +33,6 @@ pub trait Sized {
}
/// Types that can be copied by simply copying bits (i.e. `memcpy`).
#[cfg(stage0)]
#[lang="pod"]
pub trait Copy {
// Empty.
}
/// Types that can be copied by simply copying bits (i.e. `memcpy`).
#[cfg(not(stage0))]
#[lang="copy"]
pub trait Copy {
// Empty.
......@@ -270,19 +262,10 @@ pub mod marker {
/// A type which is considered "not POD", meaning that it is not
/// implicitly copyable. This is typically embedded in other types to
/// ensure that they are never copied, even if they lack a destructor.
#[cfg(not(stage0))]
#[lang="no_copy_bound"]
#[deriving(Eq,Clone)]
pub struct NoCopy;
/// A type which is considered "not POD", meaning that it is not
/// implicitly copyable. This is typically embedded in other types to
/// ensure that they are never copied, even if they lack a destructor.
#[cfg(stage0)]
#[lang="no_pod_bound"]
#[deriving(Eq,Clone)]
pub struct NoCopy;
/// A type which is considered "not sharable", meaning that
/// its contents are not threadsafe, hence they cannot be
/// shared between tasks.
......
......@@ -98,29 +98,12 @@ fn ne(&self, other: &Ident) -> bool {
/// A mark represents a unique id associated with a macro expansion
pub type Mrk = u32;
// FIXME: remove stage0 Encodables after snapshot
#[cfg(stage0)]
impl<S: Encoder> Encodable<S> for Ident {
fn encode(&self, s: &mut S) {
s.emit_str(token::get_ident(*self).get());
}
}
#[cfg(stage0)]
impl<D:Decoder> Decodable<D> for Ident {
fn decode(d: &mut D) -> Ident {
str_to_ident(d.read_str())
}
}
#[cfg(not(stage0))]
impl<S: Encoder<E>, E> Encodable<S, E> for Ident {
fn encode(&self, s: &mut S) -> Result<(), E> {
s.emit_str(token::get_ident(*self).get())
}
}
#[cfg(not(stage0))]
impl<D:Decoder<E>, E> Decodable<D, E> for Ident {
fn decode(d: &mut D) -> Result<Ident, E> {
Ok(str_to_ident(try!(d.read_str())))
......@@ -1183,26 +1166,7 @@ mod test {
use super::*;
// are ASTs encodable?
// FIXME: remove stage0 test after snapshot
#[test]
#[cfg(stage0)]
fn check_asts_encodable() {
let e = Crate {
module: Mod {view_items: Vec::new(), items: Vec::new()},
attrs: Vec::new(),
config: Vec::new(),
span: Span {
lo: BytePos(10),
hi: BytePos(20),
expn_info: None,
},
};
// doesn't matter which encoder we use....
let _f = &e as &serialize::Encodable<json::Encoder>;
}
#[test]
#[cfg(not(stage0))]
fn check_asts_encodable() {
use std::io;
let e = Crate {
......
......@@ -110,23 +110,6 @@ fn ne(&self, other: &Span) -> bool { !(*self).eq(other) }
impl TotalEq for Span {}
// FIXME: remove stage0 Encodables/Decodables after snapshot
#[cfg(stage0)]
impl<S:Encoder> Encodable<S> for Span {
/* Note #1972 -- spans are encoded but not decoded */
fn encode(&self, s: &mut S) {
s.emit_nil()
}
}
#[cfg(stage0)]
impl<D:Decoder> Decodable<D> for Span {
fn decode(_d: &mut D) -> Span {
DUMMY_SP
}
}
#[cfg(not(stage0))]
impl<S:Encoder<E>, E> Encodable<S, E> for Span {
/* Note #1972 -- spans are encoded but not decoded */
fn encode(&self, s: &mut S) -> Result<(), E> {
......@@ -134,7 +117,6 @@ fn encode(&self, s: &mut S) -> Result<(), E> {
}
}
#[cfg(not(stage0))]
impl<D:Decoder<E>, E> Decodable<D, E> for Span {
fn decode(_d: &mut D) -> Result<Span, E> {
Ok(DUMMY_SP)
......
......@@ -131,29 +131,12 @@ fn from_iterator<I: Iterator<T>>(mut iter: I) -> OwnedSlice<T> {
}
}
// FIXME: remove stage0 Encodables/Decodables after snapshot
#[cfg(stage0)]
impl<S: Encoder, T: Encodable<S>> Encodable<S> for OwnedSlice<T> {
fn encode(&self, s: &mut S) {
self.as_slice().encode(s)
}
}
#[cfg(stage0)]
impl<D: Decoder, T: Decodable<D>> Decodable<D> for OwnedSlice<T> {
fn decode(d: &mut D) -> OwnedSlice<T> {
OwnedSlice::from_vec(Decodable::decode(d))
}
}
#[cfg(not(stage0))]
impl<S: Encoder<E>, T: Encodable<S, E>, E> Encodable<S, E> for OwnedSlice<T> {
fn encode(&self, s: &mut S) -> Result<(), E> {
self.as_slice().encode(s)
}
}
#[cfg(not(stage0))]
impl<D: Decoder<E>, T: Decodable<D, E>, E> Decodable<D, E> for OwnedSlice<T> {
fn decode(d: &mut D) -> Result<OwnedSlice<T>, E> {
Ok(OwnedSlice::from_vec(match Decodable::decode(d) {
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册