Skip to content

Commit 1da9d25

Browse files
borsEliseZeroTwo
authored andcommitted
Auto merge of rust-lang#119265 - Mark-Simulacrum:remove-cache, r=cjgillot
Remove metadata decoding DefPathHash cache My expectation is that this cache is largely useless. Decoding a DefPathHash from metadata is essentially a pair of memory loads - there's no heavyweight processing involved. Caching it behind a HashMap just adds extra cost and incurs hashing overheads for the indices. Based on rust-lang#119238.
2 parents 08cc634 + f098f34 commit 1da9d25

File tree

4 files changed

+49
-23
lines changed

4 files changed

+49
-23
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -3163,8 +3163,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31633163
return;
31643164
};
31653165
if self.can_eq(self.param_env, expected_ty, ty) {
3166+
let span = stmt
3167+
.span
3168+
.from_expansion()
3169+
.then(|| {
3170+
let mac_call = rustc_span::source_map::original_sp(stmt.span, block.span);
3171+
self.tcx.sess.source_map().mac_call_stmt_semi_span(mac_call)
3172+
})
3173+
.flatten()
3174+
.unwrap_or_else(|| stmt.span.with_lo(tail_expr.span.hi()));
31663175
err.span_suggestion_short(
3167-
stmt.span.with_lo(tail_expr.span.hi()),
3176+
span,
31683177
"remove this semicolon",
31693178
"",
31703179
Applicability::MachineApplicable,

compiler/rustc_metadata/src/rmeta/decoder.rs

+8-22
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ pub(crate) struct CrateMetadata {
8888
alloc_decoding_state: AllocDecodingState,
8989
/// Caches decoded `DefKey`s.
9090
def_key_cache: Lock<FxHashMap<DefIndex, DefKey>>,
91-
/// Caches decoded `DefPathHash`es.
92-
def_path_hash_cache: Lock<FxHashMap<DefIndex, DefPathHash>>,
9391

9492
// --- Other significant crate properties ---
9593
/// ID of this crate, from the current compilation session's point of view.
@@ -1485,27 +1483,16 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
14851483
DefPath::make(self.cnum, id, |parent| self.def_key(parent))
14861484
}
14871485

1488-
fn def_path_hash_unlocked(
1489-
self,
1490-
index: DefIndex,
1491-
def_path_hashes: &mut FxHashMap<DefIndex, DefPathHash>,
1492-
) -> DefPathHash {
1493-
*def_path_hashes.entry(index).or_insert_with(|| {
1494-
// This is a hack to workaround the fact that we can't easily encode/decode a Hash64
1495-
// into the FixedSizeEncoding, as Hash64 lacks a Default impl. A future refactor to
1496-
// relax the Default restriction will likely fix this.
1497-
let fingerprint = Fingerprint::new(
1498-
self.root.stable_crate_id.as_u64(),
1499-
self.root.tables.def_path_hashes.get(self, index),
1500-
);
1501-
DefPathHash::new(self.root.stable_crate_id, fingerprint.split().1)
1502-
})
1503-
}
1504-
15051486
#[inline]
15061487
fn def_path_hash(self, index: DefIndex) -> DefPathHash {
1507-
let mut def_path_hashes = self.def_path_hash_cache.lock();
1508-
self.def_path_hash_unlocked(index, &mut def_path_hashes)
1488+
// This is a hack to workaround the fact that we can't easily encode/decode a Hash64
1489+
// into the FixedSizeEncoding, as Hash64 lacks a Default impl. A future refactor to
1490+
// relax the Default restriction will likely fix this.
1491+
let fingerprint = Fingerprint::new(
1492+
self.root.stable_crate_id.as_u64(),
1493+
self.root.tables.def_path_hashes.get(self, index),
1494+
);
1495+
DefPathHash::new(self.root.stable_crate_id, fingerprint.split().1)
15091496
}
15101497

15111498
#[inline]
@@ -1832,7 +1819,6 @@ impl CrateMetadata {
18321819
extern_crate: Lock::new(None),
18331820
hygiene_context: Default::default(),
18341821
def_key_cache: Default::default(),
1835-
def_path_hash_cache: Default::default(),
18361822
};
18371823

18381824
// Need `CrateMetadataRef` to decode `DefId`s in simplified types.

tests/ui/typeck/issue-114251.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// compile-flags: -C debug-assertions
2+
3+
macro_rules! feedu8 {
4+
() => {
5+
0u8
6+
}
7+
}
8+
9+
fn main() {
10+
let kitty = {
11+
feedu8!();
12+
//~^ HELP: remove this semicolon
13+
};
14+
15+
let cat: u8 = kitty;
16+
//~^ ERROR: mismatched types
17+
}

tests/ui/typeck/issue-114251.stderr

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-114251.rs:15:19
3+
|
4+
LL | feedu8!();
5+
| - help: remove this semicolon
6+
...
7+
LL | let cat: u8 = kitty;
8+
| -- ^^^^^ expected `u8`, found `()`
9+
| |
10+
| expected due to this
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)