1
Fork 0

rustc_metadata: go back to not using the opaque format.

This commit is contained in:
Eduard Burtescu 2016-09-01 06:19:58 +03:00
parent 903ec52ba9
commit ed593bed88
6 changed files with 165 additions and 203 deletions

View file

@ -14,9 +14,7 @@ use rustc::hir::map as ast_map;
use rustc::hir::intravisit::{Visitor, IdRangeComputingVisitor, IdRange}; use rustc::hir::intravisit::{Visitor, IdRangeComputingVisitor, IdRange};
use common as c; use cstore::CrateMetadata;
use cstore;
use decoder::DecodeContext; use decoder::DecodeContext;
use encoder::EncodeContext; use encoder::EncodeContext;
@ -28,7 +26,6 @@ use rustc::ty::{self, TyCtxt};
use syntax::ast; use syntax::ast;
use rbml::reader;
use rbml; use rbml;
use rustc_serialize::{Decodable, Encodable}; use rustc_serialize::{Decodable, Encodable};
@ -36,35 +33,31 @@ use rustc_serialize::{Decodable, Encodable};
// Top-level methods. // Top-level methods.
pub fn encode_inlined_item(ecx: &mut EncodeContext, ii: InlinedItemRef) { pub fn encode_inlined_item(ecx: &mut EncodeContext, ii: InlinedItemRef) {
ecx.tag(c::tag_ast, |ecx| { ecx.tag(::common::tag_ast, |ecx| {
ecx.tag(c::tag_id_range, |ecx| { let mut visitor = IdRangeComputingVisitor::new();
let mut visitor = IdRangeComputingVisitor::new(); match ii {
match ii { InlinedItemRef::Item(_, i) => visitor.visit_item(i),
InlinedItemRef::Item(_, i) => visitor.visit_item(i), InlinedItemRef::TraitItem(_, ti) => visitor.visit_trait_item(ti),
InlinedItemRef::TraitItem(_, ti) => visitor.visit_trait_item(ti), InlinedItemRef::ImplItem(_, ii) => visitor.visit_impl_item(ii)
InlinedItemRef::ImplItem(_, ii) => visitor.visit_impl_item(ii) }
} visitor.result().encode(ecx).unwrap();
visitor.result().encode(&mut ecx.opaque()).unwrap()
});
ecx.tag(c::tag_tree, |ecx| ii.encode(ecx).unwrap()); ii.encode(ecx).unwrap();
ecx.tag(c::tag_table, |ecx| { let mut visitor = SideTableEncodingIdVisitor {
let mut visitor = SideTableEncodingIdVisitor { ecx: ecx
ecx: ecx };
}; match ii {
match ii { InlinedItemRef::Item(_, i) => visitor.visit_item(i),
InlinedItemRef::Item(_, i) => visitor.visit_item(i), InlinedItemRef::TraitItem(_, ti) => visitor.visit_trait_item(ti),
InlinedItemRef::TraitItem(_, ti) => visitor.visit_trait_item(ti), InlinedItemRef::ImplItem(_, ii) => visitor.visit_impl_item(ii)
InlinedItemRef::ImplItem(_, ii) => visitor.visit_impl_item(ii) }
}
});
}); });
} }
/// Decodes an item from its AST in the cdata's metadata and adds it to the /// Decodes an item from its AST in the cdata's metadata and adds it to the
/// ast-map. /// ast-map.
pub fn decode_inlined_item<'a, 'tcx>(cdata: &cstore::CrateMetadata, pub fn decode_inlined_item<'a, 'tcx>(cdata: &CrateMetadata,
tcx: TyCtxt<'a, 'tcx, 'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>,
parent_def_path: ast_map::DefPath, parent_def_path: ast_map::DefPath,
parent_did: DefId, parent_did: DefId,
@ -72,16 +65,14 @@ pub fn decode_inlined_item<'a, 'tcx>(cdata: &cstore::CrateMetadata,
orig_did: DefId) orig_did: DefId)
-> &'tcx InlinedItem { -> &'tcx InlinedItem {
debug!("> Decoding inlined fn: {:?}", tcx.item_path_str(orig_did)); debug!("> Decoding inlined fn: {:?}", tcx.item_path_str(orig_did));
let from_id_range = { let dcx = &mut ast_doc.decoder();
let decoder = &mut ast_doc.get(c::tag_id_range).opaque(); dcx.tcx = Some(tcx);
IdRange { dcx.cdata = Some(cdata);
min: ast::NodeId::from_u32(u32::decode(decoder).unwrap()), dcx.from_id_range = IdRange::decode(dcx).unwrap();
max: ast::NodeId::from_u32(u32::decode(decoder).unwrap()) let cnt = dcx.from_id_range.max.as_usize() - dcx.from_id_range.min.as_usize();
} dcx.to_id_range.min = tcx.sess.reserve_node_ids(cnt);
}; dcx.to_id_range.max = ast::NodeId::new(dcx.to_id_range.min.as_usize() + cnt);
let mut dcx = DecodeContext::new(tcx, cdata, from_id_range, let ii = InlinedItem::decode(dcx).unwrap();
ast_doc.get(c::tag_tree));
let ii = InlinedItem::decode(&mut dcx).unwrap();
let ii = ast_map::map_decoded_item(&tcx.map, let ii = ast_map::map_decoded_item(&tcx.map,
parent_def_path, parent_def_path,
@ -97,7 +88,7 @@ pub fn decode_inlined_item<'a, 'tcx>(cdata: &cstore::CrateMetadata,
let inlined_did = tcx.map.local_def_id(item_node_id); let inlined_did = tcx.map.local_def_id(item_node_id);
tcx.register_item_type(inlined_did, tcx.lookup_item_type(orig_did)); tcx.register_item_type(inlined_did, tcx.lookup_item_type(orig_did));
decode_side_tables(&mut dcx, ast_doc); decode_side_tables(dcx, ast_doc);
ii ii
} }
@ -116,7 +107,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
self.end_tag().unwrap(); self.end_tag().unwrap();
} }
fn id(&mut self, id: ast::NodeId) { fn entry(&mut self, table: Table, id: ast::NodeId) {
table.encode(self).unwrap();
id.encode(self).unwrap(); id.encode(self).unwrap();
} }
} }
@ -131,67 +123,67 @@ impl<'a, 'b, 'tcx, 'v> Visitor<'v> for SideTableEncodingIdVisitor<'a, 'b, 'tcx>
} }
} }
#[derive(RustcEncodable, RustcDecodable, Debug)]
enum Table {
Def,
NodeType,
ItemSubsts,
Freevars,
MethodMap,
Adjustment,
UpvarCaptureMap,
ConstQualif,
CastKind
}
fn encode_side_tables_for_id(ecx: &mut EncodeContext, id: ast::NodeId) { fn encode_side_tables_for_id(ecx: &mut EncodeContext, id: ast::NodeId) {
let tcx = ecx.tcx; let tcx = ecx.tcx;
debug!("Encoding side tables for id {}", id); debug!("Encoding side tables for id {}", id);
if let Some(def) = tcx.expect_def_or_none(id) { if let Some(def) = tcx.expect_def_or_none(id) {
ecx.tag(c::tag_table_def, |ecx| { ecx.entry(Table::Def, id);
ecx.id(id); def.encode(ecx).unwrap();
def.encode(ecx).unwrap();
})
} }
if let Some(ty) = tcx.node_types().get(&id) { if let Some(ty) = tcx.node_types().get(&id) {
ecx.tag(c::tag_table_node_type, |ecx| { ecx.entry(Table::NodeType, id);
ecx.id(id); ty.encode(ecx).unwrap();
ty.encode(ecx).unwrap();
})
} }
if let Some(item_substs) = tcx.tables.borrow().item_substs.get(&id) { if let Some(item_substs) = tcx.tables.borrow().item_substs.get(&id) {
ecx.tag(c::tag_table_item_subst, |ecx| { ecx.entry(Table::ItemSubsts, id);
ecx.id(id); item_substs.substs.encode(ecx).unwrap();
item_substs.substs.encode(ecx).unwrap();
})
} }
if let Some(fv) = tcx.freevars.borrow().get(&id) { if let Some(fv) = tcx.freevars.borrow().get(&id) {
ecx.tag(c::tag_table_freevars, |ecx| { ecx.entry(Table::Freevars, id);
ecx.id(id); fv.encode(ecx).unwrap();
fv.encode(ecx).unwrap();
});
for freevar in fv { for freevar in fv {
ecx.tag(c::tag_table_upvar_capture_map, |ecx| { ecx.entry(Table::UpvarCaptureMap, id);
ecx.id(id); let def_id = freevar.def.def_id();
let var_id = tcx.map.as_local_node_id(def_id).unwrap();
let def_id = freevar.def.def_id(); let upvar_id = ty::UpvarId {
let var_id = tcx.map.as_local_node_id(def_id).unwrap(); var_id: var_id,
let upvar_id = ty::UpvarId { closure_expr_id: id
var_id: var_id, };
closure_expr_id: id let upvar_capture = tcx.tables
}; .borrow()
let upvar_capture = tcx.tables .upvar_capture_map
.borrow() .get(&upvar_id)
.upvar_capture_map .unwrap()
.get(&upvar_id) .clone();
.unwrap() var_id.encode(ecx).unwrap();
.clone(); upvar_capture.encode(ecx).unwrap();
var_id.encode(ecx).unwrap();
upvar_capture.encode(ecx).unwrap();
})
} }
} }
let method_call = ty::MethodCall::expr(id); let method_call = ty::MethodCall::expr(id);
if let Some(method) = tcx.tables.borrow().method_map.get(&method_call) { if let Some(method) = tcx.tables.borrow().method_map.get(&method_call) {
ecx.tag(c::tag_table_method_map, |ecx| { ecx.entry(Table::MethodMap, id);
ecx.id(id); method_call.autoderef.encode(ecx).unwrap();
method_call.autoderef.encode(ecx).unwrap(); method.encode(ecx).unwrap();
method.encode(ecx).unwrap();
})
} }
if let Some(adjustment) = tcx.tables.borrow().adjustments.get(&id) { if let Some(adjustment) = tcx.tables.borrow().adjustments.get(&id) {
@ -200,91 +192,79 @@ fn encode_side_tables_for_id(ecx: &mut EncodeContext, id: ast::NodeId) {
for autoderef in 0..adj.autoderefs { for autoderef in 0..adj.autoderefs {
let method_call = ty::MethodCall::autoderef(id, autoderef as u32); let method_call = ty::MethodCall::autoderef(id, autoderef as u32);
if let Some(method) = tcx.tables.borrow().method_map.get(&method_call) { if let Some(method) = tcx.tables.borrow().method_map.get(&method_call) {
ecx.tag(c::tag_table_method_map, |ecx| { ecx.entry(Table::MethodMap, id);
ecx.id(id); method_call.autoderef.encode(ecx).unwrap();
method_call.autoderef.encode(ecx).unwrap(); method.encode(ecx).unwrap();
method.encode(ecx).unwrap();
})
} }
} }
} }
_ => {} _ => {}
} }
ecx.tag(c::tag_table_adjustments, |ecx| { ecx.entry(Table::Adjustment, id);
ecx.id(id); adjustment.encode(ecx).unwrap();
adjustment.encode(ecx).unwrap();
})
} }
if let Some(cast_kind) = tcx.cast_kinds.borrow().get(&id) { if let Some(cast_kind) = tcx.cast_kinds.borrow().get(&id) {
ecx.tag(c::tag_table_cast_kinds, |ecx| { ecx.entry(Table::CastKind, id);
ecx.id(id); cast_kind.encode(ecx).unwrap();
cast_kind.encode(ecx).unwrap()
})
} }
if let Some(qualif) = tcx.const_qualif_map.borrow().get(&id) { if let Some(qualif) = tcx.const_qualif_map.borrow().get(&id) {
ecx.tag(c::tag_table_const_qualif, |ecx| { ecx.entry(Table::ConstQualif, id);
ecx.id(id); qualif.encode(ecx).unwrap();
qualif.encode(ecx).unwrap()
})
} }
} }
fn decode_side_tables<'a, 'tcx>(dcx: &mut DecodeContext<'a, 'tcx>, fn decode_side_tables(dcx: &mut DecodeContext, ast_doc: rbml::Doc) {
ast_doc: rbml::Doc<'a>) { while dcx.position() < ast_doc.end {
for (tag, entry_doc) in reader::docs(ast_doc.get(c::tag_table)) { let table = Decodable::decode(dcx).unwrap();
dcx.rbml_r = reader::Decoder::new(entry_doc);
let id = Decodable::decode(dcx).unwrap(); let id = Decodable::decode(dcx).unwrap();
debug!("decode_side_tables: entry for id={}, tag=0x{:x}", id, tag); debug!("decode_side_tables: entry for id={}, table={:?}", id, table);
match tag { match table {
c::tag_table_def => { Table::Def => {
let def = Decodable::decode(dcx).unwrap(); let def = Decodable::decode(dcx).unwrap();
dcx.tcx.def_map.borrow_mut().insert(id, def::PathResolution::new(def)); dcx.tcx().def_map.borrow_mut().insert(id, def::PathResolution::new(def));
} }
c::tag_table_node_type => { Table::NodeType => {
let ty = Decodable::decode(dcx).unwrap(); let ty = Decodable::decode(dcx).unwrap();
dcx.tcx.node_type_insert(id, ty); dcx.tcx().node_type_insert(id, ty);
} }
c::tag_table_item_subst => { Table::ItemSubsts => {
let item_substs = Decodable::decode(dcx).unwrap(); let item_substs = Decodable::decode(dcx).unwrap();
dcx.tcx.tables.borrow_mut().item_substs.insert(id, item_substs); dcx.tcx().tables.borrow_mut().item_substs.insert(id, item_substs);
} }
c::tag_table_freevars => { Table::Freevars => {
let fv_info = Decodable::decode(dcx).unwrap(); let fv_info = Decodable::decode(dcx).unwrap();
dcx.tcx.freevars.borrow_mut().insert(id, fv_info); dcx.tcx().freevars.borrow_mut().insert(id, fv_info);
} }
c::tag_table_upvar_capture_map => { Table::UpvarCaptureMap => {
let upvar_id = ty::UpvarId { let upvar_id = ty::UpvarId {
var_id: Decodable::decode(dcx).unwrap(), var_id: Decodable::decode(dcx).unwrap(),
closure_expr_id: id closure_expr_id: id
}; };
let ub = Decodable::decode(dcx).unwrap(); let ub = Decodable::decode(dcx).unwrap();
dcx.tcx.tables.borrow_mut().upvar_capture_map.insert(upvar_id, ub); dcx.tcx().tables.borrow_mut().upvar_capture_map.insert(upvar_id, ub);
} }
c::tag_table_method_map => { Table::MethodMap => {
let method_call = ty::MethodCall { let method_call = ty::MethodCall {
expr_id: id, expr_id: id,
autoderef: Decodable::decode(dcx).unwrap() autoderef: Decodable::decode(dcx).unwrap()
}; };
let method = Decodable::decode(dcx).unwrap(); let method = Decodable::decode(dcx).unwrap();
dcx.tcx.tables.borrow_mut().method_map.insert(method_call, method); dcx.tcx().tables.borrow_mut().method_map.insert(method_call, method);
} }
c::tag_table_adjustments => { Table::Adjustment => {
let adj = Decodable::decode(dcx).unwrap(); let adj = Decodable::decode(dcx).unwrap();
dcx.tcx.tables.borrow_mut().adjustments.insert(id, adj); dcx.tcx().tables.borrow_mut().adjustments.insert(id, adj);
} }
c::tag_table_cast_kinds => { Table::CastKind => {
let cast_kind = Decodable::decode(dcx).unwrap(); let cast_kind = Decodable::decode(dcx).unwrap();
dcx.tcx.cast_kinds.borrow_mut().insert(id, cast_kind); dcx.tcx().cast_kinds.borrow_mut().insert(id, cast_kind);
} }
c::tag_table_const_qualif => { Table::ConstQualif => {
let qualif = Decodable::decode(dcx).unwrap(); let qualif = Decodable::decode(dcx).unwrap();
dcx.tcx.const_qualif_map.borrow_mut().insert(id, qualif); dcx.tcx().const_qualif_map.borrow_mut().insert(id, qualif);
}
_ => {
bug!("unknown tag found in side tables: 0x{:x}", tag);
} }
} }
} }

View file

@ -97,28 +97,11 @@ pub const tag_items_data_item_reexport_name: usize = 0x48;
// used to encode crate_ctxt side tables // used to encode crate_ctxt side tables
pub const tag_ast: usize = 0x50; pub const tag_ast: usize = 0x50;
pub const tag_tree: usize = 0x51; // GAP 0x51
pub const tag_mir: usize = 0x52; pub const tag_mir: usize = 0x52;
pub const tag_table: usize = 0x53; // GAP 0x53...0x6a
pub const tag_id_range: usize = 0x54;
// GAP 0x55
pub const tag_table_def: usize = 0x56;
pub const tag_table_node_type: usize = 0x57;
pub const tag_table_item_subst: usize = 0x58;
pub const tag_table_freevars: usize = 0x59;
// GAP 0x5a, 0x5b, 0x5c, 0x5d, 0x5e
pub const tag_table_method_map: usize = 0x5f;
// GAP 0x60
pub const tag_table_adjustments: usize = 0x61;
// GAP 0x62, 0x63, 0x64, 0x65
pub const tag_table_upvar_capture_map: usize = 0x66;
// GAP 0x67, 0x68
pub const tag_table_const_qualif: usize = 0x69;
pub const tag_table_cast_kinds: usize = 0x6a;
pub const tag_item_trait_item_sort: usize = 0x70; pub const tag_item_trait_item_sort: usize = 0x70;

View file

@ -48,6 +48,7 @@ use std::io;
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use std::rc::Rc; use std::rc::Rc;
use std::str; use std::str;
use std::u32;
use rbml::reader; use rbml::reader;
use rbml; use rbml;
@ -59,48 +60,48 @@ use syntax::print::pprust;
use syntax_pos::{self, Span, BytePos, NO_EXPANSION}; use syntax_pos::{self, Span, BytePos, NO_EXPANSION};
pub struct DecodeContext<'a, 'tcx: 'a> { pub struct DecodeContext<'a, 'tcx: 'a> {
pub rbml_r: rbml::reader::Decoder<'a>, rbml_r: rbml::reader::Decoder<'a>,
pub tcx: TyCtxt<'a, 'tcx, 'tcx>, pub tcx: Option<TyCtxt<'a, 'tcx, 'tcx>>,
pub cdata: &'a cstore::CrateMetadata, pub cdata: Option<&'a cstore::CrateMetadata>,
from_id_range: IdRange, pub from_id_range: IdRange,
to_id_range: IdRange, pub to_id_range: IdRange,
// Cache the last used filemap for translating spans as an optimization. // Cache the last used filemap for translating spans as an optimization.
last_filemap_index: usize, last_filemap_index: usize,
} }
impl<'a, 'tcx> DecodeContext<'a, 'tcx> { impl<'doc> rbml::Doc<'doc> {
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, pub fn decoder<'tcx>(self) -> DecodeContext<'doc, 'tcx> {
cdata: &'a cstore::CrateMetadata, let id_range = IdRange {
from_id_range: IdRange, min: NodeId::from_u32(u32::MIN),
doc: rbml::Doc<'a>) max: NodeId::from_u32(u32::MAX)
-> DecodeContext<'a, 'tcx> {
// Handle the case of an empty range:
let to_id_range = if from_id_range.empty() {
from_id_range
} else {
let cnt = from_id_range.max.as_usize() - from_id_range.min.as_usize();
let to_id_min = tcx.sess.reserve_node_ids(cnt);
let to_id_max = NodeId::new(to_id_min.as_usize() + cnt);
IdRange { min: to_id_min, max: to_id_max }
}; };
DecodeContext { DecodeContext {
rbml_r: reader::Decoder::new(doc), rbml_r: reader::Decoder::new(self),
cdata: cdata, cdata: None,
tcx: tcx, tcx: None,
from_id_range: from_id_range, from_id_range: id_range,
to_id_range: to_id_range, to_id_range: id_range,
last_filemap_index: 0 last_filemap_index: 0
} }
} }
}
impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
pub fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> {
self.tcx.expect("missing TyCtxt in DecodeContext")
}
pub fn cdata(&self) -> &'a cstore::CrateMetadata {
self.cdata.expect("missing CrateMetadata in DecodeContext")
}
fn read_ty_encoded<F, R>(&mut self, op: F) -> R fn read_ty_encoded<F, R>(&mut self, op: F) -> R
where F: for<'x> FnOnce(&mut TyDecoder<'x,'tcx>) -> R where F: for<'x> FnOnce(&mut TyDecoder<'x,'tcx>) -> R
{ {
self.read_opaque(|this, doc| { self.read_opaque(|this, doc| {
Ok(op(&mut TyDecoder::with_doc( Ok(op(&mut TyDecoder::with_doc(
this.tcx, this.cdata.cnum, doc, this.tcx(), this.cdata().cnum, doc,
&mut |d| translate_def_id(&this.cdata, d)))) &mut |d| translate_def_id(this.cdata(), d))))
}).unwrap() }).unwrap()
} }
} }
@ -142,9 +143,9 @@ impl<'a, 'tcx> SpecializedDecoder<CrateNum> for DecodeContext<'a, 'tcx> {
fn specialized_decode(&mut self) -> Result<CrateNum, Self::Error> { fn specialized_decode(&mut self) -> Result<CrateNum, Self::Error> {
let cnum = CrateNum::from_u32(u32::decode(self)?); let cnum = CrateNum::from_u32(u32::decode(self)?);
if cnum == LOCAL_CRATE { if cnum == LOCAL_CRATE {
Ok(self.cdata.cnum) Ok(self.cdata().cnum)
} else { } else {
Ok(self.cdata.cnum_map.borrow()[cnum]) Ok(self.cdata().cnum_map.borrow()[cnum])
} }
} }
} }
@ -154,6 +155,12 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for DecodeContext<'a, 'tcx> {
let lo = BytePos::decode(self)?; let lo = BytePos::decode(self)?;
let hi = BytePos::decode(self)?; let hi = BytePos::decode(self)?;
let tcx = if let Some(tcx) = self.tcx {
tcx
} else {
return Ok(syntax_pos::mk_sp(lo, hi));
};
let (lo, hi) = if lo > hi { let (lo, hi) = if lo > hi {
// Currently macro expansion sometimes produces invalid Span values // Currently macro expansion sometimes produces invalid Span values
// where lo > hi. In order not to crash the compiler when trying to // where lo > hi. In order not to crash the compiler when trying to
@ -167,7 +174,7 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for DecodeContext<'a, 'tcx> {
(lo, hi) (lo, hi)
}; };
let imported_filemaps = self.cdata.imported_filemaps(&self.tcx.sess.codemap()); let imported_filemaps = self.cdata().imported_filemaps(&tcx.sess.codemap());
let filemap = { let filemap = {
// Optimize for the case that most spans within a translated item // Optimize for the case that most spans within a translated item
// originate from the same filemap. // originate from the same filemap.
@ -224,7 +231,7 @@ impl<'a, 'tcx> SpecializedDecoder<&'tcx Substs<'tcx>> for DecodeContext<'a, 'tcx
impl<'a, 'tcx> SpecializedDecoder<&'tcx ty::Region> for DecodeContext<'a, 'tcx> { impl<'a, 'tcx> SpecializedDecoder<&'tcx ty::Region> for DecodeContext<'a, 'tcx> {
fn specialized_decode(&mut self) -> Result<&'tcx ty::Region, Self::Error> { fn specialized_decode(&mut self) -> Result<&'tcx ty::Region, Self::Error> {
let r = ty::Region::decode(self)?; let r = ty::Region::decode(self)?;
Ok(self.tcx.mk_region(r)) Ok(self.tcx().mk_region(r))
} }
} }
@ -232,7 +239,7 @@ impl<'a, 'tcx> SpecializedDecoder<ty::ClosureSubsts<'tcx>> for DecodeContext<'a,
fn specialized_decode(&mut self) -> Result<ty::ClosureSubsts<'tcx>, Self::Error> { fn specialized_decode(&mut self) -> Result<ty::ClosureSubsts<'tcx>, Self::Error> {
Ok(ty::ClosureSubsts { Ok(ty::ClosureSubsts {
func_substs: Decodable::decode(self)?, func_substs: Decodable::decode(self)?,
upvar_tys: self.tcx.mk_type_list(Decodable::decode(self)?) upvar_tys: self.tcx().mk_type_list(Decodable::decode(self)?)
}) })
} }
} }
@ -240,7 +247,7 @@ impl<'a, 'tcx> SpecializedDecoder<ty::ClosureSubsts<'tcx>> for DecodeContext<'a,
impl<'a, 'tcx> SpecializedDecoder<ty::AdtDef<'tcx>> for DecodeContext<'a, 'tcx> { impl<'a, 'tcx> SpecializedDecoder<ty::AdtDef<'tcx>> for DecodeContext<'a, 'tcx> {
fn specialized_decode(&mut self) -> Result<ty::AdtDef<'tcx>, Self::Error> { fn specialized_decode(&mut self) -> Result<ty::AdtDef<'tcx>, Self::Error> {
let def_id = DefId::decode(self)?; let def_id = DefId::decode(self)?;
Ok(self.tcx.lookup_adt_def(def_id)) Ok(self.tcx().lookup_adt_def(def_id))
} }
} }
@ -739,14 +746,14 @@ pub fn get_type<'a, 'tcx>(cdata: Cmd, id: DefIndex, tcx: TyCtxt<'a, 'tcx, 'tcx>)
pub fn get_stability(cdata: Cmd, id: DefIndex) -> Option<attr::Stability> { pub fn get_stability(cdata: Cmd, id: DefIndex) -> Option<attr::Stability> {
let item = cdata.lookup_item(id); let item = cdata.lookup_item(id);
reader::maybe_get_doc(item, tag_items_data_item_stability).map(|doc| { reader::maybe_get_doc(item, tag_items_data_item_stability).map(|doc| {
Decodable::decode(&mut doc.opaque()).unwrap() Decodable::decode(&mut doc.decoder()).unwrap()
}) })
} }
pub fn get_deprecation(cdata: Cmd, id: DefIndex) -> Option<attr::Deprecation> { pub fn get_deprecation(cdata: Cmd, id: DefIndex) -> Option<attr::Deprecation> {
let item = cdata.lookup_item(id); let item = cdata.lookup_item(id);
reader::maybe_get_doc(item, tag_items_data_item_deprecation).map(|doc| { reader::maybe_get_doc(item, tag_items_data_item_deprecation).map(|doc| {
Decodable::decode(&mut doc.opaque()).unwrap() Decodable::decode(&mut doc.decoder()).unwrap()
}) })
} }
@ -764,7 +771,7 @@ pub fn get_parent_impl(cdata: Cmd, id: DefIndex) -> Option<DefId> {
pub fn get_repr_attrs(cdata: Cmd, id: DefIndex) -> Vec<attr::ReprAttr> { pub fn get_repr_attrs(cdata: Cmd, id: DefIndex) -> Vec<attr::ReprAttr> {
let item = cdata.lookup_item(id); let item = cdata.lookup_item(id);
reader::maybe_get_doc(item, tag_items_data_item_repr).map_or(vec![], |doc| { reader::maybe_get_doc(item, tag_items_data_item_repr).map_or(vec![], |doc| {
Decodable::decode(&mut doc.opaque()).unwrap() Decodable::decode(&mut doc.decoder()).unwrap()
}) })
} }
@ -786,7 +793,7 @@ pub fn get_custom_coerce_unsized_kind(
{ {
let item_doc = cdata.lookup_item(id); let item_doc = cdata.lookup_item(id);
reader::maybe_get_doc(item_doc, tag_impl_coerce_unsized_kind).map(|kind_doc| { reader::maybe_get_doc(item_doc, tag_impl_coerce_unsized_kind).map(|kind_doc| {
Decodable::decode(&mut kind_doc.opaque()).unwrap() Decodable::decode(&mut kind_doc.decoder()).unwrap()
}) })
} }
@ -982,8 +989,9 @@ pub fn maybe_get_item_mir<'a, 'tcx>(cdata: Cmd,
let item_doc = cdata.lookup_item(id); let item_doc = cdata.lookup_item(id);
reader::maybe_get_doc(item_doc, tag_mir).map(|mir_doc| { reader::maybe_get_doc(item_doc, tag_mir).map(|mir_doc| {
let id_range = IdRange { min: NodeId::new(0), max: NodeId::new(0) }; let mut dcx = mir_doc.decoder();
let mut dcx = DecodeContext::new(tcx, cdata, id_range, mir_doc); dcx.tcx = Some(tcx);
dcx.cdata = Some(cdata);
Decodable::decode(&mut dcx).unwrap() Decodable::decode(&mut dcx).unwrap()
}) })
} }
@ -1123,7 +1131,7 @@ pub fn get_trait_item_def_ids(cdata: Cmd, id: DefIndex)
pub fn get_item_variances(cdata: Cmd, id: DefIndex) -> Vec<ty::Variance> { pub fn get_item_variances(cdata: Cmd, id: DefIndex) -> Vec<ty::Variance> {
let item_doc = cdata.lookup_item(id); let item_doc = cdata.lookup_item(id);
let variance_doc = reader::get_doc(item_doc, tag_item_variances); let variance_doc = reader::get_doc(item_doc, tag_item_variances);
Decodable::decode(&mut variance_doc.opaque()).unwrap() Decodable::decode(&mut variance_doc.decoder()).unwrap()
} }
pub fn get_provided_trait_methods<'a, 'tcx>(cdata: Cmd, pub fn get_provided_trait_methods<'a, 'tcx>(cdata: Cmd,
@ -1242,7 +1250,7 @@ pub fn get_struct_field_names(cdata: Cmd, id: DefIndex) -> Vec<ast::Name> {
fn get_attributes(md: rbml::Doc) -> Vec<ast::Attribute> { fn get_attributes(md: rbml::Doc) -> Vec<ast::Attribute> {
reader::maybe_get_doc(md, tag_attributes).map_or(vec![], |attrs_doc| { reader::maybe_get_doc(md, tag_attributes).map_or(vec![], |attrs_doc| {
let mut attrs = Vec::<ast::Attribute>::decode(&mut attrs_doc.opaque()).unwrap(); let mut attrs = Vec::<ast::Attribute>::decode(&mut attrs_doc.decoder()).unwrap();
// Need new unique IDs: old thread-local IDs won't map to new threads. // Need new unique IDs: old thread-local IDs won't map to new threads.
for attr in attrs.iter_mut() { for attr in attrs.iter_mut() {
@ -1647,14 +1655,14 @@ pub fn get_imported_filemaps(metadata: &[u8]) -> Vec<syntax_pos::FileMap> {
let cm_doc = reader::get_doc(crate_doc, tag_codemap); let cm_doc = reader::get_doc(crate_doc, tag_codemap);
reader::tagged_docs(cm_doc, tag_codemap_filemap).map(|filemap_doc| { reader::tagged_docs(cm_doc, tag_codemap_filemap).map(|filemap_doc| {
Decodable::decode(&mut filemap_doc.opaque()).unwrap() Decodable::decode(&mut filemap_doc.decoder()).unwrap()
}).collect() }).collect()
} }
pub fn closure_kind(cdata: Cmd, closure_id: DefIndex) -> ty::ClosureKind { pub fn closure_kind(cdata: Cmd, closure_id: DefIndex) -> ty::ClosureKind {
let closure_doc = cdata.lookup_item(closure_id); let closure_doc = cdata.lookup_item(closure_id);
let closure_kind_doc = reader::get_doc(closure_doc, tag_items_closure_kind); let closure_kind_doc = reader::get_doc(closure_doc, tag_items_closure_kind);
ty::ClosureKind::decode(&mut closure_kind_doc.opaque()).unwrap() ty::ClosureKind::decode(&mut closure_kind_doc.decoder()).unwrap()
} }
pub fn closure_ty<'a, 'tcx>(cdata: Cmd, closure_id: DefIndex, tcx: TyCtxt<'a, 'tcx, 'tcx>) pub fn closure_ty<'a, 'tcx>(cdata: Cmd, closure_id: DefIndex, tcx: TyCtxt<'a, 'tcx, 'tcx>)
@ -1674,7 +1682,7 @@ pub fn def_key(cdata: Cmd, id: DefIndex) -> hir_map::DefKey {
fn item_def_key(item_doc: rbml::Doc) -> hir_map::DefKey { fn item_def_key(item_doc: rbml::Doc) -> hir_map::DefKey {
match reader::maybe_get_doc(item_doc, tag_def_key) { match reader::maybe_get_doc(item_doc, tag_def_key) {
Some(def_key_doc) => { Some(def_key_doc) => {
let simple_key = def_key::DefKey::decode(&mut def_key_doc.opaque()).unwrap(); let simple_key = def_key::DefKey::decode(&mut def_key_doc.decoder()).unwrap();
let name = reader::maybe_get_doc(item_doc, tag_paths_data_name).map(|name| { let name = reader::maybe_get_doc(item_doc, tag_paths_data_name).map(|name| {
token::intern(name.as_str()).as_str() token::intern(name.as_str()).as_str()
}); });

View file

@ -108,7 +108,7 @@ fn encode_def_id(ecx: &mut EncodeContext, id: DefId) {
fn encode_def_key(ecx: &mut EncodeContext, key: DefKey) { fn encode_def_key(ecx: &mut EncodeContext, key: DefKey) {
let simple_key = def_key::simplify_def_key(key); let simple_key = def_key::simplify_def_key(key);
ecx.start_tag(tag_def_key); ecx.start_tag(tag_def_key);
simple_key.encode(&mut ecx.opaque()); simple_key.encode(ecx);
ecx.end_tag(); ecx.end_tag();
} }
@ -146,7 +146,7 @@ pub fn def_to_string(_tcx: TyCtxt, did: DefId) -> String {
fn encode_item_variances(ecx: &mut EncodeContext, id: NodeId) { fn encode_item_variances(ecx: &mut EncodeContext, id: NodeId) {
let v = ecx.tcx.item_variances(ecx.tcx.map.local_def_id(id)); let v = ecx.tcx.item_variances(ecx.tcx.map.local_def_id(id));
ecx.start_tag(tag_item_variances); ecx.start_tag(tag_item_variances);
v.encode(&mut ecx.opaque()); v.encode(ecx);
ecx.end_tag(); ecx.end_tag();
} }
@ -761,7 +761,7 @@ impl<'a, 'b, 'tcx> ItemContentBuilder<'a, 'b, 'tcx> {
attr)); attr));
} }
self.start_tag(tag_items_data_item_repr); self.start_tag(tag_items_data_item_repr);
repr_attrs.encode(&mut self.opaque()); repr_attrs.encode(self.ecx);
self.end_tag(); self.end_tag();
} }
@ -796,7 +796,7 @@ fn encode_inherent_implementations(ecx: &mut EncodeContext,
fn encode_stability(ecx: &mut EncodeContext, stab_opt: Option<&attr::Stability>) { fn encode_stability(ecx: &mut EncodeContext, stab_opt: Option<&attr::Stability>) {
stab_opt.map(|stab| { stab_opt.map(|stab| {
ecx.start_tag(tag_items_data_item_stability); ecx.start_tag(tag_items_data_item_stability);
stab.encode(&mut ecx.opaque()).unwrap(); stab.encode(ecx).unwrap();
ecx.end_tag(); ecx.end_tag();
}); });
} }
@ -804,7 +804,7 @@ fn encode_stability(ecx: &mut EncodeContext, stab_opt: Option<&attr::Stability>)
fn encode_deprecation(ecx: &mut EncodeContext, depr_opt: Option<attr::Deprecation>) { fn encode_deprecation(ecx: &mut EncodeContext, depr_opt: Option<attr::Deprecation>) {
depr_opt.map(|depr| { depr_opt.map(|depr| {
ecx.start_tag(tag_items_data_item_deprecation); ecx.start_tag(tag_items_data_item_deprecation);
depr.encode(&mut ecx.opaque()).unwrap(); depr.encode(ecx).unwrap();
ecx.end_tag(); ecx.end_tag();
}); });
} }
@ -1043,7 +1043,7 @@ impl<'a, 'b, 'tcx> ItemContentBuilder<'a, 'b, 'tcx> {
{ {
Some(&kind) => { Some(&kind) => {
self.start_tag(tag_impl_coerce_unsized_kind); self.start_tag(tag_impl_coerce_unsized_kind);
kind.encode(&mut self.opaque()); kind.encode(self.ecx);
self.end_tag(); self.end_tag();
} }
None => {} None => {}
@ -1361,7 +1361,7 @@ impl<'a, 'b, 'tcx> ItemContentBuilder<'a, 'b, 'tcx> {
self.end_tag(); self.end_tag();
self.start_tag(tag_items_closure_kind); self.start_tag(tag_items_closure_kind);
tcx.closure_kind(def_id).encode(&mut self.opaque()).unwrap(); tcx.closure_kind(def_id).encode(self.ecx).unwrap();
self.end_tag(); self.end_tag();
assert!(self.mir_map.map.contains_key(&def_id)); assert!(self.mir_map.map.contains_key(&def_id));
@ -1403,7 +1403,7 @@ fn encode_item_index(ecx: &mut EncodeContext, index: IndexData) {
fn encode_attributes(ecx: &mut EncodeContext, attrs: &[ast::Attribute]) { fn encode_attributes(ecx: &mut EncodeContext, attrs: &[ast::Attribute]) {
ecx.start_tag(tag_attributes); ecx.start_tag(tag_attributes);
attrs.encode(&mut ecx.opaque()).unwrap(); attrs.encode(ecx).unwrap();
ecx.end_tag(); ecx.end_tag();
} }
@ -1538,7 +1538,7 @@ fn encode_codemap(ecx: &mut EncodeContext) {
} }
ecx.start_tag(tag_codemap_filemap); ecx.start_tag(tag_codemap_filemap);
filemap.encode(&mut ecx.opaque()).unwrap(); filemap.encode(ecx).unwrap();
ecx.end_tag(); ecx.end_tag();
} }

View file

@ -123,7 +123,6 @@ use std::str;
use rustc_serialize as serialize; use rustc_serialize as serialize;
use rbml::opaque;
use rbml::Error; use rbml::Error;
use rbml::Error::*; use rbml::Error::*;
@ -158,10 +157,6 @@ impl<'doc> Doc<'doc> {
pub fn to_string(&self) -> String { pub fn to_string(&self) -> String {
self.as_str().to_string() self.as_str().to_string()
} }
pub fn opaque(&self) -> opaque::Decoder<'doc> {
opaque::Decoder::new(self.data, self.start)
}
} }
pub struct TaggedDoc<'a> { pub struct TaggedDoc<'a> {

View file

@ -254,15 +254,11 @@ impl Encoder {
} }
} }
pub fn opaque(&mut self) -> opaque::Encoder {
opaque::Encoder::new(&mut self.writer)
}
pub fn emit_opaque<F>(&mut self, f: F) -> EncodeResult pub fn emit_opaque<F>(&mut self, f: F) -> EncodeResult
where F: FnOnce(&mut opaque::Encoder) -> EncodeResult where F: FnOnce(&mut opaque::Encoder) -> EncodeResult
{ {
self.start_tag(EsOpaque as usize)?; self.start_tag(EsOpaque as usize)?;
f(&mut self.opaque())?; f(&mut opaque::Encoder::new(&mut self.writer))?;
self.mark_stable_position(); self.mark_stable_position();
self.end_tag() self.end_tag()
} }