diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 92f8c9249c842..f0eb580cfd57e 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -196,7 +196,7 @@ pub struct Map<'ast> { /// plain old integers. map: RefCell>>, - definitions: &'ast RefCell, + definitions: RefCell, } impl<'ast> Map<'ast> { @@ -790,7 +790,7 @@ pub fn collect_definitions<'ast>(krate: &'ast ast::Crate) -> Definitions { } pub fn map_crate<'ast>(forest: &'ast mut Forest, - definitions: &'ast RefCell) + definitions: Definitions) -> Map<'ast> { let mut collector = NodeCollector::root(&forest.krate); intravisit::walk_crate(&mut collector, &forest.krate); @@ -816,7 +816,7 @@ pub fn map_crate<'ast>(forest: &'ast mut Forest, forest: forest, dep_graph: forest.dep_graph.clone(), map: RefCell::new(map), - definitions: definitions, + definitions: RefCell::new(definitions), } } diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 47378793dba8e..da36cb7c2e4f2 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -28,7 +28,7 @@ use rustc_borrowck as borrowck; use rustc_incremental; use rustc_resolve as resolve; use rustc_metadata::macro_import; -use rustc_metadata::creader::LocalCrateReader; +use rustc_metadata::creader::read_local_crates; use rustc_metadata::cstore::CStore; use rustc_trans::back::link; use rustc_trans::back::write; @@ -155,22 +155,21 @@ pub fn compile_input(sess: &Session, let dep_graph = DepGraph::new(sess.opts.build_dep_graph()); // Collect defintions for def ids. - let defs = &RefCell::new(time(sess.time_passes(), - "collecting defs", - || hir_map::collect_definitions(&expanded_crate))); + let mut defs = time(sess.time_passes(), + "collecting defs", + || hir_map::collect_definitions(&expanded_crate)); time(sess.time_passes(), "external crate/lib resolution", - || LocalCrateReader::new(sess, &cstore, defs, &expanded_crate, &id) - .read_crates(&dep_graph)); + || read_local_crates(sess, &cstore, &defs, &expanded_crate, &id, &dep_graph)); time(sess.time_passes(), "early lint checks", || lint::check_ast_crate(sess, &expanded_crate)); let (analysis, resolutions, mut hir_forest) = { - let defs = &mut *defs.borrow_mut(); - lower_and_resolve(sess, &id, defs, &expanded_crate, dep_graph, control.make_glob_map) + lower_and_resolve(sess, &id, &mut defs, &expanded_crate, dep_graph, + control.make_glob_map) }; // Discard MTWT tables that aren't required past lowering to HIR. diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index 9bbf250b9714e..bbda1965c7fac 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -26,10 +26,9 @@ use rustc::traits::ProjectionMode; use rustc::ty::{self, Ty, TyCtxt, TypeFoldable}; use rustc::infer::{self, InferOk, InferResult, TypeOrigin}; use rustc_metadata::cstore::CStore; -use rustc_metadata::creader::LocalCrateReader; +use rustc_metadata::creader::read_local_crates; use rustc::hir::map as hir_map; use rustc::session::{self, config}; -use std::cell::RefCell; use std::rc::Rc; use syntax::ast; use syntax::abi::Abi; @@ -120,13 +119,13 @@ fn test_env(source_string: &str, let dep_graph = DepGraph::new(false); let krate = driver::assign_node_ids(&sess, krate); - let defs = &RefCell::new(hir_map::collect_definitions(&krate)); - LocalCrateReader::new(&sess, &cstore, defs, &krate, "test_crate").read_crates(&dep_graph); + let mut defs = hir_map::collect_definitions(&krate); + read_local_crates(&sess, &cstore, &defs, &krate, "test_crate", &dep_graph); let _ignore = dep_graph.in_ignore(); let (_, resolutions, mut hir_forest) = { - let (defs, dep_graph) = (&mut *defs.borrow_mut(), dep_graph.clone()); - driver::lower_and_resolve(&sess, "test-crate", defs, &krate, dep_graph, MakeGlobMap::No) + driver::lower_and_resolve(&sess, "test-crate", &mut defs, &krate, dep_graph.clone(), + MakeGlobMap::No) }; let arenas = ty::CtxtArenas::new(); diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 190e8552d199a..63c6af704bbfe 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -41,12 +41,12 @@ use syntax::parse::token::InternedString; use syntax::visit; use log; -pub struct LocalCrateReader<'a> { +struct LocalCrateReader<'a> { sess: &'a Session, cstore: &'a CStore, creader: CrateReader<'a>, krate: &'a ast::Crate, - defintions: &'a RefCell, + definitions: &'a hir_map::Definitions, } pub struct CrateReader<'a> { @@ -841,25 +841,25 @@ impl<'a> CrateReader<'a> { } impl<'a> LocalCrateReader<'a> { - pub fn new(sess: &'a Session, - cstore: &'a CStore, - defs: &'a RefCell, - krate: &'a ast::Crate, - local_crate_name: &str) - -> LocalCrateReader<'a> { + fn new(sess: &'a Session, + cstore: &'a CStore, + defs: &'a hir_map::Definitions, + krate: &'a ast::Crate, + local_crate_name: &str) + -> LocalCrateReader<'a> { LocalCrateReader { sess: sess, cstore: cstore, creader: CrateReader::new(sess, cstore, local_crate_name), krate: krate, - defintions: defs, + definitions: defs, } } // Traverses an AST, reading all the information about use'd crates and // extern libraries necessary for later resolving, typechecking, linking, // etc. - pub fn read_crates(&mut self, dep_graph: &DepGraph) { + fn read_crates(&mut self, dep_graph: &DepGraph) { let _task = dep_graph.in_task(DepNode::CrateReader); self.process_crate(self.krate); @@ -902,9 +902,8 @@ impl<'a> LocalCrateReader<'a> { PathKind::Crate, true); - let defs = self.defintions.borrow(); - let def_id = defs.opt_local_def_id(i.id).unwrap(); - let len = defs.def_path(def_id.index).data.len(); + let def_id = self.definitions.opt_local_def_id(i.id).unwrap(); + let len = self.definitions.def_path(def_id.index).data.len(); self.creader.update_extern_crate(cnum, ExternCrate { @@ -982,6 +981,17 @@ impl<'a> LocalCrateReader<'a> { } } +/// Traverses an AST, reading all the information about use'd crates and extern +/// libraries necessary for later resolving, typechecking, linking, etc. +pub fn read_local_crates(sess: & Session, + cstore: & CStore, + defs: & hir_map::Definitions, + krate: & ast::Crate, + local_crate_name: &str, + dep_graph: &DepGraph) { + LocalCrateReader::new(sess, cstore, defs, krate, local_crate_name).read_crates(dep_graph) +} + /// Imports the codemap from an external crate into the codemap of the crate /// currently being compiled (the "local crate"). /// diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 895c0bb849010..6d45980b45da9 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -21,7 +21,7 @@ use rustc::lint; use rustc_trans::back::link; use rustc_resolve as resolve; use rustc_metadata::cstore::CStore; -use rustc_metadata::creader::LocalCrateReader; +use rustc_metadata::creader::read_local_crates; use syntax::{ast, codemap, errors}; use syntax::errors::emitter::ColorConfig; @@ -153,13 +153,13 @@ pub fn run_core(search_paths: SearchPaths, let krate = driver::assign_node_ids(&sess, krate); let dep_graph = DepGraph::new(false); - let defs = &RefCell::new(hir_map::collect_definitions(&krate)); - LocalCrateReader::new(&sess, &cstore, &defs, &krate, &name).read_crates(&dep_graph); + let mut defs = hir_map::collect_definitions(&krate); + read_local_crates(&sess, &cstore, &defs, &krate, &name, &dep_graph); // Lower ast -> hir and resolve. let (analysis, resolutions, mut hir_forest) = { - let defs = &mut *defs.borrow_mut(); - driver::lower_and_resolve(&sess, &name, defs, &krate, dep_graph, resolve::MakeGlobMap::No) + driver::lower_and_resolve(&sess, &name, &mut defs, &krate, dep_graph, + resolve::MakeGlobMap::No) }; let arenas = ty::CtxtArenas::new(); diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 579cbf1fd33b7..e4fbdba77a445 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -95,7 +95,7 @@ pub fn run(input: &str, .expect("phase_2_configure_and_expand aborted in rustdoc!"); let krate = driver::assign_node_ids(&sess, krate); let dep_graph = DepGraph::new(false); - let defs = &RefCell::new(hir_map::collect_definitions(&krate)); + let defs = hir_map::collect_definitions(&krate); let mut dummy_resolver = DummyResolver; let krate = lower_crate(&krate, &sess, &mut dummy_resolver); diff --git a/src/test/run-make/execution-engine/test.rs b/src/test/run-make/execution-engine/test.rs index 98412c08df520..0ad113b8d8b38 100644 --- a/src/test/run-make/execution-engine/test.rs +++ b/src/test/run-make/execution-engine/test.rs @@ -20,7 +20,6 @@ extern crate rustc_metadata; extern crate rustc_resolve; #[macro_use] extern crate syntax; -use std::cell::RefCell; use std::ffi::{CStr, CString}; use std::mem::transmute; use std::path::PathBuf; @@ -35,7 +34,7 @@ use rustc::session::config::{self, basic_options, build_configuration, Input, Op use rustc::session::build_session; use rustc_driver::{driver, abort_on_err}; use rustc_resolve::MakeGlobMap; -use rustc_metadata::creader::LocalCrateReader; +use rustc_metadata::creader::read_local_crates; use rustc_metadata::cstore::CStore; use libc::c_void; @@ -240,14 +239,14 @@ fn compile_program(input: &str, sysroot: PathBuf) let dep_graph = DepGraph::new(sess.opts.build_dep_graph()); let krate = driver::assign_node_ids(&sess, krate); - let defs = RefCell::new(ast_map::collect_definitions(&krate)); - LocalCrateReader::new(&sess, &cstore, &defs, &krate, &id).read_crates(&dep_graph); + let mut defs = ast_map::collect_definitions(&krate); + read_local_crates(&sess, &cstore, &defs, &krate, &id, &dep_graph); let (analysis, resolutions, mut hir_forest) = { - let defs = &mut *defs.borrow_mut(); - driver::lower_and_resolve(&sess, &id, defs, &krate, dep_graph, MakeGlobMap::No) + driver::lower_and_resolve(&sess, &id, &mut defs, &krate, dep_graph, MakeGlobMap::No) }; + let arenas = ty::CtxtArenas::new(); - let ast_map = ast_map::map_crate(&mut hir_forest, &defs); + let ast_map = ast_map::map_crate(&mut hir_forest, defs); abort_on_err(driver::phase_3_run_analysis_passes( &sess, ast_map, analysis, resolutions, &arenas, &id,