Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Replace Rc with Lrc for shared data
  • Loading branch information
Zoxc committed Mar 2, 2018
1 parent 878f5b0 commit b74e97c
Show file tree
Hide file tree
Showing 86 changed files with 435 additions and 413 deletions.
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
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
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 @@ -306,7 +307,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 @@ -356,7 +357,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
12 changes: 6 additions & 6 deletions src/librustc/dep_graph/graph.rs
Expand Up @@ -13,10 +13,10 @@ 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 rustc_data_structures::sync::Lrc;
use std::cell::{Ref, RefCell};
use std::env;
use std::hash::Hash;
use std::rc::Rc;
use ty::TyCtxt;
use util::common::{ProfileQueriesMsg, profq_msg};

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

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

// A vector mapping depnodes from the current graph to their associated
// 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<RefCell<IndexVec<DepNodeIndex, Fingerprint>>>
}


Expand Down Expand Up @@ -102,7 +102,7 @@ impl DepGraph {
let fingerprints = IndexVec::from_elem_n(Fingerprint::ZERO,
(prev_graph_node_count * 115) / 100);
DepGraph {
data: Some(Rc::new(DepGraphData {
data: Some(Lrc::new(DepGraphData {
previous_work_products: RefCell::new(FxHashMap()),
work_products: RefCell::new(FxHashMap()),
dep_node_debug: RefCell::new(FxHashMap()),
Expand All @@ -111,14 +111,14 @@ impl DepGraph {
colors: RefCell::new(DepNodeColorMap::new(prev_graph_node_count)),
loaded_from_cache: RefCell::new(FxHashMap()),
})),
fingerprints: Rc::new(RefCell::new(fingerprints)),
fingerprints: Lrc::new(RefCell::new(fingerprints)),
}
}

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

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/ich/caching_codemap_view.rs
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
6 changes: 3 additions & 3 deletions src/librustc/lint/mod.rs
Expand Up @@ -31,7 +31,7 @@
pub use self::Level::*;
pub use self::LintSource::*;

use std::rc::Rc;
use rustc_data_structures::sync::Lrc;

use errors::{DiagnosticBuilder, DiagnosticId};
use hir::def_id::{CrateNum, LOCAL_CRATE};
Expand Down Expand Up @@ -505,7 +505,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 @@ -518,7 +518,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
16 changes: 8 additions & 8 deletions src/librustc/middle/cstore.rs
Expand Up @@ -37,13 +37,13 @@ use util::nodemap::NodeSet;
use std::any::Any;
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
use std::rc::Rc;
use rustc_data_structures::owning_ref::ErasedBoxRef;
use syntax::ast;
use syntax::ext::base::SyntaxExtension;
use syntax::symbol::Symbol;
use syntax_pos::Span;
use rustc_back::target::Target;
use rustc_data_structures::sync::Lrc;

pub use self::NativeLibraryKind::*;

Expand Down Expand Up @@ -139,7 +139,7 @@ pub struct NativeLibrary {

pub enum LoadedMacro {
MacroDef(ast::Item),
ProcMacro(Rc<SyntaxExtension>),
ProcMacro(Lrc<SyntaxExtension>),
}

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

#[derive(Clone)]
pub struct ExternBodyNestedBodies {
pub nested_bodies: Rc<BTreeMap<hir::BodyId, hir::Body>>,
pub nested_bodies: Lrc<BTreeMap<hir::BodyId, hir::Body>>,

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

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

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

#[allow(unused_variables)]
impl CrateStore for DummyCrateStore {
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Rc<Any>
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Lrc<Any>
{ bug!("crate_data_as_rc_any") }
// item info
fn visibility_untracked(&self, def: DefId) -> ty::Visibility { bug!("visibility") }
Expand Down Expand Up @@ -325,7 +325,7 @@ impl CrateStore for DummyCrateStore {
fn def_path_hash(&self, def: DefId) -> hir_map::DefPathHash {
bug!("def_path_hash")
}
fn def_path_table(&self, cnum: CrateNum) -> Rc<DefPathTable> {
fn def_path_table(&self, cnum: CrateNum) -> Lrc<DefPathTable> {
bug!("def_path_table")
}
fn struct_field_names_untracked(&self, def: DefId) -> Vec<ast::Name> {
Expand Down Expand Up @@ -398,7 +398,7 @@ pub fn used_crates(tcx: TyCtxt, prefer: LinkagePreference)
})
.collect::<Vec<_>>();
let mut ordering = tcx.postorder_cnums(LOCAL_CRATE);
Rc::make_mut(&mut ordering).reverse();
Lrc::make_mut(&mut ordering).reverse();
libs.sort_by_key(|&(a, _)| {
ordering.iter().position(|x| *x == a)
});
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/expr_use_visitor.rs
Expand Up @@ -27,7 +27,7 @@ use middle::region;
use ty::{self, TyCtxt, adjustment};

use hir::{self, PatKind};
use std::rc::Rc;
use rustc_data_structures::sync::Lrc;
use syntax::ast;
use syntax::ptr::P;
use syntax_pos::Span;
Expand Down Expand Up @@ -279,7 +279,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx, 'tcx> {
param_env: ty::ParamEnv<'tcx>,
region_scope_tree: &'a region::ScopeTree,
tables: &'a ty::TypeckTables<'tcx>,
rvalue_promotable_map: Option<Rc<ItemLocalSet>>)
rvalue_promotable_map: Option<Lrc<ItemLocalSet>>)
-> Self
{
ExprUseVisitor {
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/middle/mem_categorization.rs
Expand Up @@ -85,6 +85,7 @@ use syntax::ast;
use syntax_pos::Span;

use std::fmt;
use rustc_data_structures::sync::Lrc;
use std::rc::Rc;
use util::nodemap::ItemLocalSet;

Expand Down Expand Up @@ -286,7 +287,7 @@ pub struct MemCategorizationContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
pub region_scope_tree: &'a region::ScopeTree,
pub tables: &'a ty::TypeckTables<'tcx>,
rvalue_promotable_map: Option<Rc<ItemLocalSet>>,
rvalue_promotable_map: Option<Lrc<ItemLocalSet>>,
infcx: Option<&'a InferCtxt<'a, 'gcx, 'tcx>>,
}

Expand Down Expand Up @@ -395,7 +396,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx, 'tcx> {
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
region_scope_tree: &'a region::ScopeTree,
tables: &'a ty::TypeckTables<'tcx>,
rvalue_promotable_map: Option<Rc<ItemLocalSet>>)
rvalue_promotable_map: Option<Lrc<ItemLocalSet>>)
-> MemCategorizationContext<'a, 'tcx, 'tcx> {
MemCategorizationContext {
tcx,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/reachable.rs
Expand Up @@ -18,7 +18,7 @@
use hir::map as hir_map;
use hir::def::Def;
use hir::def_id::{DefId, CrateNum};
use std::rc::Rc;
use rustc_data_structures::sync::Lrc;
use ty::{self, TyCtxt};
use ty::maps::Providers;
use middle::privacy;
Expand Down Expand Up @@ -377,7 +377,7 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a,
// We introduce a new-type here, so we can have a specialized HashStable
// implementation for it.
#[derive(Clone)]
pub struct ReachableSet(pub Rc<NodeSet>);
pub struct ReachableSet(pub Lrc<NodeSet>);


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

// Return the set of reachable symbols.
ReachableSet(Rc::new(reachable_context.reachable_symbols))
ReachableSet(Lrc::new(reachable_context.reachable_symbols))
}

pub fn provide(providers: &mut Providers) {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/region.rs
Expand Up @@ -20,7 +20,7 @@ use ty;

use std::fmt;
use std::mem;
use std::rc::Rc;
use rustc_data_structures::sync::Lrc;
use syntax::codemap;
use syntax::ast;
use syntax_pos::{Span, DUMMY_SP};
Expand Down Expand Up @@ -1436,7 +1436,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionResolutionVisitor<'a, 'tcx> {
}

fn region_scope_tree<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
-> Rc<ScopeTree>
-> Lrc<ScopeTree>
{
let closure_base_def_id = tcx.closure_base_def_id(def_id);
if closure_base_def_id != def_id {
Expand Down Expand Up @@ -1478,7 +1478,7 @@ fn region_scope_tree<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
ScopeTree::default()
};

Rc::new(scope_tree)
Lrc::new(scope_tree)
}

pub fn provide(providers: &mut Providers) {
Expand Down

0 comments on commit b74e97c

Please sign in to comment.