Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
@@ -1853,7 +1853,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {

// Convert strings provided as --cfg [cfgspec] into a crate_cfg
pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String>)> {
syntax::with_globals(move || {
syntax::with_default_globals(move || {
let cfg = cfgspecs.into_iter().map(|s| {
let sess = parse::ParseSess::new(FilePathMapping::empty());
let filename = FileName::cfg_spec_source_code(&s);
@@ -2735,7 +2735,7 @@ mod tests {
// When the user supplies --test we should implicitly supply --cfg test
#[test]
fn test_switch_implies_cfg_test() {
syntax::with_globals(|| {
syntax::with_default_globals(|| {
let matches = &match optgroups().parse(&["--test".to_string()]) {
Ok(m) => m,
Err(f) => panic!("test_switch_implies_cfg_test: {}", f),
@@ -2753,7 +2753,7 @@ mod tests {
#[test]
fn test_switch_implies_cfg_test_unless_cfg_test() {
use syntax::symbol::sym;
syntax::with_globals(|| {
syntax::with_default_globals(|| {
let matches = &match optgroups().parse(&["--test".to_string(),
"--cfg=test".to_string()]) {
Ok(m) => m,
@@ -2771,15 +2771,15 @@ mod tests {

#[test]
fn test_can_print_warnings() {
syntax::with_globals(|| {
syntax::with_default_globals(|| {
let matches = optgroups().parse(&["-Awarnings".to_string()]).unwrap();
let registry = errors::registry::Registry::new(&[]);
let (sessopts, _) = build_session_options_and_crate_config(&matches);
let sess = build_session(sessopts, None, registry);
assert!(!sess.diagnostic().flags.can_emit_warnings);
});

syntax::with_globals(|| {
syntax::with_default_globals(|| {
let matches = optgroups()
.parse(&["-Awarnings".to_string(), "-Dwarnings".to_string()])
.unwrap();
@@ -2789,7 +2789,7 @@ mod tests {
assert!(sess.diagnostic().flags.can_emit_warnings);
});

syntax::with_globals(|| {
syntax::with_default_globals(|| {
let matches = optgroups().parse(&["-Adead_code".to_string()]).unwrap();
let registry = errors::registry::Registry::new(&[]);
let (sessopts, _) = build_session_options_and_crate_config(&matches);
4 changes: 2 additions & 2 deletions src/librustc_allocator/expand.rs
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ use syntax::{
base::{ExtCtxt, Resolver},
build::AstBuilder,
expand::ExpansionConfig,
hygiene::{self, Mark, SyntaxContext},
hygiene::{Mark, SyntaxContext},
},
mut_visit::{self, MutVisitor},
parse::ParseSess,
@@ -96,7 +96,7 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> {
].into()),
allow_internal_unsafe: false,
local_inner_macros: false,
edition: hygiene::default_edition(),
edition: self.sess.edition,
});

// Tie the span to the macro expansion info we just created
6 changes: 4 additions & 2 deletions src/librustc_interface/interface.rs
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ use std::result;
use std::sync::{Arc, Mutex};
use syntax;
use syntax::source_map::{FileLoader, SourceMap};
use syntax_pos::edition;

pub type Result<T> = result::Result<T, ErrorReported>;

@@ -135,16 +136,17 @@ where
{
let stderr = config.stderr.take();
util::spawn_thread_pool(
config.opts.edition,
config.opts.debugging_opts.threads,
&stderr,
|| run_compiler_in_existing_thread_pool(config, f),
)
}

pub fn default_thread_pool<F, R>(f: F) -> R
pub fn default_thread_pool<F, R>(edition: edition::Edition, f: F) -> R
where
F: FnOnce() -> R + Send,
R: Send,
{
util::spawn_thread_pool(None, &None, f)
util::spawn_thread_pool(edition, None, &None, f)
}
6 changes: 2 additions & 4 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ use syntax::util::node_count::NodeCounter;
use syntax::util::lev_distance::find_best_match_for_name;
use syntax::symbol::Symbol;
use syntax::feature_gate::AttributeType;
use syntax_pos::{FileName, hygiene};
use syntax_pos::{FileName, edition::Edition, hygiene};
use syntax_ext;

use serialize::json;
@@ -70,8 +70,6 @@ use std::ops::Generator;
pub fn parse<'a>(sess: &'a Session, input: &Input) -> PResult<'a, ast::Crate> {
sess.diagnostic()
.set_continue_after_error(sess.opts.debugging_opts.continue_parse_after_error);
hygiene::set_default_edition(sess.edition());

sess.profiler(|p| p.start_activity("parsing"));
let krate = time(sess, "parsing", || match *input {
Input::File(ref file) => parse::parse_crate_from_file(file, &sess.parse_sess),
@@ -375,7 +373,7 @@ fn configure_and_expand_inner<'a>(
crate_loader,
&resolver_arenas,
);
syntax_ext::register_builtins(&mut resolver, plugin_info.syntax_exts);
syntax_ext::register_builtins(&mut resolver, plugin_info.syntax_exts, sess.edition());

// Expand all macros
sess.profiler(|p| p.start_activity("macro expansion"));
7 changes: 5 additions & 2 deletions src/librustc_interface/util.rs
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@ use syntax::util::lev_distance::find_best_match_for_name;
use syntax::source_map::{FileLoader, RealFileLoader, SourceMap};
use syntax::symbol::{Symbol, sym};
use syntax::{self, ast, attr};
use syntax_pos::edition::Edition;
#[cfg(not(parallel_compiler))]
use std::{thread, panic};

@@ -167,6 +168,7 @@ pub fn scoped_thread<F: FnOnce() -> R + Send, R: Send>(cfg: thread::Builder, f:

#[cfg(not(parallel_compiler))]
pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(
edition: Edition,
_threads: Option<usize>,
stderr: &Option<Arc<Mutex<Vec<u8>>>>,
f: F,
@@ -178,7 +180,7 @@ pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(
}

scoped_thread(cfg, || {
syntax::with_globals( || {
syntax::with_globals(edition, || {
ty::tls::GCX_PTR.set(&Lock::new(0), || {
if let Some(stderr) = stderr {
io::set_panic(Some(box Sink(stderr.clone())));
@@ -191,6 +193,7 @@ pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(

#[cfg(parallel_compiler)]
pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(
edition: Edition,
threads: Option<usize>,
stderr: &Option<Arc<Mutex<Vec<u8>>>>,
f: F,
@@ -213,7 +216,7 @@ pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(

let with_pool = move |pool: &ThreadPool| pool.install(move || f());

syntax::with_globals(|| {
syntax::with_globals(edition, || {
syntax::GLOBALS.with(|syntax_globals| {
syntax_pos::GLOBALS.with(|syntax_pos_globals| {
// The main handler runs for each Rayon worker thread and sets up
4 changes: 2 additions & 2 deletions src/librustc_metadata/encoder.rs
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ use syntax::ast;
use syntax::attr;
use syntax::source_map::Spanned;
use syntax::symbol::{keywords, sym};
use syntax_pos::{self, hygiene, FileName, SourceFile, Span};
use syntax_pos::{self, FileName, SourceFile, Span};
use log::{debug, trace};

use rustc::hir::{self, PatKind};
@@ -480,7 +480,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
hash: tcx.crate_hash(LOCAL_CRATE),
disambiguator: tcx.sess.local_crate_disambiguator(),
panic_strategy: tcx.sess.panic_strategy(),
edition: hygiene::default_edition(),
edition: tcx.sess.edition(),
has_global_allocator: has_global_allocator,
has_panic_handler: has_panic_handler,
has_default_lib_allocator: has_default_lib_allocator,
3 changes: 1 addition & 2 deletions src/librustc_plugin/registry.rs
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ use rustc::util::nodemap::FxHashMap;

use syntax::ext::base::{SyntaxExtension, NamedSyntaxExtension, NormalTT, IdentTT};
use syntax::ext::base::MacroExpanderFn;
use syntax::ext::hygiene;
use syntax::symbol::{Symbol, sym};
use syntax::ast;
use syntax::feature_gate::AttributeType;
@@ -130,7 +129,7 @@ impl<'a> Registry<'a> {
allow_internal_unsafe: false,
local_inner_macros: false,
unstable_feature: None,
edition: hygiene::default_edition(),
edition: self.sess.edition(),
});
}

4 changes: 2 additions & 2 deletions src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ use syntax::errors::DiagnosticBuilder;
use syntax::ext::base::{self, Determinacy};
use syntax::ext::base::{MacroKind, SyntaxExtension};
use syntax::ext::expand::{AstFragment, Invocation, InvocationKind};
use syntax::ext::hygiene::{self, Mark};
use syntax::ext::hygiene::Mark;
use syntax::ext::tt::macro_rules;
use syntax::feature_gate::{
feature_err, is_builtin_attr_name, AttributeGate, GateIssue, Stability, BUILTIN_ATTRIBUTES,
@@ -1100,7 +1100,7 @@ impl<'a> Resolver<'a> {
let def_id = self.definitions.local_def_id(item.id);
let ext = Lrc::new(macro_rules::compile(&self.session.parse_sess,
&self.session.features_untracked(),
item, hygiene::default_edition()));
item, self.session.edition()));
self.macro_map.insert(def_id, ext);

let def = match item.node { ast::ItemKind::MacroDef(ref def) => def, _ => unreachable!() };
16 changes: 8 additions & 8 deletions src/librustdoc/clean/cfg.rs
Original file line number Diff line number Diff line change
@@ -418,7 +418,7 @@ mod test {
use syntax::attr;
use syntax::source_map::dummy_spanned;
use syntax::symbol::Symbol;
use syntax::with_globals;
use syntax::with_default_globals;

fn word_cfg(s: &str) -> Cfg {
Cfg::Cfg(Symbol::intern(s), None)
@@ -466,7 +466,7 @@ mod test {

#[test]
fn test_cfg_not() {
with_globals(|| {
with_default_globals(|| {
assert_eq!(!Cfg::False, Cfg::True);
assert_eq!(!Cfg::True, Cfg::False);
assert_eq!(!word_cfg("test"), Cfg::Not(Box::new(word_cfg("test"))));
@@ -484,7 +484,7 @@ mod test {

#[test]
fn test_cfg_and() {
with_globals(|| {
with_default_globals(|| {
let mut x = Cfg::False;
x &= Cfg::True;
assert_eq!(x, Cfg::False);
@@ -536,7 +536,7 @@ mod test {

#[test]
fn test_cfg_or() {
with_globals(|| {
with_default_globals(|| {
let mut x = Cfg::True;
x |= Cfg::False;
assert_eq!(x, Cfg::True);
@@ -588,7 +588,7 @@ mod test {

#[test]
fn test_parse_ok() {
with_globals(|| {
with_default_globals(|| {
let mi = dummy_meta_item_word("all");
assert_eq!(Cfg::parse(&mi), Ok(word_cfg("all")));

@@ -622,7 +622,7 @@ mod test {

#[test]
fn test_parse_err() {
with_globals(|| {
with_default_globals(|| {
let mi = attr::mk_name_value_item(
DUMMY_SP,
Ident::from_str("foo"),
@@ -661,7 +661,7 @@ mod test {

#[test]
fn test_render_short_html() {
with_globals(|| {
with_default_globals(|| {
assert_eq!(
word_cfg("unix").render_short_html(),
"Unix"
@@ -741,7 +741,7 @@ mod test {

#[test]
fn test_render_long_html() {
with_globals(|| {
with_default_globals(|| {
assert_eq!(
word_cfg("unix").render_long_html(),
"This is supported on <strong>Unix</strong> only."
9 changes: 6 additions & 3 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
@@ -94,9 +94,7 @@ pub fn main() {
rustc_driver::set_sigpipe_handler();
env_logger::init();
let res = std::thread::Builder::new().stack_size(thread_stack_size).spawn(move || {
rustc_interface::interface::default_thread_pool(move || {
get_args().map(|args| main_args(&args)).unwrap_or(1)
})
get_args().map(|args| main_args(&args)).unwrap_or(1)
}).unwrap().join().unwrap_or(rustc_driver::EXIT_FAILURE);
process::exit(res);
}
@@ -382,7 +380,12 @@ fn main_args(args: &[String]) -> i32 {
Ok(opts) => opts,
Err(code) => return code,
};
rustc_interface::interface::default_thread_pool(options.edition, move || {
main_options(options)
})
}

fn main_options(options: config::Options) -> i32 {
let diag = core::new_handler(options.error_format,
None,
options.debugging_options.treat_err_as_bug,
5 changes: 2 additions & 3 deletions src/librustdoc/test.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ use rustc::session::config::{OutputType, OutputTypes, Externs, CodegenOptions};
use rustc::session::search_paths::SearchPath;
use rustc::util::common::ErrorReported;
use syntax::ast;
use syntax::with_globals;
use syntax::source_map::SourceMap;
use syntax::edition::Edition;
use syntax::feature_gate::UnstableFeatures;
@@ -386,13 +387,11 @@ pub fn make_test(s: &str,

// Uses libsyntax to parse the doctest and find if there's a main fn and the extern
// crate already is included.
let (already_has_main, already_has_extern_crate, found_macro) = crate::syntax::with_globals(|| {
let (already_has_main, already_has_extern_crate, found_macro) = with_globals(edition, || {
use crate::syntax::{parse::{self, ParseSess}, source_map::FilePathMapping};
use errors::emitter::EmitterWriter;
use errors::Handler;

syntax::ext::hygiene::set_default_edition(edition);

let filename = FileName::anon_source_code(s);
let source = crates + &everything_else;

8 changes: 5 additions & 3 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ use crate::attr::HasAttrs;
use crate::source_map::{SourceMap, Spanned, respan};
use crate::edition::Edition;
use crate::ext::expand::{self, AstFragment, Invocation};
use crate::ext::hygiene::{self, Mark, SyntaxContext, Transparency};
use crate::ext::hygiene::{Mark, SyntaxContext, Transparency};
use crate::mut_visit::{self, MutVisitor};
use crate::parse::{self, parser, DirectoryOwnership};
use crate::parse::token;
@@ -713,7 +713,7 @@ impl SyntaxExtension {
}
}

pub fn edition(&self) -> Edition {
pub fn edition(&self, default_edition: Edition) -> Edition {
match *self {
SyntaxExtension::NormalTT { edition, .. } |
SyntaxExtension::DeclMacro { edition, .. } |
@@ -725,7 +725,7 @@ impl SyntaxExtension {
SyntaxExtension::IdentTT { .. } |
SyntaxExtension::MultiDecorator(..) |
SyntaxExtension::MultiModifier(..) |
SyntaxExtension::BuiltinDerive(..) => hygiene::default_edition(),
SyntaxExtension::BuiltinDerive(..) => default_edition,
}
}
}
@@ -734,6 +734,7 @@ pub type NamedSyntaxExtension = (Name, SyntaxExtension);

pub trait Resolver {
fn next_node_id(&mut self) -> ast::NodeId;

fn get_module_scope(&mut self, id: ast::NodeId) -> Mark;

fn resolve_dollar_crates(&mut self, fragment: &AstFragment);
@@ -768,6 +769,7 @@ pub struct DummyResolver;

impl Resolver for DummyResolver {
fn next_node_id(&mut self) -> ast::NodeId { ast::DUMMY_NODE_ID }

fn get_module_scope(&mut self, _id: ast::NodeId) -> Mark { Mark::root() }

fn resolve_dollar_crates(&mut self, _fragment: &AstFragment) {}
Loading