Skip to content

Commit

Permalink
Remove the 'cfg' field from session::config::Options.
Browse files Browse the repository at this point in the history
The 'cfg' in the Options struct is only the commandline-specified
subset of the crate configuration and it's almost always wrong to
read that instead of the CrateConfig in HIR crate node.
  • Loading branch information
michaelwoerister committed Aug 11, 2016
1 parent d3578ab commit 65eb024
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 240 deletions.
226 changes: 16 additions & 210 deletions src/librustc/session/config.rs

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
38 changes: 25 additions & 13 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand All @@ -191,14 +191,15 @@ 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);

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),
},
Expand All @@ -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);
Expand Down Expand Up @@ -297,6 +299,7 @@ pub trait CompilerCalls<'a> {
fn early_callback(&mut self,
_: &getopts::Matches,
_: &config::Options,
_: &ast::CrateConfig,
_: &errors::registry::Registry,
_: ErrorOutputType)
-> Compilation {
Expand All @@ -309,6 +312,7 @@ pub trait CompilerCalls<'a> {
fn late_callback(&mut self,
_: &getopts::Matches,
_: &Session,
_: &ast::CrateConfig,
_: &Input,
_: &Option<PathBuf>,
_: &Option<PathBuf>)
Expand All @@ -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)
Expand Down Expand Up @@ -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) => {
Expand All @@ -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(),
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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;
}
Expand All @@ -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))
}

Expand Down Expand Up @@ -579,6 +593,7 @@ impl RustcDefaultCalls {


fn print_crate_info(sess: &Session,
cfg: &ast::CrateConfig,
input: Option<&Input>,
odir: &Option<PathBuf>,
ofile: &Option<PathBuf>)
Expand Down Expand Up @@ -631,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,
Expand Down
10 changes: 7 additions & 3 deletions src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub struct CrateReader<'a> {
next_crate_num: ast::CrateNum,
foreign_item_map: FnvHashMap<String, Vec<ast::NodeId>>,
local_crate_name: String,
local_crate_config: ast::CrateConfig,
}

impl<'a> visit::Visitor for LocalCrateReader<'a> {
Expand Down Expand Up @@ -152,13 +153,16 @@ enum LoadResult {
impl<'a> CrateReader<'a> {
pub fn new(sess: &'a Session,
cstore: &'a CStore,
local_crate_name: &str) -> CrateReader<'a> {
local_crate_name: &str,
local_crate_config: ast::CrateConfig)
-> CrateReader<'a> {
CrateReader {
sess: sess,
cstore: cstore,
next_crate_num: cstore.next_crate_num(),
foreign_item_map: FnvHashMap(),
local_crate_name: local_crate_name.to_owned(),
local_crate_config: local_crate_config,
}
}

Expand Down Expand Up @@ -561,7 +565,7 @@ impl<'a> CrateReader<'a> {
// NB: Don't use parse::parse_tts_from_source_str because it parses with
// quote_depth > 0.
let mut p = parse::new_parser_from_source_str(&self.sess.parse_sess,
self.sess.opts.cfg.clone(),
self.local_crate_config.clone(),
source_name.clone(),
body);
let lo = p.span.lo;
Expand Down Expand Up @@ -863,7 +867,7 @@ impl<'a> LocalCrateReader<'a> {
LocalCrateReader {
sess: sess,
cstore: cstore,
creader: CrateReader::new(sess, cstore, local_crate_name),
creader: CrateReader::new(sess, cstore, local_crate_name, krate.config.clone()),
krate: krate,
definitions: defs,
}
Expand Down
8 changes: 6 additions & 2 deletions src/librustc_metadata/macro_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ pub struct MacroLoader<'a> {
}

impl<'a> MacroLoader<'a> {
pub fn new(sess: &'a Session, cstore: &'a CStore, crate_name: &str) -> MacroLoader<'a> {
pub fn new(sess: &'a Session,
cstore: &'a CStore,
crate_name: &str,
crate_config: ast::CrateConfig)
-> MacroLoader<'a> {
MacroLoader {
sess: sess,
reader: CrateReader::new(sess, cstore, crate_name),
reader: CrateReader::new(sess, cstore, crate_name, crate_config),
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/librustc_plugin/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn load_plugins(sess: &Session,
krate: &ast::Crate,
crate_name: &str,
addl_plugins: Option<Vec<String>>) -> Vec<PluginRegistrar> {
let mut loader = PluginLoader::new(sess, cstore, crate_name);
let mut loader = PluginLoader::new(sess, cstore, crate_name, krate.config.clone());

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

impl<'a> PluginLoader<'a> {
fn new(sess: &'a Session, cstore: &'a CStore, crate_name: &str) -> PluginLoader<'a> {
fn new(sess: &'a Session,
cstore: &'a CStore,
crate_name: &str,
crate_config: ast::CrateConfig)
-> PluginLoader<'a> {
PluginLoader {
sess: sess,
reader: CrateReader::new(sess, cstore, crate_name),
reader: CrateReader::new(sess, cstore, crate_name, crate_config),
plugins: vec![],
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,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 @@ -138,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
6 changes: 2 additions & 4 deletions src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,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 @@ -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
4 changes: 2 additions & 2 deletions src/test/run-make/issue-19371/foo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn main() {

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

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

fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
let (sess, cstore) = basic_sess(sysroot);
let cfg = build_configuration(&sess);
let cfg = build_configuration(&sess, vec![]);
let control = CompileController::basic();

compile_input(&sess, &cstore,
Expand Down
4 changes: 4 additions & 0 deletions src/test/run-pass-fulldeps/compiler-calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extern crate rustc_errors as errors;
use rustc::session::Session;
use rustc::session::config::{self, Input};
use rustc_driver::{driver, CompilerCalls, Compilation};
use syntax::ast;

use std::path::PathBuf;

Expand All @@ -35,6 +36,7 @@ impl<'a> CompilerCalls<'a> for TestCalls {
fn early_callback(&mut self,
_: &getopts::Matches,
_: &config::Options,
_: &ast::CrateConfig,
_: &errors::registry::Registry,
_: config::ErrorOutputType)
-> Compilation {
Expand All @@ -45,6 +47,7 @@ impl<'a> CompilerCalls<'a> for TestCalls {
fn late_callback(&mut self,
_: &getopts::Matches,
_: &Session,
_: &ast::CrateConfig,
_: &Input,
_: &Option<PathBuf>,
_: &Option<PathBuf>)
Expand All @@ -62,6 +65,7 @@ impl<'a> CompilerCalls<'a> for TestCalls {
fn no_input(&mut self,
_: &getopts::Matches,
_: &config::Options,
_: &ast::CrateConfig,
_: &Option<PathBuf>,
_: &Option<PathBuf>,
_: &errors::registry::Registry)
Expand Down

0 comments on commit 65eb024

Please sign in to comment.