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

Replace Rc with Lrc for shared data #48586

Merged
merged 3 commits into from
Mar 3, 2018
Merged
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" }
13 changes: 10 additions & 3 deletions src/libproc_macro/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,21 @@
#![feature(rustc_private)]
#![feature(staged_api)]
#![feature(lang_items)]
#![feature(optin_builtin_traits)]

#[macro_use]
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,9 +308,14 @@ pub struct LineColumn {
#[unstable(feature = "proc_macro", issue = "38356")]
#[derive(Clone)]
pub struct SourceFile {
filemap: Rc<FileMap>,
filemap: Lrc<FileMap>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rust-lang/compiler @alexcrichton, is it safe to modify these definitions? Or are they part of a public interface?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah these are unstable and just private fields, so should be all good!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks for the quick feedback!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is IMO problematic because it will eventually be observable in user code - you should impl !Send and !Sync on SourceFile to hide the difference before we forget and stabilize it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There probably also other types this applies to in libproc_macro.

}

#[unstable(feature = "proc_macro", issue = "38356")]
impl !Send for SourceFile {}
#[unstable(feature = "proc_macro", issue = "38356")]
impl !Sync for SourceFile {}

impl SourceFile {
/// Get the path to this source file.
///
Expand Down Expand Up @@ -356,7 +363,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
Original file line number Diff line number Diff line change
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
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
6 changes: 3 additions & 3 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::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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading