rustc_metadata: go back to not using the opaque format.
This commit is contained in:
parent
903ec52ba9
commit
ed593bed88
@ -14,9 +14,7 @@ use rustc::hir::map as ast_map;
|
||||
|
||||
use rustc::hir::intravisit::{Visitor, IdRangeComputingVisitor, IdRange};
|
||||
|
||||
use common as c;
|
||||
use cstore;
|
||||
|
||||
use cstore::CrateMetadata;
|
||||
use decoder::DecodeContext;
|
||||
use encoder::EncodeContext;
|
||||
|
||||
@ -28,7 +26,6 @@ use rustc::ty::{self, TyCtxt};
|
||||
|
||||
use syntax::ast;
|
||||
|
||||
use rbml::reader;
|
||||
use rbml;
|
||||
use rustc_serialize::{Decodable, Encodable};
|
||||
|
||||
@ -36,35 +33,31 @@ use rustc_serialize::{Decodable, Encodable};
|
||||
// Top-level methods.
|
||||
|
||||
pub fn encode_inlined_item(ecx: &mut EncodeContext, ii: InlinedItemRef) {
|
||||
ecx.tag(c::tag_ast, |ecx| {
|
||||
ecx.tag(c::tag_id_range, |ecx| {
|
||||
let mut visitor = IdRangeComputingVisitor::new();
|
||||
match ii {
|
||||
InlinedItemRef::Item(_, i) => visitor.visit_item(i),
|
||||
InlinedItemRef::TraitItem(_, ti) => visitor.visit_trait_item(ti),
|
||||
InlinedItemRef::ImplItem(_, ii) => visitor.visit_impl_item(ii)
|
||||
}
|
||||
visitor.result().encode(&mut ecx.opaque()).unwrap()
|
||||
});
|
||||
ecx.tag(::common::tag_ast, |ecx| {
|
||||
let mut visitor = IdRangeComputingVisitor::new();
|
||||
match ii {
|
||||
InlinedItemRef::Item(_, i) => visitor.visit_item(i),
|
||||
InlinedItemRef::TraitItem(_, ti) => visitor.visit_trait_item(ti),
|
||||
InlinedItemRef::ImplItem(_, ii) => visitor.visit_impl_item(ii)
|
||||
}
|
||||
visitor.result().encode(ecx).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 {
|
||||
ecx: ecx
|
||||
};
|
||||
match ii {
|
||||
InlinedItemRef::Item(_, i) => visitor.visit_item(i),
|
||||
InlinedItemRef::TraitItem(_, ti) => visitor.visit_trait_item(ti),
|
||||
InlinedItemRef::ImplItem(_, ii) => visitor.visit_impl_item(ii)
|
||||
}
|
||||
});
|
||||
let mut visitor = SideTableEncodingIdVisitor {
|
||||
ecx: ecx
|
||||
};
|
||||
match ii {
|
||||
InlinedItemRef::Item(_, i) => visitor.visit_item(i),
|
||||
InlinedItemRef::TraitItem(_, ti) => visitor.visit_trait_item(ti),
|
||||
InlinedItemRef::ImplItem(_, ii) => visitor.visit_impl_item(ii)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Decodes an item from its AST in the cdata's metadata and adds it to the
|
||||
/// 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>,
|
||||
parent_def_path: ast_map::DefPath,
|
||||
parent_did: DefId,
|
||||
@ -72,16 +65,14 @@ pub fn decode_inlined_item<'a, 'tcx>(cdata: &cstore::CrateMetadata,
|
||||
orig_did: DefId)
|
||||
-> &'tcx InlinedItem {
|
||||
debug!("> Decoding inlined fn: {:?}", tcx.item_path_str(orig_did));
|
||||
let from_id_range = {
|
||||
let decoder = &mut ast_doc.get(c::tag_id_range).opaque();
|
||||
IdRange {
|
||||
min: ast::NodeId::from_u32(u32::decode(decoder).unwrap()),
|
||||
max: ast::NodeId::from_u32(u32::decode(decoder).unwrap())
|
||||
}
|
||||
};
|
||||
let mut dcx = DecodeContext::new(tcx, cdata, from_id_range,
|
||||
ast_doc.get(c::tag_tree));
|
||||
let ii = InlinedItem::decode(&mut dcx).unwrap();
|
||||
let dcx = &mut ast_doc.decoder();
|
||||
dcx.tcx = Some(tcx);
|
||||
dcx.cdata = Some(cdata);
|
||||
dcx.from_id_range = IdRange::decode(dcx).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 ii = InlinedItem::decode(dcx).unwrap();
|
||||
|
||||
let ii = ast_map::map_decoded_item(&tcx.map,
|
||||
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);
|
||||
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
|
||||
}
|
||||
@ -116,7 +107,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
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();
|
||||
}
|
||||
}
|
||||
@ -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) {
|
||||
let tcx = ecx.tcx;
|
||||
|
||||
debug!("Encoding side tables for id {}", id);
|
||||
|
||||
if let Some(def) = tcx.expect_def_or_none(id) {
|
||||
ecx.tag(c::tag_table_def, |ecx| {
|
||||
ecx.id(id);
|
||||
def.encode(ecx).unwrap();
|
||||
})
|
||||
ecx.entry(Table::Def, id);
|
||||
def.encode(ecx).unwrap();
|
||||
}
|
||||
|
||||
if let Some(ty) = tcx.node_types().get(&id) {
|
||||
ecx.tag(c::tag_table_node_type, |ecx| {
|
||||
ecx.id(id);
|
||||
ty.encode(ecx).unwrap();
|
||||
})
|
||||
ecx.entry(Table::NodeType, id);
|
||||
ty.encode(ecx).unwrap();
|
||||
}
|
||||
|
||||
if let Some(item_substs) = tcx.tables.borrow().item_substs.get(&id) {
|
||||
ecx.tag(c::tag_table_item_subst, |ecx| {
|
||||
ecx.id(id);
|
||||
item_substs.substs.encode(ecx).unwrap();
|
||||
})
|
||||
ecx.entry(Table::ItemSubsts, id);
|
||||
item_substs.substs.encode(ecx).unwrap();
|
||||
}
|
||||
|
||||
if let Some(fv) = tcx.freevars.borrow().get(&id) {
|
||||
ecx.tag(c::tag_table_freevars, |ecx| {
|
||||
ecx.id(id);
|
||||
fv.encode(ecx).unwrap();
|
||||
});
|
||||
ecx.entry(Table::Freevars, id);
|
||||
fv.encode(ecx).unwrap();
|
||||
|
||||
for freevar in fv {
|
||||
ecx.tag(c::tag_table_upvar_capture_map, |ecx| {
|
||||
ecx.id(id);
|
||||
|
||||
let def_id = freevar.def.def_id();
|
||||
let var_id = tcx.map.as_local_node_id(def_id).unwrap();
|
||||
let upvar_id = ty::UpvarId {
|
||||
var_id: var_id,
|
||||
closure_expr_id: id
|
||||
};
|
||||
let upvar_capture = tcx.tables
|
||||
.borrow()
|
||||
.upvar_capture_map
|
||||
.get(&upvar_id)
|
||||
.unwrap()
|
||||
.clone();
|
||||
var_id.encode(ecx).unwrap();
|
||||
upvar_capture.encode(ecx).unwrap();
|
||||
})
|
||||
ecx.entry(Table::UpvarCaptureMap, id);
|
||||
let def_id = freevar.def.def_id();
|
||||
let var_id = tcx.map.as_local_node_id(def_id).unwrap();
|
||||
let upvar_id = ty::UpvarId {
|
||||
var_id: var_id,
|
||||
closure_expr_id: id
|
||||
};
|
||||
let upvar_capture = tcx.tables
|
||||
.borrow()
|
||||
.upvar_capture_map
|
||||
.get(&upvar_id)
|
||||
.unwrap()
|
||||
.clone();
|
||||
var_id.encode(ecx).unwrap();
|
||||
upvar_capture.encode(ecx).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
let method_call = ty::MethodCall::expr(id);
|
||||
if let Some(method) = tcx.tables.borrow().method_map.get(&method_call) {
|
||||
ecx.tag(c::tag_table_method_map, |ecx| {
|
||||
ecx.id(id);
|
||||
method_call.autoderef.encode(ecx).unwrap();
|
||||
method.encode(ecx).unwrap();
|
||||
})
|
||||
ecx.entry(Table::MethodMap, id);
|
||||
method_call.autoderef.encode(ecx).unwrap();
|
||||
method.encode(ecx).unwrap();
|
||||
}
|
||||
|
||||
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 {
|
||||
let method_call = ty::MethodCall::autoderef(id, autoderef as u32);
|
||||
if let Some(method) = tcx.tables.borrow().method_map.get(&method_call) {
|
||||
ecx.tag(c::tag_table_method_map, |ecx| {
|
||||
ecx.id(id);
|
||||
method_call.autoderef.encode(ecx).unwrap();
|
||||
method.encode(ecx).unwrap();
|
||||
})
|
||||
ecx.entry(Table::MethodMap, id);
|
||||
method_call.autoderef.encode(ecx).unwrap();
|
||||
method.encode(ecx).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
ecx.tag(c::tag_table_adjustments, |ecx| {
|
||||
ecx.id(id);
|
||||
adjustment.encode(ecx).unwrap();
|
||||
})
|
||||
ecx.entry(Table::Adjustment, id);
|
||||
adjustment.encode(ecx).unwrap();
|
||||
}
|
||||
|
||||
if let Some(cast_kind) = tcx.cast_kinds.borrow().get(&id) {
|
||||
ecx.tag(c::tag_table_cast_kinds, |ecx| {
|
||||
ecx.id(id);
|
||||
cast_kind.encode(ecx).unwrap()
|
||||
})
|
||||
ecx.entry(Table::CastKind, id);
|
||||
cast_kind.encode(ecx).unwrap();
|
||||
}
|
||||
|
||||
if let Some(qualif) = tcx.const_qualif_map.borrow().get(&id) {
|
||||
ecx.tag(c::tag_table_const_qualif, |ecx| {
|
||||
ecx.id(id);
|
||||
qualif.encode(ecx).unwrap()
|
||||
})
|
||||
ecx.entry(Table::ConstQualif, id);
|
||||
qualif.encode(ecx).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn decode_side_tables<'a, 'tcx>(dcx: &mut DecodeContext<'a, 'tcx>,
|
||||
ast_doc: rbml::Doc<'a>) {
|
||||
for (tag, entry_doc) in reader::docs(ast_doc.get(c::tag_table)) {
|
||||
dcx.rbml_r = reader::Decoder::new(entry_doc);
|
||||
fn decode_side_tables(dcx: &mut DecodeContext, ast_doc: rbml::Doc) {
|
||||
while dcx.position() < ast_doc.end {
|
||||
let table = Decodable::decode(dcx).unwrap();
|
||||
let id = Decodable::decode(dcx).unwrap();
|
||||
debug!("decode_side_tables: entry for id={}, tag=0x{:x}", id, tag);
|
||||
match tag {
|
||||
c::tag_table_def => {
|
||||
debug!("decode_side_tables: entry for id={}, table={:?}", id, table);
|
||||
match table {
|
||||
Table::Def => {
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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 {
|
||||
var_id: Decodable::decode(dcx).unwrap(),
|
||||
closure_expr_id: id
|
||||
};
|
||||
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 {
|
||||
expr_id: id,
|
||||
autoderef: 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();
|
||||
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();
|
||||
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();
|
||||
dcx.tcx.const_qualif_map.borrow_mut().insert(id, qualif);
|
||||
}
|
||||
_ => {
|
||||
bug!("unknown tag found in side tables: 0x{:x}", tag);
|
||||
dcx.tcx().const_qualif_map.borrow_mut().insert(id, qualif);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -97,28 +97,11 @@ pub const tag_items_data_item_reexport_name: usize = 0x48;
|
||||
// used to encode crate_ctxt side tables
|
||||
pub const tag_ast: usize = 0x50;
|
||||
|
||||
pub const tag_tree: usize = 0x51;
|
||||
// GAP 0x51
|
||||
|
||||
pub const tag_mir: usize = 0x52;
|
||||
|
||||
pub const tag_table: usize = 0x53;
|
||||
|
||||
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;
|
||||
// GAP 0x53...0x6a
|
||||
|
||||
pub const tag_item_trait_item_sort: usize = 0x70;
|
||||
|
||||
|
@ -48,6 +48,7 @@ use std::io;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::rc::Rc;
|
||||
use std::str;
|
||||
use std::u32;
|
||||
|
||||
use rbml::reader;
|
||||
use rbml;
|
||||
@ -59,48 +60,48 @@ use syntax::print::pprust;
|
||||
use syntax_pos::{self, Span, BytePos, NO_EXPANSION};
|
||||
|
||||
pub struct DecodeContext<'a, 'tcx: 'a> {
|
||||
pub rbml_r: rbml::reader::Decoder<'a>,
|
||||
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
pub cdata: &'a cstore::CrateMetadata,
|
||||
from_id_range: IdRange,
|
||||
to_id_range: IdRange,
|
||||
rbml_r: rbml::reader::Decoder<'a>,
|
||||
pub tcx: Option<TyCtxt<'a, 'tcx, 'tcx>>,
|
||||
pub cdata: Option<&'a cstore::CrateMetadata>,
|
||||
pub from_id_range: IdRange,
|
||||
pub to_id_range: IdRange,
|
||||
// Cache the last used filemap for translating spans as an optimization.
|
||||
last_filemap_index: usize,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
|
||||
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
cdata: &'a cstore::CrateMetadata,
|
||||
from_id_range: IdRange,
|
||||
doc: rbml::Doc<'a>)
|
||||
-> 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 }
|
||||
impl<'doc> rbml::Doc<'doc> {
|
||||
pub fn decoder<'tcx>(self) -> DecodeContext<'doc, 'tcx> {
|
||||
let id_range = IdRange {
|
||||
min: NodeId::from_u32(u32::MIN),
|
||||
max: NodeId::from_u32(u32::MAX)
|
||||
};
|
||||
|
||||
DecodeContext {
|
||||
rbml_r: reader::Decoder::new(doc),
|
||||
cdata: cdata,
|
||||
tcx: tcx,
|
||||
from_id_range: from_id_range,
|
||||
to_id_range: to_id_range,
|
||||
rbml_r: reader::Decoder::new(self),
|
||||
cdata: None,
|
||||
tcx: None,
|
||||
from_id_range: id_range,
|
||||
to_id_range: id_range,
|
||||
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
|
||||
where F: for<'x> FnOnce(&mut TyDecoder<'x,'tcx>) -> R
|
||||
{
|
||||
self.read_opaque(|this, doc| {
|
||||
Ok(op(&mut TyDecoder::with_doc(
|
||||
this.tcx, this.cdata.cnum, doc,
|
||||
&mut |d| translate_def_id(&this.cdata, d))))
|
||||
this.tcx(), this.cdata().cnum, doc,
|
||||
&mut |d| translate_def_id(this.cdata(), d))))
|
||||
}).unwrap()
|
||||
}
|
||||
}
|
||||
@ -142,9 +143,9 @@ impl<'a, 'tcx> SpecializedDecoder<CrateNum> for DecodeContext<'a, 'tcx> {
|
||||
fn specialized_decode(&mut self) -> Result<CrateNum, Self::Error> {
|
||||
let cnum = CrateNum::from_u32(u32::decode(self)?);
|
||||
if cnum == LOCAL_CRATE {
|
||||
Ok(self.cdata.cnum)
|
||||
Ok(self.cdata().cnum)
|
||||
} 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 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 {
|
||||
// Currently macro expansion sometimes produces invalid Span values
|
||||
// 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)
|
||||
};
|
||||
|
||||
let imported_filemaps = self.cdata.imported_filemaps(&self.tcx.sess.codemap());
|
||||
let imported_filemaps = self.cdata().imported_filemaps(&tcx.sess.codemap());
|
||||
let filemap = {
|
||||
// Optimize for the case that most spans within a translated item
|
||||
// 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> {
|
||||
fn specialized_decode(&mut self) -> Result<&'tcx ty::Region, Self::Error> {
|
||||
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> {
|
||||
Ok(ty::ClosureSubsts {
|
||||
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> {
|
||||
fn specialized_decode(&mut self) -> Result<ty::AdtDef<'tcx>, Self::Error> {
|
||||
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> {
|
||||
let item = cdata.lookup_item(id);
|
||||
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> {
|
||||
let item = cdata.lookup_item(id);
|
||||
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> {
|
||||
let item = cdata.lookup_item(id);
|
||||
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);
|
||||
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);
|
||||
|
||||
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 = DecodeContext::new(tcx, cdata, id_range, mir_doc);
|
||||
let mut dcx = mir_doc.decoder();
|
||||
dcx.tcx = Some(tcx);
|
||||
dcx.cdata = Some(cdata);
|
||||
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> {
|
||||
let item_doc = cdata.lookup_item(id);
|
||||
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,
|
||||
@ -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> {
|
||||
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.
|
||||
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);
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
pub fn closure_kind(cdata: Cmd, closure_id: DefIndex) -> ty::ClosureKind {
|
||||
let closure_doc = cdata.lookup_item(closure_id);
|
||||
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>)
|
||||
@ -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 {
|
||||
match reader::maybe_get_doc(item_doc, tag_def_key) {
|
||||
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| {
|
||||
token::intern(name.as_str()).as_str()
|
||||
});
|
||||
|
@ -108,7 +108,7 @@ fn encode_def_id(ecx: &mut EncodeContext, id: DefId) {
|
||||
fn encode_def_key(ecx: &mut EncodeContext, key: DefKey) {
|
||||
let simple_key = def_key::simplify_def_key(key);
|
||||
ecx.start_tag(tag_def_key);
|
||||
simple_key.encode(&mut ecx.opaque());
|
||||
simple_key.encode(ecx);
|
||||
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) {
|
||||
let v = ecx.tcx.item_variances(ecx.tcx.map.local_def_id(id));
|
||||
ecx.start_tag(tag_item_variances);
|
||||
v.encode(&mut ecx.opaque());
|
||||
v.encode(ecx);
|
||||
ecx.end_tag();
|
||||
}
|
||||
|
||||
@ -761,7 +761,7 @@ impl<'a, 'b, 'tcx> ItemContentBuilder<'a, 'b, 'tcx> {
|
||||
attr));
|
||||
}
|
||||
self.start_tag(tag_items_data_item_repr);
|
||||
repr_attrs.encode(&mut self.opaque());
|
||||
repr_attrs.encode(self.ecx);
|
||||
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>) {
|
||||
stab_opt.map(|stab| {
|
||||
ecx.start_tag(tag_items_data_item_stability);
|
||||
stab.encode(&mut ecx.opaque()).unwrap();
|
||||
stab.encode(ecx).unwrap();
|
||||
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>) {
|
||||
depr_opt.map(|depr| {
|
||||
ecx.start_tag(tag_items_data_item_deprecation);
|
||||
depr.encode(&mut ecx.opaque()).unwrap();
|
||||
depr.encode(ecx).unwrap();
|
||||
ecx.end_tag();
|
||||
});
|
||||
}
|
||||
@ -1043,7 +1043,7 @@ impl<'a, 'b, 'tcx> ItemContentBuilder<'a, 'b, 'tcx> {
|
||||
{
|
||||
Some(&kind) => {
|
||||
self.start_tag(tag_impl_coerce_unsized_kind);
|
||||
kind.encode(&mut self.opaque());
|
||||
kind.encode(self.ecx);
|
||||
self.end_tag();
|
||||
}
|
||||
None => {}
|
||||
@ -1361,7 +1361,7 @@ impl<'a, 'b, 'tcx> ItemContentBuilder<'a, 'b, 'tcx> {
|
||||
self.end_tag();
|
||||
|
||||
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();
|
||||
|
||||
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]) {
|
||||
ecx.start_tag(tag_attributes);
|
||||
attrs.encode(&mut ecx.opaque()).unwrap();
|
||||
attrs.encode(ecx).unwrap();
|
||||
ecx.end_tag();
|
||||
}
|
||||
|
||||
@ -1538,7 +1538,7 @@ fn encode_codemap(ecx: &mut EncodeContext) {
|
||||
}
|
||||
|
||||
ecx.start_tag(tag_codemap_filemap);
|
||||
filemap.encode(&mut ecx.opaque()).unwrap();
|
||||
filemap.encode(ecx).unwrap();
|
||||
ecx.end_tag();
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,6 @@ use std::str;
|
||||
|
||||
use rustc_serialize as serialize;
|
||||
|
||||
use rbml::opaque;
|
||||
use rbml::Error;
|
||||
use rbml::Error::*;
|
||||
|
||||
@ -158,10 +157,6 @@ impl<'doc> Doc<'doc> {
|
||||
pub fn to_string(&self) -> String {
|
||||
self.as_str().to_string()
|
||||
}
|
||||
|
||||
pub fn opaque(&self) -> opaque::Decoder<'doc> {
|
||||
opaque::Decoder::new(self.data, self.start)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TaggedDoc<'a> {
|
||||
|
@ -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
|
||||
where F: FnOnce(&mut opaque::Encoder) -> EncodeResult
|
||||
{
|
||||
self.start_tag(EsOpaque as usize)?;
|
||||
f(&mut self.opaque())?;
|
||||
f(&mut opaque::Encoder::new(&mut self.writer))?;
|
||||
self.mark_stable_position();
|
||||
self.end_tag()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user