Skip to content

Commit e3e8b7f

Browse files
authored
Rollup merge of rust-lang#63750 - eddyb:lazy-seq, r=Zoxc
rustc_metadata: replace LazySeq<T> with Lazy<[T]>. Part of rust-lang#59953, split out for separate landing (see rust-lang#59953 (comment)). r? @Zoxc
2 parents 234614a + e7ceaa9 commit e3e8b7f

File tree

5 files changed

+301
-296
lines changed

5 files changed

+301
-296
lines changed

src/librustc_metadata/cstore.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ pub struct CrateMetadata {
6868
pub alloc_decoding_state: AllocDecodingState,
6969

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

7676
/// For each definition in this crate, we encode a key. When the
@@ -80,7 +80,7 @@ pub struct CrateMetadata {
8080
/// compilation support.
8181
pub def_path_table: Lrc<DefPathTable>,
8282

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

8585
pub dep_kind: Lock<DepKind>,
8686
pub source: CrateSource,

src/librustc_metadata/decoder.rs

+19-16
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,14 @@ impl<'a, 'tcx, T: Decodable> Lazy<T> {
134134
}
135135
}
136136

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

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

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

@@ -230,19 +234,18 @@ impl<'a, 'tcx> TyDecoder<'tcx> for DecodeContext<'a, 'tcx> {
230234

231235
impl<'a, 'tcx, T> SpecializedDecoder<Lazy<T>> for DecodeContext<'a, 'tcx> {
232236
fn specialized_decode(&mut self) -> Result<Lazy<T>, Self::Error> {
233-
Ok(Lazy::with_position(self.read_lazy_distance(Lazy::<T>::min_size())?))
237+
self.read_lazy_with_meta(())
234238
}
235239
}
236240

237-
impl<'a, 'tcx, T> SpecializedDecoder<LazySeq<T>> for DecodeContext<'a, 'tcx> {
238-
fn specialized_decode(&mut self) -> Result<LazySeq<T>, Self::Error> {
241+
impl<'a, 'tcx, T> SpecializedDecoder<Lazy<[T]>> for DecodeContext<'a, 'tcx> {
242+
fn specialized_decode(&mut self) -> Result<Lazy<[T]>, Self::Error> {
239243
let len = self.read_usize()?;
240-
let position = if len == 0 {
241-
0
244+
if len == 0 {
245+
Ok(Lazy::empty())
242246
} else {
243-
self.read_lazy_distance(LazySeq::<T>::min_size(len))?
244-
};
245-
Ok(LazySeq::with_position_and_length(position, len))
247+
self.read_lazy_with_meta(len)
248+
}
246249
}
247250
}
248251

@@ -378,7 +381,7 @@ impl<'tcx> MetadataBlob {
378381
}
379382

380383
pub fn get_rustc_version(&self) -> String {
381-
Lazy::with_position(METADATA_HEADER.len() + 4).decode(self)
384+
Lazy::<String>::from_position(METADATA_HEADER.len() + 4).decode(self)
382385
}
383386

384387
pub fn get_root(&self) -> CrateRoot<'tcx> {
@@ -387,7 +390,7 @@ impl<'tcx> MetadataBlob {
387390
let pos = (((slice[offset + 0] as u32) << 24) | ((slice[offset + 1] as u32) << 16) |
388391
((slice[offset + 2] as u32) << 8) |
389392
((slice[offset + 3] as u32) << 0)) as usize;
390-
Lazy::with_position(pos).decode(self)
393+
Lazy::<CrateRoot<'tcx>>::from_position(pos).decode(self)
391394
}
392395

393396
pub fn list_crate_metadata(&self,
@@ -1140,7 +1143,7 @@ impl<'a, 'tcx> CrateMetadata {
11401143
EntryKind::Fn(data) |
11411144
EntryKind::ForeignFn(data) => data.decode(self).arg_names,
11421145
EntryKind::Method(data) => data.decode(self).fn_data.arg_names,
1143-
_ => LazySeq::empty(),
1146+
_ => Lazy::empty(),
11441147
};
11451148
arg_names.decode(self).collect()
11461149
}

0 commit comments

Comments
 (0)