Skip to content

Commit

Permalink
rustc_metadata: use decoder::Metadata instead of &[u8] for Lazy<Table…
Browse files Browse the repository at this point in the history
…<T>>::get.
  • Loading branch information
eddyb committed Oct 15, 2019
1 parent cef4950 commit 972b93b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/librustc_metadata/decoder.rs
Expand Up @@ -132,8 +132,8 @@ impl<'a, 'tcx> Metadata<'a, 'tcx> for (&'a CrateMetadata, TyCtxt<'tcx>) {
}

impl<'a, 'tcx, T: Encodable + Decodable> Lazy<T> {
crate fn decode<M: Metadata<'a, 'tcx>>(self, meta: M) -> T {
let mut dcx = meta.decoder(self.position.get());
crate fn decode<M: Metadata<'a, 'tcx>>(self, metadata: M) -> T {
let mut dcx = metadata.decoder(self.position.get());
dcx.lazy_state = LazyState::NodeStart(self.position);
T::decode(&mut dcx).unwrap()
}
Expand All @@ -142,9 +142,9 @@ impl<'a, 'tcx, T: Encodable + Decodable> Lazy<T> {
impl<'a: 'x, 'tcx: 'x, 'x, T: Encodable + Decodable> Lazy<[T]> {
crate fn decode<M: Metadata<'a, 'tcx>>(
self,
meta: M,
metadata: M,
) -> impl ExactSizeIterator<Item = T> + Captures<'a> + Captures<'tcx> + 'x {
let mut dcx = meta.decoder(self.position.get());
let mut dcx = metadata.decoder(self.position.get());
dcx.lazy_state = LazyState::NodeStart(self.position);
(0..self.meta).map(move |_| T::decode(&mut dcx).unwrap())
}
Expand Down Expand Up @@ -481,7 +481,7 @@ impl<'a, 'tcx> CrateMetadata {
}

fn maybe_entry(&self, item_id: DefIndex) -> Option<Lazy<Entry<'tcx>>> {
self.root.per_def.entry.get(self.blob.raw_bytes(), item_id)
self.root.per_def.entry.get(self, item_id)
}

fn entry(&self, item_id: DefIndex) -> Entry<'tcx> {
Expand Down
18 changes: 14 additions & 4 deletions src/librustc_metadata/table.rs
@@ -1,3 +1,4 @@
use crate::decoder::Metadata;
use crate::schema::*;

use rustc::hir::def_id::{DefId, DefIndex};
Expand Down Expand Up @@ -158,10 +159,15 @@ impl<T> LazyMeta for Table<T> where Option<T>: FixedSizeEncoding {
impl<T> Lazy<Table<T>> where Option<T>: FixedSizeEncoding {
/// Given the metadata, extract out the value at a particular index (if any).
#[inline(never)]
crate fn get(&self, bytes: &[u8], i: usize) -> Option<T> {
crate fn get<'a, 'tcx, M: Metadata<'a, 'tcx>>(
&self,
metadata: M,
i: usize,
) -> Option<T> {
debug!("Table::lookup: index={:?} len={:?}", i, self.meta);

<Option<T>>::read_from_bytes_at(&bytes[self.position.get()..][..self.meta], i)
let bytes = &metadata.raw_bytes()[self.position.get()..][..self.meta];
<Option<T>>::read_from_bytes_at(bytes, i)
}
}

Expand Down Expand Up @@ -201,7 +207,11 @@ impl<T> Lazy<PerDefTable<T>> where Option<T>: FixedSizeEncoding {

/// Given the metadata, extract out the value at a particular DefIndex (if any).
#[inline(never)]
crate fn get(&self, bytes: &[u8], def_index: DefIndex) -> Option<T> {
self.as_table().get(bytes, def_index.index())
crate fn get<'a, 'tcx, M: Metadata<'a, 'tcx>>(
&self,
metadata: M,
def_index: DefIndex,
) -> Option<T> {
self.as_table().get(metadata, def_index.index())
}
}

0 comments on commit 972b93b

Please sign in to comment.