Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f65d96f

Browse files
authoredAug 15, 2016
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 #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.
2 parents b72fa8c + 67f19e5 commit f65d96f

File tree

26 files changed

+1186
-248
lines changed

26 files changed

+1186
-248
lines changed
 

‎src/librustc/lint/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl LintId {
269269
}
270270

271271
/// Setting for how to handle a lint.
272-
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug)]
272+
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
273273
pub enum Level {
274274
Allow, Warn, Deny, Forbid
275275
}

‎src/librustc/middle/cstore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub enum LinkagePreference {
7373
}
7474

7575
enum_from_u32! {
76-
#[derive(Copy, Clone, PartialEq)]
76+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7777
pub enum NativeLibraryKind {
7878
NativeStatic, // native static library (.a archive)
7979
NativeFramework, // OSX-specific

‎src/librustc/session/config.rs

Lines changed: 1026 additions & 174 deletions
Large diffs are not rendered by default.

‎src/librustc/session/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ pub fn build_session_with_codemap(sopts: config::Options,
363363
.map(|&(_, ref level)| *level != lint::Allow)
364364
.last()
365365
.unwrap_or(true);
366-
let treat_err_as_bug = sopts.treat_err_as_bug;
366+
let treat_err_as_bug = sopts.debugging_opts.treat_err_as_bug;
367367

368368
let emitter: Box<Emitter> = match sopts.error_format {
369369
config::ErrorOutputType::HumanReadable(color_config) => {

‎src/librustc/session/search_paths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct Iter<'a> {
2222
iter: slice::Iter<'a, (PathKind, PathBuf)>,
2323
}
2424

25-
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
25+
#[derive(Eq, PartialEq, Clone, Copy, Debug, PartialOrd, Ord, Hash)]
2626
pub enum PathKind {
2727
Native,
2828
Crate,

‎src/librustc_driver/driver.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ use rustc::hir::lowering::lower_crate;
1515
use rustc_mir as mir;
1616
use rustc::mir::mir_map::MirMap;
1717
use rustc::session::{Session, CompileResult, compile_result_from_err_count};
18-
use rustc::session::config::{self, Input, OutputFilenames, OutputType};
18+
use rustc::session::config::{self, Input, OutputFilenames, OutputType,
19+
OutputTypes};
1920
use rustc::session::search_paths::PathKind;
2021
use rustc::lint;
2122
use rustc::middle::{self, dependency_format, stability, reachable};
@@ -42,7 +43,6 @@ use super::Compilation;
4243

4344
use serialize::json;
4445

45-
use std::collections::HashMap;
4646
use std::env;
4747
use std::ffi::{OsString, OsStr};
4848
use std::fs;
@@ -478,7 +478,7 @@ pub fn phase_1_parse_input<'a>(sess: &'a Session,
478478
cfg: ast::CrateConfig,
479479
input: &Input)
480480
-> PResult<'a, ast::Crate> {
481-
let continue_after_error = sess.opts.continue_parse_after_error;
481+
let continue_after_error = sess.opts.debugging_opts.continue_parse_after_error;
482482
sess.diagnostic().set_continue_after_error(continue_after_error);
483483

484484
let krate = time(sess.time_passes(), "parsing", || {
@@ -667,7 +667,10 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
667667
trace_mac: sess.opts.debugging_opts.trace_macros,
668668
should_test: sess.opts.test,
669669
};
670-
let mut loader = macro_import::MacroLoader::new(sess, &cstore, crate_name);
670+
let mut loader = macro_import::MacroLoader::new(sess,
671+
&cstore,
672+
crate_name,
673+
krate.config.clone());
671674
let mut ecx = syntax::ext::base::ExtCtxt::new(&sess.parse_sess,
672675
krate.config.clone(),
673676
cfg,
@@ -1024,11 +1027,10 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
10241027
trans: &trans::CrateTranslation,
10251028
outputs: &OutputFilenames) -> CompileResult {
10261029
if sess.opts.cg.no_integrated_as {
1027-
let mut map = HashMap::new();
1028-
map.insert(OutputType::Assembly, None);
1030+
let output_types = OutputTypes::new(&[(OutputType::Assembly, None)]);
10291031
time(sess.time_passes(),
10301032
"LLVM passes",
1031-
|| write::run_passes(sess, trans, &map, outputs));
1033+
|| write::run_passes(sess, trans, &output_types, outputs));
10321034

10331035
write::run_assembler(sess, outputs);
10341036

‎src/librustc_driver/lib.rs

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ pub fn run_compiler_with_file_loader<'a, L>(args: &[String],
181181
None => return (Ok(()), None),
182182
};
183183

184-
let sopts = config::build_session_options(&matches);
184+
let (sopts, cfg) = config::build_session_options_and_crate_config(&matches);
185185

186186
if sopts.debugging_opts.debug_llvm {
187187
unsafe { llvm::LLVMRustSetDebug(1); }
@@ -191,14 +191,15 @@ pub fn run_compiler_with_file_loader<'a, L>(args: &[String],
191191

192192
do_or_return!(callbacks.early_callback(&matches,
193193
&sopts,
194+
&cfg,
194195
&descriptions,
195196
sopts.error_format),
196197
None);
197198

198199
let (odir, ofile) = make_output(&matches);
199200
let (input, input_file_path) = match make_input(&matches.free) {
200201
Some((input, input_file_path)) => callbacks.some_input(input, input_file_path),
201-
None => match callbacks.no_input(&matches, &sopts, &odir, &ofile, &descriptions) {
202+
None => match callbacks.no_input(&matches, &sopts, &cfg, &odir, &ofile, &descriptions) {
202203
Some((input, input_file_path)) => (input, input_file_path),
203204
None => return (Ok(()), None),
204205
},
@@ -214,10 +215,11 @@ pub fn run_compiler_with_file_loader<'a, L>(args: &[String],
214215
cstore.clone(),
215216
codemap);
216217
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
217-
let mut cfg = config::build_configuration(&sess);
218+
let mut cfg = config::build_configuration(&sess, cfg);
218219
target_features::add_configuration(&mut cfg, &sess);
219220

220-
do_or_return!(callbacks.late_callback(&matches, &sess, &input, &odir, &ofile), Some(sess));
221+
do_or_return!(callbacks.late_callback(&matches, &sess, &cfg, &input, &odir, &ofile),
222+
Some(sess));
221223

222224
let plugins = sess.opts.debugging_opts.extra_plugins.clone();
223225
let control = callbacks.build_controller(&sess, &matches);
@@ -297,6 +299,7 @@ pub trait CompilerCalls<'a> {
297299
fn early_callback(&mut self,
298300
_: &getopts::Matches,
299301
_: &config::Options,
302+
_: &ast::CrateConfig,
300303
_: &errors::registry::Registry,
301304
_: ErrorOutputType)
302305
-> Compilation {
@@ -309,6 +312,7 @@ pub trait CompilerCalls<'a> {
309312
fn late_callback(&mut self,
310313
_: &getopts::Matches,
311314
_: &Session,
315+
_: &ast::CrateConfig,
312316
_: &Input,
313317
_: &Option<PathBuf>,
314318
_: &Option<PathBuf>)
@@ -334,6 +338,7 @@ pub trait CompilerCalls<'a> {
334338
fn no_input(&mut self,
335339
_: &getopts::Matches,
336340
_: &config::Options,
341+
_: &ast::CrateConfig,
337342
_: &Option<PathBuf>,
338343
_: &Option<PathBuf>,
339344
_: &errors::registry::Registry)
@@ -375,7 +380,7 @@ fn handle_explain(code: &str,
375380
}
376381
}
377382

378-
fn check_cfg(sopts: &config::Options,
383+
fn check_cfg(cfg: &ast::CrateConfig,
379384
output: ErrorOutputType) {
380385
let emitter: Box<Emitter> = match output {
381386
config::ErrorOutputType::HumanReadable(color_config) => {
@@ -386,7 +391,7 @@ fn check_cfg(sopts: &config::Options,
386391
let handler = errors::Handler::with_emitter(true, false, emitter);
387392

388393
let mut saw_invalid_predicate = false;
389-
for item in sopts.cfg.iter() {
394+
for item in cfg.iter() {
390395
if item.is_meta_item_list() {
391396
saw_invalid_predicate = true;
392397
handler.emit(&MultiSpan::new(),
@@ -404,7 +409,8 @@ fn check_cfg(sopts: &config::Options,
404409
impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
405410
fn early_callback(&mut self,
406411
matches: &getopts::Matches,
407-
sopts: &config::Options,
412+
_: &config::Options,
413+
cfg: &ast::CrateConfig,
408414
descriptions: &errors::registry::Registry,
409415
output: ErrorOutputType)
410416
-> Compilation {
@@ -413,13 +419,14 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
413419
return Compilation::Stop;
414420
}
415421

416-
check_cfg(sopts, output);
422+
check_cfg(cfg, output);
417423
Compilation::Continue
418424
}
419425

420426
fn no_input(&mut self,
421427
matches: &getopts::Matches,
422428
sopts: &config::Options,
429+
cfg: &ast::CrateConfig,
423430
odir: &Option<PathBuf>,
424431
ofile: &Option<PathBuf>,
425432
descriptions: &errors::registry::Registry)
@@ -440,7 +447,13 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
440447
descriptions.clone(),
441448
cstore.clone());
442449
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
443-
let should_stop = RustcDefaultCalls::print_crate_info(&sess, None, odir, ofile);
450+
let mut cfg = config::build_configuration(&sess, cfg.clone());
451+
target_features::add_configuration(&mut cfg, &sess);
452+
let should_stop = RustcDefaultCalls::print_crate_info(&sess,
453+
&cfg,
454+
None,
455+
odir,
456+
ofile);
444457
if should_stop == Compilation::Stop {
445458
return None;
446459
}
@@ -456,11 +469,12 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
456469
fn late_callback(&mut self,
457470
matches: &getopts::Matches,
458471
sess: &Session,
472+
cfg: &ast::CrateConfig,
459473
input: &Input,
460474
odir: &Option<PathBuf>,
461475
ofile: &Option<PathBuf>)
462476
-> Compilation {
463-
RustcDefaultCalls::print_crate_info(sess, Some(input), odir, ofile)
477+
RustcDefaultCalls::print_crate_info(sess, cfg, Some(input), odir, ofile)
464478
.and_then(|| RustcDefaultCalls::list_metadata(sess, matches, input))
465479
}
466480

@@ -506,12 +520,14 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
506520
return control;
507521
}
508522

509-
if sess.opts.parse_only || sess.opts.debugging_opts.show_span.is_some() ||
523+
if sess.opts.debugging_opts.parse_only ||
524+
sess.opts.debugging_opts.show_span.is_some() ||
510525
sess.opts.debugging_opts.ast_json_noexpand {
511526
control.after_parse.stop = Compilation::Stop;
512527
}
513528

514-
if sess.opts.no_analysis || sess.opts.debugging_opts.ast_json {
529+
if sess.opts.debugging_opts.no_analysis ||
530+
sess.opts.debugging_opts.ast_json {
515531
control.after_hir_lowering.stop = Compilation::Stop;
516532
}
517533

@@ -577,6 +593,7 @@ impl RustcDefaultCalls {
577593

578594

579595
fn print_crate_info(sess: &Session,
596+
cfg: &ast::CrateConfig,
580597
input: Option<&Input>,
581598
odir: &Option<PathBuf>,
582599
ofile: &Option<PathBuf>)
@@ -629,9 +646,6 @@ impl RustcDefaultCalls {
629646
}
630647
}
631648
PrintRequest::Cfg => {
632-
let mut cfg = config::build_configuration(&sess);
633-
target_features::add_configuration(&mut cfg, &sess);
634-
635649
let allow_unstable_cfg = match get_unstable_features_setting() {
636650
UnstableFeatures::Disallow => false,
637651
_ => true,

‎src/librustc_incremental/persist/directory.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ impl<'a,'tcx> DefIdDirectoryBuilder<'a,'tcx> {
158158
}
159159
}
160160

161+
pub fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> {
162+
self.tcx
163+
}
164+
161165
pub fn add(&mut self, def_id: DefId) -> DefPathIndex {
162166
debug!("DefIdDirectoryBuilder: def_id={:?}", def_id);
163167
let tcx = self.tcx;

‎src/librustc_incremental/persist/load.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,25 @@ pub fn decode_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
101101
work_products_data: &[u8])
102102
-> Result<(), Error>
103103
{
104+
// Decode the list of work_products
105+
let mut work_product_decoder = Decoder::new(work_products_data, 0);
106+
let work_products = try!(<Vec<SerializedWorkProduct>>::decode(&mut work_product_decoder));
107+
104108
// Deserialize the directory and dep-graph.
105109
let mut dep_graph_decoder = Decoder::new(dep_graph_data, 0);
110+
let prev_commandline_args_hash = try!(u64::decode(&mut dep_graph_decoder));
111+
112+
if prev_commandline_args_hash != tcx.sess.opts.dep_tracking_hash() {
113+
// We can't reuse the cache, purge it.
114+
debug!("decode_dep_graph: differing commandline arg hashes");
115+
for swp in work_products {
116+
delete_dirty_work_product(tcx, swp);
117+
}
118+
119+
// No need to do any further work
120+
return Ok(());
121+
}
122+
106123
let directory = try!(DefIdDirectory::decode(&mut dep_graph_decoder));
107124
let serialized_dep_graph = try!(SerializedDepGraph::decode(&mut dep_graph_decoder));
108125

@@ -179,8 +196,6 @@ pub fn decode_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
179196

180197
// Add in work-products that are still clean, and delete those that are
181198
// dirty.
182-
let mut work_product_decoder = Decoder::new(work_products_data, 0);
183-
let work_products = try!(<Vec<SerializedWorkProduct>>::decode(&mut work_product_decoder));
184199
reconcile_work_products(tcx, work_products, &dirty_target_nodes);
185200

186201
dirty_clean::check_dirty_clean_annotations(tcx, &dirty_raw_source_nodes, &retraced);

‎src/librustc_incremental/persist/save.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ pub fn encode_dep_graph(preds: &Predecessors,
105105
builder: &mut DefIdDirectoryBuilder,
106106
encoder: &mut Encoder)
107107
-> io::Result<()> {
108+
// First encode the commandline arguments hash
109+
let tcx = builder.tcx();
110+
try!(tcx.sess.opts.dep_tracking_hash().encode(encoder));
111+
108112
// Create a flat list of (Input, WorkProduct) edges for
109113
// serialization.
110114
let mut edges = vec![];

‎src/librustc_metadata/creader.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub struct CrateReader<'a> {
5656
next_crate_num: ast::CrateNum,
5757
foreign_item_map: FnvHashMap<String, Vec<ast::NodeId>>,
5858
local_crate_name: String,
59+
local_crate_config: ast::CrateConfig,
5960
}
6061

6162
impl<'a> visit::Visitor for LocalCrateReader<'a> {
@@ -152,13 +153,16 @@ enum LoadResult {
152153
impl<'a> CrateReader<'a> {
153154
pub fn new(sess: &'a Session,
154155
cstore: &'a CStore,
155-
local_crate_name: &str) -> CrateReader<'a> {
156+
local_crate_name: &str,
157+
local_crate_config: ast::CrateConfig)
158+
-> CrateReader<'a> {
156159
CrateReader {
157160
sess: sess,
158161
cstore: cstore,
159162
next_crate_num: cstore.next_crate_num(),
160163
foreign_item_map: FnvHashMap(),
161164
local_crate_name: local_crate_name.to_owned(),
165+
local_crate_config: local_crate_config,
162166
}
163167
}
164168

@@ -561,7 +565,7 @@ impl<'a> CrateReader<'a> {
561565
// NB: Don't use parse::parse_tts_from_source_str because it parses with
562566
// quote_depth > 0.
563567
let mut p = parse::new_parser_from_source_str(&self.sess.parse_sess,
564-
self.sess.opts.cfg.clone(),
568+
self.local_crate_config.clone(),
565569
source_name.clone(),
566570
body);
567571
let lo = p.span.lo;
@@ -863,7 +867,7 @@ impl<'a> LocalCrateReader<'a> {
863867
LocalCrateReader {
864868
sess: sess,
865869
cstore: cstore,
866-
creader: CrateReader::new(sess, cstore, local_crate_name),
870+
creader: CrateReader::new(sess, cstore, local_crate_name, krate.config.clone()),
867871
krate: krate,
868872
definitions: defs,
869873
}

‎src/librustc_metadata/loader.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ impl<'a> Context<'a> {
400400
if self.hash.is_none() {
401401
self.should_match_name = false;
402402
if let Some(s) = self.sess.opts.externs.get(self.crate_name) {
403-
return self.find_commandline_library(s);
403+
return self.find_commandline_library(s.iter());
404404
}
405405
self.should_match_name = true;
406406
}
@@ -661,7 +661,9 @@ impl<'a> Context<'a> {
661661
(t.options.staticlib_prefix.clone(), t.options.staticlib_suffix.clone())
662662
}
663663

664-
fn find_commandline_library(&mut self, locs: &[String]) -> Option<Library> {
664+
fn find_commandline_library<'b, LOCS> (&mut self, locs: LOCS) -> Option<Library>
665+
where LOCS: Iterator<Item=&'b String>
666+
{
665667
// First, filter out all libraries that look suspicious. We only accept
666668
// files which actually exist that have the correct naming scheme for
667669
// rlibs/dylibs.
@@ -670,7 +672,7 @@ impl<'a> Context<'a> {
670672
let mut rlibs = HashMap::new();
671673
let mut dylibs = HashMap::new();
672674
{
673-
let locs = locs.iter().map(|l| PathBuf::from(l)).filter(|loc| {
675+
let locs = locs.map(|l| PathBuf::from(l)).filter(|loc| {
674676
if !loc.exists() {
675677
sess.err(&format!("extern location for {} does not exist: {}",
676678
self.crate_name, loc.display()));

‎src/librustc_metadata/macro_import.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ pub struct MacroLoader<'a> {
2929
}
3030

3131
impl<'a> MacroLoader<'a> {
32-
pub fn new(sess: &'a Session, cstore: &'a CStore, crate_name: &str) -> MacroLoader<'a> {
32+
pub fn new(sess: &'a Session,
33+
cstore: &'a CStore,
34+
crate_name: &str,
35+
crate_config: ast::CrateConfig)
36+
-> MacroLoader<'a> {
3337
MacroLoader {
3438
sess: sess,
35-
reader: CrateReader::new(sess, cstore, crate_name),
39+
reader: CrateReader::new(sess, cstore, crate_name, crate_config),
3640
}
3741
}
3842
}

‎src/librustc_plugin/load.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn load_plugins(sess: &Session,
4949
krate: &ast::Crate,
5050
crate_name: &str,
5151
addl_plugins: Option<Vec<String>>) -> Vec<PluginRegistrar> {
52-
let mut loader = PluginLoader::new(sess, cstore, crate_name);
52+
let mut loader = PluginLoader::new(sess, cstore, crate_name, krate.config.clone());
5353

5454
// do not report any error now. since crate attributes are
5555
// not touched by expansion, every use of plugin without
@@ -90,10 +90,14 @@ pub fn load_plugins(sess: &Session,
9090
}
9191

9292
impl<'a> PluginLoader<'a> {
93-
fn new(sess: &'a Session, cstore: &'a CStore, crate_name: &str) -> PluginLoader<'a> {
93+
fn new(sess: &'a Session,
94+
cstore: &'a CStore,
95+
crate_name: &str,
96+
crate_config: ast::CrateConfig)
97+
-> PluginLoader<'a> {
9498
PluginLoader {
9599
sess: sess,
96-
reader: CrateReader::new(sess, cstore, crate_name),
100+
reader: CrateReader::new(sess, cstore, crate_name, crate_config),
97101
plugins: vec![],
98102
}
99103
}

‎src/librustc_trans/back/link.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ pub fn link_binary(sess: &Session,
190190
let mut out_filenames = Vec::new();
191191
for &crate_type in sess.crate_types.borrow().iter() {
192192
// Ignore executable crates if we have -Z no-trans, as they will error.
193-
if sess.opts.no_trans && crate_type == config::CrateTypeExecutable {
193+
if sess.opts.debugging_opts.no_trans &&
194+
crate_type == config::CrateTypeExecutable {
194195
continue;
195196
}
196197

‎src/librustc_trans/back/write.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use back::lto;
1212
use back::link::{get_linker, remove};
1313
use rustc_incremental::save_trans_partition;
14-
use session::config::{OutputFilenames, Passes, SomePasses, AllPasses};
14+
use session::config::{OutputFilenames, OutputTypes, Passes, SomePasses, AllPasses};
1515
use session::Session;
1616
use session::config::{self, OutputType};
1717
use llvm;
@@ -26,7 +26,6 @@ use errors::emitter::Emitter;
2626
use syntax_pos::MultiSpan;
2727
use context::{is_pie_binary, get_reloc_model};
2828

29-
use std::collections::HashMap;
3029
use std::ffi::{CStr, CString};
3130
use std::fs;
3231
use std::path::{Path, PathBuf};
@@ -641,7 +640,7 @@ pub fn cleanup_llvm(trans: &CrateTranslation) {
641640

642641
pub fn run_passes(sess: &Session,
643642
trans: &CrateTranslation,
644-
output_types: &HashMap<OutputType, Option<PathBuf>>,
643+
output_types: &OutputTypes,
645644
crate_output: &OutputFilenames) {
646645
// It's possible that we have `codegen_units > 1` but only one item in
647646
// `trans.modules`. We could theoretically proceed and do LTO in that

‎src/librustc_trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2576,7 +2576,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
25762576
assert_module_sources::assert_module_sources(tcx, &modules);
25772577

25782578
// Skip crate items and just output metadata in -Z no-trans mode.
2579-
if tcx.sess.opts.no_trans {
2579+
if tcx.sess.opts.debugging_opts.no_trans {
25802580
let linker_info = LinkerInfo::new(&shared_ccx, &[]);
25812581
return CrateTranslation {
25822582
modules: modules,

‎src/librustdoc/core.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ pub enum MaybeTyped<'a, 'tcx: 'a> {
4545
NotTyped(&'a session::Session)
4646
}
4747

48-
pub type Externs = HashMap<String, Vec<String>>;
4948
pub type ExternalPaths = HashMap<DefId, (Vec<String>, clean::TypeKind)>;
5049

5150
pub struct DocContext<'a, 'tcx: 'a> {
@@ -99,7 +98,7 @@ impl DocAccessLevels for AccessLevels<DefId> {
9998

10099
pub fn run_core(search_paths: SearchPaths,
101100
cfgs: Vec<String>,
102-
externs: Externs,
101+
externs: config::Externs,
103102
input: Input,
104103
triple: Option<String>) -> (clean::Crate, RenderInfo)
105104
{
@@ -120,7 +119,6 @@ pub fn run_core(search_paths: SearchPaths,
120119
lint_cap: Some(lint::Allow),
121120
externs: externs,
122121
target_triple: triple.unwrap_or(config::host_triple().to_string()),
123-
cfg: config::parse_cfgspecs(cfgs),
124122
// Ensure that rustdoc works even if rustc is feature-staged
125123
unstable_features: UnstableFeatures::Allow,
126124
..config::basic_options().clone()
@@ -139,7 +137,7 @@ pub fn run_core(search_paths: SearchPaths,
139137
codemap, cstore.clone());
140138
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
141139

142-
let mut cfg = config::build_configuration(&sess);
140+
let mut cfg = config::build_configuration(&sess, config::parse_cfgspecs(cfgs));
143141
target_features::add_configuration(&mut cfg, &sess);
144142

145143
let krate = panictry!(driver::phase_1_parse_input(&sess, cfg, &input));

‎src/librustdoc/lib.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extern crate rustc_errors as errors;
5151

5252
extern crate serialize as rustc_serialize; // used by deriving
5353

54-
use std::collections::HashMap;
54+
use std::collections::{BTreeMap, BTreeSet};
5555
use std::default::Default;
5656
use std::env;
5757
use std::path::PathBuf;
@@ -60,7 +60,8 @@ use std::sync::mpsc::channel;
6060

6161
use externalfiles::ExternalHtml;
6262
use rustc::session::search_paths::SearchPaths;
63-
use rustc::session::config::{ErrorOutputType, RustcOptGroup, nightly_options};
63+
use rustc::session::config::{ErrorOutputType, RustcOptGroup, nightly_options,
64+
Externs};
6465

6566
#[macro_use]
6667
pub mod externalfiles;
@@ -323,7 +324,7 @@ pub fn main_args(args: &[String]) -> isize {
323324
/// Looks inside the command line arguments to extract the relevant input format
324325
/// and files and then generates the necessary rustdoc output for formatting.
325326
fn acquire_input(input: &str,
326-
externs: core::Externs,
327+
externs: Externs,
327328
matches: &getopts::Matches) -> Result<Output, String> {
328329
match matches.opt_str("r").as_ref().map(|s| &**s) {
329330
Some("rust") => Ok(rust_input(input, externs, matches)),
@@ -335,28 +336,28 @@ fn acquire_input(input: &str,
335336
}
336337

337338
/// Extracts `--extern CRATE=PATH` arguments from `matches` and
338-
/// returns a `HashMap` mapping crate names to their paths or else an
339+
/// returns a map mapping crate names to their paths or else an
339340
/// error message.
340-
fn parse_externs(matches: &getopts::Matches) -> Result<core::Externs, String> {
341-
let mut externs = HashMap::new();
341+
fn parse_externs(matches: &getopts::Matches) -> Result<Externs, String> {
342+
let mut externs = BTreeMap::new();
342343
for arg in &matches.opt_strs("extern") {
343344
let mut parts = arg.splitn(2, '=');
344345
let name = parts.next().ok_or("--extern value must not be empty".to_string())?;
345346
let location = parts.next()
346347
.ok_or("--extern value must be of the format `foo=bar`"
347348
.to_string())?;
348349
let name = name.to_string();
349-
externs.entry(name).or_insert(vec![]).push(location.to_string());
350+
externs.entry(name).or_insert_with(BTreeSet::new).insert(location.to_string());
350351
}
351-
Ok(externs)
352+
Ok(Externs::new(externs))
352353
}
353354

354355
/// Interprets the input file as a rust source file, passing it through the
355356
/// compiler all the way through the analysis passes. The rustdoc output is then
356357
/// generated from the cleaned AST of the crate.
357358
///
358359
/// This form of input will run all of the plug/cleaning passes
359-
fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matches) -> Output {
360+
fn rust_input(cratefile: &str, externs: Externs, matches: &getopts::Matches) -> Output {
360361
let mut default_passes = !matches.opt_present("no-defaults");
361362
let mut passes = matches.opt_strs("passes");
362363
let mut plugins = matches.opt_strs("plugins");

‎src/librustdoc/markdown.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ use std::io::prelude::*;
1414
use std::io;
1515
use std::path::{PathBuf, Path};
1616

17-
use core;
1817
use getopts;
1918
use testing;
2019
use rustc::session::search_paths::SearchPaths;
20+
use rustc::session::config::Externs;
2121

2222
use externalfiles::ExternalHtml;
2323

@@ -142,7 +142,7 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
142142
}
143143

144144
/// Run any tests/code examples in the markdown file `input`.
145-
pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: core::Externs,
145+
pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
146146
mut test_args: Vec<String>) -> isize {
147147
let input_str = load_or_return!(input, 1, 2);
148148

‎src/librustdoc/test.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ use rustc_lint;
2626
use rustc::dep_graph::DepGraph;
2727
use rustc::hir::map as hir_map;
2828
use rustc::session::{self, config};
29-
use rustc::session::config::{get_unstable_features_setting, OutputType};
29+
use rustc::session::config::{get_unstable_features_setting, OutputType,
30+
OutputTypes, Externs};
3031
use rustc::session::search_paths::{SearchPaths, PathKind};
3132
use rustc_back::dynamic_lib::DynamicLibrary;
3233
use rustc_back::tempdir::TempDir;
@@ -55,7 +56,7 @@ pub struct TestOptions {
5556
pub fn run(input: &str,
5657
cfgs: Vec<String>,
5758
libs: SearchPaths,
58-
externs: core::Externs,
59+
externs: Externs,
5960
mut test_args: Vec<String>,
6061
crate_name: Option<String>)
6162
-> isize {
@@ -89,8 +90,7 @@ pub fn run(input: &str,
8990
cstore.clone());
9091
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
9192

92-
let mut cfg = config::build_configuration(&sess);
93-
cfg.extend(config::parse_cfgspecs(cfgs.clone()));
93+
let cfg = config::build_configuration(&sess, config::parse_cfgspecs(cfgs.clone()));
9494
let krate = panictry!(driver::phase_1_parse_input(&sess, cfg, &input));
9595
let driver::ExpansionResult { defs, mut hir_forest, .. } = {
9696
phase_2_configure_and_expand(
@@ -172,7 +172,7 @@ fn scrape_test_config(krate: &::rustc::hir::Crate) -> TestOptions {
172172
}
173173

174174
fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
175-
externs: core::Externs,
175+
externs: Externs,
176176
should_panic: bool, no_run: bool, as_test_harness: bool,
177177
compile_fail: bool, mut error_codes: Vec<String>, opts: &TestOptions) {
178178
// the test harness wants its own `main` & top level functions, so
@@ -182,8 +182,7 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
182182
name: driver::anon_src(),
183183
input: test.to_owned(),
184184
};
185-
let mut outputs = HashMap::new();
186-
outputs.insert(OutputType::Exe, None);
185+
let outputs = OutputTypes::new(&[(OutputType::Exe, None)]);
187186

188187
let sessopts = config::Options {
189188
maybe_sysroot: Some(env::current_exe().unwrap().parent().unwrap()
@@ -247,8 +246,7 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
247246
let outdir = Mutex::new(TempDir::new("rustdoctest").ok().expect("rustdoc needs a tempdir"));
248247
let libdir = sess.target_filesearch(PathKind::All).get_lib_path();
249248
let mut control = driver::CompileController::basic();
250-
let mut cfg = config::build_configuration(&sess);
251-
cfg.extend(config::parse_cfgspecs(cfgs.clone()));
249+
let cfg = config::build_configuration(&sess, config::parse_cfgspecs(cfgs.clone()));
252250
let out = Some(outdir.lock().unwrap().path().to_path_buf());
253251

254252
if no_run {
@@ -396,7 +394,7 @@ pub struct Collector {
396394
names: Vec<String>,
397395
cfgs: Vec<String>,
398396
libs: SearchPaths,
399-
externs: core::Externs,
397+
externs: Externs,
400398
cnt: usize,
401399
use_headers: bool,
402400
current_header: Option<String>,
@@ -405,7 +403,7 @@ pub struct Collector {
405403
}
406404

407405
impl Collector {
408-
pub fn new(cratename: String, cfgs: Vec<String>, libs: SearchPaths, externs: core::Externs,
406+
pub fn new(cratename: String, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
409407
use_headers: bool, opts: TestOptions) -> Collector {
410408
Collector {
411409
tests: Vec::new(),

‎src/libsyntax/feature_gate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ pub fn check_crate(krate: &ast::Crate,
11941194
visit::walk_crate(&mut PostExpansionVisitor { context: &ctx }, krate);
11951195
}
11961196

1197-
#[derive(Clone, Copy)]
1197+
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
11981198
pub enum UnstableFeatures {
11991199
/// Hard errors for unstable features are active, as on
12001200
/// beta/stable channels.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that changing a tracked commandline argument invalidates
12+
// the cache while changing an untracked one doesn't.
13+
14+
// revisions:rpass1 rpass2 rpass3
15+
16+
#![feature(rustc_attrs)]
17+
18+
#![rustc_partition_translated(module="commandline_args", cfg="rpass2")]
19+
#![rustc_partition_reused(module="commandline_args", cfg="rpass3")]
20+
21+
// Between revisions 1 and 2, we are changing the debuginfo-level, which should
22+
// invalidate the cache. Between revisions 2 and 3, we are adding `--verbose`
23+
// which should have no effect on the cache:
24+
//[rpass1] compile-flags: -C debuginfo=0
25+
//[rpass2] compile-flags: -C debuginfo=2
26+
//[rpass3] compile-flags: -C debuginfo=2 --verbose
27+
28+
pub fn main() {
29+
// empty
30+
}

‎src/test/run-make/issue-19371/foo.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ extern crate syntax;
1919

2020
use rustc::dep_graph::DepGraph;
2121
use rustc::session::{build_session, Session};
22-
use rustc::session::config::{basic_options, build_configuration, Input, OutputType};
22+
use rustc::session::config::{basic_options, build_configuration, Input,
23+
OutputType, OutputTypes};
2324
use rustc_driver::driver::{compile_input, CompileController, anon_src};
2425
use rustc_metadata::cstore::CStore;
2526
use rustc_errors::registry::Registry;
@@ -51,7 +52,7 @@ fn main() {
5152

5253
fn basic_sess(sysroot: PathBuf) -> (Session, Rc<CStore>) {
5354
let mut opts = basic_options();
54-
opts.output_types.insert(OutputType::Exe, None);
55+
opts.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
5556
opts.maybe_sysroot = Some(sysroot);
5657

5758
let descriptions = Registry::new(&rustc::DIAGNOSTICS);
@@ -64,7 +65,7 @@ fn basic_sess(sysroot: PathBuf) -> (Session, Rc<CStore>) {
6465

6566
fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
6667
let (sess, cstore) = basic_sess(sysroot);
67-
let cfg = build_configuration(&sess);
68+
let cfg = build_configuration(&sess, vec![]);
6869
let control = CompileController::basic();
6970

7071
compile_input(&sess, &cstore,

‎src/test/run-pass-fulldeps/compiler-calls.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ extern crate rustc_errors as errors;
2424
use rustc::session::Session;
2525
use rustc::session::config::{self, Input};
2626
use rustc_driver::{driver, CompilerCalls, Compilation};
27+
use syntax::ast;
2728

2829
use std::path::PathBuf;
2930

@@ -35,6 +36,7 @@ impl<'a> CompilerCalls<'a> for TestCalls {
3536
fn early_callback(&mut self,
3637
_: &getopts::Matches,
3738
_: &config::Options,
39+
_: &ast::CrateConfig,
3840
_: &errors::registry::Registry,
3941
_: config::ErrorOutputType)
4042
-> Compilation {
@@ -45,6 +47,7 @@ impl<'a> CompilerCalls<'a> for TestCalls {
4547
fn late_callback(&mut self,
4648
_: &getopts::Matches,
4749
_: &Session,
50+
_: &ast::CrateConfig,
4851
_: &Input,
4952
_: &Option<PathBuf>,
5053
_: &Option<PathBuf>)
@@ -62,6 +65,7 @@ impl<'a> CompilerCalls<'a> for TestCalls {
6265
fn no_input(&mut self,
6366
_: &getopts::Matches,
6467
_: &config::Options,
68+
_: &ast::CrateConfig,
6569
_: &Option<PathBuf>,
6670
_: &Option<PathBuf>,
6771
_: &errors::registry::Registry)

‎src/tools/compiletest/src/runtest.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,6 +2008,7 @@ actual:\n\
20082008
// Add an extra flag pointing at the incremental directory.
20092009
let mut revision_props = self.props.clone();
20102010
revision_props.incremental_dir = Some(incremental_dir);
2011+
revision_props.compile_flags.push(String::from("-Zincremental-info"));
20112012

20122013
let revision_cx = TestCx {
20132014
config: self.config,

0 commit comments

Comments
 (0)
Please sign in to comment.