-
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] save generic type data to index + basic search #26356
Conversation
r? @brson (rust_highfive has picked a reviewer for you, use r? to override) |
@@ -253,16 +253,26 @@ struct IndexItem { | |||
/// A type used for the search index. | |||
struct Type { | |||
name: Option<String>, | |||
// true both for Option<T> and T, false otherwise. | |||
generic: bool, | |||
ty_params: Box<Vec<Type>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why Box<Vec<..>>
? This is only useful in rare cases, Vec itself is already only three usize large.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I didn't know any better :). It was Box<Type>
initially to avoid infinite recursion, and when I changed to Vec
I didn't reconsider the Box
. Will change, thanks!
What's the impact on the search index file size? This is especially interesting/important for libstd. |
|
I'm somewhat wary about how we can effectively make use of this in searches, it looks like you want to match generic functions against searching for a signature, but there's no guarantee that generics with a bound are actually satisfied as part of the query, so it's possible to get a lot of bogus examples, right? |
That's correct, trait bounds are not handled in any way. I felt it would be too big of a project in itself and that this could be done incrementally. However, if you think it might not be too useful as it is, feel free to close this and maybe it can be reused later 😄. |
@alexcrichton what's your verdict? |
Ok, I'm a little worried about how the search is fairly lossy (doesn't match bounds, may not work on |
Haskell's hoogle is a separate project, I think (separate from their doc generator)? Maybe this too could develop faster and more productively as a separate project. |
This PR adds more complex type data for generics to the search index, such as:
for
fn identity<T>(x: T) -> T
, andfor
fn generic_option_stuff<T>(x: Option<T>) -> i32
On the frontend side, searches such as
char -> char
will match theidentity
function above. Similarly,string, string ->
will matchstd::env::set_var
. So the search logic only tries to particularize generic types against the given query. It only does so for "base" generic types (i.e.T
, notOption<T>
) -- but the information for this is already in the index, it's only the JS logic that needs improving.A problem that I couldn't figure out how to solve is getting the full type information for
self
. Currently, we have access to the type's name (via the parent stack, implemented in #23289), but that means for example that for a method on something likeMyOption<T>
we only getname: myoption, generic: false
. Also, please note that this does not take trait bounds into account. (#mvp)cc @alexcrichton