Skip to content

Commit 02fe61b

Browse files
committed
Auto merge of #92497 - bjorn3:remove_lazy_meta_min_size, r=eddyb
Remove LazyMeta::min_size It is extremely conservative and as such barely reduces the size of encoded Lazy distances, but does increase complexity.
2 parents 23ce5fc + 717d4b3 commit 02fe61b

File tree

4 files changed

+13
-32
lines changed

4 files changed

+13
-32
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -304,18 +304,17 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
304304
&mut self,
305305
meta: T::Meta,
306306
) -> Result<Lazy<T>, <Self as Decoder>::Error> {
307-
let min_size = T::min_size(meta);
308307
let distance = self.read_usize()?;
309308
let position = match self.lazy_state {
310309
LazyState::NoNode => bug!("read_lazy_with_meta: outside of a metadata node"),
311310
LazyState::NodeStart(start) => {
312311
let start = start.get();
313-
assert!(distance + min_size <= start);
314-
start - distance - min_size
312+
assert!(distance <= start);
313+
start - distance
315314
}
316-
LazyState::Previous(last_min_end) => last_min_end.get() + distance,
315+
LazyState::Previous(last_pos) => last_pos.get() + distance,
317316
};
318-
self.lazy_state = LazyState::Previous(NonZeroUsize::new(position + min_size).unwrap());
317+
self.lazy_state = LazyState::Previous(NonZeroUsize::new(position).unwrap());
319318
Ok(Lazy::from_position_and_meta(NonZeroUsize::new(position).unwrap(), meta))
320319
}
321320

compiler/rustc_metadata/src/rmeta/encoder.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -404,24 +404,24 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
404404
&mut self,
405405
lazy: Lazy<T>,
406406
) -> Result<(), <Self as Encoder>::Error> {
407-
let min_end = lazy.position.get() + T::min_size(lazy.meta);
407+
let pos = lazy.position.get();
408408
let distance = match self.lazy_state {
409409
LazyState::NoNode => bug!("emit_lazy_distance: outside of a metadata node"),
410410
LazyState::NodeStart(start) => {
411411
let start = start.get();
412-
assert!(min_end <= start);
413-
start - min_end
412+
assert!(pos <= start);
413+
start - pos
414414
}
415-
LazyState::Previous(last_min_end) => {
415+
LazyState::Previous(last_pos) => {
416416
assert!(
417-
last_min_end <= lazy.position,
417+
last_pos <= lazy.position,
418418
"make sure that the calls to `lazy*` \
419419
are in the same order as the metadata fields",
420420
);
421-
lazy.position.get() - last_min_end.get()
421+
lazy.position.get() - last_pos.get()
422422
}
423423
};
424-
self.lazy_state = LazyState::Previous(NonZeroUsize::new(min_end).unwrap());
424+
self.lazy_state = LazyState::Previous(NonZeroUsize::new(pos).unwrap());
425425
self.emit_usize(distance)
426426
}
427427

@@ -436,7 +436,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
436436
let meta = value.encode_contents_for_lazy(self);
437437
self.lazy_state = LazyState::NoNode;
438438

439-
assert!(pos.get() + <T>::min_size(meta) <= self.position());
439+
assert!(pos.get() <= self.position());
440440

441441
Lazy::from_position_and_meta(pos, meta)
442442
}

compiler/rustc_metadata/src/rmeta/mod.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,14 @@ pub const METADATA_HEADER: &[u8] = &[b'r', b'u', b's', b't', 0, 0, 0, METADATA_V
6363
/// e.g. for `Lazy<[T]>`, this is the length (count of `T` values).
6464
trait LazyMeta {
6565
type Meta: Copy + 'static;
66-
67-
/// Returns the minimum encoded size.
68-
// FIXME(eddyb) Give better estimates for certain types.
69-
fn min_size(meta: Self::Meta) -> usize;
7066
}
7167

7268
impl<T> LazyMeta for T {
7369
type Meta = ();
74-
75-
fn min_size(_: ()) -> usize {
76-
assert_ne!(std::mem::size_of::<T>(), 0);
77-
1
78-
}
7970
}
8071

8172
impl<T> LazyMeta for [T] {
8273
type Meta = usize;
83-
84-
fn min_size(len: usize) -> usize {
85-
len * T::min_size(())
86-
}
8774
}
8875

8976
/// A value of type T referred to by its absolute position
@@ -161,8 +148,7 @@ enum LazyState {
161148
NodeStart(NonZeroUsize),
162149

163150
/// Inside a metadata node, with a previous `Lazy`.
164-
/// The position is a conservative estimate of where that
165-
/// previous `Lazy` would end (see their comments).
151+
/// The position is where that previous `Lazy` would start.
166152
Previous(NonZeroUsize),
167153
}
168154

compiler/rustc_metadata/src/rmeta/table.rs

-4
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ where
183183
Option<T>: FixedSizeEncoding,
184184
{
185185
type Meta = usize;
186-
187-
fn min_size(len: usize) -> usize {
188-
len
189-
}
190186
}
191187

192188
impl<I: Idx, T> Lazy<Table<I, T>>

0 commit comments

Comments
 (0)