Skip to content
Permalink
Browse files

locks

  • Loading branch information...
Zoxc committed Feb 15, 2018
1 parent 5ab7c89 commit 12756affd4ab4467da80ac2e18bde50a8a1c3ede
@@ -13,7 +13,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
StableHashingContextProvider};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
use std::cell::{Ref, RefCell};
use rustc_data_structures::sync::{Lrc, RwLock, ReadGuard, Lock};
use std::env;
use std::hash::Hash;
use ty::TyCtxt;
@@ -37,7 +37,7 @@ pub struct DepGraph {
// result value fingerprints. Do not rely on the length of this vector
// being the same as the number of nodes in the graph. The vector can
// contain an arbitrary number of zero-entries at the end.
fingerprints: Rc<RefCell<IndexVec<DepNodeIndex, Fingerprint>>>
fingerprints: Lrc<Lock<IndexVec<DepNodeIndex, Fingerprint>>>
}


@@ -67,27 +67,27 @@ struct DepGraphData {
/// tracking. The `current` field is the dependency graph of only the
/// current compilation session: We don't merge the previous dep-graph into
/// current one anymore.
current: RefCell<CurrentDepGraph>,
current: Lock<CurrentDepGraph>,

/// The dep-graph from the previous compilation session. It contains all
/// nodes and edges as well as all fingerprints of nodes that have them.
previous: PreviousDepGraph,

colors: RefCell<FxHashMap<DepNode, DepNodeColor>>,
colors: Lock<FxHashMap<DepNode, DepNodeColor>>,

/// When we load, there may be `.o` files, cached mir, or other such
/// things available to us. If we find that they are not dirty, we
/// load the path to the file storing those work-products here into
/// this map. We can later look for and extract that data.
previous_work_products: RefCell<FxHashMap<WorkProductId, WorkProduct>>,
previous_work_products: RwLock<FxHashMap<WorkProductId, WorkProduct>>,

/// Work-products that we generate in this run.
work_products: RefCell<FxHashMap<WorkProductId, WorkProduct>>,
work_products: RwLock<FxHashMap<WorkProductId, WorkProduct>>,

dep_node_debug: RefCell<FxHashMap<DepNode, String>>,
dep_node_debug: Lock<FxHashMap<DepNode, String>>,

// Used for testing, only populated when -Zquery-dep-graph is specified.
loaded_from_cache: RefCell<FxHashMap<DepNodeIndex, bool>>,
loaded_from_cache: Lock<FxHashMap<DepNodeIndex, bool>>,
}

impl DepGraph {
@@ -99,23 +99,23 @@ impl DepGraph {
let fingerprints = IndexVec::from_elem_n(Fingerprint::ZERO,
(prev_graph.node_count() * 115) / 100);
DepGraph {
data: Some(Rc::new(DepGraphData {
previous_work_products: RefCell::new(FxHashMap()),
work_products: RefCell::new(FxHashMap()),
dep_node_debug: RefCell::new(FxHashMap()),
current: RefCell::new(CurrentDepGraph::new()),
data: Some(Lrc::new(DepGraphData {
previous_work_products: RwLock::new(FxHashMap()),
work_products: RwLock::new(FxHashMap()),
dep_node_debug: Lock::new(FxHashMap()),
current: Lock::new(CurrentDepGraph::new()),
previous: prev_graph,
colors: RefCell::new(FxHashMap()),
loaded_from_cache: RefCell::new(FxHashMap()),
colors: Lock::new(FxHashMap()),
loaded_from_cache: Lock::new(FxHashMap()),
})),
fingerprints: Rc::new(RefCell::new(fingerprints)),
fingerprints: Lrc::new(Lock::new(fingerprints)),
}
}

pub fn new_disabled() -> DepGraph {
DepGraph {
data: None,
fingerprints: Rc::new(RefCell::new(IndexVec::new())),
fingerprints: Lrc::new(Lock::new(IndexVec::new())),
}
}

@@ -205,8 +205,8 @@ impl DepGraph {
cx: C,
arg: A,
task: fn(C, A) -> R,
push: fn(&RefCell<CurrentDepGraph>, DepNode),
pop: fn(&RefCell<CurrentDepGraph>, DepNode) -> DepNodeIndex)
push: fn(&Lock<CurrentDepGraph>, DepNode),
pop: fn(&Lock<CurrentDepGraph>, DepNode) -> DepNodeIndex)
-> (R, DepNodeIndex)
where C: DepGraphSafe + StableHashingContextProvider<ContextType=HCX>,
R: HashStable<HCX>,
@@ -417,13 +417,13 @@ impl DepGraph {

/// Access the map of work-products created during this run. Only
/// used during saving of the dep-graph.
pub fn work_products(&self) -> Ref<FxHashMap<WorkProductId, WorkProduct>> {
pub fn work_products(&self) -> ReadGuard<FxHashMap<WorkProductId, WorkProduct>> {
self.data.as_ref().unwrap().work_products.borrow()
}

/// Access the map of work-products created during the cached run. Only
/// used during saving of the dep-graph.
pub fn previous_work_products(&self) -> Ref<FxHashMap<WorkProductId, WorkProduct>> {
pub fn previous_work_products(&self) -> ReadGuard<FxHashMap<WorkProductId, WorkProduct>> {
self.data.as_ref().unwrap().previous_work_products.borrow()
}

@@ -10,14 +10,14 @@

use super::graph::CurrentDepGraph;

use std::cell::RefCell;
use rustc_data_structures::sync::Lock;

pub struct IgnoreTask<'graph> {
graph: &'graph RefCell<CurrentDepGraph>,
graph: &'graph Lock<CurrentDepGraph>,
}

impl<'graph> IgnoreTask<'graph> {
pub(super) fn new(graph: &'graph RefCell<CurrentDepGraph>) -> IgnoreTask<'graph> {
pub(super) fn new(graph: &'graph Lock<CurrentDepGraph>) -> IgnoreTask<'graph> {
graph.borrow_mut().push_ignore();
IgnoreTask {
graph,
@@ -30,9 +30,10 @@ use hir::svh::Svh;
use util::nodemap::{DefIdMap, FxHashMap};

use arena::TypedArena;
use std::cell::RefCell;
use std::io;

use rustc_data_structures::sync::Lock;

pub mod blocks;
mod collector;
mod def_collector;
@@ -259,7 +260,7 @@ pub struct Map<'hir> {
definitions: &'hir Definitions,

/// Bodies inlined from other crates are cached here.
inlined_bodies: RefCell<DefIdMap<&'hir Body>>,
inlined_bodies: Lock<DefIdMap<&'hir Body>>,

/// The reverse mapping of `node_to_hir_id`.
hir_to_node_id: FxHashMap<HirId, NodeId>,
@@ -1095,7 +1096,7 @@ pub fn map_crate<'hir>(sess: &::session::Session,
map,
hir_to_node_id,
definitions,
inlined_bodies: RefCell::new(DefIdMap()),
inlined_bodies: Lock::new(DefIdMap()),
};

hir_id_validator::check_crate(&map);
@@ -27,6 +27,7 @@
use self::TargetLint::*;

use std::slice;
use rustc_data_structures::sync::{RwLock, ReadGuard};
use lint::{EarlyLintPassObject, LateLintPassObject};
use lint::{Level, Lint, LintId, LintPass, LintBuffer};
use lint::levels::{LintLevelSets, LintLevelsBuilder};
@@ -39,7 +40,6 @@ use ty::layout::{LayoutError, LayoutOf, TyLayout};
use util::nodemap::FxHashMap;

use std::default::Default as StdDefault;
use std::cell::{Ref, RefCell};
use syntax::ast;
use syntax_pos::{MultiSpan, Span};
use errors::DiagnosticBuilder;
@@ -77,7 +77,7 @@ pub struct LintStore {

pub struct LintSession<'a, PassObject> {
/// Reference to the store of registered lints.
lints: Ref<'a, LintStore>,
lints: ReadGuard<'a, LintStore>,

/// Trait objects for each lint pass.
passes: Option<Vec<PassObject>>,
@@ -317,7 +317,7 @@ impl<'a, PassObject: LintPassObject> LintSession<'a, PassObject> {
/// Creates a new `LintSession`, by moving out the `LintStore`'s initial
/// lint levels and pass objects. These can be restored using the `restore`
/// method.
fn new(store: &'a RefCell<LintStore>) -> LintSession<'a, PassObject> {
fn new(store: &'a RwLock<LintStore>) -> LintSession<'a, PassObject> {
let mut s = store.borrow_mut();
let passes = PassObject::take_passes(&mut *s);
drop(s);
@@ -328,7 +328,7 @@ impl<'a, PassObject: LintPassObject> LintSession<'a, PassObject> {
}

/// Restores the levels back to the original lint store.
fn restore(self, store: &RefCell<LintStore>) {
fn restore(self, store: &RwLock<LintStore>) {
drop(self.lints);
let mut s = store.borrow_mut();
PassObject::restore_passes(&mut *s, self.passes);
@@ -18,7 +18,7 @@
use session::Session;
use syntax::ast;

use std::cell::Cell;
use rustc_data_structures::sync::LockCell;

pub fn update_limits(sess: &Session, krate: &ast::Crate) {
update_limit(sess, krate, &sess.recursion_limit, "recursion_limit",
@@ -27,7 +27,7 @@ pub fn update_limits(sess: &Session, krate: &ast::Crate) {
"type length limit");
}

fn update_limit(sess: &Session, krate: &ast::Crate, limit: &Cell<usize>,
fn update_limit(sess: &Session, krate: &ast::Crate, limit: &LockCell<usize>,
name: &str, description: &str) {
for attr in &krate.attrs {
if !attr.check_name(name) {
@@ -8,8 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::cell::{Ref, RefCell};
use rustc_data_structures::indexed_vec::IndexVec;
use rustc_data_structures::sync::{RwLock, ReadGuard};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
StableHasherResult};
use ich::StableHashingContext;
@@ -19,7 +19,7 @@ use rustc_serialize as serialize;

#[derive(Clone, Debug)]
pub struct Cache {
predecessors: RefCell<Option<IndexVec<BasicBlock, Vec<BasicBlock>>>>
predecessors: RwLock<Option<IndexVec<BasicBlock, Vec<BasicBlock>>>>
}


@@ -46,7 +46,7 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for Cache {
impl Cache {
pub fn new() -> Self {
Cache {
predecessors: RefCell::new(None)
predecessors: RwLock::new(None)
}
}

@@ -55,12 +55,12 @@ impl Cache {
*self.predecessors.borrow_mut() = None;
}

pub fn predecessors(&self, mir: &Mir) -> Ref<IndexVec<BasicBlock, Vec<BasicBlock>>> {
pub fn predecessors(&self, mir: &Mir) -> ReadGuard<IndexVec<BasicBlock, Vec<BasicBlock>>> {
if self.predecessors.borrow().is_none() {
*self.predecessors.borrow_mut() = Some(calculate_predecessors(mir));
}

Ref::map(self.predecessors.borrow(), |p| p.as_ref().unwrap())
ReadGuard::map(self.predecessors.borrow(), |p| p.as_ref().unwrap())
}
}

@@ -33,7 +33,7 @@ use std::slice;
use hir::{self, InlineAsm};
use std::ascii;
use std::borrow::{Cow};
use std::cell::Ref;
use rustc_data_structures::sync::ReadGuard;
use std::fmt::{self, Debug, Formatter, Write};
use std::{iter, u32};
use std::ops::{Index, IndexMut};
@@ -186,13 +186,13 @@ impl<'tcx> Mir<'tcx> {
}

#[inline]
pub fn predecessors(&self) -> Ref<IndexVec<BasicBlock, Vec<BasicBlock>>> {
pub fn predecessors(&self) -> ReadGuard<IndexVec<BasicBlock, Vec<BasicBlock>>> {
self.cache.predecessors(self)
}

#[inline]
pub fn predecessors_for(&self, bb: BasicBlock) -> Ref<Vec<BasicBlock>> {
Ref::map(self.predecessors(), |p| &p[bb])
pub fn predecessors_for(&self, bb: BasicBlock) -> ReadGuard<Vec<BasicBlock>> {
ReadGuard::map(self.predecessors(), |p| &p[bb])
}

#[inline]
Oops, something went wrong.

0 comments on commit 12756af

Please sign in to comment.
You can’t perform that action at this time.