You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
identity::<i32> is codegened only once, in crate A. The LLVM IR of crate B does not have the definition, only a declaration (because it was already instantiated for A). On the other hand, identity_i32 is codegened twice and thus available for LLVM inlining.
Expected behavior
I would have expected that crate A gets its own copy of identity::<i32>. This would match the behavior of non-generic inline functions, and it would also enable more optimizations.
Related: rust-lang/rust-clippy#2253 (the proposed change would make it meaningful to annotate generic functions with #[inline])
I would try to create a PR for this if we can agree that the expected behavior is more reasonable.
The text was updated successfully, but these errors were encountered:
Actually, this is currently only observable for -O0, -O1, -Os and -Oz, or -Zshare_generics=on with any optimization level. Unless -Zshare_generics=on becomes the default in the future, we therefore don't have to be too concerned with missed optimizations. However, with the given optimization levels, there still is a mismatch between inline non-generic and inline generic functions.
jachris
changed the title
Generic inline functions are not always inline
Generic inline functions are not always inline if generics are shared
Oct 25, 2022
Consider the following example.
Current behavior
identity::<i32>
is codegened only once, in crate A. The LLVM IR of crate B does not have the definition, only a declaration (because it was already instantiated for A). On the other hand,identity_i32
is codegened twice and thus available for LLVM inlining.Expected behavior
I would have expected that crate A gets its own copy of
identity::<i32>
. This would match the behavior of non-generic inline functions, and it would also enable more optimizations.Related: rust-lang/rust-clippy#2253 (the proposed change would make it meaningful to annotate generic functions with
#[inline]
)I would try to create a PR for this if we can agree that the expected behavior is more reasonable.
The text was updated successfully, but these errors were encountered: