Experiment: Add core::cmp::smallest and core::cmp::largest - #160687
Conversation
|
r? @nia-e rustbot has assigned @nia-e. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Reminder, once the PR becomes ready for a review, use |
0ca7197 to
9a53733
Compare
|
looks good now ^^ I'll wait a couple days to give folks time to see this given there's no ACP, and if nothing comes up r=me |
There was a problem hiding this comment.
Looks good, but one doc comment needs a tweak (or maybe the doctests are wrong and haven't been run?)
There aren't any tests for const calls or non-Copy types, but we already have splat UI tests for those. So that's not a blocker for this PR.
The place we are lacking testing for splat is incorrect argument suggestions. So if you see any weird behaviour there, please open a ticket/PR and cc me.
@rustbot label +F-splat
|
Thanks for the feedback so far everyone! I've updated this PR as per discussion on the ACP, namely making |
|
Main thing missing here would be some tests (especially for |
|
r=me once you have tests for const behaviour - smoke tests should be fine, i don't see any particular nasty edge case here. |
|
✌️ @bushrat011899, you can now approve this pull request! If @nia-e told you to " |
There aren't any edge cases in splat, either, except for the empty tuple case (which produces a negative argument difference, has splat tests, and is excluded here by design). The |
Variadic alternatives to `min` and `max` using `splat`.
6ed1781 to
7f255a8
Compare
|
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. |
While adding tests, I ran into an interesting bug with the specific "hack" that @teor2345 I'm not sure if you're aware of this quirk already, but you can confirm it yourself by removing the
In happier news, Anyway, this is probably quirky enough and last minute enough that I think a re-review might be warranted? I'm happy to merge, but better safe than sorry. |
There was a problem hiding this comment.
Replacing the internals of stable min and max requires a perf run (and a check we have benchmarks for them). I'll ask for one.
Otherwise we're good here, thanks!
Looking forward to working out the weirdness around core tests, too, but in a separate ticket/PR.
| #[unstable(feature = "cmp_splat", issue = "160728")] | ||
| #[rustc_const_unstable(feature = "cmp_splat", issue = "160728")] | ||
| #[expect(private_bounds, reason = "`SmallestArgs` is an internal implementation detail")] | ||
| #[cfg(not(test))] // FIXME: splat interacts poorly with the double linking of `core` in tests |
There was a problem hiding this comment.
Non-blocking:
While adding tests, I ran into an interesting bug with the specific "hack" that
coreandallocuse to run tests. It appears that#[rustc_splat]creates a symbol that clashes whencoregets linked twice, similar to how incoherent implementations work.
Huh, symbol clashes between splatted and un-splatted function types were fixed in #158890, and we have regression tests for incremental and non-incremental compilation:
This is a vaguely similar bug, but here, the function symbol should just be the path. Makes me wonder if type mangling is involved, or it could be something to do with const-time checks.
It would be good to open a ticket, we'll work it out from there.
This is not a blocker for merging.
There was a problem hiding this comment.
Yeah my assumption is it has something to do with symbols since the "fix" is the same as what's used for incoherent implementations. The exact error was something along the lines of two crates (core and core) both being linked with identical hashes.
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Experiment: Add `core::cmp::smallest` and `core::cmp::largest`
|
Unless the perf run pulls up notable improvements, I'd be tempted to still say not to replace |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (06cbba6): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -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)Results (primary 1.0%, secondary 1.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 2.3%, secondary 6.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.1%, secondary 0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 459.695s -> 460.71s (0.22%) |
How does 0.1% in 2 benchmarks sound?
Agreed, I'll split off that commit for now. I've got a handful of specific tests included regardless, and I'm satisfied that my implementation matches the original. |
7f255a8 to
f7eb24d
Compare
|
this is very much within what we expect for noise ^^ i'd keep them separate. but i'm happy to see this, it means we could consider doing this in the near future |
|
I asked if we have runtime benchmarks for min/max on Zulip. Notes for a later implementation replacement PR: It's possible that we don't have any runtime benchmarks, or in the benchmarks that use them, it's a tiny amount of the overall run time. A quick local benchmark check would be good. Alternatively, we could check the new assembly on Godbolt is similar to the current assembly. |
|
agreed, but not a blocker for this PR ^^ based on blocking concerns being resolved, i think this is best followed up in subsequent PRs. @bors r+ |
Rollup of 8 pull requests Successful merges: - #159593 (merge ambiguity errors that blame the same inference variable) - #160687 (Experiment: Add `core::cmp::smallest` and `core::cmp::largest`) - #160856 (Replace infers and non-rigid aliases with `Ty/Const::Error` if param env normalization fails) - #160961 (bootstrap: Overhaul matching of command-line selectors to steps) - #160975 (Remove target argument from get_proc_macros) - #161023 (bootstrap: Replace the `exit!` macro with a function `helpers::exit_process`) - #160932 (Make tidy::Version public) - #161029 (mailmap: Update my default email)
Rollup merge of #160687 - bushrat011899:experiment_splat_min_max, r=nia-e Experiment: Add `core::cmp::smallest` and `core::cmp::largest` Tracking Issue: #160728 Zulip: [#t-libs-api/api-changes > variadic min/max](https://rust-lang.zulipchat.com/#narrow/channel/327149-t-libs-api.2Fapi-changes/topic/variadic.20min.2Fmax/with/570428142) # Description Adds variadic alternatives to `cmp::min` and `cmp::max` which use `#[rustc_splat]` to allow anywhere from 1 to 12 arguments to be compared. Twelve chosen as an arbitrary limit. This doesn't have a pre-existing ACP or tracking issue (linking the `splat` issue since it's the most relevant), so I've added these two functions, `smallest` and `largest` under a new feature, `cmp_splat`. This mostly exists to demonstrate a possible solution to the problem posited in the linked Zulip thread. Happy to close if undesirable, as my current focus is on `no_std` I/O.
|
Thank you for not moving One thing I would suggest as part of whatever PR does that later: write a (Note how the version in that perf run made a bunch of debug binaries bigger, for example. Of course it's debug so that might be fine, but it'd be worth thinking about.) |
Add const-compatible `cmp_splat` test
View all comments
Tracking Issue: #160728
Zulip: #t-libs-api/api-changes > variadic min/max
Description
Adds variadic alternatives to
cmp::minandcmp::maxwhich use#[rustc_splat]to allow anywhere from 1 to 12 arguments to be compared. Twelve chosen as an arbitrary limit. This doesn't have a pre-existing ACP or tracking issue (linking thesplatissue since it's the most relevant), so I've added these two functions,smallestandlargestunder a new feature,cmp_splat.This mostly exists to demonstrate a possible solution to the problem posited in the linked Zulip thread. Happy to close if undesirable, as my current focus is on
no_stdI/O.