Skip to content
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

Add #[inline] to lots of trivial functions. #171

Merged
merged 3 commits into from
Oct 29, 2019

Conversation

m-ou-se
Copy link
Contributor

@m-ou-se m-ou-se commented Oct 9, 2019

Now the only public non-inline functions left are:

  • write_all
  • write_aligned
  • All (derived) Debug implementations

(Checked using Clippy's missing_inline_in_public_items lint.)

@m-ou-se m-ou-se requested a review from a team as a code owner October 9, 2019 08:33
@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @therealprof (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-cortex-m labels Oct 9, 2019
@m-ou-se
Copy link
Contributor Author

m-ou-se commented Oct 9, 2019

#![deny(clippy::missing_inline_in_public_items)] can be added to prevent non-inline functions from accedentally being added.

#172 fixes (and/or silences) all other Clippy warnings, so Clippy can be enabled in CI.

Now the only public non-inline functions left are:

 - write_all
 - write_aligned
 - All (derived) Debug implementations

(Checked using Clippy's missing_inline_in_public_items lint.)
@korken89
Copy link
Contributor

Overall this looks good! One question, have you done any test on the difference in size/perf. of optimized builds?
I am interested in what impact this has, even though it probably is minimal with the compiler doing a good job on inlining.

@m-ou-se
Copy link
Contributor Author

m-ou-se commented Oct 29, 2019

I have no numbers and statistics for you, but I did look at the disassembly of a few projects I'm working on. Before this change, lots of trivial functions ended up as calls to functions that do nothing other than return a constant or write or read a single register.

See also:

@m-ou-se
Copy link
Contributor Author

m-ou-se commented Oct 29, 2019

Now with some numbers:

For some random stm32 project I'm working at:

$ arm-none-eabi-size before after
   text	   data	    bss	    dec	    hex	filename
  24298	    256	    456	  25010	   61b2	before
  24150	    256	    456	  24862	   611e	after

@therealprof
Copy link
Contributor

therealprof commented Oct 29, 2019

Overall this looks good! One question, have you done any test on the difference in size/perf. of optimized builds?

Also note that upstream Rust is doing the exact same thing for trivial functions. cf. rust-lang/rust#64996

Especially the #[inline(always)] on trivial functions helps a lot on debug builds.

@korken89
Copy link
Contributor

Thanks for the update, then I say we merge this!

@korken89
Copy link
Contributor

bors r+

bors bot added a commit that referenced this pull request Oct 29, 2019
171: Add `#[inline]` to lots of trivial functions. r=korken89 a=m-ou-se

Now the only public non-inline functions left are:

 - `write_all`
 - `write_aligned`
 - All (derived) `Debug` implementations

(Checked using Clippy's [`missing_inline_in_public_items`][1] lint.)

[1]: https://rust-lang.github.io/rust-clippy/master/#missing_inline_in_public_items

Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
@bors
Copy link
Contributor

bors bot commented Oct 29, 2019

Build succeeded

@bors bors bot merged commit 90c4717 into rust-embedded:master Oct 29, 2019
@m-ou-se m-ou-se deleted the inline branch October 29, 2019 11:47
bors bot added a commit that referenced this pull request Nov 28, 2019
175: Enable the missing_inline_in_public_items clippy lint. r=jonas-schievink a=m-ou-se

This adds `#![deny(clippy::missing_inline_in_public_items)]` to make sure all functions in this crate are marked `#[inline]`, unless they are explicitly marked with `#[allow(clippy::missing_inline_in_public_items)]`.

Only three functions in this crate are not `#[inline]`:

 - `write_words`
 - `write_all`
 - `write_aligned`

Additionally, the derived `Debug` impl's also have a non-inline implementations.
This unfortunately means that the allow attribute also needs to added to any types deriving `Debug`.

See also #171 and #174 (comment).

Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
adamgreig pushed a commit that referenced this pull request Jan 12, 2022
171: update cfail tests to make them pass with latest nightly r=therealprof a=japaric



Co-authored-by: Jorge Aparicio <jorge@japaric.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-cortex-m
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants