-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tracking issue for RFC 2351, "Add is_sorted
to the standard library"
#53485
Comments
@gnzlbg Would you be interested in implementing this? You basically already wrote the code. I think it would be fancy to have this SIMD code in the standard library. (Or should we start with only the fully generic algorithm?). PS: Sorry for not having reviewed #53386 yet -- I hope I'll find the time and mental capacity to do that in the near future! @Centril The links for the unresolved questions are dead (still pointing to the 0000 file). Could you or anyone update them? :) Regarding the "Should
And people seem to agree. So I'd also say that this method should be added. |
@LukasKalbertodt done :) |
cc @SimonSapin re. the unresolved questions (particularly around |
I don't know when I can work on this, but I can mentor anyone wanting to implement this or wanting to port the implementation of the |
Oh, I didn’t realized that We do have precedent of adding some APIs that can be expressed as a terse combination of existing APIs: #49098 @clarcharr, you expressed the opposite in rust-lang/rfcs#2351 (comment). Do you still think it should not be included? |
At the time I made that comment, I didn't realise that
I feel like the usefulness of these should be re-evaluated, as it forces the key to outlive any reference to Personally, I'd prefer option 1. But option 2 is also acceptable and there may be a way to make these functions work with GAT in the future. |
@SimonSapin would you like to be the reviewer of a PR implementing this ? If so, I'd like to discuss with somebody first how the is_sorted crate is structure, and how to best implement this functionality in the std library. |
So I don't know how to properly implement this in The After talking with @SimonSapin on IRC, I am just going to add the naive versions to |
I have interest in working on this RFC. This would be a significant learning experience for me, but I don't see any reason why I should not be able to complete it. @gnzlbg If your offer for being available as a mentor is still open, I'd like to take you up on that! If there is any concern in timeline (I should be able to begin implementing this week) or preference for someone who may have more experience, I have no problem with that; just let me know! |
An efficient implementation of this is probably blocked on rust-lang/rfcs#2492 (e.g. see rust-lang/rfcs#2492 (comment)) , since until then we cannot really use SIMD in My recommendation is that if you want to implement this now, you should just adapt rust-itertools/itertools#261 which is a straight-forward plain Rust implementation. Maybe with some tweaks one can get it to auto-vectorize in some cases. This would allow us to get experience with the API until the other problems are solved. |
Thanks for the links; it makes sense that a more efficient implementation is blocked on that right now. To clarify on my initial comment (and what you picked up on in your last sentence), is the "learning" part of this would be more related to familiarizing myself with the API and codebase. I think an initial implementation based off rust-itertools/itertools#261 could be a good first step and we'll keep an eye on the progress of rust-lang/rfcs#2492? |
@SimonSapin It was asked a few comments up if you'd like to be the reviewer of this PR? I still need to assign someone to review it, but I'm just not sure who. |
Add `is_sorted` to `Iterator` and `[T]` This is an initial implementation for the first step of [RFC 2351](https://github.com/rust-lang/rfcs/blob/master/text/2351-is-sorted.md) Tracking issue: #53485
This has broken the is_sorted crate on nightly. Is the only workaround to turn the feature flag on or use an older nightly?
|
Call IsSorted::is_sorted directly. |
@clarcharr The above error happens when adding |
You can send a PR to the is_sorted crate and use the patch section in your Cargo.toml in the meantime until it is merged and published. |
@mtak- thank you for the PR, i've merged it already, will fix the doc tests and do a release so that the world keeps going. The collision between the |
Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
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! See this document for info about what commands tagged team members can give me. |
My first reaction to these APIs was to find it odd that
The If we used What pieces am I missing here? Is there something more definitive pushing us toward |
If you have |
On
I read it as "is it sorted how you want", asc, desc, in a circle, etc. I agree the API inconsistency should be explicitly addressed as ok or not. Addendum (I know tracking tickets aren't the right place for this):Leaving the meaning blank actually feels more flexible; you get to use |
@rfcbot concern inconsistent-with-sort I'm registering this concern because I'm not a fan of the inconsistency between these APIs and our existing
Yeah but as #34162 demonstrates, you often need to use
I guess this makes sense. It wasn't what I saw on first impression, but I suppose that can be fixed with docs.
I don't think I want to get into a "what's easier to read as a comparator, I think I overall need this inconsistency spelled out a bit more for me. Like I said, I'm not trying to say we should be consistent for consistency's sake. ("A foolish consistency is the hobgoblin of little minds.") But that consistency has value and I'm not sure we're gaining enough to justify throwing away that value here. |
I do personally think that the function returning Suggestion: could we go ahead and do an FCP to stabilize |
Nominating for us to sort this out. |
This could lead to a frustrating state of affairs ("I can almost use |
Responding to the "why are we doing it differently here?" part: We use |
Perhaps we should instead call it That might hurt discoverability, but it also might make it much clearer that this is useful for other (non sorting) use cases too. |
Additionally, there is precedent for comparison closures returning a |
We already have |
I found this phrasing compelling. Thank you! @rfcbot resolve inconsistent-with-sort |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
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. This will be merged soon. |
Stabilize `is_sorted` Closes: rust-lang#53485. ~~Question: does~~ https://github.com/rust-lang/rust/blob/8fe0c753f23e7050b87a444b6622caf4d2272d5d/compiler/rustc_lint_defs/src/builtin.rs#L1986-L1994 ~~need a new example?~~ edit: It causes a test failure and needs to be changed anyway. `@rustbot` label: +T-libs-api r? libs-api
Rollup merge of rust-lang#128279 - slanterns:is_sorted, r=dtolnay Stabilize `is_sorted` Closes: rust-lang#53485. ~~Question: does~~ https://github.com/rust-lang/rust/blob/8fe0c753f23e7050b87a444b6622caf4d2272d5d/compiler/rustc_lint_defs/src/builtin.rs#L1986-L1994 ~~need a new example?~~ edit: It causes a test failure and needs to be changed anyway. ``@rustbot`` label: +T-libs-api r? libs-api
Feature gate:
#![feature(is_sorted)]
This is a tracking issue for
is_sorted{_by,_by_key}
functions on[T]
andIterator
(rust-lang/rfcs#2351).Public API
Steps / History
is_sorted
toIterator
and[T]
#55045[T]::is_sorted_by{,_key}
#102977Unresolved Questions
Ord
instead of onlyPartialOrd
?is_sorted[_by_key]
requireOrd
instead ofPartialOrd
and removeIterator::is_sorted_by_key
#81382 (comment) (no,PartialOrd
is the right bound)Iterator::is_sorted_by_key
be added as well?std::cmp::is_sorted
instead?is_sorted_by
take a closure returningbool
instead ofOption<Ordering>
?bool
instead ofPartiolOrd
as return value of the comparison closure in{slice,Iteraotr}::is_sorted_by
#118811Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩
The text was updated successfully, but these errors were encountered: