about summary refs log tree commit diff
path: root/src/librustdoc/html
AgeCommit message (Collapse)AuthorLines
2023-12-17Auto merge of #119001 - notriddle:notriddle/searchwords, r=GuillaumeGomezbors-46/+28
rustdoc-search: remove parallel searchWords array This might have made sense if the algorithm could use `searchWords` to skip having to look at `searchIndex`, but since it always does a substring check on both the stock word and the normalizedName, it doesn't seem to help performance anyway. Profile: http://notriddle.com/rustdoc-html-demo-8/searchwords/index.html
2023-12-15Rollup merge of #119004 - matthiaskrgr:conv, r=compiler-errorsJubilee-1/+1
NFC don't convert types to identical types
2023-12-15rustdoc-search: remove parallel searchWords arrayMichael Howell-46/+28
This might have made sense if the algorithm could use `searchWords` to skip having to look at `searchIndex`, but since it always does a substring check on both the stock word and the normalizedName, it doesn't seem to help performance anyway.
2023-12-15NFC don't convert types to identical typesMatthias Krüger-1/+1
2023-12-15Rollup merge of #118727 - compiler-errors:lint-decorate, r=WaffleLapkinJubilee-6/+4
Don't pass lint back out of lint decorator Change the decorator function in the signature of the `emit_lint`/`span_lint`/etc family of methods from `impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>) -> &'b mut DiagnosticBuilder<'a, ()>` to `impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>)`. I consider it easier to read this way, especially when there's control flow involved. r? nnethercote though feel free to reassign
2023-12-15Rollup merge of #118986 - GuillaumeGomez:simplify-js-inline, r=notriddleMatthias Krüger-2/+2
Simplify JS code a little bit As mentioned, JS code can be simplified a little bit. r? ``@notriddle``
2023-12-15Rollup merge of #118977 - GuillaumeGomez:simplifysrc-script, r=notriddleMatthias Krüger-12/+3
Simplify `src-script.js` code Instead of keeping this value in the global scope and still use it in the function in case it wasn't used outside, let's just use it inside the function. r? ``@notriddle``
2023-12-15Don't pass lint back out of lint decoratorMichael Goulet-6/+4
2023-12-15Simplify JS code a little bitGuillaume Gomez-2/+2
2023-12-15Auto merge of #118975 - GuillaumeGomez:rollup-0emhjx0, r=GuillaumeGomezbors-34/+509
Rollup of 4 pull requests Successful merges: - #113091 (Don't merge cfg and doc(cfg) attributes for re-exports) - #115660 (rustdoc: allow resizing the sidebar / hiding the top bar) - #118863 (rustc_mir_build: Enforce `rustc::potential_query_instability` lint) - #118909 (Some cleanup and improvement for invalid ref casting impl) r? `@ghost` `@rustbot` modify labels: rollup
2023-12-15Simplify `src-script.js` codeGuillaume Gomez-12/+3
2023-12-15Rollup merge of #115660 - notriddle:notriddle/sidebar-resize, r=GuillaumeGomezGuillaume Gomez-23/+507
rustdoc: allow resizing the sidebar / hiding the top bar Fixes #97306 Preview: http://notriddle.com/rustdoc-html-demo-4/sidebar-resize/std/index.html ![image](https://github.com/rust-lang/rust/assets/1593513/a2f40ea2-0436-4e44-99e8-d160dab2a680) ## Summary This feature adds: 1. A checkbox to the Settings popover to hide the persistent navigation bar (the sidebar on large viewports and the top bar on small ones). 2. On large viewports, it adds a resize handle to the persistent sidebar. Resizing it into nothing is equivalent to turning off the persistent navigation bar checkbox in Settings. 3. If the navigation bar is hidden, a toolbar button to the left of the search appears. Clicking it brings the navigation bar back. ## Motivation While "mobile mode" is definitely a good default, it's not the only reason people have wanted to hide the sidebar: * Some people use tiling window managers, and don't like rustdoc's current breakpoints. Changing the breakpoints might help with that, but there's no perfect solution, because there's a gap between "huge screen" and "smartphone" where reasonable people can disagree about whether it makes sense for the sidebar to be on-screen. https://github.com/rust-lang/rust/issues/97306 * Some people ask for ways to reduce on-screen clutter because it makes it easier to focus. There's not a media query for that (and if there was, privacy-conscious users would turn it off). https://github.com/rust-lang/rust/issues/59829 This feature is designed to avoid these problems. Resizing the sidebar especially helps, because it provides a way to hide the sidebar without adding a new top-level button (which would add clutter), and it provides a way to make rustdoc play nicer in complex, custom screen layouts. ## Guide and Reference-level explanation On a desktop or laptop with a mouse, resize the sidebar by dragging its right edge. On any browser, including mobile phones, the sticky top bar or side bar can be hidden from the Settings area (the button with the cog wheel, next to the search bar). When it's hidden, a convenient button will appear on the search bar's left. ## Drawbacks This adds more JavaScript code to the render blocking area. ## Rationale and alternatives The most obvious way to allow people to hide the sidebar would have been to let them "manually enter mobile mode." The upside is that it's a feature we already have. The downside is that it's actually really hard to come up with a terse description. Is it: * A Setting that forces desktop viewers to always have the mobile-style top bar? If so, how do we label it? Should it be visible on mobile, and, if so, does it just not do anything? * A persistent hide/show sidebar button, present on desktop, just like on mobile? That's clutter that I'd like to avoid. ## Prior art * The new file browser in GitHub uses a similar divider with a mouse-over indicator * mdBook and macOS Finder both allow you to resize the sidebar to nothing as a gesture to hide it * https://www.nngroup.com/articles/drag-drop/ ## Future possibilities https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/Table.20of.20contents proposes a new, second sidebar (a table of contents). How should it fit in with this feature? Should it be resizeable? Hideable? Can it be accessed on mobile?
2023-12-15Rollup merge of #113091 - GuillaumeGomez:prevent-cfg-merge-reexport, r=rustdocGuillaume Gomez-11/+2
Don't merge cfg and doc(cfg) attributes for re-exports Fixes #112881. ## Explanations When re-exporting things with different `cfg`s there are two things that can happen: * The re-export uses a subset of `cfg`s, this subset is sufficient so that the item will appear exactly with the subset * The re-export uses a non-subset of `cfg`s (e.g. like the example I posted just above where the re-export is ungated), if the non-subset `cfg`s are active (e.g. compiling that example on windows) then this will be a compile error as the item doesn't exist to re-export, if the subset `cfg`s are active it behaves like 1. ### Glob re-exports? **This only applies to non-glob inlined re-exports.** For glob re-exports the item may or may not exist to be re-exported (potentially the `cfg`s on the path up until the glob can be removed, and only `cfg`s on the globbed item itself matter), for non-inlined re-exports see https://github.com/rust-lang/rust/issues/85043. cc `@Nemo157` r? `@notriddle`
2023-12-14rustdoc-search: fix a race condition in search index loadingMichael Howell-2/+8
`var` declare it in the global scope, and `const` does not. It needs to be declared in global scope.
2023-12-14Use Map instead of Object for source files and search indexGuillaume Gomez-93/+77
2023-12-13rustdoc-search: clean up handleSingleArg type handlingMichael Howell-9/+3
2023-12-13rustdoc-search: better hashing, faster unificationMichael Howell-10/+46
The hash changes are based on some tests with `arti` and various specific queries, aimed at reducing the false positive rate. Sorting the query elements so that generics always come first is instead aimed at reducing the number of Map operations on mgens, assuming if the bloom filter does find a false positive, it'll be able to reject the row without having to track a mapping. - https://hur.st/bloomfilter/?n=3&p=&m=96&k=6 Different functions have different amounts of inputs, and unification isn't very slow anyway, so figuring out a single ideal number of hash functions is nasty, but 6 keeps things low even up to 10 inputs. - https://web.archive.org/web/20210927123933/https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.72.2442&rep=rep1&type=pdf This is the `h1` and `h2`, both derived from `h0`.
2023-12-13rustdoc-search: use set ops for ranking and filteringMichael Howell-41/+187
This commit adds ranking and quick filtering to type-based search, improving performance and having it order results based on their type signatures. Motivation ---------- If I write a query like `str -> String`, a lot of functions come up. That's to be expected, but `String::from_str` should come up on top, and it doesn't right now. This is because the sorting algorithm is based on the functions name, and doesn't consider the type signature at all. `slice::join` even comes up above it! To fix this, the sorting should take into account the function's signature, and the closer match should come up on top. Guide-level description ----------------------- When searching by type signature, types with a "closer" match will show up above types that match less precisely. Reference-level explanation --------------------------- Functions signature search works in three major phases: * A compact "fingerprint," based on the [bloom filter] technique, is used to check for matches and to estimate the distance. It sometimes has false positive matches, but it also operates on 128 bit contiguous memory and requires no backtracking, so it performs a lot better than real unification. The fingerprint represents the set of items in the type signature, but it does not represent nesting, and it ignores when the same item appears more than once. The result is rejected if any query bits are absent in the function, or if the distance is higher than the current maximum and 200 results have already been found. * The second step performs unification. This is where nesting and true bag semantics are taken into account, and it has no false positives. It uses a recursive, backtracking algorithm. The result is rejected if any query elements are absent in the function. [bloom filter]: https://en.wikipedia.org/wiki/Bloom_filter Drawbacks --------- This makes the code bigger. More than that, this design is a subtle trade-off. It makes the cases I've tested against measurably faster, but it's not clear how well this extends to other crates with potentially more functions and fewer types. The more complex things get, the more important it is to gather a good set of data to test with (this is arguably more important than the actual benchmarking ifrastructure right now). Rationale and alternatives -------------------------- Throwing a bloom filter in front makes it faster. More than that, it tries to take a tactic where the system can not only check for potential matches, but also gets an accurate distance function without needing to do unification. That way it can skip unification even on items that have the needed elems, as long as they have more items than the currently found maximum. If I didn't want to be able to cheaply do set operations on the fingerprint, a [cuckoo filter] is supposed to have better performance. But the nice bit-banging set intersection doesn't work AFAIK. I also looked into [minhashing], but since it's actually an unbiased estimate of the similarity coefficient, I'm not sure how it could be used to skip unification (I wouldn't know if the estimate was too low or too high). This function actually uses the number of distinct items as its "distance function." This should give the same results that it would have gotten from a Jaccard Distance $1-\frac{|F\cap{}Q|}{|F\cup{}Q|}$, while being cheaper to compute. This is because: * The function $F$ must be a superset of the query $Q$, so their union is just $F$ and the intersection is $Q$ and it can be reduced to $1-\frac{|Q|}{|F|}. * There are no magic thresholds. These values are only being used to compare against each other while sorting (and, if 200 results are found, to compare with the maximum match). This means we only care if one value is bigger than the other, not what it's actual value is, and since $Q$ is the same for everything, it can be safely left out, reducing the formula to $1-\frac{1}{|F|} = \frac{|F|}{|F|}-\frac{1}{|F|} = |F|-1$. And, since the values are only being compared with each other, $|F|$ is fine. Prior art --------- This is significantly different from how Hoogle does it. It doesn't account for order, and it has no special account for nesting, though `Box<t>` is still two items, while `t` is only one. This should give the same results that it would have gotten from a Jaccard Distance $1-\frac{|A\cap{}B|}{|A\cup{}B|}$, while being cheaper to compute. Unresolved questions -------------------- `[]` and `()`, the slice/array and tuple/union operators, are ignored while building the signature for the query. This is because they match more than one thing, making them ambiguous. Unfortunately, this also makes them a performance cliff. Is this likely to be a problem? Right now, the system just stashes the type distance into the same field that levenshtein distance normally goes in. This means exact query matches show up on top (for example, if you have a function like `fn nothing(a: Nothing, b: i32)`, then searching for `nothing` will show it on top even if there's another function with `fn bar(x: Nothing)` that's technically a closer match in type signature. Future possibilities -------------------- It should be possible to adopt more sorting criteria to act as a tie breaker, which could be determined during unification. [cuckoo filter]: https://en.wikipedia.org/wiki/Cuckoo_filter [minhashing]: https://en.wikipedia.org/wiki/MinHash
2023-12-13rustdoc-search: remove the now-redundant `validateResult`Michael Howell-57/+0
This function dates back to 9a45c9d7c6928743f9e7a7161bf564a65bfc0577 and seems to have been made obsolete when `addIntoResult` grew the ability to check the levenshtein distance matching with commit ba824ec52beb0e49b64e86837c1402a0c2d0c971.
2023-12-13Auto merge of #118500 - ZetaNumbers:tcx_hir_refactor, r=petrochenkovbors-2/+2
Move some methods from `tcx.hir()` to `tcx` https://github.com/rust-lang/rust/pull/118256#issuecomment-1826442834 Renamed: - find -> opt_hir_node - get -> hir_node - find_by_def_id -> opt_hir_node_by_def_id - get_by_def_id -> hir_node_by_def_id
2023-12-12Rollup merge of #118886 - GuillaumeGomez:clean-up-search-vars, r=notriddleJubilee-13/+7
Clean up variables in `search.js` While reviewing https://github.com/rust-lang/rust/pull/118402, I saw a few small clean ups that were needed, mostly about variables creation. r? ```@notriddle```
2023-12-12Rollup merge of #118885 - matthiaskrgr:compl_2023, r=compiler-errorsJubilee-1/+2
clippy::complexity fixes filter_map_identity needless_bool search_is_some unit_arg map_identity needless_question_mark derivable_impls
2023-12-12Rollup merge of #118872 - GuillaumeGomez:codeblock-attr-lint, r=notriddleJubilee-43/+56
Add rustX check to codeblock attributes lint We discovered this issue [here](https://github.com/rust-lang/rust/pull/118802#discussion_r1421815943). I assume that the issue will be present in other places outside of the compiler so it's worth adding a check for it. First commit is just a small cleanup about variables creation which was a bit strange (at least more than necessary). r? ```@notriddle```
2023-12-12Clean up variables in `search.js`Guillaume Gomez-13/+7
2023-12-12clippy::complexity fixesMatthias Krüger-1/+2
filter_map_identity needless_bool search_is_some unit_arg map_identity needless_question_mark derivable_impls
2023-12-12Follow guidelines for lint suggestionsGuillaume Gomez-9/+21
2023-12-12Add `rustX` check to codeblock attributes lintGuillaume Gomez-0/+10
2023-12-12Move some methods from `tcx.hir()` to `tcx`zetanumbers-2/+2
Renamings: - find -> opt_hir_node - get -> hir_node - find_by_def_id -> opt_hir_node_by_def_id - get_by_def_id -> hir_node_by_def_id Fix rebase changes using removed methods Use `tcx.hir_node_by_def_id()` whenever possible in compiler Fix clippy errors Fix compiler Apply suggestions from code review Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com> Add FIXME for `tcx.hir()` returned type about its removal Simplify with with `tcx.hir_node_by_def_id`
2023-12-12Clean up CodeBlocks::next codeGuillaume Gomez-38/+29
2023-12-11rustdoc-search: clean up parserMichael Howell-7/+2
The `c === "="` was redundant when `isSeparatorCharacter` already checks that. The function `isStopCharacter` and `isEndCharacter` functions did exactly the same thing and have synonymous names. There doesn't seem much point in having both.
2023-12-10rustdoc-search: fix fast path unboxing bindingsMichael Howell-1/+1
2023-12-10rustdoc-search: do not treat associated type names as typesMichael Howell-13/+20
Before: http://notriddle.com/rustdoc-html-demo-6/tor-before/tor_config/ After: http://notriddle.com/rustdoc-html-demo-6/tor-after/tor_config/ Profile: http://notriddle.com/rustdoc-html-demo-6/tor-profile/ As a bit of background information: in type-based queries, a type name that does not exist gets treated as a generic type variable. This causes a counterintuitive behavior in the `tor_config` crate, which has a trait with an associated type variable called `T`. This isn't a searchable concrete type, but its name still gets stored in the typeNameIdMap, as a convenient way to intern its name.
2023-12-10remove redundant importssurechen-1/+0
detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.
2023-12-08Rollup merge of #118722 - notriddle:notriddle/dom-opt-3, r=GuillaumeGomezMatthias Krüger-19/+6
rustdoc: remove unused parameter `reversed` from onEach(Lazy) This feature was added in edec5807ac5ba90cbc0c61a5ec7b80f29e1eea33 to support JavaScript-based toggles that were later replaced with HTML `<details>`.
2023-12-08Rollup merge of #118677 - GuillaumeGomez:doc_cfg-display, r=notriddleMatthias Krüger-9/+12
[rustdoc] Fix display of features Fixes https://github.com/rust-lang/rust/issues/118615. It now looks like this: ![image](https://github.com/rust-lang/rust/assets/3050060/6e77204e-0706-44a3-89ae-2dbd1934ebbc) We can't use flex without breaking the flow, meaning we can't vertically align items as we want. Because of that, the `min-height` was problematic as it rendered weirdly and therefore needed to be removed. r? `@notriddle`
2023-12-07rustdoc: remove unused parameter `reversed` from onEach(Lazy)Michael Howell-19/+6
This feature was added in edec5807ac5ba90cbc0c61a5ec7b80f29e1eea33 to support JavaScript-based toggles that were later replaced with HTML `<details>`.
2023-12-07Fix display of features in rustdocGuillaume Gomez-9/+12
2023-12-05Rollup merge of #118594 - hdost:patch-1, r=fmeaseMatthias Krüger-1/+1
Remove mention of rust to make the error message generic. The deprecation notice is used when in crates as well. This applies to versions Rust or Crates. Relates #118148
2023-12-05Remove mention of rust to make the error message generic.Harold Dost-1/+1
The deprecation notice is used when in crates as well. This applies to versions Rust or Crates. Fixes #118148 Signed-off-by: Harold Dost <h.dost@criteo.com>
2023-12-04Rollup merge of #118600 - GuillaumeGomez:fields-heading, r=notriddleGuillaume Gomez-1/+8
[rustdoc] Don't generate the "Fields" heading if there is no field displayed Fixes https://github.com/rust-lang/rust/issues/118195. If no field is displayed, we should not generate the `Fields` heading in enum struct variants. r? ``@notriddle``
2023-12-04Rollup merge of #118508 - notriddle:notriddle/fmt-newline, r=GuillaumeGomezGuillaume Gomez-8/+50
rustdoc: do not escape quotes in body text Escaping quote marks is only needed in attributes, not text. ```console $ du -hs doc-old/ doc-new/ 670M doc-old/ 669M doc-new/ ```
2023-12-04Don't generate the "Fields" heading if there is no field displayedGuillaume Gomez-1/+8
2023-12-01rustdoc: do not escape quotes in body textMichael Howell-8/+50
Escaping quote marks is only needed in attributes, not text. ```console $ du -hs doc-old/ doc-new/ 670M doc-old/ 669M doc-new/ ```
2023-12-01Add highlighting for comments in items declarationGuillaume Gomez-8/+14
2023-12-01Rollup merge of #118483 - notriddle:notriddle/fmt-newline, r=GuillaumeGomezTakayuki Maeda-16/+8
rustdoc: `div.where` instead of fmt-newline class This is about equally readable, a lot more terse, and stops special-casing functions and methods. ```console $ du -hs doc-old/ doc-new/ 671M doc-old/ 670M doc-new/ ```
2023-11-30rustdoc: `div.where` instead of fmt-newline classMichael Howell-16/+8
This is about equally readable, a lot more terse, and stops special-casing functions and methods. ```console $ du -hs doc-old/ doc-new/ 671M doc-old/ 670M doc-new/ ```
2023-11-30Rollup merge of #118458 - notriddle:notriddle/small-section-header, ↵Matthias Krüger-16/+16
r=GuillaumeGomez rustdoc: remove small from `small-section-header` There's no such thing as a big section header, so I don't know why the name was used.
2023-11-29rustdoc: remove small from `small-section-header`Michael Howell-16/+16
There's no such thing as a big section header, so I don't know why the name was used.
2023-11-29rustdoc-search: replace TAB/NL/LF with SP firstMichael Howell-10/+6
This way, most of the parsing code doesn't need to be designed to handle it, since they should always be treated exactly the same anyhow.
2023-11-29rustdoc-search: removed dead parser codeMichael Howell-2/+0
This is already covered by the normal unexpected char path.