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.

View File

@ -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;
@ -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) => {
@ -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,
@ -251,7 +258,7 @@ pub fn compile_input(sess: &Session,
}
}
Ok((outputs, trans))
Ok((outputs, trans, tcx.dep_graph.clone()))
})??
};
@ -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,
@ -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);
@ -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,
@ -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,
@ -1134,9 +1149,10 @@ 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);
@ -1144,7 +1160,7 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
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)
}

View File

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

View File

@ -11,7 +11,6 @@
//! # Standalone Tests for the Inference Module
use driver;
use rustc::dep_graph::DepGraph;
use rustc_lint;
use rustc_resolve::MakeGlobMap;
use rustc_trans;
@ -102,11 +101,8 @@ fn test_env<F>(source_string: &str,
options.unstable_features = UnstableFeatures::Allow;
let diagnostic_handler = errors::Handler::with_emitter(true, false, emitter);
let dep_graph = DepGraph::new(false);
let _ignore = dep_graph.in_ignore();
let cstore = Rc::new(CStore::new(box ::MetadataLoader));
let sess = session::build_session_(options,
&dep_graph,
None,
diagnostic_handler,
Rc::new(CodeMap::new(FilePathMapping::empty())));
@ -130,7 +126,6 @@ fn test_env<F>(source_string: &str,
|_| Ok(()))
.expect("phase 2 aborted")
};
let _ignore = dep_graph.in_ignore();
let arena = DroplessArena::new();
let arenas = ty::GlobalArenas::new();

View File

@ -40,4 +40,5 @@ pub use persist::save_dep_graph;
pub use persist::save_trans_partition;
pub use persist::save_work_products;
pub use persist::in_incr_comp_dir;
pub use persist::prepare_session_directory;
pub use persist::finalize_session_directory;

View File

@ -114,7 +114,7 @@
//! unsupported file system and emit a warning in that case. This is not yet
//! implemented.
use rustc::hir::def_id::{CrateNum, LOCAL_CRATE};
use rustc::hir::def_id::CrateNum;
use rustc::hir::svh::Svh;
use rustc::session::Session;
use rustc::ty::TyCtxt;
@ -193,13 +193,21 @@ pub fn in_incr_comp_dir(incr_comp_session_dir: &Path, file_name: &str) -> PathBu
/// a dep-graph and work products from a previous session.
/// If the call fails, the fn may leave behind an invalid session directory.
/// The garbage collection will take care of it.
pub fn prepare_session_directory(tcx: TyCtxt) -> Result<bool, ()> {
pub fn prepare_session_directory(sess: &Session,
crate_name: &str,
crate_disambiguator: &str) {
if sess.opts.incremental.is_none() {
return
}
debug!("prepare_session_directory");
// {incr-comp-dir}/{crate-name-and-disambiguator}
let crate_dir = crate_path_tcx(tcx, LOCAL_CRATE);
let crate_dir = crate_path(sess, crate_name, crate_disambiguator);
debug!("crate-dir: {}", crate_dir.display());
try!(create_dir(tcx.sess, &crate_dir, "crate"));
if create_dir(sess, &crate_dir, "crate").is_err() {
return
}
// Hack: canonicalize the path *after creating the directory*
// because, on windows, long paths can cause problems;
@ -208,9 +216,9 @@ pub fn prepare_session_directory(tcx: TyCtxt) -> Result<bool, ()> {
let crate_dir = match crate_dir.canonicalize() {
Ok(v) => v,
Err(err) => {
tcx.sess.err(&format!("incremental compilation: error canonicalizing path `{}`: {}",
sess.err(&format!("incremental compilation: error canonicalizing path `{}`: {}",
crate_dir.display(), err));
return Err(());
return
}
};
@ -225,11 +233,16 @@ pub fn prepare_session_directory(tcx: TyCtxt) -> Result<bool, ()> {
// Lock the new session directory. If this fails, return an
// error without retrying
let (directory_lock, lock_file_path) = try!(lock_directory(tcx.sess, &session_dir));
let (directory_lock, lock_file_path) = match lock_directory(sess, &session_dir) {
Ok(e) => e,
Err(_) => return,
};
// Now that we have the lock, we can actually create the session
// directory
try!(create_dir(tcx.sess, &session_dir, "session"));
if create_dir(sess, &session_dir, "session").is_err() {
return
}
// Find a suitable source directory to copy from. Ignore those that we
// have already tried before.
@ -243,14 +256,14 @@ pub fn prepare_session_directory(tcx: TyCtxt) -> Result<bool, ()> {
debug!("no source directory found. Continuing with empty session \
directory.");
tcx.sess.init_incr_comp_session(session_dir, directory_lock);
return Ok(false)
sess.init_incr_comp_session(session_dir, directory_lock, false);
return
};
debug!("attempting to copy data from source: {}",
source_directory.display());
let print_file_copy_stats = tcx.sess.opts.debugging_opts.incremental_info;
let print_file_copy_stats = sess.opts.debugging_opts.incremental_info;
// Try copying over all files from the source directory
if let Ok(allows_links) = copy_files(&session_dir, &source_directory,
@ -259,7 +272,7 @@ pub fn prepare_session_directory(tcx: TyCtxt) -> Result<bool, ()> {
source_directory.display());
if !allows_links {
tcx.sess.warn(&format!("Hard linking files in the incremental \
sess.warn(&format!("Hard linking files in the incremental \
compilation cache failed. Copying files \
instead. Consider moving the cache \
directory to a file system which supports \
@ -268,8 +281,8 @@ pub fn prepare_session_directory(tcx: TyCtxt) -> Result<bool, ()> {
);
}
tcx.sess.init_incr_comp_session(session_dir, directory_lock);
return Ok(true)
sess.init_incr_comp_session(session_dir, directory_lock, true);
return
} else {
debug!("copying failed - trying next directory");
@ -280,13 +293,13 @@ pub fn prepare_session_directory(tcx: TyCtxt) -> Result<bool, ()> {
// Try to remove the session directory we just allocated. We don't
// know if there's any garbage in it from the failed copy action.
if let Err(err) = safe_remove_dir_all(&session_dir) {
tcx.sess.warn(&format!("Failed to delete partly initialized \
sess.warn(&format!("Failed to delete partly initialized \
session dir `{}`: {}",
session_dir.display(),
err));
}
delete_session_dir_lock_file(tcx.sess, &lock_file_path);
delete_session_dir_lock_file(sess, &lock_file_path);
mem::drop(directory_lock);
}
}

View File

@ -42,31 +42,11 @@ pub type DirtyNodes = FxHashMap<DepNodeIndex, DepNodeIndex>;
/// more general overview.
pub fn load_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
incremental_hashes_map: &IncrementalHashesMap) {
if tcx.sess.opts.incremental.is_none() {
return;
}
match prepare_session_directory(tcx) {
Ok(true) => {
// We successfully allocated a session directory and there is
// something in it to load, so continue
}
Ok(false) => {
// We successfully allocated a session directory, but there is no
// dep-graph data in it to load (because this is the first
// compilation session with this incr. comp. dir.)
return
}
Err(()) => {
// Something went wrong while trying to allocate the session
// directory. Don't try to use it any further.
return
}
}
if tcx.sess.incr_session_load_dep_graph() {
let _ignore = tcx.dep_graph.in_ignore();
load_dep_graph_if_exists(tcx, incremental_hashes_map);
}
}
fn load_dep_graph_if_exists<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
incremental_hashes_map: &IncrementalHashesMap) {

View File

@ -22,6 +22,7 @@ mod save;
mod work_product;
mod file_format;
pub use self::fs::prepare_session_directory;
pub use self::fs::finalize_session_directory;
pub use self::fs::in_incr_comp_dir;
pub use self::load::load_dep_graph;

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use rustc::dep_graph::DepNode;
use rustc::dep_graph::{DepGraph, DepNode};
use rustc::hir::def_id::DefId;
use rustc::hir::svh::Svh;
use rustc::ich::Fingerprint;
@ -79,21 +79,21 @@ pub fn save_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
&current_metadata_hashes);
}
pub fn save_work_products(sess: &Session) {
pub fn save_work_products(sess: &Session, dep_graph: &DepGraph) {
if sess.opts.incremental.is_none() {
return;
}
debug!("save_work_products()");
let _ignore = sess.dep_graph.in_ignore();
let _ignore = dep_graph.in_ignore();
let path = work_products_path(sess);
save_in(sess, path, |e| encode_work_products(sess, e));
save_in(sess, path, |e| encode_work_products(dep_graph, e));
// We also need to clean out old work-products, as not all of them are
// deleted during invalidation. Some object files don't change their
// content, they are just not needed anymore.
let new_work_products = sess.dep_graph.work_products();
let previous_work_products = sess.dep_graph.previous_work_products();
let new_work_products = dep_graph.work_products();
let previous_work_products = dep_graph.previous_work_products();
for (id, wp) in previous_work_products.iter() {
if !new_work_products.contains_key(id) {
@ -309,8 +309,9 @@ pub fn encode_metadata_hashes(tcx: TyCtxt,
Ok(())
}
pub fn encode_work_products(sess: &Session, encoder: &mut Encoder) -> io::Result<()> {
let work_products: Vec<_> = sess.dep_graph
pub fn encode_work_products(dep_graph: &DepGraph,
encoder: &mut Encoder) -> io::Result<()> {
let work_products: Vec<_> = dep_graph
.work_products()
.iter()
.map(|(id, work_product)| {

View File

@ -11,7 +11,7 @@
//! This module contains files for saving intermediate work-products.
use persist::fs::*;
use rustc::dep_graph::{WorkProduct, WorkProductId};
use rustc::dep_graph::{WorkProduct, WorkProductId, DepGraph};
use rustc::session::Session;
use rustc::session::config::OutputType;
use rustc::util::fs::link_or_copy;
@ -19,6 +19,7 @@ use std::path::PathBuf;
use std::fs as std_fs;
pub fn save_trans_partition(sess: &Session,
dep_graph: &DepGraph,
cgu_name: &str,
partition_hash: u64,
files: &[(OutputType, PathBuf)]) {
@ -60,7 +61,7 @@ pub fn save_trans_partition(sess: &Session,
saved_files,
};
sess.dep_graph.insert_work_product(&work_product_id, work_product);
dep_graph.insert_work_product(&work_product_id, work_product);
}
pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {

View File

@ -13,6 +13,7 @@ use back::link::{self, get_linker, remove};
use back::linker::LinkerInfo;
use back::symbol_export::ExportedSymbols;
use rustc_incremental::{save_trans_partition, in_incr_comp_dir};
use rustc::dep_graph::DepGraph;
use rustc::middle::cstore::{LinkMeta, EncodedMetadata};
use rustc::session::config::{self, OutputFilenames, OutputType, OutputTypes, Passes, SomePasses,
AllPasses, Sanitizer};
@ -807,6 +808,7 @@ pub fn start_async_translation(sess: &Session,
}
fn copy_module_artifacts_into_incr_comp_cache(sess: &Session,
dep_graph: &DepGraph,
compiled_modules: &CompiledModules,
crate_output: &OutputFilenames) {
if sess.opts.incremental.is_none() {
@ -826,7 +828,11 @@ fn copy_module_artifacts_into_incr_comp_cache(sess: &Session,
files.push((OutputType::Bitcode, path));
}
save_trans_partition(sess, &module.name, module.symbol_name_hash, &files);
save_trans_partition(sess,
dep_graph,
&module.name,
module.symbol_name_hash,
&files);
}
}
@ -1822,7 +1828,7 @@ pub struct OngoingCrateTranslation {
}
impl OngoingCrateTranslation {
pub fn join(self, sess: &Session) -> CrateTranslation {
pub fn join(self, sess: &Session, dep_graph: &DepGraph) -> CrateTranslation {
self.shared_emitter_main.check(sess, true);
let compiled_modules = match self.future.join() {
Ok(compiled_modules) => compiled_modules,
@ -1838,6 +1844,7 @@ impl OngoingCrateTranslation {
}
copy_module_artifacts_into_incr_comp_cache(sess,
dep_graph,
&compiled_modules,
&self.output_filenames);
produce_final_output_artifacts(sess,

View File

@ -11,7 +11,6 @@
use rustc_lint;
use rustc_driver::{driver, target_features, abort_on_err};
use rustc_driver::pretty::ReplaceBodyWithLoop;
use rustc::dep_graph::DepGraph;
use rustc::session::{self, config};
use rustc::hir::def_id::DefId;
use rustc::hir::def::Def;
@ -144,11 +143,9 @@ pub fn run_core(search_paths: SearchPaths,
false,
Some(codemap.clone()));
let dep_graph = DepGraph::new(false);
let _ignore = dep_graph.in_ignore();
let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader));
let mut sess = session::build_session_(
sessopts, &dep_graph, cpath, diagnostic_handler, codemap
sessopts, cpath, diagnostic_handler, codemap,
);
rustc_trans::init(&sess);
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));

View File

@ -22,7 +22,6 @@ use std::sync::{Arc, Mutex};
use testing;
use rustc_lint;
use rustc::dep_graph::DepGraph;
use rustc::hir;
use rustc::hir::intravisit;
use rustc::session::{self, CompileIncomplete, config};
@ -83,11 +82,9 @@ pub fn run(input: &str,
let handler =
errors::Handler::with_tty_emitter(ColorConfig::Auto, true, false, Some(codemap.clone()));
let dep_graph = DepGraph::new(false);
let _ignore = dep_graph.in_ignore();
let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader));
let mut sess = session::build_session_(
sessopts, &dep_graph, Some(input_path.clone()), handler, codemap.clone()
sessopts, Some(input_path.clone()), handler, codemap.clone(),
);
rustc_trans::init(&sess);
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
@ -100,7 +97,14 @@ pub fn run(input: &str,
let krate = ReplaceBodyWithLoop::new().fold_crate(krate);
let driver::ExpansionResult { defs, mut hir_forest, .. } = {
phase_2_configure_and_expand(
&sess, &cstore, krate, None, "rustdoc-test", None, MakeGlobMap::No, |_| Ok(())
&sess,
&cstore,
krate,
None,
"rustdoc-test",
None,
MakeGlobMap::No,
|_| Ok(()),
).expect("phase_2_configure_and_expand aborted in rustdoc!")
};
@ -120,8 +124,6 @@ pub fn run(input: &str,
render_type);
{
let dep_graph = DepGraph::new(false);
let _ignore = dep_graph.in_ignore();
let map = hir::map::map_crate(&mut hir_forest, defs);
let krate = map.krate();
let mut hir_collector = HirCollector {
@ -237,10 +239,9 @@ fn run_test(test: &str, cratename: &str, filename: &str, cfgs: Vec<String>, libs
// Compile the code
let diagnostic_handler = errors::Handler::with_emitter(true, false, box emitter);
let dep_graph = DepGraph::new(false);
let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader));
let mut sess = session::build_session_(
sessopts, &dep_graph, None, diagnostic_handler, codemap
sessopts, None, diagnostic_handler, codemap,
);
rustc_trans::init(&sess);
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));

View File

@ -58,9 +58,8 @@ fn basic_sess(sysroot: PathBuf) -> (Session, Rc<CStore>) {
opts.maybe_sysroot = Some(sysroot);
let descriptions = Registry::new(&rustc::DIAGNOSTICS);
let dep_graph = DepGraph::new(opts.build_dep_graph());
let cstore = Rc::new(CStore::new(Box::new(rustc_trans::LlvmMetadataLoader)));
let sess = build_session(opts, &dep_graph, None, descriptions);
let sess = build_session(opts, None, descriptions);
rustc_trans::init(&sess);
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
(sess, cstore)