Skip to content

Commit

Permalink
Auto merge of #34772 - jseyfried:cleanup_interner, r=eddyb
Browse files Browse the repository at this point in the history
Start cleaning up the string interner

r? @eddyb
  • Loading branch information
bors authored Jul 13, 2016
2 parents 4a12a70 + 060b5c5 commit 0b7fb80
Show file tree
Hide file tree
Showing 16 changed files with 145 additions and 395 deletions.
4 changes: 2 additions & 2 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ pub fn compile_input(sess: &Session,
}

// Discard interned strings as they are no longer required.
token::get_ident_interner().clear();
token::clear_ident_interner();

Ok((outputs, trans))
})??
Expand Down Expand Up @@ -480,7 +480,7 @@ pub fn phase_1_parse_input<'a>(sess: &'a Session,
input: &Input)
-> PResult<'a, ast::Crate> {
// These may be left in an incoherent state after a previous compile.
// `clear_tables` and `get_ident_interner().clear()` can be used to free
// `clear_tables` and `clear_ident_interner` can be used to free
// memory, but they do not restore the initial state.
syntax::ext::mtwt::reset_tables();
token::reset_ident_interner();
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ use rustc::session::early_error;
use syntax::{ast, json};
use syntax::codemap::{CodeMap, FileLoader, RealFileLoader};
use syntax::feature_gate::{GatedCfg, UnstableFeatures};
use syntax::parse::{self, PResult, token};
use syntax::parse::{self, PResult};
use syntax_pos::MultiSpan;
use errors::emitter::Emitter;

Expand Down Expand Up @@ -201,7 +201,7 @@ pub fn run_compiler_with_file_loader<'a, L>(args: &[String],
};

