Register new snapshot

This commit is contained in:
Flavio Percoco 2014-03-29 01:05:46 +01:00
parent cbfc0a5e33
commit a9c6061c9a
20 changed files with 153 additions and 5125 deletions

View File

@ -168,17 +168,6 @@ impl Input {
}
}
// 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)

View File

@ -47,17 +47,6 @@ use syntax::crateid::CrateId;
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,

View File

@ -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,

View File

@ -38,8 +38,6 @@ use std::libc;
use std::cast;
use std::cell::RefCell;
use std::io::Seek;
// FIXME: remove this attr after snapshot
#[cfg(not(stage0))]
use std::io::MemWriter;
use std::rc::Rc;
@ -81,36 +79,8 @@ trait tr_intern {
fn tr_intern(&self, xcx: &ExtendedDecodeContext) -> ast::DefId;
}
// FIXME: remove this Encoder type after snapshot
#[cfg(stage0)]
pub type Encoder<'a> = writer::Encoder<'a>;
#[cfg(not(stage0))]
pub type Encoder<'a> = writer::Encoder<'a, MemWriter>;
// FIXME: remove unwrap_ and wrap_ 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()
}
#[cfg(stage0)]
fn wrap_<T>(t: T) -> T {
t
}
#[cfg(not(stage0))]
fn wrap_<T, E>(t: T) -> Result<T, E> {
Ok(t)
}
// ______________________________________________________________________
// Top-level methods.
@ -171,7 +141,7 @@ pub fn decode_inlined_item(cdata: @cstore::crate_metadata,
path_as_str.as_ref().map(|x| x.as_slice())
});
let mut ast_dsr = reader::Decoder(ast_doc);
let from_id_range = unwrap_(Decodable::decode(&mut ast_dsr));
let from_id_range = Decodable::decode(&mut ast_dsr).unwrap();
let to_id_range = reserve_id_range(&dcx.tcx.sess, from_id_range);
let xcx = &ExtendedDecodeContext {
dcx: dcx,
@ -307,17 +277,9 @@ trait def_id_encoder_helpers {
fn emit_def_id(&mut self, did: ast::DefId);
}
#[cfg(stage0)]
impl<S:serialize::Encoder> def_id_encoder_helpers for S {
fn emit_def_id(&mut self, did: ast::DefId) {
did.encode(self)
}
}
#[cfg(not(stage0))]
impl<S:serialize::Encoder<E>, E> def_id_encoder_helpers for S {
fn emit_def_id(&mut self, did: ast::DefId) {
unwrap_(did.encode(self))
did.encode(self).unwrap()
}
}
@ -327,30 +289,15 @@ trait def_id_decoder_helpers {
cdata: @cstore::crate_metadata) -> ast::DefId;
}
#[cfg(stage0)]
impl<D:serialize::Decoder> def_id_decoder_helpers for D {
fn read_def_id(&mut self, xcx: &ExtendedDecodeContext) -> ast::DefId {
let did: ast::DefId = unwrap_(Decodable::decode(self));
did.tr(xcx)
}
fn read_def_id_noxcx(&mut self,
cdata: @cstore::crate_metadata) -> ast::DefId {
let did: ast::DefId = unwrap_(Decodable::decode(self));
decoder::translate_def_id(cdata, did)
}
}
#[cfg(not(stage0))]
impl<D:serialize::Decoder<E>, E> def_id_decoder_helpers for D {
fn read_def_id(&mut self, xcx: &ExtendedDecodeContext) -> ast::DefId {
let did: ast::DefId = unwrap_(Decodable::decode(self));
let did: ast::DefId = Decodable::decode(self).unwrap();
did.tr(xcx)
}
fn read_def_id_noxcx(&mut self,
cdata: @cstore::crate_metadata) -> ast::DefId {
let did: ast::DefId = unwrap_(Decodable::decode(self));
let did: ast::DefId = Decodable::decode(self).unwrap();
decoder::translate_def_id(cdata, did)
}
}
@ -430,7 +377,7 @@ fn simplify_ast(ii: e::InlinedItemRef) -> ast::InlinedItem {
fn decode_ast(par_doc: ebml::Doc) -> ast::InlinedItem {
let chi_doc = par_doc.get(c::tag_tree as uint);
let mut d = reader::Decoder(chi_doc);
unwrap_(Decodable::decode(&mut d))
Decodable::decode(&mut d).unwrap()
}
struct AstRenumberer<'a> {
@ -476,7 +423,7 @@ fn renumber_and_map_ast(xcx: &ExtendedDecodeContext,
fn decode_def(xcx: &ExtendedDecodeContext, doc: ebml::Doc) -> ast::Def {
let mut dsr = reader::Decoder(doc);
let def: ast::Def = unwrap_(Decodable::decode(&mut dsr));
let def: ast::Def = Decodable::decode(&mut dsr).unwrap();
def.tr(xcx)
}
@ -584,7 +531,7 @@ impl tr for ty::BoundRegion {
// Encoding and decoding of freevar information
fn encode_freevar_entry(ebml_w: &mut Encoder, fv: @freevar_entry) {
unwrap_((*fv).encode(ebml_w))
(*fv).encode(ebml_w).unwrap();
}
trait ebml_decoder_helper {
@ -595,7 +542,7 @@ trait ebml_decoder_helper {
impl<'a> ebml_decoder_helper for reader::Decoder<'a> {
fn read_freevar_entry(&mut self, xcx: &ExtendedDecodeContext)
-> freevar_entry {
let fv: freevar_entry = unwrap_(Decodable::decode(self));
let fv: freevar_entry = Decodable::decode(self).unwrap();
fv.tr(xcx)
}
}
@ -620,7 +567,7 @@ trait capture_var_helper {
impl<'a> capture_var_helper for reader::Decoder<'a> {
fn read_capture_var(&mut self, xcx: &ExtendedDecodeContext)
-> moves::CaptureVar {
let cvar: moves::CaptureVar = unwrap_(Decodable::decode(self));
let cvar: moves::CaptureVar = Decodable::decode(self).unwrap();
cvar.tr(xcx)
}
}
@ -646,7 +593,7 @@ fn encode_method_callee(ecx: &e::EncodeContext,
ebml_w: &mut Encoder,
autoderef: u32,
method: &MethodCallee) {
unwrap_(ebml_w.emit_struct("MethodCallee", 4, |ebml_w| {
ebml_w.emit_struct("MethodCallee", 4, |ebml_w| {
ebml_w.emit_struct_field("autoderef", 0u, |ebml_w| {
autoderef.encode(ebml_w)
});
@ -654,34 +601,34 @@ fn encode_method_callee(ecx: &e::EncodeContext,
method.origin.encode(ebml_w)
});
ebml_w.emit_struct_field("ty", 2u, |ebml_w| {
wrap_(ebml_w.emit_ty(ecx, method.ty))
Ok(ebml_w.emit_ty(ecx, method.ty))
});
ebml_w.emit_struct_field("substs", 3u, |ebml_w| {
wrap_(ebml_w.emit_substs(ecx, &method.substs))
Ok(ebml_w.emit_substs(ecx, &method.substs))
})
}));
}).unwrap();
}
impl<'a> read_method_callee_helper for reader::Decoder<'a> {
fn read_method_callee(&mut self, xcx: &ExtendedDecodeContext) -> (u32, MethodCallee) {
unwrap_(self.read_struct("MethodCallee", 4, |this| {
let autoderef = unwrap_(this.read_struct_field("autoderef", 0, |this| {
self.read_struct("MethodCallee", 4, |this| {
let autoderef = this.read_struct_field("autoderef", 0, |this| {
Decodable::decode(this)
}));
wrap_((autoderef, MethodCallee {
origin: unwrap_(this.read_struct_field("origin", 1, |this| {
}).unwrap();
Ok((autoderef, MethodCallee {
origin: this.read_struct_field("origin", 1, |this| {
let method_origin: MethodOrigin =
unwrap_(Decodable::decode(this));
wrap_(method_origin.tr(xcx))
})),
ty: unwrap_(this.read_struct_field("ty", 2, |this| {
wrap_(this.read_ty(xcx))
})),
substs: unwrap_(this.read_struct_field("substs", 3, |this| {
wrap_(this.read_substs(xcx))
}))
}))
Decodable::decode(this).unwrap();
Ok(method_origin.tr(xcx))
}).unwrap(),
ty: this.read_struct_field("ty", 2, |this| {
Ok(this.read_ty(xcx))
}).unwrap(),
substs: this.read_struct_field("substs", 3, |this| {
Ok(this.read_substs(xcx))
}).unwrap()
}))
}).unwrap()
}
}
@ -716,14 +663,14 @@ fn encode_vtable_res_with_key(ecx: &e::EncodeContext,
ebml_w: &mut Encoder,
autoderef: u32,
dr: typeck::vtable_res) {
unwrap_(ebml_w.emit_struct("VtableWithKey", 2, |ebml_w| {
ebml_w.emit_struct("VtableWithKey", 2, |ebml_w| {
ebml_w.emit_struct_field("autoderef", 0u, |ebml_w| {
autoderef.encode(ebml_w)
});
ebml_w.emit_struct_field("vtable_res", 1u, |ebml_w| {
wrap_(encode_vtable_res(ecx, ebml_w, dr))
Ok(encode_vtable_res(ecx, ebml_w, dr))
})
}))
}).unwrap()
}
pub fn encode_vtable_res(ecx: &e::EncodeContext,
@ -733,35 +680,35 @@ pub fn encode_vtable_res(ecx: &e::EncodeContext,
// 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.
unwrap_(ebml_w.emit_from_vec(dr.as_slice(), |ebml_w, param_tables| {
wrap_(encode_vtable_param_res(ecx, ebml_w, *param_tables))
}))
ebml_w.emit_from_vec(dr.as_slice(), |ebml_w, param_tables| {
Ok(encode_vtable_param_res(ecx, ebml_w, *param_tables))
}).unwrap()
}
pub fn encode_vtable_param_res(ecx: &e::EncodeContext,
ebml_w: &mut Encoder,
param_tables: typeck::vtable_param_res) {
unwrap_(ebml_w.emit_from_vec(param_tables.as_slice(), |ebml_w, vtable_origin| {
wrap_(encode_vtable_origin(ecx, ebml_w, vtable_origin))
}))
ebml_w.emit_from_vec(param_tables.as_slice(), |ebml_w, vtable_origin| {
Ok(encode_vtable_origin(ecx, ebml_w, vtable_origin))
}).unwrap()
}
pub fn encode_vtable_origin(ecx: &e::EncodeContext,
ebml_w: &mut Encoder,
vtable_origin: &typeck::vtable_origin) {
unwrap_(ebml_w.emit_enum("vtable_origin", |ebml_w| {
ebml_w.emit_enum("vtable_origin", |ebml_w| {
match *vtable_origin {
typeck::vtable_static(def_id, ref tys, vtable_res) => {
ebml_w.emit_enum_variant("vtable_static", 0u, 3u, |ebml_w| {
ebml_w.emit_enum_variant_arg(0u, |ebml_w| {
wrap_(ebml_w.emit_def_id(def_id))
Ok(ebml_w.emit_def_id(def_id))
});
ebml_w.emit_enum_variant_arg(1u, |ebml_w| {
wrap_(ebml_w.emit_tys(ecx, tys.as_slice()))
Ok(ebml_w.emit_tys(ecx, tys.as_slice()))
});
ebml_w.emit_enum_variant_arg(2u, |ebml_w| {
wrap_(encode_vtable_res(ecx, ebml_w, vtable_res))
Ok(encode_vtable_res(ecx, ebml_w, vtable_res))
})
})
}
@ -776,7 +723,7 @@ pub fn encode_vtable_origin(ecx: &e::EncodeContext,
})
}
}
}))
}).unwrap()
}
pub trait vtable_decoder_helpers {
@ -800,21 +747,22 @@ impl<'a> vtable_decoder_helpers for reader::Decoder<'a> {
tcx: &ty::ctxt,
cdata: @cstore::crate_metadata)
-> (u32, typeck::vtable_res) {
unwrap_(self.read_struct("VtableWithKey", 2, |this| {
let autoderef = unwrap_(this.read_struct_field("autoderef", 0, |this| {
self.read_struct("VtableWithKey", 2, |this| {
let autoderef = this.read_struct_field("autoderef", 0, |this| {
Decodable::decode(this)
}));
wrap_((autoderef, unwrap_(this.read_struct_field("vtable_res", 1, |this| {
wrap_(this.read_vtable_res(tcx, cdata))
}))))
}))
}).unwrap();
Ok((autoderef, this.read_struct_field("vtable_res", 1, |this| {
Ok(this.read_vtable_res(tcx, cdata))
}).unwrap()))
}).unwrap()
}
fn read_vtable_res(&mut self,
tcx: &ty::ctxt, cdata: @cstore::crate_metadata)
-> typeck::vtable_res {
@unwrap_(self.read_to_vec(|this|
wrap_(this.read_vtable_param_res(tcx, cdata))))
@self.read_to_vec(|this|
Ok(this.read_vtable_param_res(tcx, cdata)))
.unwrap()
.move_iter()
.collect()
}
@ -822,8 +770,9 @@ impl<'a> vtable_decoder_helpers for reader::Decoder<'a> {
fn read_vtable_param_res(&mut self,
tcx: &ty::ctxt, cdata: @cstore::crate_metadata)
-> typeck::vtable_param_res {
@unwrap_(self.read_to_vec(|this|
wrap_(this.read_vtable_origin(tcx, cdata))))
@self.read_to_vec(|this|
Ok(this.read_vtable_origin(tcx, cdata)))
.unwrap()
.move_iter()
.collect()
}
@ -831,40 +780,40 @@ impl<'a> vtable_decoder_helpers for reader::Decoder<'a> {
fn read_vtable_origin(&mut self,
tcx: &ty::ctxt, cdata: @cstore::crate_metadata)
-> typeck::vtable_origin {
unwrap_(self.read_enum("vtable_origin", |this| {
self.read_enum("vtable_origin", |this| {
this.read_enum_variant(["vtable_static",
"vtable_param",
"vtable_self"],
|this, i| {
wrap_(match i {
Ok(match i {
0 => {
typeck::vtable_static(
unwrap_(this.read_enum_variant_arg(0u, |this| {
wrap_(this.read_def_id_noxcx(cdata))
})),
unwrap_(this.read_enum_variant_arg(1u, |this| {
wrap_(this.read_tys_noxcx(tcx, cdata))
})),
unwrap_(this.read_enum_variant_arg(2u, |this| {
wrap_(this.read_vtable_res(tcx, cdata))
}))
this.read_enum_variant_arg(0u, |this| {
Ok(this.read_def_id_noxcx(cdata))
}).unwrap(),
this.read_enum_variant_arg(1u, |this| {
Ok(this.read_tys_noxcx(tcx, cdata))
}).unwrap(),
this.read_enum_variant_arg(2u, |this| {
Ok(this.read_vtable_res(tcx, cdata))
}).unwrap()
)
}
1 => {
typeck::vtable_param(
unwrap_(this.read_enum_variant_arg(0u, |this| {
this.read_enum_variant_arg(0u, |this| {
Decodable::decode(this)
})),
unwrap_(this.read_enum_variant_arg(1u, |this| {
}).unwrap(),
this.read_enum_variant_arg(1u, |this| {
this.read_uint()
}))
}).unwrap()
)
}
// hard to avoid - user input
_ => fail!("bad enum variant")
})
})
}))
}).unwrap()
}
}
@ -902,22 +851,22 @@ trait ebml_writer_helpers {
impl<'a> ebml_writer_helpers for Encoder<'a> {
fn emit_ty(&mut self, ecx: &e::EncodeContext, ty: ty::t) {
self.emit_opaque(|this| wrap_(e::write_type(ecx, this, ty)));
self.emit_opaque(|this| Ok(e::write_type(ecx, this, ty)));
}
fn emit_vstore(&mut self, ecx: &e::EncodeContext, vstore: ty::vstore) {
self.emit_opaque(|this| wrap_(e::write_vstore(ecx, this, vstore)));
self.emit_opaque(|this| Ok(e::write_vstore(ecx, this, vstore)));
}
fn emit_tys(&mut self, ecx: &e::EncodeContext, tys: &[ty::t]) {
self.emit_from_vec(tys, |this, ty| wrap_(this.emit_ty(ecx, *ty)));
self.emit_from_vec(tys, |this, ty| Ok(this.emit_ty(ecx, *ty)));
}
fn emit_type_param_def(&mut self,
ecx: &e::EncodeContext,
type_param_def: &ty::TypeParameterDef) {
self.emit_opaque(|this| {
wrap_(tyencode::enc_type_param_def(this.writer,
Ok(tyencode::enc_type_param_def(this.writer,
&ecx.ty_str_ctxt(),
type_param_def))
});
@ -932,7 +881,7 @@ impl<'a> ebml_writer_helpers for Encoder<'a> {
this.emit_struct_field("type_param_defs", 0, |this| {
this.emit_from_vec(tpbt.generics.type_param_defs(),
|this, type_param_def| {
wrap_(this.emit_type_param_def(ecx, type_param_def))
Ok(this.emit_type_param_def(ecx, type_param_def))
})
});
this.emit_struct_field("region_param_defs", 1, |this| {
@ -941,13 +890,13 @@ impl<'a> ebml_writer_helpers for Encoder<'a> {
})
});
this.emit_struct_field("ty", 1, |this| {
wrap_(this.emit_ty(ecx, tpbt.ty))
Ok(this.emit_ty(ecx, tpbt.ty))
})
});
}
fn emit_substs(&mut self, ecx: &e::EncodeContext, substs: &ty::substs) {
self.emit_opaque(|this| wrap_(tyencode::enc_substs(this.writer,
self.emit_opaque(|this| Ok(tyencode::enc_substs(this.writer,
&ecx.ty_str_ctxt(),
substs)));
}
@ -975,7 +924,7 @@ impl<'a> ebml_writer_helpers for Encoder<'a> {
this.emit_enum_variant_arg(2, |this| m.encode(this));
this.emit_enum_variant_arg(3, |this| b.encode(this));
this.emit_enum_variant_arg(4, |this| def_id.encode(this));
this.emit_enum_variant_arg(5, |this| wrap_(this.emit_substs(ecx, substs)))
this.emit_enum_variant_arg(5, |this| Ok(this.emit_substs(ecx, substs)))
})
}
}
@ -1060,7 +1009,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
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| unwrap_((*def).encode(ebml_w)));
ebml_w.tag(c::tag_table_val, |ebml_w| (*def).encode(ebml_w).unwrap());
})
}
@ -1087,7 +1036,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
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| {
wrap_(encode_freevar_entry(ebml_w, *fv_entry))
Ok(encode_freevar_entry(ebml_w, *fv_entry))
});
})
})
@ -1218,20 +1167,21 @@ trait ebml_decoder_decoder_helpers {
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 {
unwrap_(self.read_opaque(|_, doc| {
wrap_(tydecode::parse_ty_data(
self.read_opaque(|_, doc| {
Ok(tydecode::parse_ty_data(
doc.data,
cdata.cnum,
doc.start,
tcx,
|_, id| decoder::translate_def_id(cdata, id)))
}))
}).unwrap()
}
fn read_tys_noxcx(&mut self,
tcx: &ty::ctxt,
cdata: @cstore::crate_metadata) -> Vec<ty::t> {
unwrap_(self.read_to_vec(|this| wrap_(this.read_ty_noxcx(tcx, cdata)) ))
self.read_to_vec(|this| Ok(this.read_ty_noxcx(tcx, cdata)) )
.unwrap()
.move_iter()
.collect()
}
@ -1242,7 +1192,7 @@ impl<'a> ebml_decoder_decoder_helpers for reader::Decoder<'a> {
// context. However, we do not bother, because region types
// are not used during trans.
return unwrap_(self.read_opaque(|this, doc| {
return self.read_opaque(|this, doc| {
debug!("read_ty({})", type_string(doc));
let ty = tydecode::parse_ty_data(
@ -1252,8 +1202,8 @@ impl<'a> ebml_decoder_decoder_helpers for reader::Decoder<'a> {
xcx.dcx.tcx,
|s, a| this.convert_def_id(xcx, s, a));
wrap_(ty)
}));
Ok(ty)
}).unwrap();
fn type_string(doc: ebml::Doc) -> ~str {
let mut str = ~"";
@ -1265,95 +1215,96 @@ impl<'a> ebml_decoder_decoder_helpers for reader::Decoder<'a> {
}
fn read_tys(&mut self, xcx: &ExtendedDecodeContext) -> Vec<ty::t> {
unwrap_(self.read_to_vec(|this| wrap_(this.read_ty(xcx)))).move_iter().collect()
self.read_to_vec(|this| Ok(this.read_ty(xcx))).unwrap().move_iter().collect()
}
fn read_type_param_def(&mut self, xcx: &ExtendedDecodeContext)
-> ty::TypeParameterDef {
unwrap_(self.read_opaque(|this, doc| {
wrap_(tydecode::parse_type_param_def_data(
self.read_opaque(|this, doc| {
Ok(tydecode::parse_type_param_def_data(
doc.data,
doc.start,
xcx.dcx.cdata.cnum,
xcx.dcx.tcx,
|s, a| this.convert_def_id(xcx, s, a)))
}))
}).unwrap()
}
fn read_ty_param_bounds_and_ty(&mut self, xcx: &ExtendedDecodeContext)
-> ty::ty_param_bounds_and_ty {
unwrap_(self.read_struct("ty_param_bounds_and_ty", 2, |this| {
wrap_(ty::ty_param_bounds_and_ty {
generics: unwrap_(this.read_struct_field("generics", 0, |this| {
self.read_struct("ty_param_bounds_and_ty", 2, |this| {
Ok(ty::ty_param_bounds_and_ty {
generics: this.read_struct_field("generics", 0, |this| {
this.read_struct("Generics", 2, |this| {
wrap_(ty::Generics {
Ok(ty::Generics {
type_param_defs:
unwrap_(this.read_struct_field("type_param_defs",
this.read_struct_field("type_param_defs",
0,
|this| {
wrap_(Rc::new(unwrap_(this.read_to_vec(|this|
wrap_(this.read_type_param_def(xcx))))
Ok(Rc::new(this.read_to_vec(|this|
Ok(this.read_type_param_def(xcx)))
.unwrap()
.move_iter()
.collect()))
})),
}).unwrap(),
region_param_defs:
unwrap_(this.read_struct_field("region_param_defs",
this.read_struct_field("region_param_defs",
1,
|this| {
Decodable::decode(this)
}))
}).unwrap()
})
})
})),
ty: unwrap_(this.read_struct_field("ty", 1, |this| {
wrap_(this.read_ty(xcx))
}))
}).unwrap(),
ty: this.read_struct_field("ty", 1, |this| {
Ok(this.read_ty(xcx))
}).unwrap()
})
}))
}).unwrap()
}
fn read_substs(&mut self, xcx: &ExtendedDecodeContext) -> ty::substs {
unwrap_(self.read_opaque(|this, doc| {
wrap_(tydecode::parse_substs_data(doc.data,
self.read_opaque(|this, doc| {
Ok(tydecode::parse_substs_data(doc.data,
xcx.dcx.cdata.cnum,
doc.start,
xcx.dcx.tcx,
|s, a| this.convert_def_id(xcx, s, a)))
}))
}).unwrap()
}
fn read_auto_adjustment(&mut self, xcx: &ExtendedDecodeContext) -> ty::AutoAdjustment {
unwrap_(self.read_enum("AutoAdjustment", |this| {
self.read_enum("AutoAdjustment", |this| {
let variants = ["AutoAddEnv", "AutoDerefRef", "AutoObject"];
this.read_enum_variant(variants, |this, i| {
wrap_(match i {
Ok(match i {
0 => {
let region: ty::Region =
unwrap_(this.read_enum_variant_arg(0, |this| Decodable::decode(this)));
this.read_enum_variant_arg(0, |this| Decodable::decode(this)).unwrap();
let sigil: ast::Sigil =
unwrap_(this.read_enum_variant_arg(1, |this| Decodable::decode(this)));
this.read_enum_variant_arg(1, |this| Decodable::decode(this)).unwrap();
ty:: AutoAddEnv(region.tr(xcx), sigil)
}
1 => {
let auto_deref_ref: ty::AutoDerefRef =
unwrap_(this.read_enum_variant_arg(0, |this| Decodable::decode(this)));
this.read_enum_variant_arg(0, |this| Decodable::decode(this)).unwrap();
ty::AutoDerefRef(auto_deref_ref.tr(xcx))
}
2 => {
let sigil: ast::Sigil =
unwrap_(this.read_enum_variant_arg(0, |this| Decodable::decode(this)));
this.read_enum_variant_arg(0, |this| Decodable::decode(this)).unwrap();
let region: Option<ty::Region> =
unwrap_(this.read_enum_variant_arg(1, |this| Decodable::decode(this)));
this.read_enum_variant_arg(1, |this| Decodable::decode(this)).unwrap();
let m: ast::Mutability =
unwrap_(this.read_enum_variant_arg(2, |this| Decodable::decode(this)));
this.read_enum_variant_arg(2, |this| Decodable::decode(this)).unwrap();
let b: ty::BuiltinBounds =
unwrap_(this.read_enum_variant_arg(3, |this| Decodable::decode(this)));
this.read_enum_variant_arg(3, |this| Decodable::decode(this)).unwrap();
let def_id: ast::DefId =
unwrap_(this.read_enum_variant_arg(4, |this| Decodable::decode(this)));
let substs = unwrap_(
this.read_enum_variant_arg(5, |this| wrap_(this.read_substs(xcx))));
this.read_enum_variant_arg(4, |this| Decodable::decode(this)).unwrap();
let substs = this.read_enum_variant_arg(5, |this| Ok(this.read_substs(xcx)))
.unwrap();
let region = match region {
Some(r) => Some(r.tr(xcx)),
@ -1365,7 +1316,7 @@ impl<'a> ebml_decoder_decoder_helpers for reader::Decoder<'a> {
_ => fail!("bad enum variant for ty::AutoAdjustment")
})
})
}))
}).unwrap()
}
fn convert_def_id(&mut self,
@ -1448,9 +1399,9 @@ fn decode_side_tables(xcx: &ExtendedDecodeContext,
dcx.tcx.node_type_substs.borrow_mut().insert(id, tys);
}
c::tag_table_freevars => {
let fv_info = @unwrap_(val_dsr.read_to_vec(|val_dsr| {
wrap_(@val_dsr.read_freevar_entry(xcx))
})).move_iter().collect();
let fv_info = @val_dsr.read_to_vec(|val_dsr| {
Ok(@val_dsr.read_freevar_entry(xcx))
}).unwrap().move_iter().collect();
dcx.tcx.freevars.borrow_mut().insert(id, fv_info);
}
c::tag_table_tcache => {
@ -1486,8 +1437,9 @@ fn decode_side_tables(xcx: &ExtendedDecodeContext,
}
c::tag_table_capture_map => {
let cvars =
unwrap_(val_dsr.read_to_vec(
|val_dsr| wrap_(val_dsr.read_capture_var(xcx))))
val_dsr.read_to_vec(
|val_dsr| Ok(val_dsr.read_capture_var(xcx)))
.unwrap()
.move_iter()
.collect();
dcx.maps.capture_map.borrow_mut().insert(id, Rc::new(cvars));
@ -1519,7 +1471,7 @@ fn encode_item_ast(ebml_w: &mut Encoder, item: @ast::Item) {
fn decode_item_ast(par_doc: ebml::Doc) -> @ast::Item {
let chi_doc = par_doc.get(c::tag_tree as uint);
let mut d = reader::Decoder(chi_doc);
@unwrap_(Decodable::decode(&mut d))
@Decodable::decode(&mut d).unwrap()
}
#[cfg(test)]

View File

@ -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()
};

View File

@ -1,292 +0,0 @@
// 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
})
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -34,31 +34,10 @@ extern crate collections;
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;

View File

@ -1,688 +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.
//! Support code for encoding and decoding types.
/*
Core encoding and decoding interfaces.
*/
use std::path;
use std::rc::Rc;
use std::slice;
pub trait Encoder {
// Primitive types:
fn emit_nil(&mut self);
fn emit_uint(&mut self, v: uint);
fn emit_u64(&mut self, v: u64);
fn emit_u32(&mut self, v: u32);
fn emit_u16(&mut self, v: u16);
fn emit_u8(&mut self, v: u8);
fn emit_int(&mut self, v: int);
fn emit_i64(&mut self, v: i64);
fn emit_i32(&mut self, v: i32);
fn emit_i16(&mut self, v: i16);
fn emit_i8(&mut self, v: i8);
fn emit_bool(&mut self, v: bool);
fn emit_f64(&mut self, v: f64);
fn emit_f32(&mut self, v: f32);
fn emit_char(&mut self, v: char);
fn emit_str(&mut self, v: &str);
// Compound types:
fn emit_enum(&mut self, name: &str, f: |&mut Self|);
fn emit_enum_variant(&mut self,
v_name: &str,
v_id: uint,
len: uint,
f: |&mut Self|);
fn emit_enum_variant_arg(&mut self, a_idx: uint, f: |&mut Self|);
fn emit_enum_struct_variant(&mut self,
v_name: &str,
v_id: uint,
len: uint,
f: |&mut Self|);
fn emit_enum_struct_variant_field(&mut self,
f_name: &str,
f_idx: uint,
f: |&mut Self|);
fn emit_struct(&mut self, name: &str, len: uint, f: |&mut Self|);
fn emit_struct_field(&mut self,
f_name: &str,
f_idx: uint,
f: |&mut Self|);
fn emit_tuple(&mut self, len: uint, f: |&mut Self|);
fn emit_tuple_arg(&mut self, idx: uint, f: |&mut Self|);
fn emit_tuple_struct(&mut self, name: &str, len: uint, f: |&mut Self|);
fn emit_tuple_struct_arg(&mut self, f_idx: uint, f: |&mut Self|);
// Specialized types:
fn emit_option(&mut self, f: |&mut Self|);
fn emit_option_none(&mut self);
fn emit_option_some(&mut self, f: |&mut Self|);
fn emit_seq(&mut self, len: uint, f: |this: &mut Self|);
fn emit_seq_elt(&mut self, idx: uint, f: |this: &mut Self|);
fn emit_map(&mut self, len: uint, f: |&mut Self|);
fn emit_map_elt_key(&mut self, idx: uint, f: |&mut Self|);
fn emit_map_elt_val(&mut self, idx: uint, f: |&mut Self|);
}
pub trait Decoder {
// Primitive types:
fn read_nil(&mut self) -> ();
fn read_uint(&mut self) -> uint;
fn read_u64(&mut self) -> u64;
fn read_u32(&mut self) -> u32;
fn read_u16(&mut self) -> u16;
fn read_u8(&mut self) -> u8;
fn read_int(&mut self) -> int;
fn read_i64(&mut self) -> i64;
fn read_i32(&mut self) -> i32;
fn read_i16(&mut self) -> i16;
fn read_i8(&mut self) -> i8;
fn read_bool(&mut self) -> bool;
fn read_f64(&mut self) -> f64;
fn read_f32(&mut self) -> f32;
fn read_char(&mut self) -> char;
fn read_str(&mut self) -> ~str;
// Compound types:
fn read_enum<T>(&mut self, name: &str, f: |&mut Self| -> T) -> T;
fn read_enum_variant<T>(&mut self,
names: &[&str],
f: |&mut Self, uint| -> T)
-> T;
fn read_enum_variant_arg<T>(&mut self,
a_idx: uint,
f: |&mut Self| -> T)
-> T;
fn read_enum_struct_variant<T>(&mut self,
names: &[&str],
f: |&mut Self, uint| -> T)
-> T;
fn read_enum_struct_variant_field<T>(&mut self,
&f_name: &str,
f_idx: uint,
f: |&mut Self| -> T)
-> T;
fn read_struct<T>(&mut self, s_name: &str, len: uint, f: |&mut Self| -> T)
-> T;
fn read_struct_field<T>(&mut self,
f_name: &str,
f_idx: uint,
f: |&mut Self| -> T)
-> T;
fn read_tuple<T>(&mut self, f: |&mut Self, uint| -> T) -> T;
fn read_tuple_arg<T>(&mut self, a_idx: uint, f: |&mut Self| -> T) -> T;
fn read_tuple_struct<T>(&mut self,
s_name: &str,
f: |&mut Self, uint| -> T)
-> T;
fn read_tuple_struct_arg<T>(&mut self,
a_idx: uint,
f: |&mut Self| -> T)
-> T;
// Specialized types:
fn read_option<T>(&mut self, f: |&mut Self, bool| -> T) -> T;
fn read_seq<T>(&mut self, f: |&mut Self, uint| -> T) -> T;
fn read_seq_elt<T>(&mut self, idx: uint, f: |&mut Self| -> T) -> T;
fn read_map<T>(&mut self, f: |&mut Self, uint| -> T) -> T;
fn read_map_elt_key<T>(&mut self, idx: uint, f: |&mut Self| -> T) -> T;
fn read_map_elt_val<T>(&mut self, idx: uint, f: |&mut Self| -> T) -> T;
}
pub trait Encodable<S:Encoder> {
fn encode(&self, s: &mut S);
}
pub trait Decodable<D:Decoder> {
fn decode(d: &mut D) -> Self;
}
impl<S:Encoder> Encodable<S> for uint {
fn encode(&self, s: &mut S) {
s.emit_uint(*self)
}
}
impl<D:Decoder> Decodable<D> for uint {
fn decode(d: &mut D) -> uint {
d.read_uint()
}
}
impl<S:Encoder> Encodable<S> for u8 {
fn encode(&self, s: &mut S) {
s.emit_u8(*self)
}
}
impl<D:Decoder> Decodable<D> for u8 {
fn decode(d: &mut D) -> u8 {
d.read_u8()
}
}
impl<S:Encoder> Encodable<S> for u16 {
fn encode(&self, s: &mut S) {
s.emit_u16(*self)
}
}
impl<D:Decoder> Decodable<D> for u16 {
fn decode(d: &mut D) -> u16 {
d.read_u16()
}
}
impl<S:Encoder> Encodable<S> for u32 {
fn encode(&self, s: &mut S) {
s.emit_u32(*self)
}
}
impl<D:Decoder> Decodable<D> for u32 {
fn decode(d: &mut D) -> u32 {
d.read_u32()
}
}
impl<S:Encoder> Encodable<S> for u64 {
fn encode(&self, s: &mut S) {
s.emit_u64(*self)
}
}
impl<D:Decoder> Decodable<D> for u64 {
fn decode(d: &mut D) -> u64 {
d.read_u64()
}
}
impl<S:Encoder> Encodable<S> for int {
fn encode(&self, s: &mut S) {
s.emit_int(*self)
}
}
impl<D:Decoder> Decodable<D> for int {
fn decode(d: &mut D) -> int {
d.read_int()
}
}
impl<S:Encoder> Encodable<S> for i8 {
fn encode(&self, s: &mut S) {
s.emit_i8(*self)
}
}
impl<D:Decoder> Decodable<D> for i8 {
fn decode(d: &mut D) -> i8 {
d.read_i8()
}
}
impl<S:Encoder> Encodable<S> for i16 {
fn encode(&self, s: &mut S) {
s.emit_i16(*self)
}
}
impl<D:Decoder> Decodable<D> for i16 {
fn decode(d: &mut D) -> i16 {
d.read_i16()
}
}
impl<S:Encoder> Encodable<S> for i32 {
fn encode(&self, s: &mut S) {
s.emit_i32(*self)
}
}
impl<D:Decoder> Decodable<D> for i32 {
fn decode(d: &mut D) -> i32 {
d.read_i32()
}
}
impl<S:Encoder> Encodable<S> for i64 {
fn encode(&self, s: &mut S) {
s.emit_i64(*self)
}
}
impl<D:Decoder> Decodable<D> for i64 {
fn decode(d: &mut D) -> i64 {
d.read_i64()
}
}
impl<'a, S:Encoder> Encodable<S> for &'a str {
fn encode(&self, s: &mut S) {
s.emit_str(*self)
}
}
impl<S:Encoder> Encodable<S> for ~str {
fn encode(&self, s: &mut S) {
s.emit_str(*self)
}
}
impl<D:Decoder> Decodable<D> for ~str {
fn decode(d: &mut D) -> ~str {
d.read_str()
}
}
impl<S:Encoder> Encodable<S> for f32 {
fn encode(&self, s: &mut S) {
s.emit_f32(*self)
}
}
impl<D:Decoder> Decodable<D> for f32 {
fn decode(d: &mut D) -> f32 {
d.read_f32()
}
}
impl<S:Encoder> Encodable<S> for f64 {
fn encode(&self, s: &mut S) {
s.emit_f64(*self)
}
}
impl<D:Decoder> Decodable<D> for f64 {
fn decode(d: &mut D) -> f64 {
d.read_f64()
}
}
impl<S:Encoder> Encodable<S> for bool {
fn encode(&self, s: &mut S) {
s.emit_bool(*self)
}
}
impl<D:Decoder> Decodable<D> for bool {
fn decode(d: &mut D) -> bool {
d.read_bool()
}
}
impl<S:Encoder> Encodable<S> for char {
fn encode(&self, s: &mut S) {
s.emit_char(*self)
}
}
impl<D:Decoder> Decodable<D> for char {
fn decode(d: &mut D) -> char {
d.read_char()
}
}
impl<S:Encoder> Encodable<S> for () {
fn encode(&self, s: &mut S) {
s.emit_nil()
}
}
impl<D:Decoder> Decodable<D> for () {
fn decode(d: &mut D) -> () {
d.read_nil()
}
}
impl<'a, S:Encoder,T:Encodable<S>> Encodable<S> for &'a T {
fn encode(&self, s: &mut S) {
(**self).encode(s)
}
}
impl<S:Encoder,T:Encodable<S>> Encodable<S> for ~T {
fn encode(&self, s: &mut S) {
(**self).encode(s)
}
}
impl<D:Decoder,T:Decodable<D>> Decodable<D> for ~T {
fn decode(d: &mut D) -> ~T {
~Decodable::decode(d)
}
}
impl<S:Encoder,T:Encodable<S>> Encodable<S> for @T {
fn encode(&self, s: &mut S) {
(**self).encode(s)
}
}
impl<S:Encoder,T:Encodable<S>> Encodable<S> for Rc<T> {
#[inline]
fn encode(&self, s: &mut S) {
(**self).encode(s)
}
}
impl<D:Decoder,T:Decodable<D>> Decodable<D> for Rc<T> {
#[inline]
fn decode(d: &mut D) -> Rc<T> {
Rc::new(Decodable::decode(d))
}
}
impl<D:Decoder,T:Decodable<D> + 'static> Decodable<D> for @T {
fn decode(d: &mut D) -> @T {
@Decodable::decode(d)
}
}
impl<'a, S:Encoder,T:Encodable<S>> Encodable<S> for &'a [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<S:Encoder,T:Encodable<S>> Encodable<S> for ~[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 ~[T] {
fn decode(d: &mut D) -> ~[T] {
d.read_seq(|d, len| {
slice::from_fn(len, |i| {
d.read_seq_elt(i, |d| Decodable::decode(d))
})
})
}
}
impl<S:Encoder,T:Encodable<S>> Encodable<S> for Vec<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 Vec<T> {
fn decode(d: &mut D) -> Vec<T> {
d.read_seq(|d, len| {
Vec::from_fn(len, |i| {
d.read_seq_elt(i, |d| Decodable::decode(d))
})
})
}
}
impl<S:Encoder,T:Encodable<S>> Encodable<S> for Option<T> {
fn encode(&self, s: &mut S) {
s.emit_option(|s| {
match *self {
None => s.emit_option_none(),
Some(ref v) => s.emit_option_some(|s| v.encode(s)),
}
})
}
}
impl<D:Decoder,T:Decodable<D>> Decodable<D> for Option<T> {
fn decode(d: &mut D) -> Option<T> {
d.read_option(|d, b| {
if b {
Some(Decodable::decode(d))
} else {
None
}
})
}
}
impl<S:Encoder,T0:Encodable<S>,T1:Encodable<S>> Encodable<S> for (T0, T1) {
fn encode(&self, s: &mut S) {
match *self {
(ref t0, ref t1) => {
s.emit_seq(2, |s| {
s.emit_seq_elt(0, |s| t0.encode(s));
s.emit_seq_elt(1, |s| t1.encode(s));
})
}
}
}
}
impl<D:Decoder,T0:Decodable<D>,T1:Decodable<D>> Decodable<D> for (T0, T1) {
fn decode(d: &mut D) -> (T0, T1) {
d.read_seq(|d, len| {
assert_eq!(len, 2);
(
d.read_seq_elt(0, |d| Decodable::decode(d)),
d.read_seq_elt(1, |d| Decodable::decode(d))
)
})
}
}
impl<
S: Encoder,
T0: Encodable<S>,
T1: Encodable<S>,
T2: Encodable<S>
> Encodable<S> for (T0, T1, T2) {
fn encode(&self, s: &mut S) {
match *self {
(ref t0, ref t1, ref t2) => {
s.emit_seq(3, |s| {
s.emit_seq_elt(0, |s| t0.encode(s));
s.emit_seq_elt(1, |s| t1.encode(s));
s.emit_seq_elt(2, |s| t2.encode(s));
})
}
}
}
}
impl<
D: Decoder,
T0: Decodable<D>,
T1: Decodable<D>,
T2: Decodable<D>
> Decodable<D> for (T0, T1, T2) {
fn decode(d: &mut D) -> (T0, T1, T2) {
d.read_seq(|d, len| {
assert_eq!(len, 3);
(
d.read_seq_elt(0, |d| Decodable::decode(d)),
d.read_seq_elt(1, |d| Decodable::decode(d)),
d.read_seq_elt(2, |d| Decodable::decode(d))
)
})
}
}
impl<
S: Encoder,
T0: Encodable<S>,
T1: Encodable<S>,
T2: Encodable<S>,
T3: Encodable<S>
> Encodable<S> for (T0, T1, T2, T3) {
fn encode(&self, s: &mut S) {
match *self {
(ref t0, ref t1, ref t2, ref t3) => {
s.emit_seq(4, |s| {
s.emit_seq_elt(0, |s| t0.encode(s));
s.emit_seq_elt(1, |s| t1.encode(s));
s.emit_seq_elt(2, |s| t2.encode(s));
s.emit_seq_elt(3, |s| t3.encode(s));
})
}
}
}
}
impl<
D: Decoder,
T0: Decodable<D>,
T1: Decodable<D>,
T2: Decodable<D>,
T3: Decodable<D>
> Decodable<D> for (T0, T1, T2, T3) {
fn decode(d: &mut D) -> (T0, T1, T2, T3) {
d.read_seq(|d, len| {
assert_eq!(len, 4);
(
d.read_seq_elt(0, |d| Decodable::decode(d)),
d.read_seq_elt(1, |d| Decodable::decode(d)),
d.read_seq_elt(2, |d| Decodable::decode(d)),
d.read_seq_elt(3, |d| Decodable::decode(d))
)
})
}
}
impl<
S: Encoder,
T0: Encodable<S>,
T1: Encodable<S>,
T2: Encodable<S>,
T3: Encodable<S>,
T4: Encodable<S>
> Encodable<S> for (T0, T1, T2, T3, T4) {
fn encode(&self, s: &mut S) {
match *self {
(ref t0, ref t1, ref t2, ref t3, ref t4) => {
s.emit_seq(5, |s| {
s.emit_seq_elt(0, |s| t0.encode(s));
s.emit_seq_elt(1, |s| t1.encode(s));
s.emit_seq_elt(2, |s| t2.encode(s));
s.emit_seq_elt(3, |s| t3.encode(s));
s.emit_seq_elt(4, |s| t4.encode(s));
})
}
}
}
}
impl<
D: Decoder,
T0: Decodable<D>,
T1: Decodable<D>,
T2: Decodable<D>,
T3: Decodable<D>,
T4: Decodable<D>
> Decodable<D> for (T0, T1, T2, T3, T4) {
fn decode(d: &mut D) -> (T0, T1, T2, T3, T4) {
d.read_seq(|d, len| {
assert_eq!(len, 5);
(
d.read_seq_elt(0, |d| Decodable::decode(d)),
d.read_seq_elt(1, |d| Decodable::decode(d)),
d.read_seq_elt(2, |d| Decodable::decode(d)),
d.read_seq_elt(3, |d| Decodable::decode(d)),
d.read_seq_elt(4, |d| Decodable::decode(d))
)
})
}
}
impl<E: Encoder> Encodable<E> for path::posix::Path {
fn encode(&self, e: &mut E) {
self.as_vec().encode(e)
}
}
impl<D: Decoder> Decodable<D> for path::posix::Path {
fn decode(d: &mut D) -> path::posix::Path {
let bytes: ~[u8] = Decodable::decode(d);
path::posix::Path::new(bytes)
}
}
impl<E: Encoder> Encodable<E> for path::windows::Path {
fn encode(&self, e: &mut E) {
self.as_vec().encode(e)
}
}
impl<D: Decoder> Decodable<D> for path::windows::Path {
fn decode(d: &mut D) -> path::windows::Path {
let bytes: ~[u8] = Decodable::decode(d);
path::windows::Path::new(bytes)
}
}
// ___________________________________________________________________________
// Helper routines
//
// In some cases, these should eventually be coded as traits.
pub trait EncoderHelpers {
fn emit_from_vec<T>(&mut self, v: &[T], f: |&mut Self, v: &T|);
}
impl<S:Encoder> EncoderHelpers for S {
fn emit_from_vec<T>(&mut self, v: &[T], f: |&mut S, &T|) {
self.emit_seq(v.len(), |this| {
for (i, e) in v.iter().enumerate() {
this.emit_seq_elt(i, |this| {
f(this, e)
})
}
})
}
}
pub trait DecoderHelpers {
fn read_to_vec<T>(&mut self, f: |&mut Self| -> T) -> ~[T];
}
impl<D:Decoder> DecoderHelpers for D {
fn read_to_vec<T>(&mut self, f: |&mut D| -> T) -> ~[T] {
self.read_seq(|this, len| {
slice::from_fn(len, |i| {
this.read_seq_elt(i, |this| f(this))
})
})
}
}

View File

@ -42,7 +42,6 @@ pub trait Eq {
}
/// 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 {}

View File

@ -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.

View File

@ -98,29 +98,12 @@ pub type Name = u32;
/// 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 {

View File

@ -110,23 +110,6 @@ impl Eq for Span {
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 @@ impl<S:Encoder<E>, E> Encodable<S, E> for Span {
}
}
#[cfg(not(stage0))]
impl<D:Decoder<E>, E> Decodable<D, E> for Span {
fn decode(_d: &mut D) -> Result<Span, E> {
Ok(DUMMY_SP)

View File

@ -131,29 +131,12 @@ impl<T> FromIterator<T> for 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) {

View File

@ -288,16 +288,6 @@ mod test {
use util::parser_testing::{string_to_expr, string_to_item};
use util::parser_testing::string_to_stmt;
// FIXME: remove stage0 to_json_str after snapshot
#[cfg(stage0)]
fn to_json_str<'a, E: Encodable<json::Encoder<'a>>>(val: &E) -> ~str {
let mut writer = MemWriter::new();
let mut encoder = json::Encoder::new(&mut writer as &mut io::Writer);
val.encode(&mut encoder);
str::from_utf8_owned(writer.unwrap()).unwrap()
}
#[cfg(not(stage0))]
fn to_json_str<'a, E: Encodable<json::Encoder<'a>, io::IoError>>(val: &E) -> ~str {
let mut writer = MemWriter::new();
let mut encoder = json::Encoder::new(&mut writer as &mut io::Writer);

View File

@ -602,29 +602,12 @@ impl<'a> Equiv<&'a str> for InternedString {
}
}
// FIXME: remove stage0 Encodables/Decodables after snapshot
#[cfg(stage0)]
impl<D:Decoder> Decodable<D> for InternedString {
fn decode(d: &mut D) -> InternedString {
get_name(get_ident_interner().intern(d.read_str()))
}
}
#[cfg(stage0)]
impl<E:Encoder> Encodable<E> for InternedString {
fn encode(&self, e: &mut E) {
e.emit_str(self.string.as_slice())
}
}
#[cfg(not(stage0))]
impl<D:Decoder<E>, E> Decodable<D, E> for InternedString {
fn decode(d: &mut D) -> Result<InternedString, E> {
Ok(get_name(get_ident_interner().intern(try!(d.read_str()))))
}
}
#[cfg(not(stage0))]
impl<S:Encoder<E>, E> Encodable<S, E> for InternedString {
fn encode(&self, s: &mut S) -> Result<(), E> {
s.emit_str(self.string.as_slice())

View File

@ -1018,22 +1018,6 @@ impl ToJson for Metric {
}
}
// FIXME: remove decode_ after snapshot
#[cfg(stage0)]
fn decode_(json: Json) -> MetricMap {
let mut decoder = json::Decoder::new(json);
MetricMap(Decodable::decode(&mut decoder))
}
#[cfg(not(stage0))]
fn decode_(json: Json) -> MetricMap {
let mut decoder = json::Decoder::new(json);
MetricMap(match Decodable::decode(&mut decoder) {
Ok(t) => t,
Err(e) => fail!("failure decoding JSON: {}", e)
})
}
impl MetricMap {
@ -1051,7 +1035,11 @@ impl MetricMap {
assert!(p.exists());
let mut f = File::open(p).unwrap();
let value = json::from_reader(&mut f as &mut io::Reader).unwrap();
decode_(value)
let mut decoder = json::Decoder::new(value);
MetricMap(match Decodable::decode(&mut decoder) {
Ok(t) => t,
Err(e) => fail!("failure decoding JSON: {}", e)
})
}
/// Write MetricDiff to a file.

View File

@ -490,24 +490,6 @@ impl Eq for Uuid {
impl TotalEq for Uuid {}
// FIXME #9845: Test these more thoroughly
// FIXME: remove stage0 Encodable/Decodable after snapshot
#[cfg(stage0)]
impl<T: Encoder> Encodable<T> for Uuid {
/// Encode a UUID as a hypenated string
fn encode(&self, e: &mut T) {
e.emit_str(self.to_hyphenated_str())
}
}
#[cfg(stage0)]
impl<T: Decoder> Decodable<T> for Uuid {
/// Decode a UUID from a string
fn decode(d: &mut T) -> Uuid {
from_str(d.read_str()).unwrap()
}
}
#[cfg(not(stage0))]
impl<T: Encoder<E>, E> Encodable<T, E> for Uuid {
/// Encode a UUID as a hypenated string
fn encode(&self, e: &mut T) -> Result<(), E> {
@ -515,7 +497,6 @@ impl<T: Encoder<E>, E> Encodable<T, E> for Uuid {
}
}
#[cfg(not(stage0))]
impl<T: Decoder<E>, E> Decodable<T, E> for Uuid {
/// Decode a UUID from a string
fn decode(d: &mut T) -> Result<Uuid, E> {
@ -547,17 +528,6 @@ mod test {
use std::str;
use std::io::MemWriter;
// FIXME: remove unwrap_ after snapshot
#[cfg(stage0)]
fn unwrap_<T>(t: T) -> T {
t
}
#[cfg(not(stage0))]
fn unwrap_<T, E>(t: Result<T, E>) -> T {
t.unwrap()
}
#[test]
fn test_nil() {
let nil = Uuid::nil();
@ -829,7 +799,7 @@ mod test {
let mut wr = MemWriter::new();
let _ = u.encode(&mut ebml::writer::Encoder(&mut wr));
let doc = ebml::reader::Doc(wr.get_ref());
let u2 = unwrap_(Decodable::decode(&mut ebml::reader::Decoder(doc)));
let u2 = Decodable::decode(&mut ebml::reader::Decoder(doc)).unwrap();
assert_eq!(u, u2);
}

View File

@ -1,3 +1,11 @@
S 2014-03-28 b8601a3
freebsd-x86_64 c6b0651b2a90697754920ad381c13f9b7942ab47
linux-i386 3bef5684fd0582fbd4ddebd4514182d4f72924f7
linux-x86_64 a7b2af1076d48e4a687a71a21478293e834349bd
macos-i386 41fb091c3bf5f0ebe9341f26129be82782266ddd
macos-x86_64 22b884a3876cb3e40ad942ad68a496b5f239fca5
winnt-i386 65174e80fbf69f92e41110b0bcc7e15704ca359b
S 2014-03-22 94e4e91
freebsd-x86_64 7793127e1b9ad22cb2e020f9bb01f34526cc4656
linux-i386 aa53699d32d7acb86a6447f988c4ac73ac310bab