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.
pub external_traits: Rc<RefCell<FxHashMap<DefId, Trait>>>,
pub masked_crates: FxHashSet<CrateNum>,
pub collapsed: bool,
}
impl Clean<Crate> for hir::Crate {
@ -221,6 +222,7 @@ impl Clean<Crate> for hir::Crate {
primitives,
external_traits: cx.external_traits.clone(),
masked_crates,
collapsed: false,
}
}
}

View file

@ -220,22 +220,22 @@ impl Options {
println!("{:>20} - {}", pass.name, pass.description);
}
println!("\nDefault passes for rustdoc:");
for &name in passes::DEFAULT_PASSES {
println!("{:>20}", name);
for pass in passes::DEFAULT_PASSES {
println!("{:>20}", pass.name);
}
println!("\nPasses run with `--document-private-items`:");
for &name in passes::DEFAULT_PRIVATE_PASSES {
println!("{:>20}", name);
for pass in passes::DEFAULT_PRIVATE_PASSES {
println!("{:>20}", pass.name);
}
if nightly_options::is_nightly_build() {
println!("\nPasses run with `--show-coverage`:");
for &name in passes::DEFAULT_COVERAGE_PASSES {
println!("{:>20}", name);
for pass in passes::DEFAULT_COVERAGE_PASSES {
println!("{:>20}", pass.name);
}
println!("\nPasses run with `--show-coverage --document-private-items`:");
for &name in passes::PRIVATE_COVERAGE_PASSES {
println!("{:>20}", name);
for pass in passes::PRIVATE_COVERAGE_PASSES {
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.
let RustdocOptions {
@ -427,8 +427,8 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
},
_ => continue,
};
for p in value.as_str().split_whitespace() {
sink.push(p.to_string());
for name in value.as_str().split_whitespace() {
sink.push(name.to_string());
}
}
@ -439,25 +439,26 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
}
}
let mut passes: Vec<String> =
passes::defaults(default_passes).iter().map(|p| p.to_string()).collect();
passes.extend(manual_passes);
let passes = passes::defaults(default_passes).iter().chain(manual_passes.into_iter()
.flat_map(|name| {
if let Some(pass) = passes::find_pass(&name) {
Some(pass)
} else {
error!("unknown pass {}, skipping", name);
None
}
}));
info!("Executing passes");
for pass_name in &passes {
match passes::find_pass(pass_name).map(|p| p.pass) {
Some(pass) => {
debug!("running pass {}", pass_name);
krate = pass(krate, &ctxt);
}
None => error!("unknown pass {}, skipping", *pass_name),
}
for pass in passes {
debug!("running pass {}", pass.name);
krate = (pass.pass)(krate, &ctxt);
}
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,
/// The local file sources we've emitted and their respective url-paths.
pub local_sources: FxHashMap<PathBuf, String>,
/// All the passes that were run on this crate.
pub passes: FxHashSet<String>,
/// Whether the collapsed pass ran
pub collapsed: bool,
/// The base-URL of the issue tracker for when an item has been tagged with
/// an issue number.
pub issue_tracker_base_url: Option<String>,
@ -229,15 +229,10 @@ 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
/// `collapsed_doc_value` of the given item.
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())
} else {
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`
pub fn run(mut krate: clean::Crate,
options: RenderOptions,
passes: FxHashSet<String>,
renderinfo: RenderInfo,
diag: &errors::Handler,
edition: Edition) -> Result<(), Error> {
@ -557,8 +551,8 @@ pub fn run(mut krate: clean::Crate,
};
let mut errors = Arc::new(ErrorStorage::new());
let mut scx = SharedContext {
collapsed: krate.collapsed,
src_root,
passes,
include_sources: true,
local_sources: Default::default(),
issue_tracker_base_url: None,

View file

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

View file

@ -30,7 +30,9 @@ impl DocFragment {
}
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;

View file

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