How to inline cross crate function in 2020

Hello,

I compile a crate A that depends of another crate B that contains very small functions ( 2 or 3 lines ).
When I compile the crate A, all functions are called callq A...fct... but not inline. I need to #[inline] all functions in B to allow inlining.

B contains a lot of small functions and I don't want to #[inline] all of them.

I generate asm with this cargo rustc --release -- -C lto --emit asm

Thank you

Are they inlined if they're in the same crate? If you already turned on lto, then there isn't much more you can do besides adding #[inline].

2 Likes

To enforce cross-crate inlining you have to use #[inline]
There is nothing wrong with it, because it is still up to compiler to decide whether to inline or not.

In case of lto it should inline even without #[inline]

1 Like

Ok so #[inline] is still a hint for the compiler.
Without #[inline] I have no cross-crate inlining even with lto.
Thank you

Yeah, it's a hint. There's a separate attribute for always inlining: #[inline(always)].

1 Like

And even that is just a stronger request, not a demand; the compiler can choose to not inline the requested code.

2 Likes

Without #[inline] I have no cross-crate inlining even with lto.

Well this is surprising...
I pretty sure that lto was supposed to enable cross-crate inlining too.
Maybe the behavior was changed, in which case #[inline] across your public API makes sense when you see it fitting

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.