Auto merge of #35340 - michaelwoerister:incr-comp-cli-args, r=nikomatsakis
Take commandline arguments into account for incr. comp. Implements the conservative strategy described in https://github.com/rust-lang/rust/issues/33727. From now one, every time a new commandline option is added, one has to specify if it influences the incremental compilation cache. I've tried to implement this as automatic as possible: One just has to added either the `[TRACKED]` or the `[UNTRACKED]` marker next to the field. The `Options`, `CodegenOptions`, and `DebuggingOptions` definitions in `session::config` show plenty of examples. The PR removes some cruft from `session::config::Options`, mostly unnecessary copies of flags also present in `DebuggingOptions` or `CodeGenOptions` in the same struct. One notable removal is the `cfg` field that contained the values passed via `--cfg` commandline arguments. I chose to remove it because (1) its content is only a subset of what later is stored in `hir::Crate::config` and it's pretty likely that reading the cfgs from `Options` would not be what you wanted, and (2) we could not incorporate it into the dep-tracking hash of the `Options` struct because of how the test framework works, leaving us with a piece of untracked but vital data. It is now recommended (just as before) to access the crate config via the `krate()` method in the HIR map. Because the `cfg` field is not present in the `Options` struct any more, some methods in the `CompilerCalls` trait now take the crate config as an explicit parameter -- which might constitute a breaking change for plugin authors.
This commit is contained in:
commit
f65d96fe3f
26 changed files with 1183 additions and 245 deletions
|
|
@ -15,7 +15,8 @@ use rustc::hir::lowering::lower_crate;
|
|||
use rustc_mir as mir;
|
||||
use rustc::mir::mir_map::MirMap;
|
||||
use rustc::session::{Session, CompileResult, compile_result_from_err_count};
|
||||
use rustc::session::config::{self, Input, OutputFilenames, OutputType};
|
||||
use rustc::session::config::{self, Input, OutputFilenames, OutputType,
|
||||
OutputTypes};
|
||||
use rustc::session::search_paths::PathKind;
|
||||
use rustc::lint;
|
||||
use rustc::middle::{self, dependency_format, stability, reachable};
|
||||
|
|
@ -42,7 +43,6 @@ use super::Compilation;
|
|||
|
||||
use serialize::json;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::ffi::{OsString, OsStr};
|
||||
use std::fs;
|
||||
|
|
@ -478,7 +478,7 @@ pub fn phase_1_parse_input<'a>(sess: &'a Session,
|
|||
cfg: ast::CrateConfig,
|
||||
input: &Input)
|
||||
-> PResult<'a, ast::Crate> {
|
||||
let continue_after_error = sess.opts.continue_parse_after_error;
|
||||
let continue_after_error = sess.opts.debugging_opts.continue_parse_after_error;
|
||||
sess.diagnostic().set_continue_after_error(continue_after_error);
|
||||
|
||||
let krate = time(sess.time_passes(), "parsing", || {
|
||||
|
|
@ -667,7 +667,10 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
|
|||
trace_mac: sess.opts.debugging_opts.trace_macros,
|
||||
should_test: sess.opts.test,
|
||||
};
|
||||
let mut loader = macro_import::MacroLoader::new(sess, &cstore, crate_name);
|
||||
let mut loader = macro_import::MacroLoader::new(sess,
|
||||
&cstore,
|
||||
crate_name,
|
||||
krate.config.clone());
|
||||
let mut ecx = syntax::ext::base::ExtCtxt::new(&sess.parse_sess,
|
||||
krate.config.clone(),
|
||||
cfg,
|
||||
|
|
@ -1024,11 +1027,10 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
|
|||
trans: &trans::CrateTranslation,
|
||||
outputs: &OutputFilenames) -> CompileResult {
|
||||
if sess.opts.cg.no_integrated_as {
|
||||
let mut map = HashMap::new();
|
||||
map.insert(OutputType::Assembly, None);
|
||||
let output_types = OutputTypes::new(&[(OutputType::Assembly, None)]);
|
||||
time(sess.time_passes(),
|
||||
"LLVM passes",
|
||||
|| write::run_passes(sess, trans, &map, outputs));
|
||||
|| write::run_passes(sess, trans, &output_types, outputs));
|
||||
|
||||
write::run_assembler(sess, outputs);
|
||||
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ pub fn run_compiler_with_file_loader<'a, L>(args: &[String],
|
|||
None => return (Ok(()), None),
|
||||
};
|
||||
|
||||
let sopts = config::build_session_options(&matches);
|
||||
let (sopts, cfg) = config::build_session_options_and_crate_config(&matches);
|
||||
|
||||
if sopts.debugging_opts.debug_llvm {
|
||||
unsafe { llvm::LLVMRustSetDebug(1); }
|
||||
|
|
@ -191,6 +191,7 @@ pub fn run_compiler_with_file_loader<'a, L>(args: &[String],
|
|||
|
||||
do_or_return!(callbacks.early_callback(&matches,
|
||||
&sopts,
|
||||
&cfg,
|
||||
&descriptions,
|
||||
sopts.error_format),
|
||||
None);
|
||||
|
|
@ -198,7 +199,7 @@ pub fn run_compiler_with_file_loader<'a, L>(args: &[String],
|
|||
let (odir, ofile) = make_output(&matches);
|
||||
let (input, input_file_path) = match make_input(&matches.free) {
|
||||
Some((input, input_file_path)) => callbacks.some_input(input, input_file_path),
|
||||
None => match callbacks.no_input(&matches, &sopts, &odir, &ofile, &descriptions) {
|
||||
None => match callbacks.no_input(&matches, &sopts, &cfg, &odir, &ofile, &descriptions) {
|
||||
Some((input, input_file_path)) => (input, input_file_path),
|
||||
None => return (Ok(()), None),
|
||||
},
|
||||
|
|
@ -214,10 +215,11 @@ pub fn run_compiler_with_file_loader<'a, L>(args: &[String],
|
|||
cstore.clone(),
|
||||
codemap);
|
||||
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
||||
let mut cfg = config::build_configuration(&sess);
|
||||
let mut cfg = config::build_configuration(&sess, cfg);
|
||||
target_features::add_configuration(&mut cfg, &sess);
|
||||
|
||||
do_or_return!(callbacks.late_callback(&matches, &sess, &input, &odir, &ofile), Some(sess));
|
||||
do_or_return!(callbacks.late_callback(&matches, &sess, &cfg, &input, &odir, &ofile),
|
||||
Some(sess));
|
||||
|
||||
let plugins = sess.opts.debugging_opts.extra_plugins.clone();
|
||||
let control = callbacks.build_controller(&sess, &matches);
|
||||
|
|
@ -297,6 +299,7 @@ pub trait CompilerCalls<'a> {
|
|||
fn early_callback(&mut self,
|
||||
_: &getopts::Matches,
|
||||
_: &config::Options,
|
||||
_: &ast::CrateConfig,
|
||||
_: &errors::registry::Registry,
|
||||
_: ErrorOutputType)
|
||||
-> Compilation {
|
||||
|
|
@ -309,6 +312,7 @@ pub trait CompilerCalls<'a> {
|
|||
fn late_callback(&mut self,
|
||||
_: &getopts::Matches,
|
||||
_: &Session,
|
||||
_: &ast::CrateConfig,
|
||||
_: &Input,
|
||||
_: &Option<PathBuf>,
|
||||
_: &Option<PathBuf>)
|
||||
|
|
@ -334,6 +338,7 @@ pub trait CompilerCalls<'a> {
|
|||
fn no_input(&mut self,
|
||||
_: &getopts::Matches,
|
||||
_: &config::Options,
|
||||
_: &ast::CrateConfig,
|
||||
_: &Option<PathBuf>,
|
||||
_: &Option<PathBuf>,
|
||||
_: &errors::registry::Registry)
|
||||
|
|
@ -375,7 +380,7 @@ fn handle_explain(code: &str,
|
|||
}
|
||||
}
|
||||
|
||||
fn check_cfg(sopts: &config::Options,
|
||||
fn check_cfg(cfg: &ast::CrateConfig,
|
||||
output: ErrorOutputType) {
|
||||
let emitter: Box<Emitter> = match output {
|
||||
config::ErrorOutputType::HumanReadable(color_config) => {
|
||||
|
|
@ -386,7 +391,7 @@ fn check_cfg(sopts: &config::Options,
|
|||
let handler = errors::Handler::with_emitter(true, false, emitter);
|
||||
|
||||
let mut saw_invalid_predicate = false;
|
||||
for item in sopts.cfg.iter() {
|
||||
for item in cfg.iter() {
|
||||
if item.is_meta_item_list() {
|
||||
saw_invalid_predicate = true;
|
||||
handler.emit(&MultiSpan::new(),
|
||||
|
|
@ -404,7 +409,8 @@ fn check_cfg(sopts: &config::Options,
|
|||
impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
|
||||
fn early_callback(&mut self,
|
||||
matches: &getopts::Matches,
|
||||
sopts: &config::Options,
|
||||
_: &config::Options,
|
||||
cfg: &ast::CrateConfig,
|
||||
descriptions: &errors::registry::Registry,
|
||||
output: ErrorOutputType)
|
||||
-> Compilation {
|
||||
|
|
@ -413,13 +419,14 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
|
|||
return Compilation::Stop;
|
||||
}
|
||||
|
||||
check_cfg(sopts, output);
|
||||
check_cfg(cfg, output);
|
||||
Compilation::Continue
|
||||
}
|
||||
|
||||
fn no_input(&mut self,
|
||||
matches: &getopts::Matches,
|
||||
sopts: &config::Options,
|
||||
cfg: &ast::CrateConfig,
|
||||
odir: &Option<PathBuf>,
|
||||
ofile: &Option<PathBuf>,
|
||||
descriptions: &errors::registry::Registry)
|
||||
|
|
@ -440,7 +447,13 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
|
|||
descriptions.clone(),
|
||||
cstore.clone());
|
||||
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
||||
let should_stop = RustcDefaultCalls::print_crate_info(&sess, None, odir, ofile);
|
||||
let mut cfg = config::build_configuration(&sess, cfg.clone());
|
||||
target_features::add_configuration(&mut cfg, &sess);
|
||||
let should_stop = RustcDefaultCalls::print_crate_info(&sess,
|
||||
&cfg,
|
||||
None,
|
||||
odir,
|
||||
ofile);
|
||||
if should_stop == Compilation::Stop {
|
||||
return None;
|
||||
}
|
||||
|
|
@ -456,11 +469,12 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
|
|||
fn late_callback(&mut self,
|
||||
matches: &getopts::Matches,
|
||||
sess: &Session,
|
||||
cfg: &ast::CrateConfig,
|
||||
input: &Input,
|
||||
odir: &Option<PathBuf>,
|
||||
ofile: &Option<PathBuf>)
|
||||
-> Compilation {
|
||||
RustcDefaultCalls::print_crate_info(sess, Some(input), odir, ofile)
|
||||
RustcDefaultCalls::print_crate_info(sess, cfg, Some(input), odir, ofile)
|
||||
.and_then(|| RustcDefaultCalls::list_metadata(sess, matches, input))
|
||||
}
|
||||
|
||||
|
|
@ -506,12 +520,14 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
|
|||
return control;
|
||||
}
|
||||
|
||||
if sess.opts.parse_only || sess.opts.debugging_opts.show_span.is_some() ||
|
||||
if sess.opts.debugging_opts.parse_only ||
|
||||
sess.opts.debugging_opts.show_span.is_some() ||
|
||||
sess.opts.debugging_opts.ast_json_noexpand {
|
||||
control.after_parse.stop = Compilation::Stop;
|
||||
}
|
||||
|
||||
if sess.opts.no_analysis || sess.opts.debugging_opts.ast_json {
|
||||
if sess.opts.debugging_opts.no_analysis ||
|
||||
sess.opts.debugging_opts.ast_json {
|
||||
control.after_hir_lowering.stop = Compilation::Stop;
|
||||
}
|
||||
|
||||
|
|
@ -577,6 +593,7 @@ impl RustcDefaultCalls {
|
|||
|
||||
|
||||
fn print_crate_info(sess: &Session,
|
||||
cfg: &ast::CrateConfig,
|
||||
input: Option<&Input>,
|
||||
odir: &Option<PathBuf>,
|
||||
ofile: &Option<PathBuf>)
|
||||
|
|
@ -629,9 +646,6 @@ impl RustcDefaultCalls {
|
|||
}
|
||||
}
|
||||
PrintRequest::Cfg => {
|
||||
let mut cfg = config::build_configuration(&sess);
|
||||
target_features::add_configuration(&mut cfg, &sess);
|
||||
|
||||
let allow_unstable_cfg = match get_unstable_features_setting() {
|
||||
UnstableFeatures::Disallow => false,
|
||||
_ => true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue