Skip to content

Commit 717d4b3

Browse files
committed
Remove LazyMeta::min_size
It is extremely conservative and as such barely reduces the size of encoded Lazy distances, but does increase complexity.
1 parent 03360be commit 717d4b3

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
@@ -62,27 +62,14 @@ pub const METADATA_HEADER: &[u8] = &[b'r', b'u', b's', b't', 0, 0, 0, METADATA_V
6262
/// e.g. for `Lazy<[T]>`, this is the length (count of `T` values).
6363
trait LazyMeta {
6464
type Meta: Copy + 'static;
65-
66-
/// Returns the minimum encoded size.
67-
// FIXME(eddyb) Give better estimates for certain types.
68-
fn min_size(meta: Self::Meta) -> usize;
6965
}
7066

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

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

8875
/// A value of type T referred to by its absolute position
@@ -160,8 +147,7 @@ enum LazyState {
160147
NodeStart(NonZeroUsize),
161148

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

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)