Skip to content

Commit ab47007

Browse files
committed
Auto merge of #123097 - oli-obk:perf_experiment, r=<try>
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 37f9798 + cf38050 commit ab47007

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

compiler/rustc_hir/src/definitions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -380,14 +380,14 @@ 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);
386386
self.table
387387
.def_path_hash_to_index
388388
.get(&hash.local_hash())
389389
.map(|local_def_index| LocalDefId { local_def_index })
390-
.unwrap_or_else(|| err())
390+
.unwrap_or_else(|| panic!("{err_msg:?}"))
391391
}
392392

393393
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
@@ -1063,15 +1063,23 @@ impl<'tcx> TyCtxt<'tcx> {
10631063
/// Converts a `DefPathHash` to its corresponding `DefId` in the current compilation
10641064
/// session, if it still exists. This is used during incremental compilation to
10651065
/// turn a deserialized `DefPathHash` into its current `DefId`.
1066-
pub fn def_path_hash_to_def_id(self, hash: DefPathHash, err: &mut dyn FnMut() -> !) -> DefId {
1066+
pub fn def_path_hash_to_def_id(
1067+
self,
1068+
hash: DefPathHash,
1069+
err_msg: &dyn std::fmt::Debug,
1070+
) -> DefId {
10671071
debug!("def_path_hash_to_def_id({:?})", hash);
10681072

10691073
let stable_crate_id = hash.stable_crate_id();
10701074

10711075
// If this is a DefPathHash from the local crate, we can look up the
10721076
// DefId in the tcx's `Definitions`.
10731077
if stable_crate_id == self.stable_crate_id(LOCAL_CRATE) {
1074-
self.untracked.definitions.read().local_def_path_hash_to_def_id(hash, err).to_def_id()
1078+
self.untracked
1079+
.definitions
1080+
.read()
1081+
.local_def_path_hash_to_def_id(hash, err_msg)
1082+
.to_def_id()
10751083
} else {
10761084
// If this is a DefPathHash from an upstream crate, let the CrateStore map
10771085
// it to a DefId.

0 commit comments

Comments
 (0)