Skip to content

Commit d81b233

Browse files
committed
Auto merge of #122671 - Mark-Simulacrum:const-panic-msg, r=Nilstrieb
Codegen const panic messages as function calls This skips emitting extra arguments at every callsite (of which there can be many). For a librustc_driver build with overflow checks enabled, this cuts 0.7MB from the resulting shared library (see [perf]). A sample improvement from nightly: ``` leaq str.0(%rip), %rdi leaq .Lalloc_d6aeb8e2aa19de39a7f0e861c998af13(%rip), %rdx movl $25, %esi callq *_ZN4core9panicking5panic17h17cabb89c5bcc999E@GOTPCREL(%rip) ``` to this PR: ``` leaq .Lalloc_d6aeb8e2aa19de39a7f0e861c998af13(%rip), %rdi callq *_RNvNtNtCsduqIKoij8JB_4core9panicking11panic_const23panic_const_div_by_zero@GOTPCREL(%rip) ``` [perf]: https://perf.rust-lang.org/compare.html?start=a7e4de13c1785819f4d61da41f6704ed69d5f203&end=64fbb4f0b2d621ff46d559d1e9f5ad89a8d7789b&stat=instructions:u
2 parents 0c0894c + 285e880 commit d81b233

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/shims/panic.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
256256
}
257257

258258
_ => {
259-
// Forward everything else to `panic` lang item.
260-
this.start_panic(msg.description(), unwind)?;
259+
// Call the lang item associated with this message.
260+
let fn_item = this.tcx.require_lang_item(msg.panic_function(), None);
261+
let instance = ty::Instance::mono(this.tcx.tcx, fn_item);
262+
this.call_function(
263+
instance,
264+
Abi::Rust,
265+
&[],
266+
None,
267+
StackPopCleanup::Goto { ret: None, unwind },
268+
)?;
261269
}
262270
}
263271
Ok(())

0 commit comments

Comments
 (0)