-
Couldn't load subscription status.
- Fork 13.9k
rustdoc-search: simplify rules for generics and type params #127589
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
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. |
|
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. |
|
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. |
|
Thanks everyone! @bors r+ |
|
☀️ Test successful - checks-actions |
|
Finished benchmarking commit (d4822c2): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowOur benchmarks found a performance regression caused by this PR. Next Steps:
@rustbot label: +perf-regression Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (secondary 0.1%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (secondary 1.6%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 787.302s -> 785.736s (-0.20%) |
|
This PR adds the name of the generic type parameter to the search index. That information takes time to gather and serialize. @rustbot label: +perf-regression-triaged |

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 -> UCx -> TyCtxtDescription
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 ifBis in the error type andAis in the success type. The top level of the function search is unaffected.i32 -> strand get back a function with the type signature&Future<i32> -> Box<str>.Find the discussion on