Skip to content

Commit e8af0f4

Browse files
committed
Auto merge of rust-lang#48586 - Zoxc:atomic-rc, r=michaelwoerister
Replace Rc with Lrc for shared data This replaces `Rc`s reachable from `TyCtxt` with `Lrc`. This has no effect unless `cfg(parallel_queries)` is set. It also contains a fix for the `Decodable` impl for `Arc`. r? @nikomatsakis
2 parents 9cb18a9 + fce7201 commit e8af0f4

Some content is hidden

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

87 files changed

+442
-414
lines changed

src/Cargo.lock

+5
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

+10-3
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,21 @@
3838
#![feature(rustc_private)]
3939
#![feature(staged_api)]
4040
#![feature(lang_items)]
41+
#![feature(optin_builtin_traits)]
4142

4243
#[macro_use]
4344
extern crate syntax;
4445
extern crate syntax_pos;
4546
extern crate rustc_errors;
47+
extern crate rustc_data_structures;
4648

4749
mod diagnostic;
4850

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

5254
use std::{ascii, fmt, iter};
53-
use std::rc::Rc;
55+
use rustc_data_structures::sync::Lrc;
5456
use std::str::FromStr;
5557

5658
use syntax::ast;
@@ -306,9 +308,14 @@ pub struct LineColumn {
306308
#[unstable(feature = "proc_macro", issue = "38356")]
307309
#[derive(Clone)]
308310
pub struct SourceFile {
309-
filemap: Rc<FileMap>,
311+
filemap: Lrc<FileMap>,
310312
}
311313

314+
#[unstable(feature = "proc_macro", issue = "38356")]
315+
impl !Send for SourceFile {}
316+
#[unstable(feature = "proc_macro", issue = "38356")]
317+
impl !Sync for SourceFile {}
318+
312319
impl SourceFile {
313320
/// Get the path to this source file.
314321
///
@@ -356,7 +363,7 @@ impl fmt::Debug for SourceFile {
356363
#[unstable(feature = "proc_macro", issue = "38356")]
357364
impl PartialEq for SourceFile {
358365
fn eq(&self, other: &Self) -> bool {
359-
Rc::ptr_eq(&self.filemap, &other.filemap)
366+
Lrc::ptr_eq(&self.filemap, &other.filemap)
360367
}
361368
}
362369

src/librustc/dep_graph/graph.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ 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 rustc_data_structures::sync::Lrc;
1617
use std::cell::{Ref, RefCell};
1718
use std::env;
1819
use std::hash::Hash;
19-
use std::rc::Rc;
2020
use ty::TyCtxt;
2121
use util::common::{ProfileQueriesMsg, profq_msg};
2222

@@ -32,13 +32,13 @@ use super::prev::PreviousDepGraph;
3232

3333
#[derive(Clone)]
3434
pub struct DepGraph {
35-
data: Option<Rc<DepGraphData>>,
35+
data: Option<Lrc<DepGraphData>>,
3636

3737
// A vector mapping depnodes from the current graph to their associated
3838
// result value fingerprints. Do not rely on the length of this vector
3939
// being the same as the number of nodes in the graph. The vector can
4040
// contain an arbitrary number of zero-entries at the end.
41-
fingerprints: Rc<RefCell<IndexVec<DepNodeIndex, Fingerprint>>>
41+
fingerprints: Lrc<RefCell<IndexVec<DepNodeIndex, Fingerprint>>>
4242
}
4343

4444

@@ -102,7 +102,7 @@ impl DepGraph {
102102
let fingerprints = IndexVec::from_elem_n(Fingerprint::ZERO,
103103
(prev_graph_node_count * 115) / 100);
104104
DepGraph {
105-
data: Some(Rc::new(DepGraphData {
105+
data: Some(Lrc::new(DepGraphData {
106106
previous_work_products: RefCell::new(FxHashMap()),
107107
work_products: RefCell::new(FxHashMap()),
108108
dep_node_debug: RefCell::new(FxHashMap()),
@@ -111,14 +111,14 @@ impl DepGraph {
111111
colors: RefCell::new(DepNodeColorMap::new(prev_graph_node_count)),
112112
loaded_from_cache: RefCell::new(FxHashMap()),
113113
})),
114-
fingerprints: Rc::new(RefCell::new(fingerprints)),
114+
fingerprints: Lrc::new(RefCell::new(fingerprints)),
115115
}
116116
}
117117

118118
pub fn new_disabled() -> DepGraph {
119119
DepGraph {
120120
data: None,
121-
fingerprints: Rc::new(RefCell::new(IndexVec::new())),
121+
fingerprints: Lrc::new(RefCell::new(IndexVec::new())),
122122
}
123123
}
124124

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/mod.rs

+3-3
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::Lrc;
3535

3636
use errors::{DiagnosticBuilder, DiagnosticId};
3737
use hir::def_id::{CrateNum, LOCAL_CRATE};
@@ -505,7 +505,7 @@ pub fn struct_lint_level<'a>(sess: &'a Session,
505505
}
506506

507507
fn lint_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, cnum: CrateNum)
508-
-> Rc<LintLevelMap>
508+
-> Lrc<LintLevelMap>
509509
{
510510
assert_eq!(cnum, LOCAL_CRATE);
511511
let mut builder = LintLevelMapBuilder {
@@ -518,7 +518,7 @@ fn lint_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, cnum: CrateNum)
518518
intravisit::walk_crate(builder, krate);
519519
});
520520

521-
Rc::new(builder.levels.build_map())
521+
Lrc::new(builder.levels.build_map())
522522
}
523523

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

src/librustc/middle/cstore.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ use util::nodemap::NodeSet;
3737
use std::any::Any;
3838
use std::collections::BTreeMap;
3939
use std::path::{Path, PathBuf};
40-
use std::rc::Rc;
4140
use rustc_data_structures::owning_ref::ErasedBoxRef;
4241
use syntax::ast;
4342
use syntax::ext::base::SyntaxExtension;
4443
use syntax::symbol::Symbol;
4544
use syntax_pos::Span;
4645
use rustc_back::target::Target;
46+
use rustc_data_structures::sync::Lrc;
4747

4848
pub use self::NativeLibraryKind::*;
4949

@@ -139,7 +139,7 @@ pub struct NativeLibrary {
139139

140140
pub enum LoadedMacro {
141141
MacroDef(ast::Item),
142-
ProcMacro(Rc<SyntaxExtension>),
142+
ProcMacro(Lrc<SyntaxExtension>),
143143
}
144144

145145
#[derive(Copy, Clone, Debug)]
@@ -206,7 +206,7 @@ pub struct ExternConstBody<'tcx> {
206206

207207
#[derive(Clone)]
208208
pub struct ExternBodyNestedBodies {
209-
pub nested_bodies: Rc<BTreeMap<hir::BodyId, hir::Body>>,
209+
pub nested_bodies: Lrc<BTreeMap<hir::BodyId, hir::Body>>,
210210

211211
// It would require a lot of infrastructure to enable stable-hashing Bodies
212212
// from other crates, so we hash on export and just store the fingerprint
@@ -225,7 +225,7 @@ pub struct ExternBodyNestedBodies {
225225
/// (it'd break incremental compilation) and should only be called pre-HIR (e.g.
226226
/// during resolve)
227227
pub trait CrateStore {
228-
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Rc<Any>;
228+
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Lrc<Any>;
229229

230230
// access to the metadata loader
231231
fn metadata_loader(&self) -> &MetadataLoader;
@@ -234,7 +234,7 @@ pub trait CrateStore {
234234
fn def_key(&self, def: DefId) -> DefKey;
235235
fn def_path(&self, def: DefId) -> hir_map::DefPath;
236236
fn def_path_hash(&self, def: DefId) -> hir_map::DefPathHash;
237-
fn def_path_table(&self, cnum: CrateNum) -> Rc<DefPathTable>;
237+
fn def_path_table(&self, cnum: CrateNum) -> Lrc<DefPathTable>;
238238

239239
// "queries" used in resolve that aren't tracked for incremental compilation
240240
fn visibility_untracked(&self, def: DefId) -> ty::Visibility;
@@ -297,7 +297,7 @@ pub struct DummyCrateStore;
297297

298298
#[allow(unused_variables)]
299299
impl CrateStore for DummyCrateStore {
300-
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Rc<Any>
300+
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Lrc<Any>
301301
{ bug!("crate_data_as_rc_any") }
302302
// item info
303303
fn visibility_untracked(&self, def: DefId) -> ty::Visibility { bug!("visibility") }
@@ -325,7 +325,7 @@ impl CrateStore for DummyCrateStore {
325325
fn def_path_hash(&self, def: DefId) -> hir_map::DefPathHash {
326326
bug!("def_path_hash")
327327
}
328-
fn def_path_table(&self, cnum: CrateNum) -> Rc<DefPathTable> {
328+
fn def_path_table(&self, cnum: CrateNum) -> Lrc<DefPathTable> {
329329
bug!("def_path_table")
330330
}
331331
fn struct_field_names_untracked(&self, def: DefId) -> Vec<ast::Name> {
@@ -398,7 +398,7 @@ pub fn used_crates(tcx: TyCtxt, prefer: LinkagePreference)
398398
})
399399
.collect::<Vec<_>>();
400400
let mut ordering = tcx.postorder_cnums(LOCAL_CRATE);
401-
Rc::make_mut(&mut ordering).reverse();
401+
Lrc::make_mut(&mut ordering).reverse();
402402
libs.sort_by_key(|&(a, _)| {
403403
ordering.iter().position(|x| *x == a)
404404
});

src/librustc/middle/expr_use_visitor.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use middle::region;
2727
use ty::{self, TyCtxt, adjustment};
2828

2929
use hir::{self, PatKind};
30-
use std::rc::Rc;
30+
use rustc_data_structures::sync::Lrc;
3131
use syntax::ast;
3232
use syntax::ptr::P;
3333
use syntax_pos::Span;
@@ -279,7 +279,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx, 'tcx> {
279279
param_env: ty::ParamEnv<'tcx>,
280280
region_scope_tree: &'a region::ScopeTree,
281281
tables: &'a ty::TypeckTables<'tcx>,
282-
rvalue_promotable_map: Option<Rc<ItemLocalSet>>)
282+
rvalue_promotable_map: Option<Lrc<ItemLocalSet>>)
283283
-> Self
284284
{
285285
ExprUseVisitor {

src/librustc/middle/mem_categorization.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ use syntax::ast;
8585
use syntax_pos::Span;
8686

8787
use std::fmt;
88+
use rustc_data_structures::sync::Lrc;
8889
use std::rc::Rc;
8990
use util::nodemap::ItemLocalSet;
9091

@@ -286,7 +287,7 @@ pub struct MemCategorizationContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
286287
pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
287288
pub region_scope_tree: &'a region::ScopeTree,
288289
pub tables: &'a ty::TypeckTables<'tcx>,
289-
rvalue_promotable_map: Option<Rc<ItemLocalSet>>,
290+
rvalue_promotable_map: Option<Lrc<ItemLocalSet>>,
290291
infcx: Option<&'a InferCtxt<'a, 'gcx, 'tcx>>,
291292
}
292293

@@ -395,7 +396,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx, 'tcx> {
395396
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
396397
region_scope_tree: &'a region::ScopeTree,
397398
tables: &'a ty::TypeckTables<'tcx>,
398-
rvalue_promotable_map: Option<Rc<ItemLocalSet>>)
399+
rvalue_promotable_map: Option<Lrc<ItemLocalSet>>)
399400
-> MemCategorizationContext<'a, 'tcx, 'tcx> {
400401
MemCategorizationContext {
401402
tcx,

src/librustc/middle/reachable.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use hir::map as hir_map;
1919
use hir::def::Def;
2020
use hir::def_id::{DefId, CrateNum};
21-
use std::rc::Rc;
21+
use rustc_data_structures::sync::Lrc;
2222
use ty::{self, TyCtxt};
2323
use ty::maps::Providers;
2424
use middle::privacy;
@@ -377,7 +377,7 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a,
377377
// We introduce a new-type here, so we can have a specialized HashStable
378378
// implementation for it.
379379
#[derive(Clone)]
380-
pub struct ReachableSet(pub Rc<NodeSet>);
380+
pub struct ReachableSet(pub Lrc<NodeSet>);
381381

382382

383383
fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) -> ReachableSet {
@@ -425,7 +425,7 @@ fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) ->
425425
reachable_context.propagate();
426426

427427
// Return the set of reachable symbols.
428-
ReachableSet(Rc::new(reachable_context.reachable_symbols))
428+
ReachableSet(Lrc::new(reachable_context.reachable_symbols))
429429
}
430430

431431
pub fn provide(providers: &mut Providers) {

src/librustc/middle/region.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use ty;
2020

2121
use std::fmt;
2222
use std::mem;
23-
use std::rc::Rc;
23+
use rustc_data_structures::sync::Lrc;
2424
use syntax::codemap;
2525
use syntax::ast;
2626
use syntax_pos::{Span, DUMMY_SP};
@@ -1436,7 +1436,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionResolutionVisitor<'a, 'tcx> {
14361436
}
14371437

14381438
fn region_scope_tree<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
1439-
-> Rc<ScopeTree>
1439+
-> Lrc<ScopeTree>
14401440
{
14411441
let closure_base_def_id = tcx.closure_base_def_id(def_id);
14421442
if closure_base_def_id != def_id {
@@ -1478,7 +1478,7 @@ fn region_scope_tree<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
14781478
ScopeTree::default()
14791479
};
14801480

1481-
Rc::new(scope_tree)
1481+
Lrc::new(scope_tree)
14821482
}
14831483

14841484
pub fn provide(providers: &mut Providers) {

0 commit comments

Comments
 (0)