Skip to content

Commit d31c481

Browse files
Auto merge of #146483 - fmease:rustdoc-gen-mac-exp-perf-fix, r=<try>
[perf] rustdoc
2 parents a171994 + abca022 commit d31c481

File tree

21 files changed

+93
-795
lines changed

21 files changed

+93
-795
lines changed

src/doc/rustdoc/src/unstable-features.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,3 @@ will be split as follows:
813813
"you today?",
814814
]
815815
```
816-
817-
## `--generate-macro-expansion`: Generate macros expansion toggles in source code
818-
819-
This flag enables the generation of toggles to expand macros in the HTML source code pages.

src/librustdoc/config.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,6 @@ pub(crate) struct RenderOptions {
305305
pub(crate) parts_out_dir: Option<PathToParts>,
306306
/// disable minification of CSS/JS
307307
pub(crate) disable_minification: bool,
308-
/// If `true`, HTML source pages will generate the possibility to expand macros.
309-
pub(crate) generate_macro_expansion: bool,
310308
}
311309

312310
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -795,7 +793,6 @@ impl Options {
795793
let show_type_layout = matches.opt_present("show-type-layout");
796794
let nocapture = matches.opt_present("nocapture");
797795
let generate_link_to_definition = matches.opt_present("generate-link-to-definition");
798-
let generate_macro_expansion = matches.opt_present("generate-macro-expansion");
799796
let extern_html_root_takes_precedence =
800797
matches.opt_present("extern-html-root-takes-precedence");
801798
let html_no_source = matches.opt_present("html-no-source");
@@ -811,13 +808,6 @@ impl Options {
811808
.with_note("`--generate-link-to-definition` option will be ignored")
812809
.emit();
813810
}
814-
if generate_macro_expansion && (show_coverage || output_format != OutputFormat::Html) {
815-
dcx.struct_warn(
816-
"`--generate-macro-expansion` option can only be used with HTML output format",
817-
)
818-
.with_note("`--generate-macro-expansion` option will be ignored")
819-
.emit();
820-
}
821811

822812
let scrape_examples_options = ScrapeExamplesOptions::new(matches, dcx);
823813
let with_examples = matches.opt_strs("with-examples");
@@ -899,7 +889,6 @@ impl Options {
899889
unstable_features,
900890
emit,
901891
generate_link_to_definition,
902-
generate_macro_expansion,
903892
call_locations,
904893
no_emit_shared: false,
905894
html_no_source,

src/librustdoc/core.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use crate::clean::inline::build_trait;
3131
use crate::clean::{self, ItemId};
3232
use crate::config::{Options as RustdocOptions, OutputFormat, RenderOptions};
3333
use crate::formats::cache::Cache;
34-
use crate::html::macro_expansion::{ExpandedCode, source_macro_expansion};
3534
use crate::passes;
3635
use crate::passes::Condition::*;
3736
use crate::passes::collect_intra_doc_links::LinkCollector;
@@ -335,19 +334,11 @@ pub(crate) fn run_global_ctxt(
335334
show_coverage: bool,
336335
render_options: RenderOptions,
337336
output_format: OutputFormat,
338-
) -> (clean::Crate, RenderOptions, Cache, FxHashMap<rustc_span::BytePos, Vec<ExpandedCode>>) {
337+
) -> (clean::Crate, RenderOptions, Cache) {
339338
// Certain queries assume that some checks were run elsewhere
340339
// (see https://github.com/rust-lang/rust/pull/73566#issuecomment-656954425),
341340
// so type-check everything other than function bodies in this crate before running lints.
342341

343-
let expanded_macros = {
344-
// We need for these variables to be removed to ensure that the `Crate` won't be "stolen"
345-
// anymore.
346-
let (_resolver, krate) = &*tcx.resolver_for_lowering().borrow();
347-
348-
source_macro_expansion(&krate, &render_options, output_format, tcx.sess.source_map())
349-
};
350-
351342
// NOTE: this does not call `tcx.analysis()` so that we won't
352343
// typeck function bodies or run the default rustc lints.
353344
// (see `override_queries` in the `config`)
@@ -457,7 +448,7 @@ pub(crate) fn run_global_ctxt(
457448

458449
tcx.dcx().abort_if_errors();
459450

460-
(krate, ctxt.render_options, ctxt.cache, expanded_macros)
451+
(krate, ctxt.render_options, ctxt.cache)
461452
}
462453

463454
/// Due to <https://github.com/rust-lang/rust/pull/73566>,

src/librustdoc/formats/renderer.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ pub(crate) trait FormatRenderer<'tcx>: Sized {
3131
/// reset the information between each call to `item` by using `restore_module_data`.
3232
type ModuleData;
3333

34+
/// Sets up any state required for the renderer. When this is called the cache has already been
35+
/// populated.
36+
fn init(
37+
krate: clean::Crate,
38+
options: RenderOptions,
39+
cache: Cache,
40+
tcx: TyCtxt<'tcx>,
41+
) -> Result<(Self, clean::Crate), Error>;
42+
3443
/// This method is called right before call [`Self::item`]. This method returns a type
3544
/// containing information that needs to be reset after the [`Self::item`] method has been
3645
/// called with the [`Self::restore_module_data`] method.
@@ -96,23 +105,18 @@ fn run_format_inner<'tcx, T: FormatRenderer<'tcx>>(
96105
}
97106

98107
/// Main method for rendering a crate.
99-
pub(crate) fn run_format<
100-
'tcx,
101-
T: FormatRenderer<'tcx>,
102-
F: FnOnce(clean::Crate, RenderOptions, Cache, TyCtxt<'tcx>) -> Result<(T, clean::Crate), Error>,
103-
>(
108+
pub(crate) fn run_format<'tcx, T: FormatRenderer<'tcx>>(
104109
krate: clean::Crate,
105110
options: RenderOptions,
106111
cache: Cache,
107112
tcx: TyCtxt<'tcx>,
108-
init: F,
109113
) -> Result<(), Error> {
110114
let prof = &tcx.sess.prof;
111115

112116
let emit_crate = options.should_emit_crate();
113117
let (mut format_renderer, krate) = prof
114118
.verbose_generic_activity_with_arg("create_renderer", T::descr())
115-
.run(|| init(krate, options, cache, tcx))?;
119+
.run(|| T::init(krate, options, cache, tcx))?;
116120

117121
if !emit_crate {
118122
return Ok(());

0 commit comments

Comments
 (0)