rustc_metadata: Encode/decode DefPathHash
es without an Option
This commit is contained in:
parent
c60cc43985
commit
f4e2b954a1
5 changed files with 20 additions and 11 deletions
|
@ -1319,7 +1319,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||||
) -> DefPathHash {
|
) -> DefPathHash {
|
||||||
*def_path_hashes
|
*def_path_hashes
|
||||||
.entry(index)
|
.entry(index)
|
||||||
.or_insert_with(|| self.root.tables.def_path_hashes.get(self, index).unwrap())
|
.or_insert_with(|| self.root.tables.def_path_hashes.get(self, index))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -478,13 +478,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
let def_key = self.lazy(table.def_key(def_index));
|
let def_key = self.lazy(table.def_key(def_index));
|
||||||
let def_path_hash = table.def_path_hash(def_index);
|
let def_path_hash = table.def_path_hash(def_index);
|
||||||
self.tables.def_keys.set_some(def_index, def_key);
|
self.tables.def_keys.set_some(def_index, def_key);
|
||||||
self.tables.def_path_hashes.set_some(def_index, def_path_hash);
|
self.tables.def_path_hashes.set(def_index, def_path_hash);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (def_index, def_key, def_path_hash) in table.enumerated_keys_and_path_hashes() {
|
for (def_index, def_key, def_path_hash) in table.enumerated_keys_and_path_hashes() {
|
||||||
let def_key = self.lazy(def_key);
|
let def_key = self.lazy(def_key);
|
||||||
self.tables.def_keys.set_some(def_index, def_key);
|
self.tables.def_keys.set_some(def_index, def_key);
|
||||||
self.tables.def_path_hashes.set_some(def_index, *def_path_hash);
|
self.tables.def_path_hashes.set(def_index, *def_path_hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -350,6 +350,7 @@ define_tables! {
|
||||||
is_macro_rules: Table<DefIndex, bool>,
|
is_macro_rules: Table<DefIndex, bool>,
|
||||||
is_type_alias_impl_trait: Table<DefIndex, bool>,
|
is_type_alias_impl_trait: Table<DefIndex, bool>,
|
||||||
attr_flags: Table<DefIndex, AttrFlags>,
|
attr_flags: Table<DefIndex, AttrFlags>,
|
||||||
|
def_path_hashes: Table<DefIndex, DefPathHash>,
|
||||||
explicit_item_bounds: Table<DefIndex, LazyArray<(ty::Predicate<'static>, Span)>>,
|
explicit_item_bounds: Table<DefIndex, LazyArray<(ty::Predicate<'static>, Span)>>,
|
||||||
inferred_outlives_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
|
inferred_outlives_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
|
||||||
inherent_impls: Table<DefIndex, LazyArray<DefIndex>>,
|
inherent_impls: Table<DefIndex, LazyArray<DefIndex>>,
|
||||||
|
@ -403,7 +404,6 @@ define_tables! {
|
||||||
// `DefPathTable` up front, since we may only ever use a few
|
// `DefPathTable` up front, since we may only ever use a few
|
||||||
// definitions from any given crate.
|
// definitions from any given crate.
|
||||||
def_keys: Table<DefIndex, LazyValue<DefKey>>,
|
def_keys: Table<DefIndex, LazyValue<DefKey>>,
|
||||||
def_path_hashes: Table<DefIndex, DefPathHash>,
|
|
||||||
proc_macro_quoted_spans: Table<usize, LazyValue<Span>>,
|
proc_macro_quoted_spans: Table<usize, LazyValue<Span>>,
|
||||||
generator_diagnostic_data: Table<DefIndex, LazyValue<GeneratorDiagnosticData<'static>>>,
|
generator_diagnostic_data: Table<DefIndex, LazyValue<GeneratorDiagnosticData<'static>>>,
|
||||||
variant_data: Table<DefIndex, LazyValue<VariantData>>,
|
variant_data: Table<DefIndex, LazyValue<VariantData>>,
|
||||||
|
|
|
@ -44,6 +44,12 @@ impl<T> IsDefault for LazyArray<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl IsDefault for DefPathHash {
|
||||||
|
fn is_default(&self) -> bool {
|
||||||
|
self.0 == Fingerprint::ZERO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Helper trait, for encoding to, and decoding from, a fixed number of bytes.
|
/// Helper trait, for encoding to, and decoding from, a fixed number of bytes.
|
||||||
/// Used mainly for Lazy positions and lengths.
|
/// Used mainly for Lazy positions and lengths.
|
||||||
/// Unchecked invariant: `Self::default()` should encode as `[0; BYTE_LEN]`,
|
/// Unchecked invariant: `Self::default()` should encode as `[0; BYTE_LEN]`,
|
||||||
|
@ -191,21 +197,18 @@ fixed_size_enum! {
|
||||||
}
|
}
|
||||||
|
|
||||||
// We directly encode `DefPathHash` because a `LazyValue` would incur a 25% cost.
|
// We directly encode `DefPathHash` because a `LazyValue` would incur a 25% cost.
|
||||||
impl FixedSizeEncoding for Option<DefPathHash> {
|
impl FixedSizeEncoding for DefPathHash {
|
||||||
type ByteArray = [u8; 16];
|
type ByteArray = [u8; 16];
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_bytes(b: &[u8; 16]) -> Self {
|
fn from_bytes(b: &[u8; 16]) -> Self {
|
||||||
// NOTE: There's a collision between `None` and `Some(0)`.
|
DefPathHash(Fingerprint::from_le_bytes(*b))
|
||||||
Some(DefPathHash(Fingerprint::from_le_bytes(*b)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn write_to_bytes(self, b: &mut [u8; 16]) {
|
fn write_to_bytes(self, b: &mut [u8; 16]) {
|
||||||
match self {
|
debug_assert!(!self.is_default());
|
||||||
None => unreachable!(),
|
*b = self.0.to_le_bytes();
|
||||||
Some(DefPathHash(fingerprint)) => *b = fingerprint.to_le_bytes(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,6 +119,12 @@ impl DefPathHash {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for DefPathHash {
|
||||||
|
fn default() -> Self {
|
||||||
|
DefPathHash(Fingerprint::ZERO)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Borrow<Fingerprint> for DefPathHash {
|
impl Borrow<Fingerprint> for DefPathHash {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn borrow(&self) -> &Fingerprint {
|
fn borrow(&self) -> &Fingerprint {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue