Skip to content

Commit

Permalink
Remove ReentrantMutex
Browse files Browse the repository at this point in the history
This drops the parking_lot dependency; the ReentrantMutex type appeared
to be unused (at least, no compilation failures occurred).

This is technically a possible change in behavior of its users, as
lock() would wait on other threads releasing their guards, but since we
didn't actually remove any threading or such in this code, it appears
that we never used that behavior (the behavior change is only noticeable
if the type previously was used in two threads, in a single thread
ReentrantMutex is useless).
  • Loading branch information
Mark-Simulacrum committed Aug 11, 2019
1 parent 8f80a8d commit c574810
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 16 deletions.
1 change: 0 additions & 1 deletion Cargo.lock
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
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"
6 changes: 2 additions & 4 deletions src/librustdoc/clean/inline.rs
Expand Up @@ -574,8 +574,7 @@ 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;
Expand All @@ -588,8 +587,7 @@ pub fn record_extern_trait(cx: &DocContext<'_>, did: DefId) {
let trait_ = build_external_trait(cx, did);

{
let external_traits = cx.external_traits.lock();
external_traits.borrow_mut().insert(did, trait_);
cx.external_traits.borrow_mut().insert(did, trait_);
}
cx.active_extern_traits.borrow_mut().remove_item(&did);
}
4 changes: 1 addition & 3 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -45,8 +45,6 @@ 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,7 +131,7 @@ 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: Arc<RefCell<FxHashMap<DefId, Trait>>>,
pub masked_crates: FxHashSet<CrateNum>,
}

Expand Down
3 changes: 1 addition & 2 deletions src/librustdoc/core.rs
Expand Up @@ -22,7 +22,6 @@ 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;
Expand Down Expand Up @@ -50,7 +49,7 @@ pub struct DocContext<'tcx> {
/// 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: Arc<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>>,
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/fold.rs
Expand Up @@ -105,12 +105,12 @@ pub trait DocFolder : Sized {
c.module = c.module.take().and_then(|module| self.fold_item(module));

{
let guard = c.external_traits.lock();
let traits = guard.replace(Default::default());
guard.borrow_mut().extend(traits.into_iter().map(|(k, mut v)| {
let mut guard = c.external_traits.borrow_mut();
let external_traits = std::mem::replace(&mut *guard, Default::default());
*guard = external_traits.into_iter().map(|(k, mut v)| {
v.items = v.items.into_iter().filter_map(|i| self.fold_item(i)).collect();
(k, v)
}));
}).collect();
}
c
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render.rs
Expand Up @@ -659,7 +659,7 @@ pub fn run(mut krate: clean::Crate,
crate_version: krate.version.take(),
orphan_impl_items: Vec::new(),
orphan_trait_impls: Vec::new(),
traits: krate.external_traits.lock().replace(Default::default()),
traits: krate.external_traits.replace(Default::default()),
deref_trait_did,
deref_mut_trait_did,
owned_box_did,
Expand Down

0 comments on commit c574810

Please sign in to comment.