rustc: Remove Session::dep_graph

This commit removes the `dep_graph` field from the `Session` type according to
issue #44390. Most of the fallout here was relatively straightforward and the
`prepare_session_directory` function was rejiggered a bit to reuse the results
in the later-called `load_dep_graph` function.

Closes #44390
This commit is contained in:
Alex Crichton 2017-09-09 11:02:18 -07:00
parent 5dfc84cfa7
commit 1cf956f2ba
16 changed files with 142 additions and 113 deletions

View file

@ -40,6 +40,7 @@
//! get confused if the spans from leaf AST nodes occur in multiple places
//! in the HIR, especially for multiple identifiers.
use dep_graph::DepGraph;
use hir;
use hir::map::{Definitions, DefKey};
use hir::def_id::{DefIndex, DefId, CRATE_DEF_INDEX};
@ -122,13 +123,14 @@ pub trait Resolver {
pub fn lower_crate(sess: &Session,
cstore: &CrateStore,
dep_graph: &DepGraph,
krate: &Crate,
resolver: &mut Resolver)
-> hir::Crate {
// We're constructing the HIR here; we don't care what we will
// read, since we haven't even constructed the *input* to
// incr. comp. yet.
let _ignore = sess.dep_graph.in_ignore();
let _ignore = dep_graph.in_ignore();
LoweringContext {
crate_root: std_inject::injected_crate_name(krate),

View file

@ -1949,7 +1949,6 @@ mod dep_tracking {
#[cfg(test)]
mod tests {
use dep_graph::DepGraph;
use errors;
use getopts;
use lint;
@ -1982,7 +1981,6 @@ mod tests {
// When the user supplies --test we should implicitly supply --cfg test
#[test]
fn test_switch_implies_cfg_test() {
let dep_graph = DepGraph::new(false);
let matches =
&match optgroups().parse(&["--test".to_string()]) {
Ok(m) => m,
@ -1990,7 +1988,7 @@ mod tests {
};
let registry = errors::registry::Registry::new(&[]);
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
let sess = build_session(sessopts, &dep_graph, None, registry);
let sess = build_session(sessopts, None, registry);
let cfg = build_configuration(&sess, cfg);
assert!(cfg.contains(&(Symbol::intern("test"), None)));
}
@ -1999,7 +1997,6 @@ mod tests {
// another --cfg test
#[test]
fn test_switch_implies_cfg_test_unless_cfg_test() {
let dep_graph = DepGraph::new(false);
let matches =
&match optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]) {
Ok(m) => m,
@ -2009,7 +2006,7 @@ mod tests {
};
let registry = errors::registry::Registry::new(&[]);
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
let sess = build_session(sessopts, &dep_graph, None, registry);
let sess = build_session(sessopts, None, registry);
let cfg = build_configuration(&sess, cfg);
let mut test_items = cfg.iter().filter(|&&(name, _)| name == "test");
assert!(test_items.next().is_some());
@ -2018,14 +2015,13 @@ mod tests {
#[test]
fn test_can_print_warnings() {
let dep_graph = DepGraph::new(false);
{
let matches = optgroups().parse(&[
"-Awarnings".to_string()
]).unwrap();
let registry = errors::registry::Registry::new(&[]);
let (sessopts, _) = build_session_options_and_crate_config(&matches);
let sess = build_session(sessopts, &dep_graph, None, registry);
let sess = build_session(sessopts, None, registry);
assert!(!sess.diagnostic().can_emit_warnings);
}
@ -2036,7 +2032,7 @@ mod tests {
]).unwrap();
let registry = errors::registry::Registry::new(&[]);
let (sessopts, _) = build_session_options_and_crate_config(&matches);
let sess = build_session(sessopts, &dep_graph, None, registry);
let sess = build_session(sessopts, None, registry);
assert!(sess.diagnostic().can_emit_warnings);
}
@ -2046,7 +2042,7 @@ mod tests {
]).unwrap();
let registry = errors::registry::Registry::new(&[]);
let (sessopts, _) = build_session_options_and_crate_config(&matches);
let sess = build_session(sessopts, &dep_graph, None, registry);
let sess = build_session(sessopts, None, registry);
assert!(sess.diagnostic().can_emit_warnings);
}
}

View file

@ -11,7 +11,6 @@
pub use self::code_stats::{CodeStats, DataTypeKind, FieldInfo};
pub use self::code_stats::{SizeKind, TypeSizeInfo, VariantInfo};
use dep_graph::DepGraph;
use hir::def_id::{CrateNum, DefIndex};
use lint;
@ -58,7 +57,6 @@ pub mod search_paths;
// Represents the data associated with a compilation
// session for a single crate.
pub struct Session {
pub dep_graph: DepGraph,
pub target: config::Config,
pub host: Target,
pub opts: config::Options,
@ -91,7 +89,7 @@ pub struct Session {
// forms a unique global identifier for the crate. It is used to allow
// multiple crates with the same name to coexist. See the
// trans::back::symbol_names module for more information.
pub crate_disambiguator: RefCell<Symbol>,
pub crate_disambiguator: RefCell<Option<Symbol>>,
pub features: RefCell<feature_gate::Features>,
/// The maximum recursion limit for potentially infinitely recursive
@ -169,7 +167,10 @@ enum DiagnosticBuilderMethod {
impl Session {
pub fn local_crate_disambiguator(&self) -> Symbol {
*self.crate_disambiguator.borrow()
match *self.crate_disambiguator.borrow() {
Some(sym) => sym,
None => bug!("accessing disambiguator before initialization"),
}
}
pub fn struct_span_warn<'a, S: Into<MultiSpan>>(&'a self,
sp: S,
@ -501,9 +502,29 @@ impl Session {
kind)
}
pub fn set_incr_session_load_dep_graph(&self, load: bool) {
let mut incr_comp_session = self.incr_comp_session.borrow_mut();
match *incr_comp_session {
IncrCompSession::Active { ref mut load_dep_graph, .. } => {
*load_dep_graph = load;
}
_ => {}
}
}
pub fn incr_session_load_dep_graph(&self) -> bool {
let incr_comp_session = self.incr_comp_session.borrow();
match *incr_comp_session {
IncrCompSession::Active { load_dep_graph, .. } => load_dep_graph,
_ => false,
}
}
pub fn init_incr_comp_session(&self,
session_dir: PathBuf,
lock_file: flock::Lock) {
lock_file: flock::Lock,
load_dep_graph: bool) {
let mut incr_comp_session = self.incr_comp_session.borrow_mut();
if let IncrCompSession::NotInitialized = *incr_comp_session { } else {
@ -513,6 +534,7 @@ impl Session {
*incr_comp_session = IncrCompSession::Active {
session_directory: session_dir,
lock_file,
load_dep_graph,
};
}
@ -617,14 +639,12 @@ impl Session {
}
pub fn build_session(sopts: config::Options,
dep_graph: &DepGraph,
local_crate_source_file: Option<PathBuf>,
registry: errors::registry::Registry)
-> Session {
let file_path_mapping = sopts.file_path_mapping();
build_session_with_codemap(sopts,
dep_graph,
local_crate_source_file,
registry,
Rc::new(codemap::CodeMap::new(file_path_mapping)),
@ -632,7 +652,6 @@ pub fn build_session(sopts: config::Options,
}
pub fn build_session_with_codemap(sopts: config::Options,
dep_graph: &DepGraph,
local_crate_source_file: Option<PathBuf>,
registry: errors::registry::Registry,
codemap: Rc<codemap::CodeMap>,
@ -672,14 +691,12 @@ pub fn build_session_with_codemap(sopts: config::Options,
emitter);
build_session_(sopts,
dep_graph,
local_crate_source_file,
diagnostic_handler,
codemap)
}
pub fn build_session_(sopts: config::Options,
dep_graph: &DepGraph,
local_crate_source_file: Option<PathBuf>,
span_diagnostic: errors::Handler,
codemap: Rc<codemap::CodeMap>)
@ -715,7 +732,6 @@ pub fn build_session_(sopts: config::Options,
let working_dir = file_path_mapping.map_prefix(working_dir);
let sess = Session {
dep_graph: dep_graph.clone(),
target: target_cfg,
host,
opts: sopts,
@ -735,7 +751,7 @@ pub fn build_session_(sopts: config::Options,
plugin_attributes: RefCell::new(Vec::new()),
crate_types: RefCell::new(Vec::new()),
dependency_formats: RefCell::new(FxHashMap()),
crate_disambiguator: RefCell::new(Symbol::intern("")),
crate_disambiguator: RefCell::new(None),
features: RefCell::new(feature_gate::Features::new()),
recursion_limit: Cell::new(64),
type_length_limit: Cell::new(1048576),
@ -793,6 +809,7 @@ pub enum IncrCompSession {
Active {
session_directory: PathBuf,
lock_file: flock::Lock,
load_dep_graph: bool,
},
// This is the state after the session directory has been finalized. In this
// state, the contents of the directory must not be modified any more.