Skip to content

Commit

Permalink
Auto merge of #35340 - michaelwoerister:incr-comp-cli-args, r=nikomat…
Browse files Browse the repository at this point in the history
…sakis

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.
  • Loading branch information
bors authored Aug 15, 2016
2 parents 191c2ac + 30b5452 commit 0df53cf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 26 deletions.
6 changes: 2 additions & 4 deletions core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ pub enum MaybeTyped<'a, 'tcx: 'a> {
NotTyped(&'a session::Session)
}

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

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

pub fn run_core(search_paths: SearchPaths,
cfgs: Vec<String>,
externs: Externs,
externs: config::Externs,
input: Input,
triple: Option<String>) -> (clean::Crate, RenderInfo)
{
Expand All @@ -120,7 +119,6 @@ pub fn run_core(search_paths: SearchPaths,
lint_cap: Some(lint::Allow),
externs: externs,
target_triple: triple.unwrap_or(config::host_triple().to_string()),
cfg: config::parse_cfgspecs(cfgs),
// Ensure that rustdoc works even if rustc is feature-staged
unstable_features: UnstableFeatures::Allow,
..config::basic_options().clone()
Expand All @@ -139,7 +137,7 @@ pub fn run_core(search_paths: SearchPaths,
codemap, cstore.clone());
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, config::parse_cfgspecs(cfgs));
target_features::add_configuration(&mut cfg, &sess);

let krate = panictry!(driver::phase_1_parse_input(&sess, cfg, &input));
Expand Down
19 changes: 10 additions & 9 deletions lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extern crate rustc_errors as errors;

extern crate serialize as rustc_serialize; // used by deriving

use std::collections::HashMap;
use std::collections::{BTreeMap, BTreeSet};
use std::default::Default;
use std::env;
use std::path::PathBuf;
Expand All @@ -60,7 +60,8 @@ use std::sync::mpsc::channel;

use externalfiles::ExternalHtml;
use rustc::session::search_paths::SearchPaths;
use rustc::session::config::{ErrorOutputType, RustcOptGroup, nightly_options};
use rustc::session::config::{ErrorOutputType, RustcOptGroup, nightly_options,
Externs};

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

/// Extracts `--extern CRATE=PATH` arguments from `matches` and
/// returns a `HashMap` mapping crate names to their paths or else an
/// returns a map mapping crate names to their paths or else an
/// error message.
fn parse_externs(matches: &getopts::Matches) -> Result<core::Externs, String> {
let mut externs = HashMap::new();
fn parse_externs(matches: &getopts::Matches) -> Result<Externs, String> {
let mut externs = BTreeMap::new();
for arg in &matches.opt_strs("extern") {
let mut parts = arg.splitn(2, '=');
let name = parts.next().ok_or("--extern value must not be empty".to_string())?;
let location = parts.next()
.ok_or("--extern value must be of the format `foo=bar`"
.to_string())?;
let name = name.to_string();
externs.entry(name).or_insert(vec![]).push(location.to_string());
externs.entry(name).or_insert_with(BTreeSet::new).insert(location.to_string());
}
Ok(externs)
Ok(Externs::new(externs))
}

/// Interprets the input file as a rust source file, passing it through the
/// compiler all the way through the analysis passes. The rustdoc output is then
/// generated from the cleaned AST of the crate.
///
/// This form of input will run all of the plug/cleaning passes
fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matches) -> Output {
fn rust_input(cratefile: &str, externs: Externs, matches: &getopts::Matches) -> Output {
let mut default_passes = !matches.opt_present("no-defaults");
let mut passes = matches.opt_strs("passes");
let mut plugins = matches.opt_strs("plugins");
Expand Down
4 changes: 2 additions & 2 deletions markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use std::io::prelude::*;
use std::io;
use std::path::{PathBuf, Path};

use core;
use getopts;
use testing;
use rustc::session::search_paths::SearchPaths;
use rustc::session::config::Externs;

use externalfiles::ExternalHtml;

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

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

Expand Down
20 changes: 9 additions & 11 deletions test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ use rustc_lint;
use rustc::dep_graph::DepGraph;
use rustc::hir::map as hir_map;
use rustc::session::{self, config};
use rustc::session::config::{get_unstable_features_setting, OutputType};
use rustc::session::config::{get_unstable_features_setting, OutputType,
OutputTypes, Externs};
use rustc::session::search_paths::{SearchPaths, PathKind};
use rustc_back::dynamic_lib::DynamicLibrary;
use rustc_back::tempdir::TempDir;
Expand Down Expand Up @@ -55,7 +56,7 @@ pub struct TestOptions {
pub fn run(input: &str,
cfgs: Vec<String>,
libs: SearchPaths,
externs: core::Externs,
externs: Externs,
mut test_args: Vec<String>,
crate_name: Option<String>)
-> isize {
Expand Down Expand Up @@ -89,8 +90,7 @@ pub fn run(input: &str,
cstore.clone());
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));

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

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

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

if no_run {
Expand Down Expand Up @@ -396,7 +394,7 @@ pub struct Collector {
names: Vec<String>,
cfgs: Vec<String>,
libs: SearchPaths,
externs: core::Externs,
externs: Externs,
cnt: usize,
use_headers: bool,
current_header: Option<String>,
Expand All @@ -405,7 +403,7 @@ pub struct Collector {
}

impl Collector {
pub fn new(cratename: String, cfgs: Vec<String>, libs: SearchPaths, externs: core::Externs,
pub fn new(cratename: String, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
use_headers: bool, opts: TestOptions) -> Collector {
Collector {
tests: Vec::new(),
Expand Down

0 comments on commit 0df53cf

Please sign in to comment.