-
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
rustdoc-search: simplify rules for generics and type params #127589
base: master
Are you sure you want to change the base?
Conversation
Some changes occurred in HTML/CSS/JS. cc @GuillaumeGomez, @jsha Some changes occurred in GUI tests. |
This comment has been minimized.
This comment has been minimized.
0c751b2
to
104a4eb
Compare
104a4eb
to
759df53
Compare
☔ The latest upstream changes (presumably #128253) made this pull request unmergeable. Please resolve the merge conflicts. |
759df53
to
29d228b
Compare
Excellent, this is great—thanks! Although do you mind clarifying what you mean by "The top level of the function search is unaffected"? Could you give an example?
Hmm, this seems like the opposite of what we discussed in the meeting. The goal is to have a 1:1 matching, not N:1, so (using your example)
The older rule seems to be N:1 too based on checking the nightly std docs, so I'm not sure what change this PR makes. Please correct me if I misunderstood. One more thing: What does it mean for a generic parameter to be "unboxed" as compared to being "matched"? |
The actual function parameters can be given in any order. The stuff within the
That's how it currently works in the master branch, but #124544 (comment) by @jsha asked for this change. "One last suggestion: What if we removed the feature of requiring
The older rule was 1:1. I suspect that almost all of the confusion about rustdoc's type-driven search comes from reordering, which is why I'm happy to remove it.
Given a function with this signature: I can search for it with this query: That is, the generic parameter |
Sounds good 👍
Hmm, seems like we'll need to have more team discussion on this point then. It sounds like fmease and I are in favor of the stricter " However, it seems that implementing the former approach properly might require rethinking some aspects of the search design and implementation. Namely, it seems that currently This may all be too difficult to implement especially given the constraints of using browser JS. Or we may decide that we want a looser behavior in fact. But I wanted to lay this out to make sure we're explicit about the decision.
That is probably true, and I agree that removing reordering is the most important change. Figuring out how exactly generics are interpreted is a bigger discussion that may be best handled in a future PR.
Thanks 👍 |
After posting my reply, I went to read @jsha's original comment, and it made me wonder if what actually bothered him was reordering. I suspect that after reordering is removed, it behaves fine in general and with defaulted type parameters. IMO, requiring them to match different types is also not unusual since it more closely matches (though definitely not completely) the normal semantics of generics in Rust. Allowing
|
It only matches parameters. For example,
As it says in the where clause, "A matches T", the VecDequeue's first type parameter, not VecDequeue itself. That's also why the word "VecDequeue" is not bold. |
We're going to need to decide this at some point. This PR is as good a point as any, provided the other PR, adding the user-visible type signatures to the search results, isn't blocked. |
Ah, I think I was confused because
So when we search, it can match something inside another type? That seems a bit counterintuitive to me and like it would generate excess results. Was this added so that |
You're basically correct about the reasoning, yes. Hoogle mentioned it in their design docs. https://ndmitchell.com/downloads/slides-hoogle_finding_functions_from_types-16_may_2011.pdf "A note on 'boxing'". For example, However, it looks like they only do it with special-cased types? https://github.com/ndmitchell/hoogle/blob/8149c93c40a542bf8f098047e1acbc347fc9f4e6/docs/TypeSearch.md#rewrites describes a special rule, and when I try to test it, I can only see boxing with Maybe and IO. I didn't special-case anything because it's not clear which things should be special-cased for Rust.
Yup, that's bad. The blanket impl is being translated wrong. |
rustdoc: Fix handling of `Self` type in search index and refactor its representation ### Summary - Add enum variant `clean::Type::SelfTy` and use it instead of `clean::Type::Generic(kw::SelfUpper)`. - Stop treating `Self` as a generic in the search index. - Remove struct formerly known as `clean::SelfTy` (constructed as representation of function receiver type). We're better off without it. ### Before ![image](https://github.com/user-attachments/assets/d257bdd8-3a62-4c71-84a5-9c950f2e4f00) ### After ![image](https://github.com/user-attachments/assets/8f6d3f22-92c1-41e3-9ab8-a881b66816c0) r? `@notriddle` cc rust-lang#127589 (comment)
rustdoc: Fix handling of `Self` type in search index and refactor its representation ### Summary - Add enum variant `clean::Type::SelfTy` and use it instead of `clean::Type::Generic(kw::SelfUpper)`. - Stop treating `Self` as a generic in the search index. - Remove struct formerly known as `clean::SelfTy` (constructed as representation of function receiver type). We're better off without it. ### Before ![image](https://github.com/user-attachments/assets/d257bdd8-3a62-4c71-84a5-9c950f2e4f00) ### After ![image](https://github.com/user-attachments/assets/8f6d3f22-92c1-41e3-9ab8-a881b66816c0) r? ``@notriddle`` cc rust-lang#127589 (comment)
rustdoc: Fix handling of `Self` type in search index and refactor its representation ### Summary - Add enum variant `clean::Type::SelfTy` and use it instead of `clean::Type::Generic(kw::SelfUpper)`. - Stop treating `Self` as a generic in the search index. - Remove struct formerly known as `clean::SelfTy` (constructed as representation of function receiver type). We're better off without it. ### Before ![image](https://github.com/user-attachments/assets/d257bdd8-3a62-4c71-84a5-9c950f2e4f00) ### After ![image](https://github.com/user-attachments/assets/8f6d3f22-92c1-41e3-9ab8-a881b66816c0) r? ```@notriddle``` cc rust-lang#127589 (comment)
Rollup merge of rust-lang#128471 - camelid:rustdoc-self, r=notriddle rustdoc: Fix handling of `Self` type in search index and refactor its representation ### Summary - Add enum variant `clean::Type::SelfTy` and use it instead of `clean::Type::Generic(kw::SelfUpper)`. - Stop treating `Self` as a generic in the search index. - Remove struct formerly known as `clean::SelfTy` (constructed as representation of function receiver type). We're better off without it. ### Before ![image](https://github.com/user-attachments/assets/d257bdd8-3a62-4c71-84a5-9c950f2e4f00) ### After ![image](https://github.com/user-attachments/assets/8f6d3f22-92c1-41e3-9ab8-a881b66816c0) r? ```@notriddle``` cc rust-lang#127589 (comment)
To clarify my previous comment:
Maybe after removing reordering, the
I don't understand this. It seems to me the opposite is true. I wrote previously:
So for instance |
4946c07
to
bbdd6e8
Compare
This comment has been minimized.
This comment has been minimized.
bbdd6e8
to
eb5487e
Compare
I've added the unboxing flag feature in another commit (and also rebased onto head). It now does unboxing on Box, &, Future, Option, Result, and (Tuple), but not anything else. As for the
It sounds like you also want type params in the search query to match with concrete types in the function, and not just with the function's own type params. I'm not sure that's very useful. First of all, it's not how Hoogle works. If I run a search Second of all, the use case I have in mind is that someone's searching for a function because they plan to call it, so the stuff before the arrow is what they have, while the stuff after the arrow is what they want to get. If they're writing a type param, it's probably because they are themselves authoring a generic function. |
☔ The latest upstream changes (presumably #129809) made this pull request unmergeable. Please resolve the merge conflicts. |
eb5487e
to
3936dd1
Compare
This comment has been minimized.
This comment has been minimized.
3936dd1
to
f7500c7
Compare
☔ The latest upstream changes (presumably #131078) made this pull request unmergeable. Please resolve the merge conflicts. |
this is ultimately an issue of universal qualification vs existential qualification vs some halfway compromise that may be less confusing for new users, but also lacks formal backing formally speaking, there are two ways type variables can exist: there's the regular "for all T" type variables that rust tends to use (universal qualification) there's also "there exists some T" type variables (existential qualification). in rust these corrospond to impl Trait in return position if rustdoc search treats type variables as universally quantified, it makes sense for them to match only other generics, and also to have the A != B if rustdoc search treats them as existential, removing A != B makes sense, but it would also make sense for them to be able to match concrete types |
This reduces code size while still matching the common case for plain, concrete types.
This commit is a response to feedback on the displayed type signatures results, by making generics act stricter. Generics are tightened by making order significant. This means `Vec<Allocator>` now matches only with a true vector of allocators, instead of matching the second type param. It also makes unboxing within generics stricter, so `Result<A, B>` only matches if `B` is in the error type and `A` is in the success type. The top level of the function search is unaffected. Find the discussion on: * <https://rust-lang.zulipchat.com/#narrow/stream/393423-t-rustdoc.2Fmeetings/topic/meeting.202024-07-08/near/449965149> * <rust-lang#124544 (comment)> * <https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/deciding.20on.20semantics.20of.20generics.20in.20rustdoc.20search/near/476841363>
f7500c7
to
12dc24f
Compare
It seems like everyone but @jsha wants A != B semantics for search. Am I understanding that correctly? |
Team member @notriddle 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! See this document for info about what commands tagged team members can give me. |
@rfcbot reviewed |
@rfcbot reviewed Thanks for the hard work! The results look great. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
Heads up!: This PR is a follow-up that depends on #124544. It adds 12dc24f, a change to the filtering behavior, and 9900ea4, a minor ranking tweak.
Part of rust-lang/rust-project-goals#112
This PR overturns #109802
Preview
Box<[A]> -> Vec<B>
Box<[A]> -> Vec<A>
T -> U
Cx -> TyCtxt
Description
This commit is a response to feedback on the displayed type signatures results, by making generics act stricter.
Vec<Allocator>
now matches only with a true vector of allocators, instead of matching the second type param. It also makes unboxing within generics stricter, soResult<A, B>
only matches ifB
is in the error type andA
is in the success type. The top level of the function search is unaffected.i32 -> str
and get back a function with the type signature&Future<i32> -> Box<str>
.Find the discussion on