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
This commit is contained in:
commit
db2f9759f4
12 changed files with 253 additions and 61 deletions
|
|
@ -16,10 +16,17 @@ struct Location<'a> {
|
|||
_col: u32,
|
||||
}
|
||||
|
||||
#[lang = "panic"]
|
||||
#[lang = "panic_const_div_by_zero"]
|
||||
#[inline]
|
||||
#[track_caller]
|
||||
fn panic(_: &'static str) -> ! {
|
||||
fn panic_div_zero() -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[lang = "panic_const_div_overflow"]
|
||||
#[inline]
|
||||
#[track_caller]
|
||||
fn panic_div_overflow() -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
|
|
@ -55,4 +62,5 @@ pub fn foo() {
|
|||
|
||||
//~ MONO_ITEM fn foo
|
||||
//~ MONO_ITEM fn <i32 as Div>::div
|
||||
//~ MONO_ITEM fn panic
|
||||
//~ MONO_ITEM fn panic_div_zero
|
||||
//~ MONO_ITEM fn panic_div_overflow
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
//@[NOASSERT] compile-flags: -Coverflow-checks=off
|
||||
|
||||
// CHECK-LABEL: define{{.*}} @assertion
|
||||
// ASSERT: call void @{{.*4core9panicking5panic}}
|
||||
// ASSERT: call void @{{.*4core9panicking11panic_const24panic_const_add_overflow}}
|
||||
// NOASSERT: ret i8 0
|
||||
#[no_mangle]
|
||||
pub fn assertion() -> u8 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue