Skip to content

Commit 6062e7e

Browse files
authored
Auto merge of #37431 - jseyfried:refactor_crate_config, r=eddyb
Move `CrateConfig` from `Crate` to `ParseSess` This is a syntax-[breaking-change]. Most breakage can be fixed by removing a `CrateConfig` argument. r? @eddyb
2 parents aef5ca5 + cbd2475 commit 6062e7e

File tree

39 files changed

+130
-298
lines changed

39 files changed

+130
-298
lines changed

src/libproc_macro/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,8 @@ impl FromStr for TokenStream {
136136
fn from_str(src: &str) -> Result<TokenStream, LexError> {
137137
__internal::with_parse_sess(|sess| {
138138
let src = src.to_string();
139-
let cfg = Vec::new();
140139
let name = "<proc-macro source code>".to_string();
141-
let mut parser = parse::new_parser_from_source_str(sess, cfg, name,
142-
src);
140+
let mut parser = parse::new_parser_from_source_str(sess, name, src);
143141
let mut ret = TokenStream { inner: Vec::new() };
144142
loop {
145143
match parser.parse_item() {

src/librustc/hir/lowering.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ impl<'a> LoweringContext<'a> {
124124
hir::Crate {
125125
module: self.lower_mod(&c.module),
126126
attrs: self.lower_attrs(&c.attrs),
127-
config: c.config.clone().into(),
128127
span: c.span,
129128
exported_macros: c.exported_macros.iter().map(|m| self.lower_macro_def(m)).collect(),
130129
items: items,

src/librustc/hir/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ pub type CrateConfig = HirVec<P<MetaItem>>;
413413
pub struct Crate {
414414
pub module: Mod,
415415
pub attrs: HirVec<Attribute>,
416-
pub config: CrateConfig,
417416
pub span: Span,
418417
pub exported_macros: HirVec<MacroDef>,
419418

src/librustc/session/config.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,10 +1237,9 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
12371237
pub fn parse_cfgspecs(cfgspecs: Vec<String> ) -> ast::CrateConfig {
12381238
cfgspecs.into_iter().map(|s| {
12391239
let sess = parse::ParseSess::new();
1240-
let mut parser = parse::new_parser_from_source_str(&sess,
1241-
Vec::new(),
1242-
"cfgspec".to_string(),
1243-
s.to_string());
1240+
let mut parser =
1241+
parse::new_parser_from_source_str(&sess, "cfgspec".to_string(), s.to_string());
1242+
12441243
let meta_item = panictry!(parser.parse_meta_item());
12451244

12461245
if !parser.reader.is_eof() {

src/librustc_driver/driver.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ pub struct Resolutions {
6767

6868
pub fn compile_input(sess: &Session,
6969
cstore: &CStore,
70-
cfg: ast::CrateConfig,
7170
input: &Input,
7271
outdir: &Option<PathBuf>,
7372
output: &Option<PathBuf>,
@@ -91,7 +90,7 @@ pub fn compile_input(sess: &Session,
9190
// large chunks of memory alive and we want to free them as soon as
9291
// possible to keep the peak memory usage low
9392
let (outputs, trans) = {
94-
let krate = match phase_1_parse_input(sess, cfg, input) {
93+
let krate = match phase_1_parse_input(sess, input) {
9594
Ok(krate) => krate,
9695
Err(mut parse_error) => {
9796
parse_error.emit();
@@ -482,23 +481,17 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> {
482481
}
483482
}
484483

485-
pub fn phase_1_parse_input<'a>(sess: &'a Session,
486-
cfg: ast::CrateConfig,
487-
input: &Input)
488-
-> PResult<'a, ast::Crate> {
484+
pub fn phase_1_parse_input<'a>(sess: &'a Session, input: &Input) -> PResult<'a, ast::Crate> {
489485
let continue_after_error = sess.opts.debugging_opts.continue_parse_after_error;
490486
sess.diagnostic().set_continue_after_error(continue_after_error);
491487

492488
let krate = time(sess.time_passes(), "parsing", || {
493489
match *input {
494490
Input::File(ref file) => {
495-
parse::parse_crate_from_file(file, cfg.clone(), &sess.parse_sess)
491+
parse::parse_crate_from_file(file, &sess.parse_sess)
496492
}
497493
Input::Str { ref input, ref name } => {
498-
parse::parse_crate_from_source_str(name.clone(),
499-
input.clone(),
500-
cfg.clone(),
501-
&sess.parse_sess)
494+
parse::parse_crate_from_source_str(name.clone(), input.clone(), &sess.parse_sess)
502495
}
503496
}
504497
})?;
@@ -636,7 +629,7 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
636629
// its contents but the results of name resolution on those contents. Hopefully we'll push
637630
// this back at some point.
638631
let _ignore = sess.dep_graph.in_ignore();
639-
let mut crate_loader = CrateLoader::new(sess, &cstore, crate_name, krate.config.clone());
632+
let mut crate_loader = CrateLoader::new(sess, &cstore, crate_name);
640633
crate_loader.preprocess(&krate);
641634
let resolver_arenas = Resolver::arenas();
642635
let mut resolver =
@@ -677,7 +670,7 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
677670
should_test: sess.opts.test,
678671
..syntax::ext::expand::ExpansionConfig::default(crate_name.to_string())
679672
};
680-
let mut ecx = ExtCtxt::new(&sess.parse_sess, krate.config.clone(), cfg, &mut resolver);
673+
let mut ecx = ExtCtxt::new(&sess.parse_sess, cfg, &mut resolver);
681674
let err_count = ecx.parse_sess.span_diagnostic.err_count();
682675

683676
let krate = ecx.monotonic_expander().expand_crate(krate);

src/librustc_driver/lib.rs

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -205,24 +205,20 @@ pub fn run_compiler<'a>(args: &[String],
205205

206206
let loader = file_loader.unwrap_or(box RealFileLoader);
207207
let codemap = Rc::new(CodeMap::with_file_loader(loader));
208-
let sess = session::build_session_with_codemap(sopts,
209-
&dep_graph,
210-
input_file_path,
211-
descriptions,
212-
cstore.clone(),
213-
codemap,
214-
emitter_dest);
208+
let mut sess = session::build_session_with_codemap(
209+
sopts, &dep_graph, input_file_path, descriptions, cstore.clone(), codemap, emitter_dest,
210+
);
215211
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
212+
216213
let mut cfg = config::build_configuration(&sess, cfg);
217214
target_features::add_configuration(&mut cfg, &sess);
215+
sess.parse_sess.config = cfg;
218216

219-
do_or_return!(callbacks.late_callback(&matches, &sess, &cfg, &input, &odir, &ofile),
220-
Some(sess));
217+
do_or_return!(callbacks.late_callback(&matches, &sess, &input, &odir, &ofile), Some(sess));
221218

222219
let plugins = sess.opts.debugging_opts.extra_plugins.clone();
223220
let control = callbacks.build_controller(&sess, &matches);
224-
(driver::compile_input(&sess, &cstore, cfg, &input, &odir, &ofile,
225-
Some(plugins), &control),
221+
(driver::compile_input(&sess, &cstore, &input, &odir, &ofile, Some(plugins), &control),
226222
Some(sess))
227223
}
228224

@@ -310,7 +306,6 @@ pub trait CompilerCalls<'a> {
310306
fn late_callback(&mut self,
311307
_: &getopts::Matches,
312308
_: &Session,
313-
_: &ast::CrateConfig,
314309
_: &Input,
315310
_: &Option<PathBuf>,
316311
_: &Option<PathBuf>)
@@ -439,19 +434,18 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
439434
}
440435
let dep_graph = DepGraph::new(sopts.build_dep_graph());
441436
let cstore = Rc::new(CStore::new(&dep_graph));
442-
let sess = build_session(sopts.clone(),
437+
let mut sess = build_session(sopts.clone(),
443438
&dep_graph,
444439
None,
445440
descriptions.clone(),
446441
cstore.clone());
447442
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
448443
let mut cfg = config::build_configuration(&sess, cfg.clone());
449444
target_features::add_configuration(&mut cfg, &sess);
450-
let should_stop = RustcDefaultCalls::print_crate_info(&sess,
451-
&cfg,
452-
None,
453-
odir,
454-
ofile);
445+
sess.parse_sess.config = cfg;
446+
let should_stop =
447+
RustcDefaultCalls::print_crate_info(&sess, None, odir, ofile);
448+
455449
if should_stop == Compilation::Stop {
456450
return None;
457451
}
@@ -467,12 +461,11 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
467461
fn late_callback(&mut self,
468462
matches: &getopts::Matches,
469463
sess: &Session,
470-
cfg: &ast::CrateConfig,
471464
input: &Input,
472465
odir: &Option<PathBuf>,
473466
ofile: &Option<PathBuf>)
474467
-> Compilation {
475-
RustcDefaultCalls::print_crate_info(sess, cfg, Some(input), odir, ofile)
468+
RustcDefaultCalls::print_crate_info(sess, Some(input), odir, ofile)
476469
.and_then(|| RustcDefaultCalls::list_metadata(sess, matches, input))
477470
}
478471

@@ -593,7 +586,6 @@ impl RustcDefaultCalls {
593586

594587

595588
fn print_crate_info(sess: &Session,
596-
cfg: &ast::CrateConfig,
597589
input: Option<&Input>,
598590
odir: &Option<PathBuf>,
599591
ofile: &Option<PathBuf>)
@@ -649,8 +641,8 @@ impl RustcDefaultCalls {
649641
let allow_unstable_cfg = UnstableFeatures::from_environment()
650642
.is_nightly_build();
651643

652-
for cfg in cfg {
653-
if !allow_unstable_cfg && GatedCfg::gate(&*cfg).is_some() {
644+
for cfg in &sess.parse_sess.config {
645+
if !allow_unstable_cfg && GatedCfg::gate(cfg).is_some() {
654646
continue;
655647
}
656648

@@ -1036,13 +1028,10 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
10361028
fn parse_crate_attrs<'a>(sess: &'a Session, input: &Input) -> PResult<'a, Vec<ast::Attribute>> {
10371029
match *input {
10381030
Input::File(ref ifile) => {
1039-
parse::parse_crate_attrs_from_file(ifile, Vec::new(), &sess.parse_sess)
1031+
parse::parse_crate_attrs_from_file(ifile, &sess.parse_sess)
10401032
}
10411033
Input::Str { ref name, ref input } => {
1042-
parse::parse_crate_attrs_from_source_str(name.clone(),
1043-
input.clone(),
1044-
Vec::new(),
1045-
&sess.parse_sess)
1034+
parse::parse_crate_attrs_from_source_str(name.clone(), input.clone(), &sess.parse_sess)
10461035
}
10471036
}
10481037
}

src/librustc_driver/test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,11 @@ fn test_env<F>(source_string: &str,
106106
let sess = session::build_session_(options, &dep_graph, None, diagnostic_handler,
107107
Rc::new(CodeMap::new()), cstore.clone());
108108
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
109-
let krate_config = Vec::new();
110109
let input = config::Input::Str {
111110
name: driver::anon_src(),
112111
input: source_string.to_string(),
113112
};
114-
let krate = driver::phase_1_parse_input(&sess, krate_config, &input).unwrap();
113+
let krate = driver::phase_1_parse_input(&sess, &input).unwrap();
115114
let driver::ExpansionResult { defs, resolutions, mut hir_forest, .. } = {
116115
driver::phase_2_configure_and_expand(
117116
&sess, &cstore, krate, None, "test", None, MakeGlobMap::No, |_| Ok(()),

src/librustc_incremental/persist/dirty_clean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl<'a, 'tcx, 'm> DirtyCleanMetadataVisitor<'a, 'tcx, 'm> {
264264
/// flag called `foo`.
265265
fn check_config(tcx: TyCtxt, attr: &ast::Attribute) -> bool {
266266
debug!("check_config(attr={:?})", attr);
267-
let config = &tcx.map.krate().config;
267+
let config = &tcx.sess.parse_sess.config;
268268
debug!("check_config: config={:?}", config);
269269
for item in attr.meta_item_list().unwrap_or(&[]) {
270270
if item.check_name(CFG) {

src/librustc_metadata/creader.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ pub struct CrateLoader<'a> {
5252
next_crate_num: CrateNum,
5353
foreign_item_map: FnvHashMap<String, Vec<ast::NodeId>>,
5454
local_crate_name: String,
55-
local_crate_config: ast::CrateConfig,
5655
}
5756

5857
fn dump_crates(cstore: &CStore) {
@@ -144,18 +143,13 @@ enum LoadResult {
144143
}
145144

146145
impl<'a> CrateLoader<'a> {
147-
pub fn new(sess: &'a Session,
148-
cstore: &'a CStore,
149-
local_crate_name: &str,
150-
local_crate_config: ast::CrateConfig)
151-
-> Self {
146+
pub fn new(sess: &'a Session, cstore: &'a CStore, local_crate_name: &str) -> Self {
152147
CrateLoader {
153148
sess: sess,
154149
cstore: cstore,
155150
next_crate_num: cstore.next_crate_num(),
156151
foreign_item_map: FnvHashMap(),
157152
local_crate_name: local_crate_name.to_owned(),
158-
local_crate_config: local_crate_config,
159153
}
160154
}
161155

@@ -541,7 +535,6 @@ impl<'a> CrateLoader<'a> {
541535
// NB: Don't use parse::parse_tts_from_source_str because it parses with
542536
// quote_depth > 0.
543537
let mut p = parse::new_parser_from_source_str(&self.sess.parse_sess,
544-
self.local_crate_config.clone(),
545538
source_name.clone(),
546539
def.body);
547540
let lo = p.span.lo;

src/librustc_plugin/load.rs

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

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

9191
impl<'a> PluginLoader<'a> {
92-
fn new(sess: &'a Session,
93-
cstore: &'a CStore,
94-
crate_name: &str,
95-
crate_config: ast::CrateConfig)
96-
-> PluginLoader<'a> {
92+
fn new(sess: &'a Session, cstore: &'a CStore, crate_name: &str) -> Self {
9793
PluginLoader {
9894
sess: sess,
99-
reader: CrateLoader::new(sess, cstore, crate_name, crate_config),
95+
reader: CrateLoader::new(sess, cstore, crate_name),
10096
plugins: vec![],
10197
}
10298
}

0 commit comments

Comments
 (0)