Skip to content

Commit 01a8b5f

Browse files
committed
Auto merge of #69290 - wesleywiser:speed_up_ctfe_stress_4, r=RalfJung
Check `RUSTC_CTFE_BACKTRACE` much less by generating fewer errors Before this change, `get_size_and_align()` calls `get_fn_alloc()` *a lot* in CTFE heavy code. This previously returned an `Error` which would check if `RUSTC_CTFE_BACKTRACE` was set on construction. Doing this turned out to be a performance hotspot as @nnethercote discovered in #68792. This is an alternate take on that PR which resolves the performance issue by generating *many* fewer errors. Previously, `ctfe-stress-4` would generate over 5,000,000 errors each of which would check for the presence of the environment variable. With these changes, that number is reduced to 30. r? @RalfJung
2 parents 2851e59 + 9f3bc82 commit 01a8b5f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/librustc_mir/interpret/memory.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
560560

561561
// # Function pointers
562562
// (both global from `alloc_map` and local from `extra_fn_ptr_map`)
563-
if let Ok(_) = self.get_fn_alloc(id) {
563+
if let Some(_) = self.get_fn_alloc(id) {
564564
return if let AllocCheck::Dereferenceable = liveness {
565565
// The caller requested no function pointers.
566566
throw_unsup!(DerefFunctionPointer)
@@ -602,14 +602,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
602602
}
603603
}
604604

605-
fn get_fn_alloc(&self, id: AllocId) -> InterpResult<'tcx, FnVal<'tcx, M::ExtraFnVal>> {
605+
fn get_fn_alloc(&self, id: AllocId) -> Option<FnVal<'tcx, M::ExtraFnVal>> {
606606
trace!("reading fn ptr: {}", id);
607607
if let Some(extra) = self.extra_fn_ptr_map.get(&id) {
608-
Ok(FnVal::Other(*extra))
608+
Some(FnVal::Other(*extra))
609609
} else {
610610
match self.tcx.alloc_map.lock().get(id) {
611-
Some(GlobalAlloc::Function(instance)) => Ok(FnVal::Instance(instance)),
612-
_ => throw_unsup!(ExecuteMemory),
611+
Some(GlobalAlloc::Function(instance)) => Some(FnVal::Instance(instance)),
612+
_ => None,
613613
}
614614
}
615615
}
@@ -622,7 +622,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
622622
if ptr.offset.bytes() != 0 {
623623
throw_unsup!(InvalidFunctionPointer)
624624
}
625-
self.get_fn_alloc(ptr.alloc_id)
625+
self.get_fn_alloc(ptr.alloc_id).ok_or_else(|| err_unsup!(ExecuteMemory).into())
626626
}
627627

628628
pub fn mark_immutable(&mut self, id: AllocId) -> InterpResult<'tcx> {

0 commit comments

Comments
 (0)