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

Mechanical translation towards making GlobalCtxt implement Sync #46958

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/libproc_macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ crate-type = ["dylib"]
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
rustc_errors = { path = "../librustc_errors" }
rustc_data_structures = { path = "../librustc_data_structures" }
7 changes: 4 additions & 3 deletions src/libproc_macro/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@
extern crate syntax;
extern crate syntax_pos;
extern crate rustc_errors;
extern crate rustc_data_structures;

mod diagnostic;

#[unstable(feature = "proc_macro", issue = "38356")]
pub use diagnostic::{Diagnostic, Level};

use std::{ascii, fmt, iter};
use std::rc::Rc;
use rustc_data_structures::sync::Lrc;
use std::str::FromStr;

use syntax::ast;
Expand Down Expand Up @@ -277,7 +278,7 @@ pub struct LineColumn {
#[unstable(feature = "proc_macro", issue = "38356")]
#[derive(Clone)]
pub struct SourceFile {
filemap: Rc<FileMap>,
filemap: Lrc<FileMap>,
}

impl SourceFile {
Expand Down Expand Up @@ -327,7 +328,7 @@ impl fmt::Debug for SourceFile {
#[unstable(feature = "proc_macro", issue = "38356")]
impl PartialEq for SourceFile {
fn eq(&self, other: &Self) -> bool {
Rc::ptr_eq(&self.filemap, &other.filemap)
Lrc::ptr_eq(&self.filemap, &other.filemap)
}
}

Expand Down
45 changes: 22 additions & 23 deletions src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ 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 std::rc::Rc;
use ty::TyCtxt;
use util::common::{ProfileQueriesMsg, profq_msg};

Expand All @@ -32,7 +31,7 @@ use super::prev::PreviousDepGraph;

#[derive(Clone)]
pub struct DepGraph {
data: Option<Rc<DepGraphData>>,
data: Option<Lrc<DepGraphData>>,

// At the moment we are using DepNode as key here. In the future it might
// be possible to use an IndexVec<DepNodeIndex, _> here. At the moment there
Expand All @@ -41,7 +40,7 @@ pub struct DepGraph {
// we need to have a dep-graph to generate DepNodeIndices.
// - The architecture is still in flux and it's not clear what how to best
// implement things.
fingerprints: Rc<RefCell<FxHashMap<DepNode, Fingerprint>>>
fingerprints: Lrc<Lock<FxHashMap<DepNode, Fingerprint>>>
}


Expand Down Expand Up @@ -71,50 +70,50 @@ 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 {

pub fn new(prev_graph: PreviousDepGraph) -> DepGraph {
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(FxHashMap())),
fingerprints: Lrc::new(Lock::new(FxHashMap())),
}
}

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

Expand Down Expand Up @@ -196,8 +195,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>,
Expand Down Expand Up @@ -384,13 +383,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()
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/dep_graph/raii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ use hir::print::Nested;
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;
Expand Down Expand Up @@ -255,7 +256,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>,
Expand Down Expand Up @@ -1090,7 +1091,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);
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/ich/caching_codemap_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::rc::Rc;
use rustc_data_structures::sync::Lrc;
use syntax::codemap::CodeMap;
use syntax_pos::{BytePos, FileMap};

Expand All @@ -18,7 +18,7 @@ struct CacheEntry {
line_number: usize,
line_start: BytePos,
line_end: BytePos,
file: Rc<FileMap>,
file: Lrc<FileMap>,
file_index: usize,
}

Expand Down Expand Up @@ -51,7 +51,7 @@ impl<'cm> CachingCodemapView<'cm> {

pub fn byte_pos_to_line_and_col(&mut self,
pos: BytePos)
-> Option<(Rc<FileMap>, usize, BytePos)> {
-> Option<(Lrc<FileMap>, usize, BytePos)> {
self.time_stamp += 1;

// Check if the position is in one of the cached lines
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/ich/hcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for Span {
// Since the same expansion context is usually referenced many
// times, we cache a stable hash of it and hash that instead of
// recursing every time.
use std::cell::RefCell;
// FIXME: Move this to Session or a syntax_pos global
thread_local! {
static CACHE: RefCell<FxHashMap<hygiene::Mark, u64>> =
RefCell::new(FxHashMap());
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
Expand Down Expand Up @@ -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>>,
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
pub use self::Level::*;
pub use self::LintSource::*;

use std::rc::Rc;
use rustc_data_structures::sync::{Send, Sync, Lrc};

use errors::{DiagnosticBuilder, DiagnosticId};
use hir::def_id::{CrateNum, LOCAL_CRATE};
Expand Down Expand Up @@ -257,8 +257,8 @@ pub trait EarlyLintPass: LintPass {
}

/// A lint pass boxed up as a trait object.
pub type EarlyLintPassObject = Box<EarlyLintPass + 'static>;
pub type LateLintPassObject = Box<for<'a, 'tcx> LateLintPass<'a, 'tcx> + 'static>;
pub type EarlyLintPassObject = Box<EarlyLintPass + Send + Sync + 'static>;
pub type LateLintPassObject = Box<for<'a, 'tcx> LateLintPass<'a, 'tcx> + Send + Sync + 'static>;

/// Identifies a lint known to the compiler.
#[derive(Clone, Copy, Debug)]
Expand Down Expand Up @@ -480,7 +480,7 @@ pub fn struct_lint_level<'a>(sess: &'a Session,
}

fn lint_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, cnum: CrateNum)
-> Rc<LintLevelMap>
-> Lrc<LintLevelMap>
{
assert_eq!(cnum, LOCAL_CRATE);
let mut builder = LintLevelMapBuilder {
Expand All @@ -493,7 +493,7 @@ fn lint_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, cnum: CrateNum)
intravisit::walk_crate(builder, krate);
});

Rc::new(builder.levels.build_map())
Lrc::new(builder.levels.build_map())
}

struct LintLevelMapBuilder<'a, 'tcx: 'a> {
Expand Down
Loading