We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
DefPathHash
Option
1 parent c60cc43 commit f4e2b95Copy full SHA for f4e2b95
compiler/rustc_metadata/src/rmeta/decoder.rs
@@ -1319,7 +1319,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1319
) -> DefPathHash {
1320
*def_path_hashes
1321
.entry(index)
1322
- .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))
1323
}
1324
1325
#[inline]
compiler/rustc_metadata/src/rmeta/encoder.rs
@@ -478,13 +478,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
478
let def_key = self.lazy(table.def_key(def_index));
479
let def_path_hash = table.def_path_hash(def_index);
480
self.tables.def_keys.set_some(def_index, def_key);
481
- self.tables.def_path_hashes.set_some(def_index, def_path_hash);
+ self.tables.def_path_hashes.set(def_index, def_path_hash);
482
483
} else {
484
for (def_index, def_key, def_path_hash) in table.enumerated_keys_and_path_hashes() {
485
let def_key = self.lazy(def_key);
486
487
- self.tables.def_path_hashes.set_some(def_index, *def_path_hash);
+ self.tables.def_path_hashes.set(def_index, *def_path_hash);
488
489
490
compiler/rustc_metadata/src/rmeta/mod.rs
@@ -350,6 +350,7 @@ define_tables! {
350
is_macro_rules: Table<DefIndex, bool>,
351
is_type_alias_impl_trait: Table<DefIndex, bool>,
352
attr_flags: Table<DefIndex, AttrFlags>,
353
+ def_path_hashes: Table<DefIndex, DefPathHash>,
354
explicit_item_bounds: Table<DefIndex, LazyArray<(ty::Predicate<'static>, Span)>>,
355
inferred_outlives_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
356
inherent_impls: Table<DefIndex, LazyArray<DefIndex>>,
@@ -403,7 +404,6 @@ define_tables! {
403
404
// `DefPathTable` up front, since we may only ever use a few
405
// definitions from any given crate.
406
def_keys: Table<DefIndex, LazyValue<DefKey>>,
- def_path_hashes: Table<DefIndex, DefPathHash>,
407
proc_macro_quoted_spans: Table<usize, LazyValue<Span>>,
408
generator_diagnostic_data: Table<DefIndex, LazyValue<GeneratorDiagnosticData<'static>>>,
409
variant_data: Table<DefIndex, LazyValue<VariantData>>,
compiler/rustc_metadata/src/rmeta/table.rs
@@ -44,6 +44,12 @@ impl<T> IsDefault for LazyArray<T> {
44
45
46
47
+impl IsDefault for DefPathHash {
48
+ fn is_default(&self) -> bool {
49
+ self.0 == Fingerprint::ZERO
50
+ }
51
+}
52
+
53
/// Helper trait, for encoding to, and decoding from, a fixed number of bytes.
54
/// Used mainly for Lazy positions and lengths.
55
/// Unchecked invariant: `Self::default()` should encode as `[0; BYTE_LEN]`,
@@ -191,21 +197,18 @@ fixed_size_enum! {
191
197
192
198
193
199
// We directly encode `DefPathHash` because a `LazyValue` would incur a 25% cost.
194
-impl FixedSizeEncoding for Option<DefPathHash> {
200
+impl FixedSizeEncoding for DefPathHash {
195
201
type ByteArray = [u8; 16];
196
202
203
204
fn from_bytes(b: &[u8; 16]) -> Self {
- // NOTE: There's a collision between `None` and `Some(0)`.
- Some(DefPathHash(Fingerprint::from_le_bytes(*b)))
205
+ DefPathHash(Fingerprint::from_le_bytes(*b))
206
207
208
209
fn write_to_bytes(self, b: &mut [u8; 16]) {
- match self {
- None => unreachable!(),
- Some(DefPathHash(fingerprint)) => *b = fingerprint.to_le_bytes(),
- }
210
+ debug_assert!(!self.is_default());
211
+ *b = self.0.to_le_bytes();
212
213
214
compiler/rustc_span/src/def_id.rs
@@ -119,6 +119,12 @@ impl DefPathHash {
119
120
121
122
+impl Default for DefPathHash {
123
+ fn default() -> Self {
124
+ DefPathHash(Fingerprint::ZERO)
125
126
127
128
impl Borrow<Fingerprint> for DefPathHash {
129
130
fn borrow(&self) -> &Fingerprint {
0 commit comments