rust: bitfield: mark `Debug` impl as `#[inline]`
Subsystems (2)
PATCH 1/1 rust: bitfield: mark `Debug` impl as `#[inline]`
From: Gary Guo <[email protected]>
A Debug impl is for debugging and is normally not used, and therefore should ideally not be code-generated unless used. However, Rust has no way of knowing if a dependent crate is going to use the trait impl or not, so unless it is marked as #[inline], it will be code-generated in the defining crate (as it is not generic).
Mark the impl generated by bitfield macro #[inline], so they do not stay in the binary unless used.
This reduces nova-core.o .text by 17% (from 151922 bytes to 125676 bytes).
--- rust/kernel/bitfield.rs | 1 + 1 file changed, 1 insertion(+)
rust/kernel/bitfield.rs +1 -0
@@ -535,6 +535,7 @@ const fn [<__with_ $field>]( // `Debug` implementation. (@debug $name:ident { $($field:ident;)* }) => { impl ::kernel::fmt::Debug for $name { + #[inline] fn fmt(&self, f: &mut ::kernel::fmt::Formatter<'_>) -> ::kernel::fmt::Result { f.debug_struct(stringify!($name)) .field("<raw>", &::kernel::prelude::fmt!("{:#x}", self.inner))
base-commit: 7f07865bda5f5770d2f7927bc76cb2b4acd46074
Signature · 1 line
2.54.0
Quoted 8 lines · Gary Guo
From: Gary Guo <[email protected]>
A
Debugimpl is for debugging and is normally not used, and therefore should ideally not be code-generated unless used. However, Rust has no way of knowing if a dependent crate is going to use the trait impl or not, so unless it is marked as#[inline], it will be code-generated in the defining crate (as it is not generic).
Quoted 6 lines
Mark the impl generated by bitfield macro
#[inline], so they do not stay in the binary unless used.This reduces nova-core.o .text by 17% (from 151922 bytes to 125676 bytes).
Signed-off-by Gary Guo <[email protected]>
Quoted 8 lines · Gary Guo
From: Gary Guo <[email protected]>
A
Debugimpl is for debugging and is normally not used, and therefore should ideally not be code-generated unless used. However, Rust has no way of knowing if a dependent crate is going to use the trait impl or not, so unless it is marked as#[inline], it will be code-generated in the defining crate (as it is not generic).
Quoted 6 lines
Mark the impl generated by bitfield macro
#[inline], so they do not stay in the binary unless used.This reduces nova-core.o .text by 17% (from 151922 bytes to 125676 bytes).
Signed-off-by Gary Guo <[email protected]>
Ouch, well-spotted. Thanks for this.
Alexandre Courbot
maintainerQuoted 12 lines · Alexandre Courbot
Quoted 11 lines · Gary Guo
From: Gary Guo <[email protected]>
A
Debugimpl is for debugging and is normally not used, and therefore should ideally not be code-generated unless used. However, Rust has no way of knowing if a dependent crate is going to use the trait impl or not, so unless it is marked as#[inline], it will be code-generated in the defining crate (as it is not generic).Mark the impl generated by bitfield macro
#[inline], so they do not stay in the binary unless used.
Quoted 7 lines
Quoted 3 lines
This reduces nova-core.o .text by 17% (from 151922 bytes to 125676 bytes).
Signed-off-by Gary Guo <[email protected]>Ouch, well-spotted. Thanks for this.
Btw, should this be
?
Quoted 6 lines · Alexandre Courbot
Btw, should this be
Fixes b7b8b4ccdad4 ("rust: extract `bitfield!` macro from `register!`")?
I think it is reasonable either way. One can see it as a "size improvement" or as a "fix" if it was unintentional to not have the annotation.
It also depends on the magnitude of the size reduction -- if it were very low, would we see it as a fix?
Cheers,
Miguel
Quoted 2 lines · Gary Guo
This reduces nova-core.o .text by 17% (from 151922 bytes to 125676 bytes).
That's definitely something :)
I wonder if we could lint this for fmt bits.
Cheers,
Miguel
Miguel Ojeda
AppliedQuoted 9 lines · Gary Guo
From: Gary Guo <[email protected]>
A
Debugimpl is for debugging and is normally not used, and therefore should ideally not be code-generated unless used. However, Rust has no way of knowing if a dependent crate is going to use the trait impl or not, so unless it is marked as#[inline], it will be code-generated in the defining crate (as it is not generic).
Quoted 6 lines
Mark the impl generated by bitfield macro
#[inline], so they do not stay in the binary unless used.This reduces nova-core.o .text by 17% (from 151922 bytes to 125676 bytes).
Signed-off-by Gary Guo <[email protected]>
Applied to rust-fixes -- thanks!
I am going to pick a couple actual fixes in the coming days, so I decided to pick this one too for the ride since it is trivial. I may still rebase though.
Cheers,
Miguel