-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Stabilize core::hint::cold_path
#151576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Stabilize core::hint::cold_path
#151576
Conversation
`cold_path` has been around unstably for a while and is a rather useful
tool to have. It does what it is supposed to and there are no known
remaining issues, so stabilize it here (including const).
Newly stable API:
// in core::hint
pub const fn cold_path();
I have opted to exclude `likely` and `unlikely` for now since they have
had some concerns about ease of use that `cold_path` doesn't suffer
from. `cold_path` is also significantly more flexible; in addition to
working with boolean `if` conditions, it can be used in `match` arms,
`if let`, closures, and other control flow blocks. `likely` and
`unlikely` are also possible to implement in user code via `cold_path`,
if desired.
|
Cc also @x17jiri since you did a lot of the work here. |
|
Trivial stabilization; Anecdotally, I do find
Technically, so can |
|
Cc @nikic
Those tracking issues track features that actually exist unstably in the compiler, or do they not? If they do, please don't close them without removing the implementation (which IMO should be a separate PR). |
There isn't anything linked at #26179 and that issue number doesn't show up in the source, and it doesn't seem like we have any special handling for it based on diagnostics for closures. I was thinking we had this at some point too but perhaps it got ripped out. We do parse the attribute in places we definitely shouldn't (below builds on stable without issue): fn foo(a: u32) {}
match 10 {
#[cold] _ => {}
}
#[cold] if true {}
foo(#[cold] 10);But that isn't unique to match 10 {
#[unsafe(no_mangle)] _ => {}
}
#[unsafe(no_mangle)] if true {}
foo(#[unsafe(no_mangle)] 10); |
|
Does stabilizing this impact design space for hinting that there are multiple paths with different coldness? The current lowering just produces a magic branch weight, but it could be possible to pass through the weight you want. |
I'm skeptical that exposing any extra knobs along those lines will ever be useful, especially across compiler upgrades (if you see any performance benefit from it, it's likely from the thirty-steps-removed perturbation on heuristic in very late backend passes like regalloc and machine block placement). In any case, I don't see a plausible design that would be significantly impacted by
So I think it's expected and fine if a hypothetical feature that gives more control over the branch weights would end up as an entirely different interface from Footnotes
|
|
A small bit of prior discussion about probabilities came up on the bit tracking issue, starting around #26179 (comment). I don't think there has been much interest or design work since but ageed with what Hanna said, that having |
|
@rfcbot fcp merge |
|
Error encounted: |
|
@rfcbot fcp merge libs-api,lang |
|
Team member @BurntSushi has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
@tgross35: As a tracking matter, I'd suggest moving
As a documentation matter, I'd suggest demonstrating this in the docs for
I would like to see us later add some manner of @rfcbot reviewed |
|
The tracking issue and documentation updates are reasonable. Split the issues, updates are in #151612. |
cold_pathhas been around unstably for a while and is a rather useful tool to have. It does what it is supposed to and there are no known remaining issues, so stabilize it here (including const).Newly stable API:
I have opted to exclude
likelyandunlikelyfor now since they have had some concerns about ease of use thatcold_pathdoesn't suffer from.cold_pathis also significantly more flexible; in addition to working with booleanifconditions, it can be used inmatcharms,if let, closures, and other control flow blocks.likelyandunlikelyare also possible to implement in user code viacold_path, if desired.Closes: #136873 (tracking issue)
There has been some design and implementation work for making
#[cold]function in more places, such asifarms,matcharms, and closure bodies. Considering a stablecold_pathwill cover all of these usecases, it does not seem worth pursuing a more powerful#[cold]as an alternative way to do the same thing. If the lang team agrees, then:Closes: #26179
Closes: #120193
Cc @rust-lang/lang
Cc @rust-lang/libs-api
Cc @rust-lang/wg-const-eval