-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Treat other items as functions for the purpose of type-based search #131806
Treat other items as functions for the purpose of type-based search #131806
Conversation
This comment has been minimized.
This comment has been minimized.
The test failure in the gui test doesn't seem like a bug. It really is finding an item that it didn't use to find. You can just bump the number. |
Some changes occurred in GUI tests. |
This comment has been minimized.
This comment has been minimized.
Looks nice @rfcbot poll is this a good idea? |
Team member @notriddle has asked teams: T-rustdoc-frontend, for consensus on:
|
i just realized something: since this is implemented in rust code, unlike my other PRs, we don't have to make this insta-stable, it would actually be pretty easy to gate this behind a nightly feature (similarly to what is done with rustdoc-json) i would honestly prefer running this as a t-rustdoc experiment first, since it still has a few unresolved questions (eg. how it will interact with generics) personally, i would like to ship a MVP as a nightly-only feature, allowing me to start getting user feedback while i continue to iterate on it. |
We could, technically, put this behind a Making it a javascript Settings option would get it in front of more people. |
hmm.. i guess that would involve explicitly filtering only functions when doing type-based search unless that setting was enabled? |
Exactly, yes. |
That seems extremely strange to have constants and statics when we filter on functions. |
It's how hoogle works. treating constants as pure nullary functions is not that unusual, especially if we're treating field accessors as unary functions. when someone searches the alternative is having different syntaxes for every way to get a value... which is more work both in implementation complexity, and also for users, who now have to perform 3 different queries to see every way they can construct a certain type. |
I see, thanks for the explanation. With this point of view, it indeed does make sense. The only requirement for this change for me will then to have documentation explaining what you just wrote. Sounds like a nice improvement. |
It seems like we're all in agreement that this should be done, but the next question is how? insta-stable, settings panel, or nightly feature? how i write the documentation will depend on how it is implemented. |
As far as I know, any change in search is insta-stable. As for how to implement it, what are the different ways you see? |
well, since this is actually implemented in rust, and not js, we do actually have easy access to feature gates, although it might be a bit confusing.
I just mean should it be gated behind anything, because if it is, i'll add an extra section for it, but if not, i'll replace/modify the existing type-based search section. |
Changes to search are usually insta-stable. It's not an API, so if something turns out to be a bad idea, we can undo it. |
somehow #132123 didn't cause a merge conflict?? |
I can see this making sense for consts and statics, but it feels like a stretch to consider struct fields as unary functions -- it also doesn't seem useful. |
the point is to improve devx in the case where you are looking for a getter method, but there isn't one, since you are expected to just access the field directly. this is especially common with things like as i explained to GG:
|
I agreed for consts and statics, not for fields. ^^' I agree with @camelid: it's too much of a fetch here. I'm not sure trying to reach parity with hoogle should be a goal for rustdoc either. |
But why consts and statics, then? What makes them different from fields? |
Probably the biggest concern I have with fields is it feels like noise. For most structs, you already know what the fields are just from the sidebar of the struct's page. When I search for e.g. I don't feel super strongly about this, but comparing it to Hoogle is a little bit of a false comparison because in Haskell fields are actually functions (and same with constants). In Rust, it's more of an analogy -- we don't have |
Hm, I hadn't considered this form of search. I would say we can de-prioritize fields when no return type is given, but I'd like to wait and do that in a follow-up PR. |
It would certainly be possible to exclude fields from the single-element type-based queries: diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js
index eed64d024c0..f41975bf759 100644
--- a/src/librustdoc/html/static/js/search.js
+++ b/src/librustdoc/html/static/js/search.js
@@ -52,6 +52,7 @@ const itemTypes = [
// used for special search precedence
const TY_GENERIC = itemTypes.indexOf("generic");
const TY_IMPORT = itemTypes.indexOf("import");
+const TY_STRUCTFIELD = itemTypes.indexOf("structfield");
const ROOT_PATH = typeof window !== "undefined" ? window.rootPath : "../";
// Hard limit on how deep to recurse into generics when doing type-driven search.
@@ -2984,7 +2985,7 @@ class DocSearch {
fullId,
parsedQuery.typeFingerprint,
);
- if (tfpDist !== null) {
+ if (tfpDist !== null && row.ty !== TY_STRUCTFIELD) {
const in_args = row.type && row.type.inputs
&& checkIfInList(row.type.inputs, elem, row.type.where_clause, null, 0);
const returned = row.type && row.type.output
@@ -3285,6 +3286,9 @@ class DocSearch {
parsedQuery.elems.sort(sortQ);
parsedQuery.returned.sort(sortQ);
for (let i = 0, nSearchIndex = this.searchIndex.length; i < nSearchIndex; ++i) {
+ if (this.searchIndex[i].ty === TY_STRUCTFIELD && parsedQuery.foundElems === 1) {
+ continue;
+ }
handleArgs(this.searchIndex[i], i, results_others);
}
} The other option is to make the ranking algorithm sort them lower. diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js
index eed64d024c0..349db638986 100644
--- a/src/librustdoc/html/static/js/search.js
+++ b/src/librustdoc/html/static/js/search.js
@@ -52,6 +52,7 @@ const itemTypes = [
// used for special search precedence
const TY_GENERIC = itemTypes.indexOf("generic");
const TY_IMPORT = itemTypes.indexOf("import");
+const TY_STRUCTFIELD = itemTypes.indexOf("structfield");
const ROOT_PATH = typeof window !== "undefined" ? window.rootPath : "../";
// Hard limit on how deep to recurse into generics when doing type-driven search.
@@ -2144,6 +2144,13 @@ class DocSearch {
return a - b;
}
+ // sort fields lower in type-based search
+ a = aaa.item.ty === TY_STRUCTFIELD;
+ b = bbb.item.ty === TY_STRUCTFIELD;
+ if (a !== b && isType) {
+ return a - b;
+ }
+
// Sort by distance in the name part, the last part of the path
// (less changes required to match means higher rankings)
a = (aaa.dist);
All else being equal, I prefer ranking. Also, by that reasoning, shouldn't we also exclude methods? |
@bors r=notriddle rollup |
…-func, r=notriddle Treat other items as functions for the purpose of type-based search specifically, constants and statics are nullary functions, and struct fields are unary functions. fixes rust-lang#130204 r? `@notriddle`
…llaumeGomez Rollup of 6 pull requests Successful merges: - rust-lang#131806 (Treat other items as functions for the purpose of type-based search) - rust-lang#132654 (std: lazily allocate the main thread handle) - rust-lang#135003 (deprecate `std::intrinsics::transmute` etc, use `std::mem::*` instead) - rust-lang#135428 (rustdoc: Remove `AttributesExt` trait magic that added needless complexity) - rust-lang#135498 (Prefer lower `TraitUpcasting` candidates in selection) - rust-lang#135529 (remove outdated FIXME) r? `@ghost` `@rustbot` modify labels: rollup
Is this a bug in the test suite? The failure is from the test introduced in #135302, and seems to want |
i'm pretty sure this is a bug in error_text.push(queryName + "==> '" + JSON.stringify(elem) + "' was supposed " +
"to be before '" + JSON.stringify(results[key][entry_pos]) + "'"); the second part should be using
this conflicts with what the error message suggests is printed. |
constants and statics are nullary functions, and struct fields are unary functions. functions (along with methods and trait methods) are prioritized over other items, like fields and constants.
fe6deb0
to
9397d13
Compare
@bors r+ |
…-func, r=notriddle Treat other items as functions for the purpose of type-based search specifically, constants and statics are nullary functions, and struct fields are unary functions. fixes rust-lang#130204 r? `@notriddle`
…, r=notriddle fix error for when results in a rustdoc-js test are in the wrong order see rust-lang#131806 (comment)
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#131806 (Treat other items as functions for the purpose of type-based search) - rust-lang#134290 (Windows x86: Change i128 to return via the vector ABI) - rust-lang#134980 (Location-sensitive polonius prototype: endgame) - rust-lang#135558 (Detect if-else chains with a missing final else in type errors) - rust-lang#135594 (fix error for when results in a rustdoc-js test are in the wrong order) - rust-lang#135601 (Fix suggestion to convert dereference of raw pointer to ref) - rust-lang#135604 (Expand docs for `E0207` with additional example) r? `@ghost` `@rustbot` modify labels: rollup
…, r=notriddle fix error for when results in a rustdoc-js test are in the wrong order see rust-lang#131806 (comment)
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#131806 (Treat other items as functions for the purpose of type-based search) - rust-lang#134980 (Location-sensitive polonius prototype: endgame) - rust-lang#135558 (Detect if-else chains with a missing final else in type errors) - rust-lang#135594 (fix error for when results in a rustdoc-js test are in the wrong order) - rust-lang#135601 (Fix suggestion to convert dereference of raw pointer to ref) - rust-lang#135604 (Expand docs for `E0207` with additional example) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#135594 - lolbinarycat:tester.js-order-error, r=notriddle fix error for when results in a rustdoc-js test are in the wrong order see rust-lang#131806 (comment)
Rollup merge of rust-lang#131806 - lolbinarycat:rustdoc-search-all-is-func, r=notriddle Treat other items as functions for the purpose of type-based search specifically, constants and statics are nullary functions, and struct fields are unary functions. fixes rust-lang#130204 r? ``@notriddle``
specifically, constants and statics are nullary functions, and struct fields are unary functions.
fixes #130204
r? @notriddle