Skip to content

Commit 385fa9d

Browse files
committed
Auto merge of #123097 - oli-obk:perf_experiment, r=petrochenkov
Try using a `dyn Debug` trait object instead of a closure These closures were introduced in #93098 let's see if we can't use fmt::Arguments instead cc `@Aaron1011`
2 parents a4b11c8 + 0dca136 commit 385fa9d

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

compiler/rustc_hir/src/definitions.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -380,14 +380,19 @@ impl Definitions {
380380
pub fn local_def_path_hash_to_def_id(
381381
&self,
382382
hash: DefPathHash,
383-
err: &mut dyn FnMut() -> !,
383+
err_msg: &dyn std::fmt::Debug,
384384
) -> LocalDefId {
385385
debug_assert!(hash.stable_crate_id() == self.table.stable_crate_id);
386+
#[cold]
387+
#[inline(never)]
388+
fn err(err_msg: &dyn std::fmt::Debug) -> ! {
389+
panic!("{err_msg:?}")
390+
}
386391
self.table
387392
.def_path_hash_to_index
388393
.get(&hash.local_hash())
389394
.map(|local_def_index| LocalDefId { local_def_index })
390-
.unwrap_or_else(|| err())
395+
.unwrap_or_else(|| err(err_msg))
391396
}
392397

393398
pub fn def_path_hash_to_def_index_map(&self) -> &DefPathHashMap {

compiler/rustc_middle/src/dep_graph/dep_node.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,10 @@ impl DepNodeExt for DepNode {
194194
/// has been removed.
195195
fn extract_def_id(&self, tcx: TyCtxt<'_>) -> Option<DefId> {
196196
if tcx.fingerprint_style(self.kind) == FingerprintStyle::DefPathHash {
197-
Some(tcx.def_path_hash_to_def_id(DefPathHash(self.hash.into()), &mut || {
198-
panic!("Failed to extract DefId: {:?} {}", self.kind, self.hash)
199-
}))
197+
Some(tcx.def_path_hash_to_def_id(
198+
DefPathHash(self.hash.into()),
199+
&("Failed to extract DefId", self.kind, self.hash),
200+
))
200201
} else {
201202
None
202203
}
@@ -390,9 +391,10 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for HirId {
390391
let (local_hash, local_id) = Fingerprint::from(dep_node.hash).split();
391392
let def_path_hash = DefPathHash::new(tcx.stable_crate_id(LOCAL_CRATE), local_hash);
392393
let def_id = tcx
393-
.def_path_hash_to_def_id(def_path_hash, &mut || {
394-
panic!("Failed to extract HirId: {:?} {}", dep_node.kind, dep_node.hash)
395-
})
394+
.def_path_hash_to_def_id(
395+
def_path_hash,
396+
&("Failed to extract HirId", dep_node.kind, dep_node.hash),
397+
)
396398
.expect_local();
397399
let local_id = local_id
398400
.as_u64()

compiler/rustc_middle/src/query/on_disk_cache.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -737,9 +737,10 @@ impl<'a, 'tcx> SpanDecoder for CacheDecoder<'a, 'tcx> {
737737
// If we get to this point, then all of the query inputs were green,
738738
// which means that the definition with this hash is guaranteed to
739739
// still exist in the current compilation session.
740-
self.tcx.def_path_hash_to_def_id(def_path_hash, &mut || {
741-
panic!("Failed to convert DefPathHash {def_path_hash:?}")
742-
})
740+
self.tcx.def_path_hash_to_def_id(
741+
def_path_hash,
742+
&("Failed to convert DefPathHash", def_path_hash),
743+
)
743744
}
744745

745746
fn decode_attr_id(&mut self) -> rustc_span::AttrId {

compiler/rustc_middle/src/ty/context.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -1121,15 +1121,23 @@ impl<'tcx> TyCtxt<'tcx> {
11211121
/// Converts a `DefPathHash` to its corresponding `DefId` in the current compilation
11221122
/// session, if it still exists. This is used during incremental compilation to
11231123
/// turn a deserialized `DefPathHash` into its current `DefId`.
1124-
pub fn def_path_hash_to_def_id(self, hash: DefPathHash, err: &mut dyn FnMut() -> !) -> DefId {
1124+
pub fn def_path_hash_to_def_id(
1125+
self,
1126+
hash: DefPathHash,
1127+
err_msg: &dyn std::fmt::Debug,
1128+
) -> DefId {
11251129
debug!("def_path_hash_to_def_id({:?})", hash);
11261130

11271131
let stable_crate_id = hash.stable_crate_id();
11281132

11291133
// If this is a DefPathHash from the local crate, we can look up the
11301134
// DefId in the tcx's `Definitions`.
11311135
if stable_crate_id == self.stable_crate_id(LOCAL_CRATE) {
1132-
self.untracked.definitions.read().local_def_path_hash_to_def_id(hash, err).to_def_id()
1136+
self.untracked
1137+
.definitions
1138+
.read()
1139+
.local_def_path_hash_to_def_id(hash, err_msg)
1140+
.to_def_id()
11331141
} else {
11341142
// If this is a DefPathHash from an upstream crate, let the CrateStore map
11351143
// it to a DefId.

0 commit comments

Comments
 (0)