Skip to content
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

Make it possible to have const impls for Iterator #92433

Closed
wants to merge 5 commits into from

Conversation

fee1-dead
Copy link
Member

Currently based on #92432. PR is unblocked and considered to be ready when #92432 is merged and all the issue numbers are updated.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 30, 2021
@rust-highfive
Copy link
Collaborator

r? @dtolnay

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 30, 2021
@rust-log-analyzer

This comment has been minimized.

Comment on lines +2706 to +2722
F: ~const FnMut(&Self::Item) -> R,
F: ~const Drop,
R: ~const Try<Output = bool>,
R::Residual: Residual<Option<Self::Item>>,
{
#[inline]
fn check<I, V, R>(
mut f: impl FnMut(&I) -> V,
) -> impl FnMut((), I) -> ControlFlow<R::TryType>
where
V: Try<Output = bool, Residual = R>,
R: Residual<Option<I>>,
{
move |(), x| match f(&x).branch() {
ControlFlow::Continue(false) => ControlFlow::CONTINUE,
ControlFlow::Continue(true) => ControlFlow::Break(Try::from_output(Some(x))),
ControlFlow::Break(r) => ControlFlow::Break(FromResidual::from_residual(r)),
}
<<R as Try>::Residual as Residual<Option<Self::Item>>>::TryType:
~const Try<Output = Option<Self::Item>>,
<<R as Try>::Residual as Residual<Option<Self::Item>>>::TryType: ~const FromResidual,
Self::Item: ~const Drop,
{
pub struct Check<F>(F);

impl_const_closure! {
impl<F, I, V, R> const FnMut for Check<F>
where
F: ~const FnMut(&I) -> V,
F: ~const Drop,
I: ~const Drop,
V: ~const Try<Output = bool, Residual = R>,
R: Residual<Option<I>>,
R::TryType: ~const Try<Output = Option<I>>,
R::TryType: ~const FromResidual,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Holy boilerplate. 😬

Maybe we need some "everything ~const" sugar?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding ~const super traits could possibly make this easier, however it needs work and we need to wait for it to land in bootstrap to incoporate its changes.

@rust-log-analyzer

This comment has been minimized.

@fee1-dead fee1-dead marked this pull request as ready for review January 1, 2022 12:30
@fee1-dead fee1-dead changed the title [Draft] Make it possible to have const impls for Iterator Make it possible to have const impls for Iterator Jan 1, 2022
@fee1-dead fee1-dead marked this pull request as draft January 1, 2022 12:31
@fee1-dead fee1-dead marked this pull request as ready for review January 1, 2022 13:18
match self {
ControlFlow::Continue(..) => None,
ControlFlow::Continue(_x) => None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's up with that? please add a HACK comment referencing the issue that will allow us to go back to the previous

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, I remember this. Please open an issue for it and link it here

@camelid camelid added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 11, 2022
Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would prefer not to land this change until rustdoc's handling of ~const bounds is in better shape. Iterator is such a central trait, it's used all the time by beginners, and many of its signatures are gnarly enough already prior to this PR that I think it's not the right tradeoff to introduce this much noise and glitchiness into it right now.

Now is the time to tap the brakes a little on filling the standard library with ~const and allow rustdoc to catch up a little. Maybe if the rustdoc folks aren't already on top of it, one of you would be willing to shift some attention over there?

Below is a representative screenshot of before and after. The before is completely within the reach of a beginner to understand. The after is totally unintelligible.

Someone needs to figure out what to do in rustdoc to avoid these API docs becoming unintelligible in the presence of ~const. Do ~const Drop bounds need to be signaled at all? Do ~const bounds need to be shunted behind an "expand" toggle or accordion or something?

Screenshot from 2022-01-15 19-46-18
Screenshot from 2022-01-15 19-46-29

@rust-lang/libs-api @rust-lang/libs @rust-lang/libs-contributors

@dtolnay dtolnay added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 16, 2022
@BurntSushi
Copy link
Member

Not only is that signature unintelligible to beginners, it's also unintelligible to at least one libs-api member. I don't know what ~const is.

@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jan 16, 2022
@fee1-dead
Copy link
Member Author

With the current change and x doc --stage 1 most of the changes in rustdoc have been fixed. But there are still some regressions for some nightly apis: try_find and try_reduce.

The ~const modifier should not be shown at all. It is still experimental at this point and its syntax might change.

image
image

@fee1-dead fee1-dead removed the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Jan 17, 2022
@dtolnay dtolnay added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 22, 2022
@fee1-dead
Copy link
Member Author

Just concealing the ~const doesn't solve the comprehensibility issue here.

You just found another issue that was introduced in #92229. Basically that PR removes ~const Drop bounds but the whole where clause is still kept.

Would you be willing to engage with the rustdoc folks explicitly to work out a plan for reducing the negative impact of the ~const work on documentation?

Yes, but most of the work needed (for rustdoc) is done in this PR, and the best way forward would be changes from the language side i.e. ~const super traits, and ~const associated type bounds that removes the need for bounds like <T as IntoIterator>::IntoIter: ~const Iterator on some of these methods.

The specific regression has been fixed. After a thorough review I think the latest change only introduces minor noise on some methods and only major bound jargon on unstable try_reduce and try_find. Sorry for bothering you with back and forth reviewing, I should have reviewed the doc changes before I opened this PR :/

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 22, 2022
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point I still don't find this an acceptable regression in the usability of the Iterator docs. I put more Before/After below. Someone from @rust-lang/libs-api should feel free to let me know if I am being too picky on this. I feel there needs to be more design work from the rustdoc side to find a way to simplify and present the more complex bounds that ~const seems to necessitate.

I'm going to remove this PR from review by converting it to a draft and I don't plan to review it again, but would ask the author to send any rustdoc work separately for review by the rustdoc folks, or guidance on how to proceed here. We can keep this PR open as a draft to hold rebases of the Iterator changes for comparison as any rustdoc fixes start landing in other PRs.

Before After
Screenshot from 2022-01-27 21-02-47 Screenshot from 2022-01-27 21-02-59
Screenshot from 2022-01-27 21-06-02 Screenshot from 2022-01-27 21-06-11
Screenshot from 2022-01-27 21-06-38 Screenshot from 2022-01-27 21-06-48

@dtolnay dtolnay marked this pull request as draft January 28, 2022 05:18
@dtolnay dtolnay removed their assignment Jan 28, 2022
@fee1-dead
Copy link
Member Author

In order to make no changes to the library documentation, we need two things:

  1. Small tweaks on rustdoc's side, Improve rustdoc const bounds #93412
  2. Improve our traits' API by adding ~const in assoc type bounds and super traits. (To avoid inserting extra bounds at the generic functions that use those traits) Super traits require Allow trait A: ~const B #93429 to land in bootstrap first.

There is another option which could be easier: Add an attribute to configure and prevent rustdoc from showing the actual complexity and show a minimized version, rustdoc_show_these_generics_instead_of_def(where ...)

@bors
Copy link
Contributor

bors commented Jan 29, 2022

☔ The latest upstream changes (presumably #93457) made this pull request unmergeable. Please resolve the merge conflicts.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 6, 2022
…nds, r=GuillaumeGomez

Improve rustdoc const bounds

 - Rustdoc no longer displays `~const` in trait bounds, because it currently means nothing for stable users, and because we still haven't decided on the final syntax yet.
 - Rustdoc will hide trait bounds where the trait is `Drop` AND it is `~const`, i.e. `~const Drop` bounds because it has no effect on stable users as well.
 - Because of additional logic that hides the whole `where` statement where it consists of `~const Drop` bounds (so it doesn't display `struct Foo<T>() where ;` like that), bounds that have no trait e.g. `where [T; N+1]: ;` are also hidden.

Cherry-picked from rust-lang#92433.
@Dylan-DPC
Copy link
Member

@fee1-dead any updates on this?

@fee1-dead fee1-dead added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 9, 2022
@fee1-dead
Copy link
Member Author

@fee1-dead any updates on this?

currently blocked on several other changes

@fee1-dead fee1-dead closed this Nov 21, 2022
@fee1-dead fee1-dead deleted the const-it branch November 21, 2022 14:29
@dtolnay dtolnay self-assigned this Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-blocked Status: Blocked on something else such as an RFC or other implementation work. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.