-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Warn about missing #[inline]
on trivial public methods
#12797
Comments
#[inline]
on _trivial_ public methods#[inline]
on trivial public methods
It could be potentially expanded to handled cases like an |
Is this really still true today? As of recently rustc has started automatically adding |
I agree with you in priciple y21, but last I read about the auto-inlining in rustc it was extremely simple. Maybe it has improved though (and maybe I should open an issue on rustc instead). Does anyone know the unit-tests for this is for rustc, so we can check which cases are actually handled? |
The PR that improved it is rust-lang/rust#116505. It adds the The exact criteria are: Interestingly, that But anyway, if there are other trivial functions that aren't caught by this I do think an issue on the rust issue tracker would be better. Everyone would benefit from better heuristics in that area. A clippy lint would duplicate what's already done in rustc but just with different heuristics that may or may not be better. There are some subtleties too that would need to be taken into account, which Rust's inliner does, such as being careful if a field access invokes |
Well put @y21 |
What it does
Check for trivial functions marked
pub
that aren't marked#[inline]
(or#[inline(always)]
or#[inline(never)]
).Related issue:
#[inline]
on generic functions #11187Advantage
Adding
#[inline]
to trivial methods can have a huge effect on performance when the methods are called cross-crate and LTO is not enabled.The Rust compilers sometimes auto-inlines some of these methods, but not reliably so (at least not yet).
Drawbacks
Defining what makes for a "trivial" function will not be easy. Suggestion is to only trigger the lint if the function restricts itself to:
Example
Could be written as:
A lot of people don't realize that
#[inline]
is also important when implementing simple trait functions like these, so that's why I'm calling it out explicitly.The text was updated successfully, but these errors were encountered: