Skip to content

Commit 66c8763

Browse files
committed
rustc_metadata: replace LazySeq<T> with Lazy<[T]>.
1 parent 6ae65dd commit 66c8763

File tree

5 files changed

+298
-291
lines changed

5 files changed

+298
-291
lines changed

src/librustc_metadata/cstore.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ pub struct CrateMetadata {
6565
pub alloc_decoding_state: AllocDecodingState,
6666

6767
// NOTE(eddyb) we pass `'static` to a `'tcx` parameter because this
68-
// lifetime is only used behind `Lazy` / `LazySeq`, and therefore
69-
// acts like an universal (`for<'tcx>`), that is paired up with
70-
// whichever `TyCtxt` is being used to decode those values.
68+
// lifetime is only used behind `Lazy`, and therefore acts like an
69+
// universal (`for<'tcx>`), that is paired up with whichever `TyCtxt`
70+
// is being used to decode those values.
7171
pub root: schema::CrateRoot<'static>,
7272

7373
/// For each public item in this crate, we encode a key. When the
@@ -77,7 +77,7 @@ pub struct CrateMetadata {
7777
/// compilation support.
7878
pub def_path_table: Lrc<DefPathTable>,
7979

80-
pub trait_impls: FxHashMap<(u32, DefIndex), schema::LazySeq<DefIndex>>,
80+
pub trait_impls: FxHashMap<(u32, DefIndex), schema::Lazy<[DefIndex]>>,
8181

8282
pub dep_kind: Lock<DepKind>,
8383
pub source: CrateSource,

src/librustc_metadata/decoder.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ impl<'a, 'tcx: 'a, T: Decodable> Lazy<T> {
135135
}
136136
}
137137

138-
impl<'a, 'tcx: 'a, T: Decodable> LazySeq<T> {
138+
impl<'a, 'tcx: 'a, T: Decodable> Lazy<[T]> {
139139
pub fn decode<M: Metadata<'a, 'tcx>>(
140140
self,
141141
meta: M,
142142
) -> impl Iterator<Item = T> + Captures<'tcx> + 'a {
143143
let mut dcx = meta.decoder(self.position);
144144
dcx.lazy_state = LazyState::NodeStart(self.position);
145-
(0..self.len).map(move |_| T::decode(&mut dcx).unwrap())
145+
(0..self.meta).map(move |_| T::decode(&mut dcx).unwrap())
146146
}
147147
}
148148

@@ -155,18 +155,22 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
155155
self.cdata.expect("missing CrateMetadata in DecodeContext")
156156
}
157157

158-
fn read_lazy_distance(&mut self, min_size: usize) -> Result<usize, <Self as Decoder>::Error> {
158+
fn read_lazy_with_meta<T: ?Sized + LazyMeta>(
159+
&mut self,
160+
meta: T::Meta,
161+
) -> Result<Lazy<T>, <Self as Decoder>::Error> {
162+
let min_size = T::min_size(meta);
159163
let distance = self.read_usize()?;
160164
let position = match self.lazy_state {
161-
LazyState::NoNode => bug!("read_lazy_distance: outside of a metadata node"),
165+
LazyState::NoNode => bug!("read_lazy_with_meta: outside of a metadata node"),
162166
LazyState::NodeStart(start) => {
163167
assert!(distance + min_size <= start);
164168
start - distance - min_size
165169
}
166170
LazyState::Previous(last_min_end) => last_min_end + distance,
167171
};
168172
self.lazy_state = LazyState::Previous(position + min_size);
169-
Ok(position)
173+
Ok(Lazy::from_position_and_meta(position, meta))
170174
}
171175
}
172176

@@ -232,19 +236,18 @@ impl<'a, 'tcx: 'a> TyDecoder<'a, 'tcx> for DecodeContext<'a, 'tcx> {
232236

233237
impl<'a, 'tcx, T> SpecializedDecoder<Lazy<T>> for DecodeContext<'a, 'tcx> {
234238
fn specialized_decode(&mut self) -> Result<Lazy<T>, Self::Error> {
235-
Ok(Lazy::with_position(self.read_lazy_distance(Lazy::<T>::min_size())?))
239+
self.read_lazy_with_meta(())
236240
}
237241
}
238242

239-
impl<'a, 'tcx, T> SpecializedDecoder<LazySeq<T>> for DecodeContext<'a, 'tcx> {
240-
fn specialized_decode(&mut self) -> Result<LazySeq<T>, Self::Error> {
243+
impl<'a, 'tcx, T> SpecializedDecoder<Lazy<[T]>> for DecodeContext<'a, 'tcx> {
244+
fn specialized_decode(&mut self) -> Result<Lazy<[T]>, Self::Error> {
241245
let len = self.read_usize()?;
242-
let position = if len == 0 {
243-
0
246+
if len == 0 {
247+
Ok(Lazy::empty())
244248
} else {
245-
self.read_lazy_distance(LazySeq::<T>::min_size(len))?
246-
};
247-
Ok(LazySeq::with_position_and_length(position, len))
249+
self.read_lazy_with_meta(len)
250+
}
248251
}
249252
}
250253

@@ -372,7 +375,7 @@ impl<'tcx> MetadataBlob {
372375
}
373376

374377
pub fn get_rustc_version(&self) -> String {
375-
Lazy::with_position(METADATA_HEADER.len() + 4).decode(self)
378+
Lazy::<String>::from_position(METADATA_HEADER.len() + 4).decode(self)
376379
}
377380

378381
pub fn get_root(&self) -> CrateRoot<'tcx> {
@@ -381,7 +384,7 @@ impl<'tcx> MetadataBlob {
381384
let pos = (((slice[offset + 0] as u32) << 24) | ((slice[offset + 1] as u32) << 16) |
382385
((slice[offset + 2] as u32) << 8) |
383386
((slice[offset + 3] as u32) << 0)) as usize;
384-
Lazy::with_position(pos).decode(self)
387+
Lazy::<CrateRoot<'tcx>>::from_position(pos).decode(self)
385388
}
386389

387390
pub fn list_crate_metadata(&self,
@@ -1109,7 +1112,7 @@ impl<'a, 'tcx> CrateMetadata {
11091112
EntryKind::Fn(data) |
11101113
EntryKind::ForeignFn(data) => data.decode(self).arg_names,
11111114
EntryKind::Method(data) => data.decode(self).fn_data.arg_names,
1112-
_ => LazySeq::empty(),
1115+
_ => Lazy::empty(),
11131116
};
11141117
arg_names.decode(self).collect()
11151118
}

0 commit comments

Comments
 (0)