-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Encode trait impls using nested Tables #74807
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,24 +93,34 @@ impl<T: Encodable> FixedSizeEncoding for Option<Lazy<T>> { | |
} | ||
} | ||
|
||
impl<T: Encodable> FixedSizeEncoding for Option<Lazy<[T]>> { | ||
fixed_size_encoding_byte_len_and_defaults!(u32::BYTE_LEN * 2); | ||
macro_rules! meta_body { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
-impl<T: Encodable> FixedSizeEncoding for Option<Lazy<[T]>> {
+impl<T: ?Sized + Encodable + LazyMeta<Meta = usize>> FixedSizeEncoding for Option<Lazy<T>> { Although perhaps that is still considered overlapping, I'm not sure of the coherence rules around this. |
||
($T:ident) => { | ||
fixed_size_encoding_byte_len_and_defaults!(u32::BYTE_LEN * 2); | ||
|
||
fn from_bytes(b: &[u8]) -> Self { | ||
Some(Lazy::from_position_and_meta( | ||
<Option<Lazy<$T>>>::from_bytes(b)?.position, | ||
u32::from_bytes(&b[u32::BYTE_LEN..]) as usize, | ||
)) | ||
} | ||
|
||
fn from_bytes(b: &[u8]) -> Self { | ||
Some(Lazy::from_position_and_meta( | ||
<Option<Lazy<T>>>::from_bytes(b)?.position, | ||
u32::from_bytes(&b[u32::BYTE_LEN..]) as usize, | ||
)) | ||
} | ||
fn write_to_bytes(self, b: &mut [u8]) { | ||
self.map(|lazy| Lazy::<$T>::from_position(lazy.position)).write_to_bytes(b); | ||
|
||
fn write_to_bytes(self, b: &mut [u8]) { | ||
self.map(|lazy| Lazy::<T>::from_position(lazy.position)).write_to_bytes(b); | ||
let len = self.map_or(0, |lazy| lazy.meta); | ||
let len: u32 = len.try_into().unwrap(); | ||
|
||
len.write_to_bytes(&mut b[u32::BYTE_LEN..]); | ||
} | ||
}; | ||
} | ||
|
||
let len = self.map_or(0, |lazy| lazy.meta); | ||
let len: u32 = len.try_into().unwrap(); | ||
impl<I: Idx, T: Encodable> FixedSizeEncoding for Option<Lazy<Table<I, Lazy<[T], usize>>, usize>> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
meta_body!(T); | ||
} | ||
|
||
len.write_to_bytes(&mut b[u32::BYTE_LEN..]); | ||
} | ||
impl<T: Encodable> FixedSizeEncoding for Option<Lazy<[T]>> { | ||
meta_body!(T); | ||
} | ||
|
||
/// Random-access table (i.e. offering constant-time `get`/`set`), similar to | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have sparse tables yet (I've been meaning to do that but haven't gotten around to it) so you should look at how much this change increases the size of
libcore-*.rlib
andlibstd-*.rlib
etc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could maybe make this cheaper by removing the inner table and keeping a cache that's keyed on the
u32
with a value ofFxHashMap<DefIndex, Lazy<[DefIndex]>>
for every crate.Also, the
u32
, should that beCrateNum
? That would be clearer and as aTable
it shouldn't cause problems I don't think.