about summary refs log tree commit diff
path: root/src/librustdoc/html/render
AgeCommit message (Collapse)AuthorLines
2021-03-26Rollup merge of #83055 - aDotInTheVoid:selective-strip-item-doc, r=jyn514Dylan DPC-0/+2
[rustdoc] Don't document stripped items in JSON renderer. Fixes #80664, see [my comment there](https://github.com/rust-lang/rust/issues/80664#issuecomment-797557948) for why Note that we already do something similar in `convert_item`: https://github.com/rust-lang/rust/blob/bb4cdf8ec034dca5c056ec9295f38062e5b7e871/src/librustdoc/json/conversions.rs#L28-L31 ``@rustbot`` modify labels: +T-rustdoc +A-rustdoc-json r? ``@jyn514`` cc ``@CraftSpider``
2021-03-24Split clean::Constant enum into a struct and an enumGuillaume Gomez-1/+1
2021-03-24Store tcx and cache when they are used multiple times instead of calling ↵Guillaume Gomez-58/+66
functions every time
2021-03-24Rework rustdoc const typeGuillaume Gomez-100/+126
2021-03-24Don't call `item` on modules for json rendererNixon Enraght-Moony-0/+2
Closes #80664
2021-03-24Rollup merge of #83415 - camelid:remove-crate-module-option, r=jyn514Dylan DPC-33/+27
Remove unnecessary `Option` wrapping around `Crate.module` I'm wondering if it was originally there so that we could `take` the module which enables `after_krate` to take an `&Crate`. However, the two impls of `after_krate` only use `Crate.name`, so we can pass just the name instead.
2021-03-24Rollup merge of #83051 - GuillaumeGomez:sidebar-trait-items-order, ↵Dylan DPC-4/+4
r=CraftSpider,jyn514 Sidebar trait items order We were actually sorting `Symbol` and not `String`, creating a completely invalid sort result. I added a test to prevent regressions. r? ``@jyn514``
2021-03-23Auto merge of #82994 - camelid:rename-source-to-span, r=jyn514bors-6/+6
Rename `source` to `span` and `span` to `source` - Rename `clean::Item.source` to `span` - Rename `clean::Span::span()` to `clean::Span::inner()` - Rename `rustdoc_json_types::Item.source` to `span` - rustdoc-json: Rename `Import.span` to `Import.source` *See also the [discussion on Zulip][z] (this is a bit more than discussed in that conversation, but all the changes are related).* r? `@jyn514` [z]: https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/get.20span.20of.20file.20from.20name/near/229603729
2021-03-23Remove unnecessary `Option` wrapping around `Crate.module`Camelid-33/+27
I'm wondering if it was originally there so that we could `take` the module which enables `after_krate` to take an `&Crate`. However, the two impls of `after_krate` only use `Crate.name`, so we can pass just the name instead.
2021-03-23Use &str instead of StringGuillaume Gomez-3/+3
2021-03-23Fix sidebar trait items sortGuillaume Gomez-3/+3
2021-03-23Rollup merge of #82732 - GuillaumeGomez:remove-theme-file, r=Nemo157Yuki Okushi-56/+5
Remove theme.js file Fixes #82616. The first commit moves the `theme.js` file into `main.js`, which requires to also run a small `.replace` on the `main.js` content. The second commit is just a small cleanup to centralize DOM ids. Since it removes a file from rustdoc output: cc `@rust-lang/docs-rs` cc `@jsha` r? `@jyn514`
2021-03-23Rollup merge of #80705 - tspiteri:italic-and-update-SourceCodePro, ↵Yuki Okushi-2/+3
r=GuillaumeGomez Update Source Code Pro and include italics Fixes #65502. #65665, a similar PR to this was merged but reverted because of https://github.com/rust-lang/rust/pull/65665#issuecomment-556860510. The issue in that comment is the upstream issue https://github.com/adobe-fonts/source-code-pro/issues/217 which should now be fixed in the upstream since [2.032R-ro/1.052R-it/1.012R-VAR release](https://github.com/adobe-fonts/source-code-pro/releases/tag/2.032R-ro/1.052R-it/1.012R-VAR), so I think this can now be merged. A couple of notes from the original PR: * Since this PR changes the font set, I think docs.rs would have to be updated if this PR is merged. * The fonts have a double extension (.ttf.woff); this is to keep the names consistent with the upstream font release which does that to distinguish these from the .otf.woff files (Source Code Pro otf renders poorly on older Windows system apps).
2021-03-22Auto merge of #82855 - jyn514:no-temporaries, r=GuillaumeGomezbors-18/+26
Avoid temporary allocations in `render_assoc_item` `render_assoc_item` came up as very hot in a profile of rustdoc on `bevy`. This avoids some temporary allocations just to calculate the length of the header. This should be a strict improvement, since all string formatting was done twice before. cc #82845
2021-03-21Rename `clean::Span::span()` to `clean::Span::inner()`Camelid-1/+1
Otherwise you get a lot of instances of `item.span.span()`, which is just plain confusing. `item.span.inner()` conveys the correct meaning of "get the type that `clean::Span` wraps".
2021-03-21Rename `clean::Item.source` to `span`Camelid-6/+6
Its type is called `clean::Span`, and also the name in the rest of rustdoc and rustc for this kind of field is `span`.
2021-03-10rustdoc: tweak the search index formatMichael Howell-23/+54
This essentially switches search-index.js from a "array of struct" to a "struct of array" format, like this: { "doc": "Crate documentation", "t": [ 1, 1, 2, 3, ... ], "n": [ "Something", "SomethingElse", "whatever", "do_stuff", ... ], "q": [ "a::b", "", "", "", ... ], "d": [ "A Struct That Does Something", "Another Struct", "a function", "another function", ... ], "i": [ 0, 0, 1, 1, ... ], "f": [ null, null, [], [], ... ], "p": ..., "a": ... } So `{ty: 1, name: "Something", path: "a::b", desc: "A Struct That Does Something", parent_idx: 0, search_type: null}` is the first item. This makes the uncompressed version smaller, but it really shows on the compressed version: notriddle:rust$ wc -c new-search-index1.52.0.js 2622427 new-search-index1.52.0.js notriddle:rust$ wc -c old-search-index1.52.0.js 2725046 old-search-index1.52.0.js notriddle:rust$ gzip new-search-index1.52.0.js notriddle:rust$ gzip old-search-index1.52.0.js notriddle:rust$ wc -c new-search-index1.52.0.js.gz 239385 new-search-index1.52.0.js.gz notriddle:rust$ wc -c old-search-index1.52.0.js.gz 296328 old-search-index1.52.0.js.gz notriddle:rust$ That's a 4% improvement on the uncompressed version (fewer `[]`), and 20% improvement after gzipping it, thanks to putting like-typed data next to each other. Any compression algorithm based on a sliding window will probably show this kind of improvement.
2021-03-09Simplify some of the rendering code in the indexMichael Howell-5/+1
It's kinda silly using serde seq for fixed-length stuff.
2021-03-09Auto merge of #82356 - camelid:render-cleanup, r=GuillaumeGomezbors-43/+71
rustdoc: Cleanup `html::render::Context` - Move most shared fields to `SharedContext` (except for `cache`, which isn't mutated anyway) - Replace a use of `Arc` with `Rc` - Make a bunch of fields private - Add static size assertion for `Context` - Don't share `id_map` and `deref_id_map`
2021-03-07Avoid temporary allocations in `render_assoc_item`Joshua Nelson-18/+26
`render_assoc_item` came up as very hot in a profile of rustdoc on `bevy`. This avoids some temporary allocations just to calculate the length of the header. This should be a strict improvement, since all string formatting was done twice before.
2021-03-07Update Source Code Pro and include italicsTrevor Spiteri-2/+3
2021-03-07Rollup merge of #82803 - jyn514:unversioned-files, r=GuillaumeGomezYuki Okushi-15/+25
rustdoc: Add an unstable option to print all unversioned files This allows sharing those files between different doc invocations without having to know their names ahead of time. Helps with https://github.com/rust-lang/docs.rs/issues/1302. r? ````@GuillaumeGomez```` cc ````@pietroalbini```` ````@Nemo157````
2021-03-05Undo addition of boxesCamelid-7/+7
I don't think the boxing helped performance, in fact I think it potentially made it worse. The data was still being copied, but now it was through a pointer. Thinking about it more, I think boxing might only help when you're passing a big object around by value all the time, rather than the slowdown being that you're cloning it.
2021-03-05Don't unnecessarily clone some fields in `Context`Camelid-6/+15
There was no need to clone `id_map` because it was reset before each item was rendered. `deref_id_map` was not reset, but it was keyed by `DefId` and thus was unlikely to have collisions (at least for now). Now we just clone the fields that need to be cloned, and instead create fresh versions of the others.
2021-03-05Box some fields to reduce `Context` sizeCamelid-5/+5
Reduced from 152 bytes to 88 bytes.
2021-03-05Don't share `id_map` and `deref_id_map`Camelid-21/+20
All the tests passed, so it doesn't seem they need to be shared. Plus they should be item/page-specific. I'm not sure why they were shared before. I think the reason `id_map` worked as a shared value before is that it is cleared before rendering each item (in `render_item`). And then I'm guessing `deref_id_map` worked because it's a hashmap keyed by `DefId`, so there was no overlap (though I'm guessing we could have had issues in the future). Note that `id_map` currently still has to be cleared because otherwise child items would inherit the `id_map` of their parent. I'm hoping to figure out a way to stop cloning `Context`, but until then we have to reset `id_map`.
2021-03-05rustdoc: Add static size assertion for `Context`Camelid-0/+4
It's cloned a lot, so we don't want it to grow in size unexpectedly. Only run the assert on x86-64 since the size is architecture-dependent.
2021-03-05rustdoc: Make a bunch of fields privateCamelid-12/+18
Also create issue for removing shared mutable state.
2021-03-05rustdoc: Replace `Arc` around `SharedContext` with `Rc`Camelid-6/+5
It doesn't look like it's shared across threads, so it doesn't need to be thread-safe. Of course, since we're using Rust, we'll get an error if we try to share it across threads, so this should be safe :)
2021-03-05rustdoc: Move most shared fields to `SharedContext`Camelid-37/+48
...and remove `Rc`s for the moved fields. The only shared one that I didn't move was `cache`; see the doc-comment I added to `cache` for details.
2021-03-05Add an unstable option to print all unversioned filesJoshua Nelson-18/+22
This allows sharing those files between different doc invocations without having to know their names ahead of time.
2021-03-05Store `UNVERSIONED_FILES` in a data structureJoshua Nelson-15/+21
This allows querying it programatically.
2021-03-05Remove theme.js file creation and move its code inside main.jsGuillaume Gomez-56/+5
2021-03-05Make ItemKind::ExternCrate looks like hir::ItemKind::ExternCrate to make ↵Guillaume Gomez-3/+3
transition over hir::ItemKind simpler
2021-03-04Corrected imports for render tests and mod filesNicholas-Baron-3/+4
Due to a rebase, some edits were needed in the mod file.
2021-03-04Moved `write_shared` to its own fileNicholas-Baron-535/+549
2021-03-04Moved the `make_item_keywords` function to `context.rs` as it is only used thereNicholas-Baron-5/+6
2021-03-04Moved `print_item` and helpers to a separate fileNicholas-Baron-1404/+1430
2021-03-04Moved Context and its impls to a separate fileNicholas-Baron-593/+618
2021-03-04Rollup merge of #82310 - jsha:rustdoc-search-onfocus, r=GuillaumeGomezYuki Okushi-7/+10
Load rustdoc's JS search index on-demand. Instead of being loaded on every page, the JS search index is now loaded when either (a) there is a `?search=` param, or (b) the search input is focused. This saves both CPU and bandwidth. As of Feb 2021, https://doc.rust-lang.org/search-index1.50.0.js is 273,838 bytes gzipped or 2,544,939 bytes uncompressed. Evaluating it takes 445 ms of CPU time in Chrome 88 on a i7-10710U CPU (out of a total ~2,100 ms page reload). Tested on Firefox and Chrome. New: https://jacob.hoffman-andrews.com/rust/search-on-demand/std/primitive.slice.html https://jacob.hoffman-andrews.com/rust/search-on-demand/std/primitive.slice.html?search=fn Old: https://jacob.hoffman-andrews.com/rust/search-on-load/std/primitive.slice.html https://jacob.hoffman-andrews.com/rust/search-on-load/std/primitive.slice.html?search=fn
2021-03-03Rollup merge of #81223 - GuillaumeGomez:generate-redirect-map, r=jyn514Yuki Okushi-10/+43
[rustdoc] Generate redirect map file Fixes #81134. So with this code: ```rust #![crate_name = "foo"] pub use private::Quz; pub use hidden::Bar; mod private { pub struct Quz; } #[doc(hidden)] pub mod hidden { pub struct Bar; } #[macro_export] macro_rules! foo { () => {} } ``` It generates: ```json { "foo/macro.foo!.html": "foo/macro.foo.html", "foo/private/struct.Quz.html": "foo/struct.Quz.html", "foo/hidden/struct.Bar.html": "foo/struct.Bar.html" } ``` Do the pathes look as you expected ````@pietroalbini?```` r? ````@jyn514````
2021-03-02Load rustdoc's JS search index on-demand.Jacob Hoffman-Andrews-7/+10
Instead of being loaded on every page, the JS search index is now loaded when either (a) there is a `?search=` param, or (b) the search input is focused. This saves both CPU and bandwidth. As of Feb 2021, https://doc.rust-lang.org/search-index1.50.0.js is 273,838 bytes gzipped or 2,544,939 bytes uncompressed. Evaluating it takes 445 ms of CPU time in Chrome 88 on a i7-10710U CPU (out of a total ~2,100 ms page reload). Generate separate JS file with crate names. This is much smaller than the full search index, and is used in the "hot path" to draw the page. In particular it's used to crate the dropdown for the search bar, and to append a list of crates to the sidebar (on some pages). Skip early search that can bypass 500ms timeout. This was occurring when someone had typed some text during the load of search-index.js. Their query was usually not ready to execute, and the search itself is fairly expensive, delaying the overall load, which delayed the input / keyup events, which delayed eventually executing the query.
2021-03-01Remove the dummy cache in `DocContext`Joshua Nelson-2/+1
The same information is available everywhere; the only reason the dummy cache was needed is because it waas previously stored in three different places. This consolidates the info a bit so the cache in `DocContext` is used throughout. As a bonus, it means `renderinfo` is used much much less. - Return a `Cache` from `run_global_ctxt`, not `RenderInfo` - Remove the unused `render_info` from `run_renderer` - Remove RefCell around `inlined` - Add intra-doc links
2021-02-26Rollup merge of #82545 - jsha:woff2, r=GuillaumeGomezGuillaume Gomez-0/+2
rustdoc: add optional woff2 versions of FiraSans. For browsers that support woff2 (most modern ones: https://caniuse.com/woff2), this offers a reduction in download size for these two fonts from 362k to 257k (32% reduction). It decreases the total page size for `struct.String.html` (counting all subresources) by about 2.5%. If this is interesting, I'm happy to apply the same treatment to the other fonts, but these two are the biggest.
2021-02-26Embed woff2 files in rustdoc binary.Jacob Hoffman-Andrews-0/+2
2021-02-25Rollup merge of #82484 - bugadani:docfix, r=jyn514Aaron Hill-1/+11
rustdoc: Remove duplicate "List of all items" Closes #82477 r? `@jyn514`
2021-02-24Add testDániel Buga-0/+11
2021-02-24Remove duplicate stringDániel Buga-1/+0
2021-02-23Put clean::Trait extra information into a new struct to make it more coherentGuillaume Gomez-4/+4
2021-02-23Remove is_spotlight field from `Trait`Guillaume Gomez-4/+5