Skip to content

Commit 0df53cf

Browse files
authored
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 rust-lang/rust#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 191c2ac + 30b5452 commit 0df53cf

File tree

4 files changed

+23
-26
lines changed

4 files changed

+23
-26
lines changed

core.rs

+2-4
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));

lib.rs

+10-9
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");

markdown.rs

+2-2
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

test.rs

+9-11
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(),

0 commit comments

Comments
 (0)