Repository navigation
Stabilize optimize attribute - #157273
Stabilize optimize attribute#157273
optimize attribute#157273Conversation
|
rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead. cc @rust-lang/rust-analyzer |
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
deb33c2 to
1de7123
Compare
This comment has been minimized.
This comment has been minimized.
1de7123 to
56db805
Compare
|
Given the interactions here, I expect this will need a lang+compiler FCP @rustbot label +I-lang-nominated +I-compiler-nominated See some recent discussion about this feature on Zulip #t-lang > status of #[optimize] attribute |
This comment has been minimized.
This comment has been minimized.
|
Marking as S-blocked given the current status. |
56db805 to
680ec3c
Compare
|
These commits modify Please ensure that if you've changed the output:
|
|
With my For example, can applying or removing this attribute on an item influence the contexts in which that item may be used without compile errors or other changes that would be considered public-API-breaking? |
I don't believe this is possible - the attribute should only influence how the compiler optimizes functions, and compiler optimizations should not have any visible effects. |
There was a problem hiding this comment.
Discussion: hm, I wonder if this attribute deserves an entry in the rustc book (a bit like lint levels), because while sure there's the Reference PR, but this is more like a compiler knob?
|
See also #138272 for another example of |
|
FYI LLVM 23 also has a noipa attribute. The combination of optnone + noipa should also disable all inter-procedural analysis and optimization. We may want to make optimize(none) to that. |
|
#160524 resolves the implementation concerns here from my side -- on the MIR-opt side, |
This comment has been minimized.
This comment has been minimized.
|
I rebased the stabilization PR and updated the reference PR to include the "equivalent to -Copt-level=0" behaviour for |
This comment has been minimized.
This comment has been minimized.
|
@TaKO8Ki, @jdonszelmann, @nikomatsakis, @scottmcm Your checkboxes are remaining at #157273 (comment) |
This commit stabilizes the `#[optimize]` attribute, which allows for more fine-grained control of optimization levels.
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@veluca93 Does this PR have tests on: whether applying the attribute to a function affects closures defined within that function? And does the reference PR specify this? |
Well, not this PR, it was merged in a previous one :-) The test is in tests/codegen-llvm/optimize-closures-inheritance.rs. As for the reference PR: now it does ;) |
|
@rfcbot resolve should-apply-to-closures |
|
@scottmcm friendly ping :-) |
|
@rfcbot resolve make-optimize-none-be-c-opt-level-0 |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
|
Is this also covered by wherever the docs will go for
rust/compiler/rustc_codegen_ssa/src/base.rs Line 1224 in 7d2cd0f |
It was saying the wrong thing, now it should say the right thing :-) (rust-lang/reference#2278) |
|
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
|
Note This PR was benchmarked as part of triage of its containing rollup: triage URL. Finished benchmarking commit (aab12df): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)This perf run didn't have relevant results for this metric. CyclesThis perf run didn't have relevant results for this metric. Binary sizeThis perf run didn't have relevant results for this metric. Artifact size: 408.59 MiB -> 408.65 MiB (0.01%) |
|
Probably noise, all PRs in the rollup seem to have similar results |
View all comments
FCP proposal and checkboxes
This commit stabilizes the
#[optimize]attribute, which allows for more fine-grained control of optimization levels.Stabilization report
Summary
Tracking issue: #54882
Reference PRs: rust-lang/reference#2278
cc @rust-lang/lang @rust-lang/lang-advisors @rust-lang/t-compiler
What is stabilized
What isn't stabilized
We might want to allow specifying a per-function optimization level (i.e.
#[optimize(level = 3)]). To my understanding, backend support for this is not quite there yet (and this - or other - extensions have consequently not been implemented yet).Applying the attribute on a module level is also not implemented yet.
Design
Reference
RFC history
Answers to unresolved question
Not yet.
Not yet.
Post-RFC changes
The
optimize(none)variant was added. The variants above were discussed here: #54882 (comment)Key points
#[optimize(none)]implies#[inline(never)]to be effective (#[optimize(none)] should imply #[inline(never)] #136329)#[optimize]is applied to an incompatible item #128458Nightly uses
The standard library itself uses this attribute in a few places
Implementation
Major part
rust/compiler/rustc_codegen_llvm/src/attributes.rs
Line 416 in c0bb140
#[optimize]is applied to an incompatible item #128458optimize(none): Add#[optimize(none)]#128657#[optimize(none)]implies#[inline(never)]#136358 (includes disabling MIR opts)Coverage
Tool changes
Trivial changes to rust-analyzer to support the new attribute as an inert attribute: rust-lang/rust-analyzer#22511
Type system, opsem
Breaks the AM?
As far as the AM is concerned, this attribute doesn't exist.
Acknowledgments
Most of the work was not done by me, I'm just writing the stabilization report :-)
@nagisa did the initial implementation, @clubby789 implemented optimize(none) and fixed the attribute being allowed in too many places.
Note
Concerns (0 active)
are-we-happy-wiht-capability-and-scope-of-this-attributeresolved in this commentmeaning-of-optimize-sizeresolved in this commentexplicitly-decide-on-effect-on-nested-functionsresolved in this commentManaged by
@rustbot—see help for details.