let dep_graph = DepGraph::new(sopts.build_dep_graph());
let cstore = Rc::new(CStore::new(&dep_graph, token::get_ident_interner()));
let cstore = Rc::new(CStore::new(&dep_graph));
let codemap = Rc::new(CodeMap::with_file_loader(loader));
let sess = session::build_session_with_codemap(sopts,
&dep_graph,
Expand Down Expand Up @@ -432,7 +432,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
return None;
}
let dep_graph = DepGraph::new(sopts.build_dep_graph());
let cstore = Rc::new(CStore::new(&dep_graph, token::get_ident_interner()));
let cstore = Rc::new(CStore::new(&dep_graph));
let sess = build_session(sopts.clone(),
&dep_graph,
None,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fn test_env<F>(source_string: &str,

let dep_graph = DepGraph::new(false);
let _ignore = dep_graph.in_ignore();
let cstore = Rc::new(CStore::new(&dep_graph, token::get_ident_interner()));
let cstore = Rc::new(CStore::new(&dep_graph));
let sess = session::build_session_(options, &dep_graph, None, diagnostic_handler,
Rc::new(CodeMap::new()), cstore.clone());
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
Expand Down
1 change: 0 additions & 1 deletion src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,6 @@ impl<'a> CrateReader<'a> {
let source_name = format!("<{} macros>", item.ident);
let mut macros = vec![];
decoder::each_exported_macro(ekrate.metadata.as_slice(),
&self.cstore.intr,
|name, attrs, span, body| {
// NB: Don't use parse::parse_tts_from_source_str because it parses with
// quote_depth > 0.
Expand Down
39 changes: 13 additions & 26 deletions src/librustc_metadata/csearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
{
self.dep_graph.read(DepNode::MetaData(def));
let cdata = self.get_crate_data(def.krate);
decoder::get_adt_def(&self.intr, &cdata, def.index, tcx)
decoder::get_adt_def(&cdata, def.index, tcx)
}

fn method_arg_names(&self, did: DefId) -> Vec<String>
Expand All @@ -140,13 +140,13 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
fn item_name(&self, def: DefId) -> ast::Name {
self.dep_graph.read(DepNode::MetaData(def));
let cdata = self.get_crate_data(def.krate);
decoder::get_item_name(&self.intr, &cdata, def.index)
decoder::get_item_name(&cdata, def.index)
}

fn opt_item_name(&self, def: DefId) -> Option<ast::Name> {
self.dep_graph.read(DepNode::MetaData(def));
let cdata = self.get_crate_data(def.krate);
decoder::maybe_get_item_name(&self.intr, &cdata, def.index)
decoder::maybe_get_item_name(&cdata, def.index)
}

fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId>
Expand Down Expand Up @@ -176,7 +176,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
{
self.dep_graph.read(DepNode::MetaData(def));
let cdata = self.get_crate_data(def.krate);
decoder::get_provided_trait_methods(self.intr.clone(), &cdata, def.index, tcx)
decoder::get_provided_trait_methods(&cdata, def.index, tcx)
}

fn trait_item_def_ids(&self, def: DefId)
Expand Down Expand Up @@ -222,7 +222,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
-> Vec<Rc<ty::AssociatedConst<'tcx>>> {
self.dep_graph.read(DepNode::MetaData(def));
let cdata = self.get_crate_data(def.krate);
decoder::get_associated_consts(self.intr.clone(), &cdata, def.index, tcx)
decoder::get_associated_consts(&cdata, def.index, tcx)
}

fn impl_parent(&self, impl_def: DefId) -> Option<DefId> {
Expand All @@ -243,11 +243,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
{
self.dep_graph.read(DepNode::MetaData(def));
let cdata = self.get_crate_data(def.krate);
decoder::get_impl_or_trait_item(
self.intr.clone(),
&cdata,
def.index,
tcx)
decoder::get_impl_or_trait_item(&cdata, def.index, tcx)
}

fn is_const_fn(&self, did: DefId) -> bool
Expand Down Expand Up @@ -460,7 +456,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
{
self.dep_graph.read(DepNode::MetaData(def));
let cdata = self.get_crate_data(def.krate);
decoder::get_struct_field_names(&self.intr, &cdata, def.index)
decoder::get_struct_field_names(&cdata, def.index)
}

fn item_children(&self, def_id: DefId) -> Vec<ChildItem>
Expand All @@ -469,14 +465,9 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
let mut result = vec![];
let crate_data = self.get_crate_data(def_id.krate);
let get_crate_data = |cnum| self.get_crate_data(cnum);
decoder::each_child_of_item(
self.intr.clone(), &crate_data,
def_id.index, get_crate_data,
|def, name, vis| result.push(ChildItem {
def: def,
name: name,
vis: vis
}));
decoder::each_child_of_item(&crate_data, def_id.index, get_crate_data, |def, name, vis| {
result.push(ChildItem { def: def, name: name, vis: vis });
});
result
}

Expand All @@ -485,13 +476,9 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
let mut result = vec![];
let crate_data = self.get_crate_data(cnum);
let get_crate_data = |cnum| self.get_crate_data(cnum);
decoder::each_top_level_item_of_crate(
self.intr.clone(), &crate_data, get_crate_data,
|def, name, vis| result.push(ChildItem {
def: def,
name: name,
vis: vis
}));
decoder::each_top_level_item_of_crate(&crate_data, get_crate_data, |def, name, vis| {
result.push(ChildItem { def: def, name: name, vis: vis });
});
result
}

Expand Down
6 changes: 1 addition & 5 deletions src/librustc_metadata/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ use flate::Bytes;
use syntax::ast;
use syntax::attr;
use syntax::codemap;
use syntax::parse::token::IdentInterner;
use syntax_pos;

pub use middle::cstore::{NativeLibraryKind, LinkagePreference};
Expand Down Expand Up @@ -106,21 +105,18 @@ pub struct CStore {
used_libraries: RefCell<Vec<(String, NativeLibraryKind)>>,
used_link_args: RefCell<Vec<String>>,
statically_included_foreign_items: RefCell<NodeSet>,
pub intr: Rc<IdentInterner>,
pub visible_parent_map: RefCell<DefIdMap<DefId>>,
}

impl CStore {
pub fn new(dep_graph: &DepGraph,
intr: Rc<IdentInterner>) -> CStore {
pub fn new(dep_graph: &DepGraph) -> CStore {
CStore {
dep_graph: dep_graph.clone(),
metas: RefCell::new(FnvHashMap()),
extern_mod_crate_map: RefCell::new(FnvHashMap()),
used_crate_sources: RefCell::new(Vec::new()),
used_libraries: RefCell::new(Vec::new()),
used_link_args: RefCell::new(Vec::new()),
intr: intr,
statically_included_foreign_items: RefCell::new(NodeSet()),
visible_parent_map: RefCell::new(FnvHashMap()),
}
Expand Down
Loading

0 comments on commit 0b7fb80

Please sign in to comment.