Skip to content

Marked Debug implementations for primitive types as #[inline] #47840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from Jan 31, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libcore/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ macro_rules! array_impls {

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: fmt::Debug> fmt::Debug for [T; $N] {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(&&self[..], f)
}
Expand Down
1 change: 1 addition & 0 deletions src/libcore/fmt/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ macro_rules! floating {
($ty:ident) => (
#[stable(feature = "rust1", since = "1.0.0")]
impl Debug for $ty {
#[inline]
fn fmt(&self, fmt: &mut Formatter) -> Result {
float_to_decimal_common(fmt, self, true, 1)
}
Expand Down
10 changes: 10 additions & 0 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1558,10 +1558,12 @@ macro_rules! fmt_refs {
$(
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized + $tr> $tr for &'a T {
#[inline]
fn fmt(&self, f: &mut Formatter) -> Result { $tr::fmt(&**self, f) }
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized + $tr> $tr for &'a mut T {
#[inline]
fn fmt(&self, f: &mut Formatter) -> Result { $tr::fmt(&**self, f) }
}
)*
Expand All @@ -1586,6 +1588,7 @@ impl Display for ! {

#[stable(feature = "rust1", since = "1.0.0")]
impl Debug for bool {
#[inline]
fn fmt(&self, f: &mut Formatter) -> Result {
Display::fmt(self, f)
}
Expand All @@ -1600,6 +1603,7 @@ impl Display for bool {

#[stable(feature = "rust1", since = "1.0.0")]
impl Debug for str {
#[inline]
fn fmt(&self, f: &mut Formatter) -> Result {
f.write_char('"')?;
let mut from = 0;
Expand Down Expand Up @@ -1628,6 +1632,7 @@ impl Display for str {

#[stable(feature = "rust1", since = "1.0.0")]
impl Debug for char {
#[inline]
fn fmt(&self, f: &mut Formatter) -> Result {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, this one should not be inline.

f.write_char('\'')?;
for c in self.escape_debug() {
Expand Down Expand Up @@ -1701,10 +1706,12 @@ impl<'a, T: ?Sized> Pointer for &'a mut T {

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> Debug for *const T {
#[inline]
fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) }
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> Debug for *mut T {
#[inline]
fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) }
}

Expand All @@ -1718,6 +1725,7 @@ macro_rules! tuple {
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($name:Debug),*> Debug for ($($name,)*) where last_type!($($name,)+): ?Sized {
#[allow(non_snake_case, unused_assignments, deprecated)]
#[inline]
fn fmt(&self, f: &mut Formatter) -> Result {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an example of one we don't need to mark inline. We want to mark those that are not generic and forwarding directly to another non-generic function as inline.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! With those conditions, should the only ones that I mark inline be non-float numbers, the unit type and bools? Just making sure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree.

I'm not 100% sure which trade off is the best for the function pointers, ideas welcome.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd even skip the unit type if pad is a method that inlines. We don't want to inline a bigger function with this PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unit type's pad method doesn't inline, so I think I'll inline the unit type's fmt function. For function pointers, I think I'll avoid marking them as inline them for now.

let mut builder = f.debug_tuple("");
let ($(ref $name,)*) = *self;
Expand All @@ -1741,13 +1749,15 @@ tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, }

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Debug> Debug for [T] {
#[inline]
fn fmt(&self, f: &mut Formatter) -> Result {
f.debug_list().entries(self.iter()).finish()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl Debug for () {
#[inline]
fn fmt(&self, f: &mut Formatter) -> Result {
f.pad("()")
}
Expand Down
1 change: 1 addition & 0 deletions src/libcore/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ macro_rules! debug {
($T:ident) => {
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Debug for $T {
#[inline]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one, definitely

fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
Expand Down
1 change: 1 addition & 0 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2202,6 +2202,7 @@ macro_rules! fnptr_impls_safety_abi {

#[stable(feature = "fnptr_impls", since = "1.4.0")]
impl<Ret, $($Arg),*> fmt::Debug for $FnTy {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Pointer::fmt(&(*self as *const ()), f)
}
Expand Down