Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: general cleanup #63453

Merged
merged 14 commits into from
Aug 11, 2019
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3252,7 +3252,6 @@ name = "rustdoc"
version = "0.0.0"
dependencies = [
"minifier 0.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"pulldown-cmark 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-rayon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ pulldown-cmark = { version = "0.5.3", default-features = false }
minifier = "0.0.33"
rayon = { version = "0.2.0", package = "rustc-rayon" }
tempfile = "3"
parking_lot = "0.7"
3 changes: 2 additions & 1 deletion src/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use rustc::traits;
use rustc::ty::ToPredicate;
use rustc::ty::subst::Subst;
use rustc::infer::InferOk;
use rustc::hir::def_id::LOCAL_CRATE;
use syntax_pos::DUMMY_SP;

use super::*;
Expand All @@ -27,7 +28,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {

debug!("get_blanket_impls({:?})", ty);
let mut impls = Vec::new();
for &trait_def_id in self.cx.all_traits.iter() {
for &trait_def_id in self.cx.tcx.all_traits(LOCAL_CRATE).iter() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this won't remove some auto impl discovering...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is (AFAICT) equivalent because queries once evaluated are always the same, and in this case we don't touch the all_traits vector except on creation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if tests pass then I guess nothing changed in the trait discovery so that's all good.

if !self.cx.renderinfo.borrow().access_levels.is_public(trait_def_id) ||
self.cx.generated_synthetics
.borrow_mut()
Expand Down
17 changes: 5 additions & 12 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,7 @@ pub fn load_attrs<'hir>(cx: &DocContext<'hir>, did: DefId) -> Attrs<'hir> {
/// These names are used later on by HTML rendering to generate things like
/// source links back to the original item.
pub fn record_extern_fqn(cx: &DocContext<'_>, did: DefId, kind: clean::TypeKind) {
let mut crate_name = cx.tcx.crate_name(did.krate).to_string();
if did.is_local() {
crate_name = cx.crate_name.clone().unwrap_or(crate_name);
}
let crate_name = cx.tcx.crate_name(did.krate).to_string();

let relative = cx.tcx.def_path(did).data.into_iter().filter_map(|elem| {
// extern blocks have an empty name
Expand Down Expand Up @@ -577,22 +574,18 @@ pub fn record_extern_trait(cx: &DocContext<'_>, did: DefId) {
}

{
let external_traits = cx.external_traits.lock();
if external_traits.borrow().contains_key(&did) ||
if cx.external_traits.borrow().contains_key(&did) ||
cx.active_extern_traits.borrow().contains(&did)
{
return;
}
}

cx.active_extern_traits.borrow_mut().push(did);
cx.active_extern_traits.borrow_mut().insert(did);

debug!("record_extern_trait: {:?}", did);
let trait_ = build_external_trait(cx, did);

{
let external_traits = cx.external_traits.lock();
external_traits.borrow_mut().insert(did, trait_);
}
cx.active_extern_traits.borrow_mut().remove_item(&did);
cx.external_traits.borrow_mut().insert(did, trait_);
cx.active_extern_traits.borrow_mut().remove(&did);
}
26 changes: 4 additions & 22 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@ use std::fmt;
use std::hash::{Hash, Hasher};
use std::default::Default;
use std::{mem, slice, vec};
use std::iter::{FromIterator, once};
use std::iter::FromIterator;
use std::rc::Rc;
use std::cell::RefCell;
use std::sync::Arc;
use std::u32;

use parking_lot::ReentrantMutex;

use crate::core::{self, DocContext};
use crate::doctree;
use crate::html::render::{cache, ExternalLocation};
Expand Down Expand Up @@ -133,8 +131,9 @@ pub struct Crate {
pub primitives: Vec<(DefId, PrimitiveType, Attributes)>,
// These are later on moved into `CACHEKEY`, leaving the map empty.
// Only here so that they can be filtered through the rustdoc passes.
pub external_traits: Arc<ReentrantMutex<RefCell<FxHashMap<DefId, Trait>>>>,
pub external_traits: Rc<RefCell<FxHashMap<DefId, Trait>>>,
pub masked_crates: FxHashSet<CrateNum>,
pub collapsed: bool,
}

impl Clean<Crate> for hir::Crate {
Expand Down Expand Up @@ -223,6 +222,7 @@ impl Clean<Crate> for hir::Crate {
primitives,
external_traits: cx.external_traits.clone(),
masked_crates,
collapsed: false,
}
}
}
Expand Down Expand Up @@ -4398,24 +4398,6 @@ impl Clean<TypeBindingKind> for hir::TypeBindingKind {
}
}

pub fn def_id_to_path(
cx: &DocContext<'_>,
did: DefId,
name: Option<String>
) -> Vec<String> {
let crate_name = name.unwrap_or_else(|| cx.tcx.crate_name(did.krate).to_string());
let relative = cx.tcx.def_path(did).data.into_iter().filter_map(|elem| {
// extern blocks have an empty name
let s = elem.data.to_string();
if !s.is_empty() {
Some(s)
} else {
None
}
});
once(crate_name).chain(relative).collect()
}

pub fn enter_impl_trait<F, R>(cx: &DocContext<'_>, f: F) -> R
where
F: FnOnce() -> R,
Expand Down
18 changes: 9 additions & 9 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -378,7 +378,7 @@ impl Options {
&matches.opt_strs("html-after-content"),
&matches.opt_strs("markdown-before-content"),
&matches.opt_strs("markdown-after-content"),
&diag, &mut id_map, edition) {
&diag, &mut id_map, edition, &None) {
Some(eh) => eh,
None => return Err(3),
};
Expand Down
47 changes: 20 additions & 27 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ use syntax::json::JsonEmitter;
use syntax::symbol::sym;
use errors;
use errors::emitter::{Emitter, EmitterWriter};
use parking_lot::ReentrantMutex;

use std::cell::RefCell;
use std::mem;
use rustc_data_structures::sync::{self, Lrc};
use std::sync::Arc;
use std::rc::Rc;

use crate::config::{Options as RustdocOptions, RenderOptions};
Expand All @@ -46,16 +44,14 @@ pub struct DocContext<'tcx> {

pub tcx: TyCtxt<'tcx>,
pub resolver: Rc<RefCell<interface::BoxedResolver>>,
/// The stack of module NodeIds up till this point
pub crate_name: Option<String>,
pub cstore: Lrc<CStore>,
/// Later on moved into `html::render::CACHE_KEY`
pub renderinfo: RefCell<RenderInfo>,
/// Later on moved through `clean::Crate` into `html::render::CACHE_KEY`
pub external_traits: Arc<ReentrantMutex<RefCell<FxHashMap<DefId, clean::Trait>>>>,
pub external_traits: Rc<RefCell<FxHashMap<DefId, clean::Trait>>>,
/// Used while populating `external_traits` to ensure we don't process the same trait twice at
/// the same time.
pub active_extern_traits: RefCell<Vec<DefId>>,
pub active_extern_traits: RefCell<FxHashSet<DefId>>,
// The current set of type and lifetime substitutions,
// for expanding type aliases at the HIR level:

Expand All @@ -72,7 +68,6 @@ pub struct DocContext<'tcx> {
/// Auto-trait or blanket impls processed so far, as `(self_ty, trait_def_id)`.
// FIXME(eddyb) make this a `ty::TraitRef<'tcx>` set.
pub generated_synthetics: RefCell<FxHashSet<(Ty<'tcx>, DefId)>>,
pub all_traits: Vec<DefId>,
pub auto_traits: Vec<DefId>,
}

Expand Down Expand Up @@ -227,7 +222,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 {
Expand Down Expand Up @@ -332,7 +327,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
file_loader: None,
diagnostic_output: DiagnosticOutput::Default,
stderr: None,
crate_name: crate_name.clone(),
crate_name,
lint_caps,
};

Expand Down Expand Up @@ -368,11 +363,9 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
let mut renderinfo = RenderInfo::default();
renderinfo.access_levels = access_levels;

let all_traits = tcx.all_traits(LOCAL_CRATE).to_vec();
let ctxt = DocContext {
tcx,
resolver,
crate_name,
cstore: compiler.cstore().clone(),
external_traits: Default::default(),
active_extern_traits: Default::default(),
Expand All @@ -384,10 +377,9 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
fake_def_ids: Default::default(),
all_fake_def_ids: Default::default(),
generated_synthetics: Default::default(),
auto_traits: all_traits.iter().cloned().filter(|trait_def_id| {
auto_traits: tcx.all_traits(LOCAL_CRATE).iter().cloned().filter(|trait_def_id| {
tcx.trait_is_auto(*trait_def_id)
}).collect(),
all_traits,
};
debug!("crate: {:?}", tcx.hir().krate());

Expand Down Expand Up @@ -432,8 +424,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());
}
}

Expand All @@ -444,25 +436,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)
})
})
}
Loading