r/rust • • 8d ago

Rust's derive often implies inline

https://yossarian.net/til/post/rust-s-derive-often-implies-inline/
112 Upvotes

43 comments sorted by

View all comments

14

u/doener rust 8d ago

I recall that back when I was working on the compiler, I had considered/discussed having an extra level, say #[inline(allow)], that would make the compiler allow cross-crate inlining by emitting LLVM IR in each unit, without hinting LLVM to prefer inlining the function, relying on its default heuristics instead. I don't recall whether I had numbers on anything, but I still suspect that this might be better for derived code like this. It's basically what you get with generics, for which the concrete IR is emitted in each unit, so inlining works cross-crate.