Skip to content

Commit 0f44eb3

Browse files
committedNov 9, 2023
Auto merge of rust-lang#117727 - saethlin:inline-derived-fmt, r=nnethercote
Emit #[inline] on derive(Debug) While working on rust-lang#116583 I noticed that the `cross_crate_inlinable` query identifies a lot of derived `Debug` impls as a MIR body that's little more than a call, which suggests they may be a good candidate for `#[inline]`. So here I've implemented that change specifically. It seems to provide a nice improvement to build times.
2 parents eae4135 + d32d923 commit 0f44eb3

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed
 

‎compiler/rustc_builtin_macros/src/deriving/debug.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn expand_deriving_debug(
3333
explicit_self: true,
3434
nonself_args: vec![(fmtr, sym::f)],
3535
ret_ty: Path(path_std!(fmt::Result)),
36-
attributes: ast::AttrVec::new(),
36+
attributes: thin_vec![cx.attr_word(sym::inline, span)],
3737
fieldless_variants_strategy:
3838
FieldlessVariantsStrategy::SpecializeIfAllVariantsFieldless,
3939
combine_substructure: combine_substructure(Box::new(|a, b, c| {

‎tests/codegen/simd/unpadded-simd.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@
55
#![crate_type = "lib"]
66
#![feature(repr_simd)]
77

8-
#[derive(Copy, Clone, Debug)]
8+
#[derive(Copy, Clone)]
99
#[repr(simd)]
1010
pub struct int16x4_t(pub i16, pub i16, pub i16, pub i16);
1111

12-
#[derive(Copy, Clone, Debug)]
12+
#[derive(Copy, Clone)]
1313
pub struct int16x4x2_t(pub int16x4_t, pub int16x4_t);
14+
1415
// CHECK: %int16x4x2_t = type { <4 x i16>, <4 x i16> }
16+
#[no_mangle]
17+
fn takes_int16x4x2_t(t: int16x4x2_t) -> int16x4x2_t {
18+
t
19+
}

‎tests/ui/deriving/deriving-all-codegen.stdout

+15
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ impl ::core::clone::Clone for Empty {
3333
impl ::core::marker::Copy for Empty { }
3434
#[automatically_derived]
3535
impl ::core::fmt::Debug for Empty {
36+
#[inline]
3637
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3738
::core::fmt::Formatter::write_str(f, "Empty")
3839
}
@@ -97,6 +98,7 @@ impl ::core::clone::Clone for Point {
9798
impl ::core::marker::Copy for Point { }
9899
#[automatically_derived]
99100
impl ::core::fmt::Debug for Point {
101+
#[inline]
100102
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
101103
::core::fmt::Formatter::debug_struct_field2_finish(f, "Point", "x",
102104
&self.x, "y", &&self.y)
@@ -183,6 +185,7 @@ impl ::core::clone::Clone for PackedPoint {
183185
impl ::core::marker::Copy for PackedPoint { }
184186
#[automatically_derived]
185187
impl ::core::fmt::Debug for PackedPoint {
188+
#[inline]
186189
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
187190
::core::fmt::Formatter::debug_struct_field2_finish(f, "PackedPoint",
188191
"x", &{ self.x }, "y", &&{ self.y })
@@ -276,6 +279,7 @@ impl ::core::clone::Clone for Big {
276279
impl ::core::marker::Copy for Big { }
277280
#[automatically_derived]
278281
impl ::core::fmt::Debug for Big {
282+
#[inline]
279283
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
280284
let names: &'static _ =
281285
&["b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8"];
@@ -475,6 +479,7 @@ impl Copy for PackedManualCopy {}
475479
struct Unsized([u32]);
476480
#[automatically_derived]
477481
impl ::core::fmt::Debug for Unsized {
482+
#[inline]
478483
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
479484
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Unsized",
480485
&&self.0)
@@ -527,6 +532,7 @@ impl ::core::cmp::Ord for Unsized {
527532
struct PackedUnsizedU8([u8]);
528533
#[automatically_derived]
529534
impl ::core::fmt::Debug for PackedUnsizedU8 {
535+
#[inline]
530536
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
531537
::core::fmt::Formatter::debug_tuple_field1_finish(f,
532538
"PackedUnsizedU8", &&self.0)
@@ -569,6 +575,7 @@ impl<T: ::core::marker::Copy + Trait, U: ::core::marker::Copy>
569575
#[automatically_derived]
570576
impl<T: ::core::fmt::Debug + Trait, U: ::core::fmt::Debug> ::core::fmt::Debug
571577
for Generic<T, U> where T::A: ::core::fmt::Debug {
578+
#[inline]
572579
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
573580
::core::fmt::Formatter::debug_struct_field3_finish(f, "Generic", "t",
574581
&self.t, "ta", &self.ta, "u", &&self.u)
@@ -687,6 +694,7 @@ impl<T: ::core::fmt::Debug + ::core::marker::Copy + Trait,
687694
U: ::core::fmt::Debug + ::core::marker::Copy> ::core::fmt::Debug for
688695
PackedGeneric<T, U> where T::A: ::core::fmt::Debug + ::core::marker::Copy
689696
{
697+
#[inline]
690698
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
691699
::core::fmt::Formatter::debug_tuple_field3_finish(f, "PackedGeneric",
692700
&{ self.0 }, &{ self.1 }, &&{ self.2 })
@@ -797,6 +805,7 @@ impl ::core::clone::Clone for Enum0 {
797805
impl ::core::marker::Copy for Enum0 { }
798806
#[automatically_derived]
799807
impl ::core::fmt::Debug for Enum0 {
808+
#[inline]
800809
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
801810
match *self {}
802811
}
@@ -856,6 +865,7 @@ impl ::core::clone::Clone for Enum1 {
856865
}
857866
#[automatically_derived]
858867
impl ::core::fmt::Debug for Enum1 {
868+
#[inline]
859869
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
860870
match self {
861871
Enum1::Single { x: __self_0 } =>
@@ -932,6 +942,7 @@ impl ::core::clone::Clone for Fieldless1 {
932942
}
933943
#[automatically_derived]
934944
impl ::core::fmt::Debug for Fieldless1 {
945+
#[inline]
935946
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
936947
::core::fmt::Formatter::write_str(f, "A")
937948
}
@@ -995,6 +1006,7 @@ impl ::core::clone::Clone for Fieldless {
9951006
impl ::core::marker::Copy for Fieldless { }
9961007
#[automatically_derived]
9971008
impl ::core::fmt::Debug for Fieldless {
1009+
#[inline]
9981010
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9991011
::core::fmt::Formatter::write_str(f,
10001012
match self {
@@ -1083,6 +1095,7 @@ impl ::core::clone::Clone for Mixed {
10831095
impl ::core::marker::Copy for Mixed { }
10841096
#[automatically_derived]
10851097
impl ::core::fmt::Debug for Mixed {
1098+
#[inline]
10861099
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10871100
match self {
10881101
Mixed::P => ::core::fmt::Formatter::write_str(f, "P"),
@@ -1217,6 +1230,7 @@ impl ::core::clone::Clone for Fielded {
12171230
}
12181231
#[automatically_derived]
12191232
impl ::core::fmt::Debug for Fielded {
1233+
#[inline]
12201234
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
12211235
match self {
12221236
Fielded::X(__self_0) =>
@@ -1341,6 +1355,7 @@ impl<T: ::core::marker::Copy, U: ::core::marker::Copy> ::core::marker::Copy
13411355
#[automatically_derived]
13421356
impl<T: ::core::fmt::Debug, U: ::core::fmt::Debug> ::core::fmt::Debug for
13431357
EnumGeneric<T, U> {
1358+
#[inline]
13441359
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
13451360
match self {
13461361
EnumGeneric::One(__self_0) =>

0 commit comments

Comments
 (0)
Please sign in to comment.