Skip to content

Commit

Permalink
Auto merge of #44502 - alexcrichton:remove-session-dep-graph, r=micha…
Browse files Browse the repository at this point in the history
…elwoerister

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
  • Loading branch information
bors committed Sep 14, 2017
2 parents 5dfc84c + 1cf956f commit 2d288a5
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 113 deletions.
4 changes: 3 additions & 1 deletion src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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),
Expand Down
14 changes: 5 additions & 9 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1949,7 +1949,6 @@ mod dep_tracking {

#[cfg(test)]
mod tests {
use dep_graph::DepGraph;
use errors;
use getopts;
use lint;
Expand Down Expand Up @@ -1982,15 +1981,14 @@ 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,
Err(f) => panic!("test_switch_implies_cfg_test: {}", f)
};
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)));
}
Expand All @@ -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,
Expand All @@ -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());
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}
}
Expand Down
41 changes: 29 additions & 12 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -513,6 +534,7 @@ impl Session {
*incr_comp_session = IncrCompSession::Active {
session_directory: session_dir,
lock_file,
load_dep_graph,
};
}

Expand Down Expand Up @@ -617,22 +639,19 @@ 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)),
None)
}

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>,
Expand Down Expand Up @@ -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>)
Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand Down Expand Up @@ -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.
Expand Down
36 changes: 26 additions & 10 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#![cfg_attr(not(feature="llvm"), allow(dead_code))]

use rustc::dep_graph::DepGraph;
use rustc::hir::{self, map as hir_map};
use rustc::hir::lowering::lower_crate;
use rustc::ich::Fingerprint;
Expand Down Expand Up @@ -115,7 +116,7 @@ pub fn compile_input(sess: &Session,
// We need nested scopes here, because the intermediate results can keep
// large chunks of memory alive and we want to free them as soon as
// possible to keep the peak memory usage low
let (outputs, trans): (OutputFilenames, OngoingCrateTranslation) = {
let (outputs, trans, dep_graph): (OutputFilenames, OngoingCrateTranslation, DepGraph) = {
let krate = match phase_1_parse_input(control, sess, input) {
Ok(krate) => krate,
Err(mut parse_error) => {
Expand Down Expand Up @@ -144,7 +145,13 @@ pub fn compile_input(sess: &Session,
::rustc_trans_utils::link::find_crate_name(Some(sess), &krate.attrs, input);
let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = {
phase_2_configure_and_expand(
sess, &cstore, krate, registry, &crate_name, addl_plugins, control.make_glob_map,
sess,
&cstore,
krate,
registry,
&crate_name,
addl_plugins,
control.make_glob_map,
|expanded_crate| {
let mut state = CompileState::state_after_expand(
input, sess, outdir, output, &cstore, expanded_crate, &crate_name,
Expand Down Expand Up @@ -251,7 +258,7 @@ pub fn compile_input(sess: &Session,
}
}

Ok((outputs, trans))
Ok((outputs, trans, tcx.dep_graph.clone()))
})??
};

Expand All @@ -266,7 +273,7 @@ pub fn compile_input(sess: &Session,
sess.code_stats.borrow().print_type_sizes();
}

let (phase5_result, trans) = phase_5_run_llvm_passes(sess, trans);
let (phase5_result, trans) = phase_5_run_llvm_passes(sess, &dep_graph, trans);

controller_entry_point!(after_llvm,
sess,
Expand Down Expand Up @@ -624,7 +631,15 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
*sess.features.borrow_mut() = features;

*sess.crate_types.borrow_mut() = collect_crate_types(sess, &krate.attrs);
*sess.crate_disambiguator.borrow_mut() = Symbol::intern(&compute_crate_disambiguator(sess));

let disambiguator = Symbol::intern(&compute_crate_disambiguator(sess));
*sess.crate_disambiguator.borrow_mut() = Some(disambiguator);
rustc_incremental::prepare_session_directory(
sess,
&crate_name,
&disambiguator.as_str(),
);
let dep_graph = DepGraph::new(sess.opts.build_dep_graph());

time(time_passes, "recursion limit", || {
middle::recursion_limit::update_limits(sess, &krate);
Expand Down Expand Up @@ -694,7 +709,7 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
// item, much like we do for macro expansion. In other words, the hash reflects not just
// its contents but the results of name resolution on those contents. Hopefully we'll push
// this back at some point.
let _ignore = sess.dep_graph.in_ignore();
let _ignore = dep_graph.in_ignore();
let mut crate_loader = CrateLoader::new(sess, &cstore, crate_name);
let resolver_arenas = Resolver::arenas();
let mut resolver = Resolver::new(sess,
Expand Down Expand Up @@ -847,13 +862,13 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,

// Lower ast -> hir.
let hir_forest = time(time_passes, "lowering ast -> hir", || {
let hir_crate = lower_crate(sess, cstore, &krate, &mut resolver);
let hir_crate = lower_crate(sess, cstore, &dep_graph, &krate, &mut resolver);

if sess.opts.debugging_opts.hir_stats {
hir_stats::print_hir_stats(&hir_crate);
}

hir_map::Forest::new(hir_crate, &sess.dep_graph)
hir_map::Forest::new(hir_crate, &dep_graph)
});

time(time_passes,
Expand Down Expand Up @@ -1134,17 +1149,18 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
/// as a side effect.
#[cfg(feature="llvm")]
pub fn phase_5_run_llvm_passes(sess: &Session,
dep_graph: &DepGraph,
trans: write::OngoingCrateTranslation)
-> (CompileResult, trans::CrateTranslation) {
let trans = trans.join(sess);
let trans = trans.join(sess, dep_graph);

if sess.opts.debugging_opts.incremental_info {
write::dump_incremental_data(&trans);
}

time(sess.time_passes(),
"serialize work products",
move || rustc_incremental::save_work_products(sess));
move || rustc_incremental::save_work_products(sess, dep_graph));

(sess.compile_status(), trans)
}
Expand Down
14 changes: 8 additions & 6 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ use pretty::{PpMode, UserIdentifiedItem};
use rustc_resolve as resolve;
use rustc_save_analysis as save;
use rustc_save_analysis::DumpHandler;
use rustc::dep_graph::DepGraph;
use rustc::session::{self, config, Session, build_session, CompileResult};
use rustc::session::CompileIncomplete;
use rustc::session::config::{Input, PrintRequest, OutputType, ErrorOutputType};
Expand Down Expand Up @@ -294,13 +293,12 @@ pub fn run_compiler<'a>(args: &[String],
},
};

let dep_graph = DepGraph::new(sopts.build_dep_graph());
let cstore = Rc::new(CStore::new(box ::MetadataLoader));

let loader = file_loader.unwrap_or(box RealFileLoader);
let codemap = Rc::new(CodeMap::with_file_loader(loader, sopts.file_path_mapping()));
let mut sess = session::build_session_with_codemap(
sopts, &dep_graph, input_file_path, descriptions, codemap, emitter_dest,
sopts, input_file_path, descriptions, codemap, emitter_dest,
);
rustc_trans::init(&sess);
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
Expand All @@ -318,7 +316,13 @@ pub fn run_compiler<'a>(args: &[String],

let plugins = sess.opts.debugging_opts.extra_plugins.clone();
let control = callbacks.build_controller(&sess, &matches);
(driver::compile_input(&sess, &cstore, &input, &odir, &ofile, Some(plugins), &control),
(driver::compile_input(&sess,
&cstore,
&input,
&odir,
&ofile,
Some(plugins),
&control),
Some(sess))
}

Expand Down Expand Up @@ -580,9 +584,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
describe_lints(&ls, false);
return None;
}
let dep_graph = DepGraph::new(sopts.build_dep_graph());
let mut sess = build_session(sopts.clone(),
&dep_graph,
None,
descriptions.clone());
rustc_trans::init(&sess);
Expand Down
Loading

0 comments on commit 2d288a5

Please sign in to comment.