move rbml_w into the self struct
This commit is contained in:
parent
baccdc01ae
commit
d49e1a9191
2 changed files with 400 additions and 425 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -20,29 +20,33 @@ use std::ops::{Deref, DerefMut};
|
|||
|
||||
/// Builder that can encode new items, adding them into the index.
|
||||
/// Item encoding cannot be nested.
|
||||
pub struct IndexBuilder<'a, 'tcx: 'a> {
|
||||
pub struct IndexBuilder<'a, 'tcx: 'a, 'encoder: 'a> {
|
||||
items: IndexData,
|
||||
builder: ItemContentBuilder<'a, 'tcx>,
|
||||
builder: ItemContentBuilder<'a, 'tcx, 'encoder>,
|
||||
}
|
||||
|
||||
/// Builder that can encode the content of items, but can't start a
|
||||
/// new item itself. Most code is attached to here.
|
||||
pub struct ItemContentBuilder<'a, 'tcx: 'a> {
|
||||
pub struct ItemContentBuilder<'a, 'tcx: 'a, 'encoder: 'a> {
|
||||
xrefs: FnvHashMap<XRef<'tcx>, u32>, // sequentially-assigned
|
||||
ecx: &'a EncodeContext<'a, 'tcx>,
|
||||
pub ecx: &'a EncodeContext<'a, 'tcx>,
|
||||
pub rbml_w: &'a mut Encoder<'encoder>,
|
||||
}
|
||||
|
||||
/// "interned" entries referenced by id
|
||||
#[derive(PartialEq, Eq, Hash)]
|
||||
pub enum XRef<'tcx> { Predicate(ty::Predicate<'tcx>) }
|
||||
|
||||
impl<'a, 'tcx> IndexBuilder<'a, 'tcx> {
|
||||
pub fn new(ecx: &'a EncodeContext<'a, 'tcx>) -> Self {
|
||||
impl<'a, 'tcx, 'encoder> IndexBuilder<'a, 'tcx, 'encoder> {
|
||||
pub fn new(ecx: &'a EncodeContext<'a, 'tcx>,
|
||||
rbml_w: &'a mut Encoder<'encoder>)
|
||||
-> Self {
|
||||
IndexBuilder {
|
||||
items: IndexData::new(ecx.tcx.map.num_local_def_ids()),
|
||||
builder: ItemContentBuilder {
|
||||
ecx: ecx,
|
||||
xrefs: FnvHashMap(),
|
||||
rbml_w: rbml_w,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -53,15 +57,15 @@ impl<'a, 'tcx> IndexBuilder<'a, 'tcx> {
|
|||
///
|
||||
/// Returns a dep-graph task that you should keep live as long as
|
||||
/// the data for this item is being emitted.
|
||||
pub fn record<OP>(&mut self, id: DefId, rbml_w: &mut Encoder, op: OP)
|
||||
where OP: FnOnce(&mut ItemContentBuilder<'a, 'tcx>, &mut Encoder)
|
||||
pub fn record<OP>(&mut self, id: DefId, op: OP)
|
||||
where OP: FnOnce(&mut ItemContentBuilder<'a, 'tcx, 'encoder>)
|
||||
{
|
||||
let position = rbml_w.mark_stable_position();
|
||||
let position = self.rbml_w.mark_stable_position();
|
||||
self.items.record(id, position);
|
||||
let _task = self.ecx.tcx.dep_graph.in_task(DepNode::MetaData(id));
|
||||
rbml_w.start_tag(tag_items_data_item).unwrap();
|
||||
op(self, rbml_w);
|
||||
rbml_w.end_tag().unwrap();
|
||||
self.rbml_w.start_tag(tag_items_data_item).unwrap();
|
||||
op(self);
|
||||
self.rbml_w.end_tag().unwrap();
|
||||
}
|
||||
|
||||
pub fn into_fields(self) -> (IndexData, FnvHashMap<XRef<'tcx>, u32>) {
|
||||
|
|
@ -69,21 +73,21 @@ impl<'a, 'tcx> IndexBuilder<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Deref for IndexBuilder<'a, 'tcx> {
|
||||
type Target = ItemContentBuilder<'a, 'tcx>;
|
||||
impl<'a, 'tcx, 'encoder> Deref for IndexBuilder<'a, 'tcx, 'encoder> {
|
||||
type Target = ItemContentBuilder<'a, 'tcx, 'encoder>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.builder
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> DerefMut for IndexBuilder<'a, 'tcx> {
|
||||
impl<'a, 'tcx, 'encoder> DerefMut for IndexBuilder<'a, 'tcx, 'encoder> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.builder
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> ItemContentBuilder<'a, 'tcx> {
|
||||
impl<'a, 'tcx, 'encoder> ItemContentBuilder<'a, 'tcx, 'encoder> {
|
||||
pub fn ecx(&self) -> &'a EncodeContext<'a, 'tcx> {
|
||||
self.ecx
|
||||
}
|
||||
|
|
@ -93,3 +97,4 @@ impl<'a, 'tcx> ItemContentBuilder<'a, 'tcx> {
|
|||
*self.xrefs.entry(xref).or_insert(old_len)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue