1
Fork 0

Store typed Passes

This commit is contained in:
Mark Rousskov 2019-08-10 16:43:39 -04:00
parent 6be2857a6c
commit 00319519bb
7 changed files with 65 additions and 68 deletions

View file

@ -133,6 +133,7 @@ pub struct Crate {
// Only here so that they can be filtered through the rustdoc passes. // Only here so that they can be filtered through the rustdoc passes.
pub external_traits: Rc<RefCell<FxHashMap<DefId, Trait>>>, pub external_traits: Rc<RefCell<FxHashMap<DefId, Trait>>>,
pub masked_crates: FxHashSet<CrateNum>, pub masked_crates: FxHashSet<CrateNum>,
pub collapsed: bool,
} }
impl Clean<Crate> for hir::Crate { impl Clean<Crate> for hir::Crate {
@ -221,6 +222,7 @@ impl Clean<Crate> for hir::Crate {
primitives, primitives,
external_traits: cx.external_traits.clone(), external_traits: cx.external_traits.clone(),
masked_crates, masked_crates,
collapsed: false,
} }
} }
} }

View file

@ -220,22 +220,22 @@ impl Options {
println!("{:>20} - {}", pass.name, pass.description); println!("{:>20} - {}", pass.name, pass.description);
} }
println!("\nDefault passes for rustdoc:"); println!("\nDefault passes for rustdoc:");
for &name in passes::DEFAULT_PASSES { for pass in passes::DEFAULT_PASSES {
println!("{:>20}", name); println!("{:>20}", pass.name);
} }
println!("\nPasses run with `--document-private-items`:"); println!("\nPasses run with `--document-private-items`:");
for &name in passes::DEFAULT_PRIVATE_PASSES { for pass in passes::DEFAULT_PRIVATE_PASSES {
println!("{:>20}", name); println!("{:>20}", pass.name);
} }
if nightly_options::is_nightly_build() { if nightly_options::is_nightly_build() {
println!("\nPasses run with `--show-coverage`:"); println!("\nPasses run with `--show-coverage`:");
for &name in passes::DEFAULT_COVERAGE_PASSES { for pass in passes::DEFAULT_COVERAGE_PASSES {
println!("{:>20}", name); println!("{:>20}", pass.name);
} }
println!("\nPasses run with `--show-coverage --document-private-items`:"); println!("\nPasses run with `--show-coverage --document-private-items`:");
for &name in passes::PRIVATE_COVERAGE_PASSES { for pass in passes::PRIVATE_COVERAGE_PASSES {
println!("{:>20}", name); println!("{:>20}", pass.name);
} }
} }

View file

@ -223,7 +223,7 @@ pub fn new_handler(error_format: ErrorOutputType,
) )
} }
pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOptions, Vec<String>) { pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOptions) {
// Parse, resolve, and typecheck the given crate. // Parse, resolve, and typecheck the given crate.
let RustdocOptions { let RustdocOptions {
@ -427,8 +427,8 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
}, },
_ => continue, _ => continue,
}; };
for p in value.as_str().split_whitespace() { for name in value.as_str().split_whitespace() {
sink.push(p.to_string()); sink.push(name.to_string());
} }
} }
@ -439,25 +439,26 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
} }
} }
let mut passes: Vec<String> = let passes = passes::defaults(default_passes).iter().chain(manual_passes.into_iter()
passes::defaults(default_passes).iter().map(|p| p.to_string()).collect(); .flat_map(|name| {
passes.extend(manual_passes); if let Some(pass) = passes::find_pass(&name) {
Some(pass)
} else {
error!("unknown pass {}, skipping", name);
None
}
}));
info!("Executing passes"); info!("Executing passes");
for pass_name in &passes { for pass in passes {
match passes::find_pass(pass_name).map(|p| p.pass) { debug!("running pass {}", pass.name);
Some(pass) => { krate = (pass.pass)(krate, &ctxt);
debug!("running pass {}", pass_name);
krate = pass(krate, &ctxt);
}
None => error!("unknown pass {}, skipping", *pass_name),
}
} }
ctxt.sess().abort_if_errors(); ctxt.sess().abort_if_errors();
(krate, ctxt.renderinfo.into_inner(), render_options, passes) (krate, ctxt.renderinfo.into_inner(), render_options)
}) })
}) })
} }

View file

@ -185,8 +185,8 @@ struct SharedContext {
pub include_sources: bool, pub include_sources: bool,
/// The local file sources we've emitted and their respective url-paths. /// The local file sources we've emitted and their respective url-paths.
pub local_sources: FxHashMap<PathBuf, String>, pub local_sources: FxHashMap<PathBuf, String>,
/// All the passes that were run on this crate. /// Whether the collapsed pass ran
pub passes: FxHashSet<String>, pub collapsed: bool,
/// The base-URL of the issue tracker for when an item has been tagged with /// The base-URL of the issue tracker for when an item has been tagged with
/// an issue number. /// an issue number.
pub issue_tracker_base_url: Option<String>, pub issue_tracker_base_url: Option<String>,
@ -229,15 +229,10 @@ impl SharedContext {
} }
impl SharedContext { impl SharedContext {
/// Returns `true` if the `collapse-docs` pass was run on this crate.
pub fn was_collapsed(&self) -> bool {
self.passes.contains("collapse-docs")
}
/// Based on whether the `collapse-docs` pass was run, return either the `doc_value` or the /// Based on whether the `collapse-docs` pass was run, return either the `doc_value` or the
/// `collapsed_doc_value` of the given item. /// `collapsed_doc_value` of the given item.
pub fn maybe_collapsed_doc_value<'a>(&self, item: &'a clean::Item) -> Option<Cow<'a, str>> { pub fn maybe_collapsed_doc_value<'a>(&self, item: &'a clean::Item) -> Option<Cow<'a, str>> {
if self.was_collapsed() { if self.collapsed {
item.collapsed_doc_value().map(|s| s.into()) item.collapsed_doc_value().map(|s| s.into())
} else { } else {
item.doc_value().map(|s| s.into()) item.doc_value().map(|s| s.into())
@ -526,7 +521,6 @@ pub fn initial_ids() -> Vec<String> {
/// Generates the documentation for `crate` into the directory `dst` /// Generates the documentation for `crate` into the directory `dst`
pub fn run(mut krate: clean::Crate, pub fn run(mut krate: clean::Crate,
options: RenderOptions, options: RenderOptions,
passes: FxHashSet<String>,
renderinfo: RenderInfo, renderinfo: RenderInfo,
diag: &errors::Handler, diag: &errors::Handler,
edition: Edition) -> Result<(), Error> { edition: Edition) -> Result<(), Error> {
@ -557,8 +551,8 @@ pub fn run(mut krate: clean::Crate,
}; };
let mut errors = Arc::new(ErrorStorage::new()); let mut errors = Arc::new(ErrorStorage::new());
let mut scx = SharedContext { let mut scx = SharedContext {
collapsed: krate.collapsed,
src_root, src_root,
passes,
include_sources: true, include_sources: true,
local_sources: Default::default(), local_sources: Default::default(),
issue_tracker_base_url: None, issue_tracker_base_url: None,

View file

@ -80,7 +80,6 @@ struct Output {
krate: clean::Crate, krate: clean::Crate,
renderinfo: html::render::RenderInfo, renderinfo: html::render::RenderInfo,
renderopts: config::RenderOptions, renderopts: config::RenderOptions,
passes: Vec<String>,
} }
pub fn main() { pub fn main() {
@ -419,14 +418,13 @@ fn main_options(options: config::Options) -> i32 {
return rustc_driver::EXIT_SUCCESS; return rustc_driver::EXIT_SUCCESS;
} }
let Output { krate, passes, renderinfo, renderopts } = out; let Output { krate, renderinfo, renderopts } = out;
info!("going to format"); info!("going to format");
let (error_format, treat_err_as_bug, ui_testing, edition) = diag_opts; let (error_format, treat_err_as_bug, ui_testing, edition) = diag_opts;
let diag = core::new_handler(error_format, None, treat_err_as_bug, ui_testing); let diag = core::new_handler(error_format, None, treat_err_as_bug, ui_testing);
match html::render::run( match html::render::run(
krate, krate,
renderopts, renderopts,
passes.into_iter().collect(),
renderinfo, renderinfo,
&diag, &diag,
edition, edition,
@ -459,7 +457,7 @@ where R: 'static + Send,
let result = rustc_driver::report_ices_to_stderr_if_any(move || { let result = rustc_driver::report_ices_to_stderr_if_any(move || {
let crate_name = options.crate_name.clone(); let crate_name = options.crate_name.clone();
let crate_version = options.crate_version.clone(); let crate_version = options.crate_version.clone();
let (mut krate, renderinfo, renderopts, passes) = core::run_core(options); let (mut krate, renderinfo, renderopts) = core::run_core(options);
info!("finished with rustc"); info!("finished with rustc");
@ -473,7 +471,6 @@ where R: 'static + Send,
krate: krate, krate: krate,
renderinfo: renderinfo, renderinfo: renderinfo,
renderopts, renderopts,
passes: passes
})).unwrap(); })).unwrap();
}); });

View file

@ -30,7 +30,9 @@ impl DocFragment {
} }
pub fn collapse_docs(krate: clean::Crate, _: &DocContext<'_>) -> clean::Crate { pub fn collapse_docs(krate: clean::Crate, _: &DocContext<'_>) -> clean::Crate {
Collapser.fold_crate(krate) let mut krate = Collapser.fold_crate(krate);
krate.collapsed = true;
krate
} }
struct Collapser; struct Collapser;

View file

@ -57,8 +57,9 @@ pub struct Pass {
pub description: &'static str, pub description: &'static str,
} }
/// The full list of passes. /// The full list of passes.
pub const PASSES: &'static [Pass] = &[ pub const PASSES: &[Pass] = &[
CHECK_PRIVATE_ITEMS_DOC_TESTS, CHECK_PRIVATE_ITEMS_DOC_TESTS,
STRIP_HIDDEN, STRIP_HIDDEN,
UNINDENT_COMMENTS, UNINDENT_COMMENTS,
@ -73,43 +74,43 @@ pub const PASSES: &'static [Pass] = &[
]; ];
/// The list of passes run by default. /// The list of passes run by default.
pub const DEFAULT_PASSES: &[&str] = &[ pub const DEFAULT_PASSES: &[Pass] = &[
"collect-trait-impls", COLLECT_TRAIT_IMPLS,
"collapse-docs", COLLAPSE_DOCS,
"unindent-comments", UNINDENT_COMMENTS,
"check-private-items-doc-tests", CHECK_PRIVATE_ITEMS_DOC_TESTS,
"strip-hidden", STRIP_HIDDEN,
"strip-private", STRIP_PRIVATE,
"collect-intra-doc-links", COLLECT_INTRA_DOC_LINKS,
"check-code-block-syntax", CHECK_CODE_BLOCK_SYNTAX,
"propagate-doc-cfg", PROPAGATE_DOC_CFG,
]; ];
/// The list of default passes run with `--document-private-items` is passed to rustdoc. /// The list of default passes run with `--document-private-items` is passed to rustdoc.
pub const DEFAULT_PRIVATE_PASSES: &[&str] = &[ pub const DEFAULT_PRIVATE_PASSES: &[Pass] = &[
"collect-trait-impls", COLLECT_TRAIT_IMPLS,
"collapse-docs", COLLAPSE_DOCS,
"unindent-comments", UNINDENT_COMMENTS,
"check-private-items-doc-tests", CHECK_PRIVATE_ITEMS_DOC_TESTS,
"strip-priv-imports", STRIP_PRIV_IMPORTS,
"collect-intra-doc-links", COLLECT_INTRA_DOC_LINKS,
"check-code-block-syntax", CHECK_CODE_BLOCK_SYNTAX,
"propagate-doc-cfg", PROPAGATE_DOC_CFG,
]; ];
/// The list of default passes run when `--doc-coverage` is passed to rustdoc. /// The list of default passes run when `--doc-coverage` is passed to rustdoc.
pub const DEFAULT_COVERAGE_PASSES: &'static [&'static str] = &[ pub const DEFAULT_COVERAGE_PASSES: &[Pass] = &[
"collect-trait-impls", COLLECT_TRAIT_IMPLS,
"strip-hidden", STRIP_HIDDEN,
"strip-private", STRIP_PRIVATE,
"calculate-doc-coverage", CALCULATE_DOC_COVERAGE,
]; ];
/// The list of default passes run when `--doc-coverage --document-private-items` is passed to /// The list of default passes run when `--doc-coverage --document-private-items` is passed to
/// rustdoc. /// rustdoc.
pub const PRIVATE_COVERAGE_PASSES: &'static [&'static str] = &[ pub const PRIVATE_COVERAGE_PASSES: &[Pass] = &[
"collect-trait-impls", COLLECT_TRAIT_IMPLS,
"calculate-doc-coverage", CALCULATE_DOC_COVERAGE,
]; ];
/// A shorthand way to refer to which set of passes to use, based on the presence of /// A shorthand way to refer to which set of passes to use, based on the presence of
@ -124,7 +125,7 @@ pub enum DefaultPassOption {
} }
/// Returns the given default set of passes. /// Returns the given default set of passes.
pub fn defaults(default_set: DefaultPassOption) -> &'static [&'static str] { pub fn defaults(default_set: DefaultPassOption) -> &'static [Pass] {
match default_set { match default_set {
DefaultPassOption::Default => DEFAULT_PASSES, DefaultPassOption::Default => DEFAULT_PASSES,
DefaultPassOption::Private => DEFAULT_PRIVATE_PASSES, DefaultPassOption::Private => DEFAULT_PRIVATE_PASSES,