With multiple codegen units (default since a long while back now), #[inline]
has more effects as alexcrichton writes here: https://github.com/rust-lang/hashbrown/pull/119#issuecomment-537539046
No,
#[inline]
is very different than simply just an inline hint. As I mentioned before, there's no equivalent in C++ for what#[inline]
does. In debug mode rustc basically ignores#[inline]
, pretending you didn't even write it. In release mode the compiler will, by default, codegen an#[inline]
function into every single referencing codegen unit , and then it will also addinlinehint
. This means that if you have 16 CGUs and they all reference a hash map, every single one is getting the entire hash map implementation inlined into it.
This means it is a pretty forceful annotation and I think it makes sense to ask for something like #[inline(enable)]
or #[inline(nohint)]
that doesn't have such strong effects. You'd want a base attribute to just enable inlining, then on top of that one can add the inlinehint (stronger hint for inlining) and/or whether to emit the function in every codegen unit.
(This topic brings to mind - documentation - how do we share this inlining knowledge in the ecosystem - would it be feasible to include non-normative descriptions of what inlining can entail, in the reference? (Current Rust reference description of #[inline]
)