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
{{ message }}
Repository navigation
#[optimize(none)] should imply #[inline(never)] #136329
The #[optimize(none)] attribute was recently added in #128657. And according to the discussion in the tracking issue at #54882, it seems like the main motivation of #[optimize(none)] is for debugging.
In this case, it seems like the compiler is inlining foo() into bar() and then proceeding to optimize bar(). This seems counterproductive for debugging. Therefore, I think that #[optimize(none)] should imply #[inline(never)]. Or if that is "too magic", then the compiler should at least produce a warning or error.
Meta
Reproduces on godbolt with rustc 1.86.0-nightly (ae5de6c75 2025-01-29)
This is surprisingly subtle. On the one hand, in LLVM IR every function marked optnone must be marked noinline. So it might make sense for the MIR inliner to behave the same. On the other hand, LLVM's LangRef describes optnone like this:
This function attribute indicates that most optimization passes will skip this function, with the exception of interprocedural optimization passes.
And IPO passes can lead to inlining-equivalent effects, as discussed (for example) in #73739. So I don't know if the proposed fix is actually a reliable way to achieve "call to optimize(none) function is never eliminated" or something like that. Such calls might still get eliminated on the basis of IPO even if this specific call currently isn't eliminated with noinline. @nikic mentioned a hypothetical LLVM IR-level noipa attribute in #73739 but as far as I know this still doesn't exist.
As I mentioned in #136358 (comment), it seems like the real problem is that the MIR optimizer isn't correctly obeying #[optimize(none)] at a higher level. It shouldn't even get around to trying inlining. So I think the fix is in a suboptimal place.
Activity
clubby789 commentedon Jan 31, 2025
cc #128657
Looks like it's being inlined in MIR
hanna-kruppe commentedon Jan 31, 2025
This is surprisingly subtle. On the one hand, in LLVM IR every function marked
optnonemust be markednoinline. So it might make sense for the MIR inliner to behave the same. On the other hand, LLVM's LangRef describesoptnonelike this:And IPO passes can lead to inlining-equivalent effects, as discussed (for example) in #73739. So I don't know if the proposed fix is actually a reliable way to achieve "call to
optimize(none)function is never eliminated" or something like that. Such calls might still get eliminated on the basis of IPO even if this specific call currently isn't eliminated withnoinline. @nikic mentioned a hypothetical LLVM IR-levelnoipaattribute in #73739 but as far as I know this still doesn't exist.Rollup merge of rust-lang#136358 - clubby789:opt-none-noinline, r=sae…
Rollup merge of rust-lang#136358 - clubby789:opt-none-noinline, r=sae…
Rollup merge of rust-lang#136358 - clubby789:opt-none-noinline, r=sae…
Rollup merge of rust-lang#136358 - clubby789:opt-none-noinline, r=sae…
Rollup merge of rust-lang#136358 - clubby789:opt-none-noinline, r=sae…
Rollup merge of rust-lang#136358 - clubby789:opt-none-noinline, r=sae…
Unrolled build for rust-lang#136358
briansmith commentedon Feb 6, 2025
As I mentioned in #136358 (comment), it seems like the real problem is that the MIR optimizer isn't correctly obeying
#[optimize(none)]at a higher level. It shouldn't even get around to trying inlining. So I think the fix is in a suboptimal place.stabilize optimize attribute (size, speed, and none)
Rollup merge of rust-lang#157273 - veluca93:optimize-attribte, r=wesl…
Rollup merge of rust-lang#157273 - veluca93:optimize-attribte, r=wesl…
Rollup merge of rust-lang#157273 - veluca93:optimize-attribte, r=wesl…
Unrolled build for #157273 in rollup 163957
Rollup merge of #157273 - veluca93:optimize-attribte, r=wesleywiser