Skip to content

Commit e3a63ed

Browse files
committed
Mechanical translation which results in GlobalCtxt being Sync
1 parent 3bb008d commit e3a63ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+720
-686
lines changed

src/Cargo.lock

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/libproc_macro/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ crate-type = ["dylib"]
1111
syntax = { path = "../libsyntax" }
1212
syntax_pos = { path = "../libsyntax_pos" }
1313
rustc_errors = { path = "../librustc_errors" }
14+
rustc_data_structures = { path = "../librustc_data_structures" }

src/libproc_macro/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@
4343
extern crate syntax;
4444
extern crate syntax_pos;
4545
extern crate rustc_errors;
46+
extern crate rustc_data_structures;
4647

4748
mod diagnostic;
4849

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

5253
use std::{ascii, fmt, iter};
53-
use std::rc::Rc;
54+
use rustc_data_structures::sync::Lrc;
5455
use std::str::FromStr;
5556

5657
use syntax::ast;
@@ -275,7 +276,7 @@ pub struct LineColumn {
275276
#[unstable(feature = "proc_macro", issue = "38356")]
276277
#[derive(Clone)]
277278
pub struct SourceFile {
278-
filemap: Rc<FileMap>,
279+
filemap: Lrc<FileMap>,
279280
}
280281

281282
impl SourceFile {
@@ -325,7 +326,7 @@ impl fmt::Debug for SourceFile {
325326
#[unstable(feature = "proc_macro", issue = "38356")]
326327
impl PartialEq for SourceFile {
327328
fn eq(&self, other: &Self) -> bool {
328-
Rc::ptr_eq(&self.filemap, &other.filemap)
329+
Lrc::ptr_eq(&self.filemap, &other.filemap)
329330
}
330331
}
331332

src/librustc/dep_graph/graph.rs

+22-23
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
1313
StableHashingContextProvider};
1414
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1515
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
16-
use std::cell::{Ref, RefCell};
16+
use rustc_data_structures::sync::{Lrc, RwLock, ReadGuard, Lock};
1717
use std::env;
1818
use std::hash::Hash;
19-
use std::rc::Rc;
2019
use ty::TyCtxt;
2120
use util::common::{ProfileQueriesMsg, profq_msg};
2221

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

3332
#[derive(Clone)]
3433
pub struct DepGraph {
35-
data: Option<Rc<DepGraphData>>,
34+
data: Option<Lrc<DepGraphData>>,
3635

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

4746

@@ -71,50 +70,50 @@ struct DepGraphData {
7170
/// tracking. The `current` field is the dependency graph of only the
7271
/// current compilation session: We don't merge the previous dep-graph into
7372
/// current one anymore.
74-
current: RefCell<CurrentDepGraph>,
73+
current: Lock<CurrentDepGraph>,
7574

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

80-
colors: RefCell<FxHashMap<DepNode, DepNodeColor>>,
79+
colors: Lock<FxHashMap<DepNode, DepNodeColor>>,
8180

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

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

91-
dep_node_debug: RefCell<FxHashMap<DepNode, String>>,
90+
dep_node_debug: Lock<FxHashMap<DepNode, String>>,
9291

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

9796
impl DepGraph {
9897

9998
pub fn new(prev_graph: PreviousDepGraph) -> DepGraph {
10099
DepGraph {
101-
data: Some(Rc::new(DepGraphData {
102-
previous_work_products: RefCell::new(FxHashMap()),
103-
work_products: RefCell::new(FxHashMap()),
104-
dep_node_debug: RefCell::new(FxHashMap()),
105-
current: RefCell::new(CurrentDepGraph::new()),
100+
data: Some(Lrc::new(DepGraphData {
101+
previous_work_products: RwLock::new(FxHashMap()),
102+
work_products: RwLock::new(FxHashMap()),
103+
dep_node_debug: Lock::new(FxHashMap()),
104+
current: Lock::new(CurrentDepGraph::new()),
106105
previous: prev_graph,
107-
colors: RefCell::new(FxHashMap()),
108-
loaded_from_cache: RefCell::new(FxHashMap()),
106+
colors: Lock::new(FxHashMap()),
107+
loaded_from_cache: Lock::new(FxHashMap()),
109108
})),
110-
fingerprints: Rc::new(RefCell::new(FxHashMap())),
109+
fingerprints: Lrc::new(Lock::new(FxHashMap())),
111110
}
112111
}
113112

114113
pub fn new_disabled() -> DepGraph {
115114
DepGraph {
116115
data: None,
117-
fingerprints: Rc::new(RefCell::new(FxHashMap())),
116+
fingerprints: Lrc::new(Lock::new(FxHashMap())),
118117
}
119118
}
120119

@@ -196,8 +195,8 @@ impl DepGraph {
196195
cx: C,
197196
arg: A,
198197
task: fn(C, A) -> R,
199-
push: fn(&RefCell<CurrentDepGraph>, DepNode),
200-
pop: fn(&RefCell<CurrentDepGraph>, DepNode) -> DepNodeIndex)
198+
push: fn(&Lock<CurrentDepGraph>, DepNode),
199+
pop: fn(&Lock<CurrentDepGraph>, DepNode) -> DepNodeIndex)
201200
-> (R, DepNodeIndex)
202201
where C: DepGraphSafe + StableHashingContextProvider<ContextType=HCX>,
203202
R: HashStable<HCX>,
@@ -384,13 +383,13 @@ impl DepGraph {
384383

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

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

src/librustc/dep_graph/raii.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
use super::graph::CurrentDepGraph;
1212

13-
use std::cell::RefCell;
13+
use rustc_data_structures::sync::Lock;
1414

1515
pub struct IgnoreTask<'graph> {
16-
graph: &'graph RefCell<CurrentDepGraph>,
16+
graph: &'graph Lock<CurrentDepGraph>,
1717
}
1818

1919
impl<'graph> IgnoreTask<'graph> {
20-
pub(super) fn new(graph: &'graph RefCell<CurrentDepGraph>) -> IgnoreTask<'graph> {
20+
pub(super) fn new(graph: &'graph Lock<CurrentDepGraph>) -> IgnoreTask<'graph> {
2121
graph.borrow_mut().push_ignore();
2222
IgnoreTask {
2323
graph,

src/librustc/hir/map/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ use hir::print::Nested;
2929
use util::nodemap::{DefIdMap, FxHashMap};
3030

3131
use arena::TypedArena;
32-
use std::cell::RefCell;
3332
use std::io;
3433

34+
use rustc_data_structures::sync::Lock;
35+
3536
pub mod blocks;
3637
mod collector;
3738
mod def_collector;
@@ -255,7 +256,7 @@ pub struct Map<'hir> {
255256
definitions: &'hir Definitions,
256257

257258
/// Bodies inlined from other crates are cached here.
258-
inlined_bodies: RefCell<DefIdMap<&'hir Body>>,
259+
inlined_bodies: Lock<DefIdMap<&'hir Body>>,
259260

260261
/// The reverse mapping of `node_to_hir_id`.
261262
hir_to_node_id: FxHashMap<HirId, NodeId>,
@@ -1091,7 +1092,7 @@ pub fn map_crate<'hir>(sess: &::session::Session,
10911092
map,
10921093
hir_to_node_id,
10931094
definitions,
1094-
inlined_bodies: RefCell::new(DefIdMap()),
1095+
inlined_bodies: Lock::new(DefIdMap()),
10951096
};
10961097

10971098
hir_id_validator::check_crate(&map);

src/librustc/ich/caching_codemap_view.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::rc::Rc;
11+
use rustc_data_structures::sync::Lrc;
1212
use syntax::codemap::CodeMap;
1313
use syntax_pos::{BytePos, FileMap};
1414

@@ -18,7 +18,7 @@ struct CacheEntry {
1818
line_number: usize,
1919
line_start: BytePos,
2020
line_end: BytePos,
21-
file: Rc<FileMap>,
21+
file: Lrc<FileMap>,
2222
file_index: usize,
2323
}
2424

@@ -51,7 +51,7 @@ impl<'cm> CachingCodemapView<'cm> {
5151

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

5757
// Check if the position is in one of the cached lines

src/librustc/lint/context.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use self::TargetLint::*;
2828

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

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

7878
pub struct LintSession<'a, PassObject> {
7979
/// Reference to the store of registered lints.
80-
lints: Ref<'a, LintStore>,
80+
lints: ReadGuard<'a, LintStore>,
8181

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

330330
/// Restores the levels back to the original lint store.
331-
fn restore(self, store: &RefCell<LintStore>) {
331+
fn restore(self, store: &RwLock<LintStore>) {
332332
drop(self.lints);
333333
let mut s = store.borrow_mut();
334334
PassObject::restore_passes(&mut *s, self.passes);

src/librustc/lint/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
pub use self::Level::*;
3232
pub use self::LintSource::*;
3333

34-
use std::rc::Rc;
34+
use rustc_data_structures::sync::{Send, Sync, Lrc};
3535

3636
use errors::{DiagnosticBuilder, DiagnosticId};
3737
use hir::def_id::{CrateNum, LOCAL_CRATE};
@@ -257,8 +257,8 @@ pub trait EarlyLintPass: LintPass {
257257
}
258258

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

263263
/// Identifies a lint known to the compiler.
264264
#[derive(Clone, Copy, Debug)]
@@ -479,7 +479,7 @@ pub fn struct_lint_level<'a>(sess: &'a Session,
479479
}
480480

481481
fn lint_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, cnum: CrateNum)
482-
-> Rc<LintLevelMap>
482+
-> Lrc<LintLevelMap>
483483
{
484484
assert_eq!(cnum, LOCAL_CRATE);
485485
let mut builder = LintLevelMapBuilder {
@@ -492,7 +492,7 @@ fn lint_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, cnum: CrateNum)
492492
intravisit::walk_crate(builder, krate);
493493
});
494494

495-
Rc::new(builder.levels.build_map())
495+
Lrc::new(builder.levels.build_map())
496496
}
497497

498498
struct LintLevelMapBuilder<'a, 'tcx: 'a> {

0 commit comments

Comments
 (0)