Skip to content

Commit

Permalink
Auto merge of rust-lang#117727 - saethlin:inline-derived-fmt, r=nneth…
Browse files Browse the repository at this point in the history
…ercote

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.
  • Loading branch information
bors committed Nov 9, 2023
2 parents eae4135 + d32d923 commit 0f44eb3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/deriving/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn expand_deriving_debug(
explicit_self: true,
nonself_args: vec![(fmtr, sym::f)],
ret_ty: Path(path_std!(fmt::Result)),
attributes: ast::AttrVec::new(),
attributes: thin_vec![cx.attr_word(sym::inline, span)],
fieldless_variants_strategy:
FieldlessVariantsStrategy::SpecializeIfAllVariantsFieldless,
combine_substructure: combine_substructure(Box::new(|a, b, c| {
Expand Down
9 changes: 7 additions & 2 deletions tests/codegen/simd/unpadded-simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
#![crate_type = "lib"]
#![feature(repr_simd)]

#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone)]
#[repr(simd)]
pub struct int16x4_t(pub i16, pub i16, pub i16, pub i16);

#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone)]
pub struct int16x4x2_t(pub int16x4_t, pub int16x4_t);

// CHECK: %int16x4x2_t = type { <4 x i16>, <4 x i16> }
#[no_mangle]
fn takes_int16x4x2_t(t: int16x4x2_t) -> int16x4x2_t {
t
}
15 changes: 15 additions & 0 deletions tests/ui/deriving/deriving-all-codegen.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl ::core::clone::Clone for Empty {
impl ::core::marker::Copy for Empty { }
#[automatically_derived]
impl ::core::fmt::Debug for Empty {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f, "Empty")
}
Expand Down Expand Up @@ -97,6 +98,7 @@ impl ::core::clone::Clone for Point {
impl ::core::marker::Copy for Point { }
#[automatically_derived]
impl ::core::fmt::Debug for Point {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "Point", "x",
&self.x, "y", &&self.y)
Expand Down Expand Up @@ -183,6 +185,7 @@ impl ::core::clone::Clone for PackedPoint {
impl ::core::marker::Copy for PackedPoint { }
#[automatically_derived]
impl ::core::fmt::Debug for PackedPoint {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "PackedPoint",
"x", &{ self.x }, "y", &&{ self.y })
Expand Down Expand Up @@ -276,6 +279,7 @@ impl ::core::clone::Clone for Big {
impl ::core::marker::Copy for Big { }
#[automatically_derived]
impl ::core::fmt::Debug for Big {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let names: &'static _ =
&["b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8"];
Expand Down Expand Up @@ -475,6 +479,7 @@ impl Copy for PackedManualCopy {}
struct Unsized([u32]);
#[automatically_derived]
impl ::core::fmt::Debug for Unsized {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Unsized",
&&self.0)
Expand Down Expand Up @@ -527,6 +532,7 @@ impl ::core::cmp::Ord for Unsized {
struct PackedUnsizedU8([u8]);
#[automatically_derived]
impl ::core::fmt::Debug for PackedUnsizedU8 {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"PackedUnsizedU8", &&self.0)
Expand Down Expand Up @@ -569,6 +575,7 @@ impl<T: ::core::marker::Copy + Trait, U: ::core::marker::Copy>
#[automatically_derived]
impl<T: ::core::fmt::Debug + Trait, U: ::core::fmt::Debug> ::core::fmt::Debug
for Generic<T, U> where T::A: ::core::fmt::Debug {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f, "Generic", "t",
&self.t, "ta", &self.ta, "u", &&self.u)
Expand Down Expand Up @@ -687,6 +694,7 @@ impl<T: ::core::fmt::Debug + ::core::marker::Copy + Trait,
U: ::core::fmt::Debug + ::core::marker::Copy> ::core::fmt::Debug for
PackedGeneric<T, U> where T::A: ::core::fmt::Debug + ::core::marker::Copy
{
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field3_finish(f, "PackedGeneric",
&{ self.0 }, &{ self.1 }, &&{ self.2 })
Expand Down Expand Up @@ -797,6 +805,7 @@ impl ::core::clone::Clone for Enum0 {
impl ::core::marker::Copy for Enum0 { }
#[automatically_derived]
impl ::core::fmt::Debug for Enum0 {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {}
}
Expand Down Expand Up @@ -856,6 +865,7 @@ impl ::core::clone::Clone for Enum1 {
}
#[automatically_derived]
impl ::core::fmt::Debug for Enum1 {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Enum1::Single { x: __self_0 } =>
Expand Down Expand Up @@ -932,6 +942,7 @@ impl ::core::clone::Clone for Fieldless1 {
}
#[automatically_derived]
impl ::core::fmt::Debug for Fieldless1 {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f, "A")
}
Expand Down Expand Up @@ -995,6 +1006,7 @@ impl ::core::clone::Clone for Fieldless {
impl ::core::marker::Copy for Fieldless { }
#[automatically_derived]
impl ::core::fmt::Debug for Fieldless {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
Expand Down Expand Up @@ -1083,6 +1095,7 @@ impl ::core::clone::Clone for Mixed {
impl ::core::marker::Copy for Mixed { }
#[automatically_derived]
impl ::core::fmt::Debug for Mixed {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Mixed::P => ::core::fmt::Formatter::write_str(f, "P"),
Expand Down Expand Up @@ -1217,6 +1230,7 @@ impl ::core::clone::Clone for Fielded {
}
#[automatically_derived]
impl ::core::fmt::Debug for Fielded {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Fielded::X(__self_0) =>
Expand Down Expand Up @@ -1341,6 +1355,7 @@ impl<T: ::core::marker::Copy, U: ::core::marker::Copy> ::core::marker::Copy
#[automatically_derived]
impl<T: ::core::fmt::Debug, U: ::core::fmt::Debug> ::core::fmt::Debug for
EnumGeneric<T, U> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
EnumGeneric::One(__self_0) =>
Expand Down

0 comments on commit 0f44eb3

Please sign in to comment.