Skip to content

Commit a1f2dce

Browse files
committed
Move edition outside the hygiene lock and avoid accessing it
1 parent 50a0def commit a1f2dce

39 files changed

+155
-139
lines changed

src/librustc/session/config.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1853,7 +1853,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
18531853

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

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

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

2792-
syntax::with_globals(|| {
2792+
syntax::with_default_globals(|| {
27932793
let matches = optgroups().parse(&["-Adead_code".to_string()]).unwrap();
27942794
let registry = errors::registry::Registry::new(&[]);
27952795
let (sessopts, _) = build_session_options_and_crate_config(&matches);

src/librustc_allocator/expand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use syntax::{
1414
base::{ExtCtxt, Resolver},
1515
build::AstBuilder,
1616
expand::ExpansionConfig,
17-
hygiene::{self, Mark, SyntaxContext},
17+
hygiene::{Mark, SyntaxContext},
1818
},
1919
mut_visit::{self, MutVisitor},
2020
parse::ParseSess,
@@ -96,7 +96,7 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> {
9696
].into()),
9797
allow_internal_unsafe: false,
9898
local_inner_macros: false,
99-
edition: hygiene::default_edition(),
99+
edition: self.sess.edition,
100100
});
101101

102102
// Tie the span to the macro expansion info we just created

src/librustc_interface/interface.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use std::result;
1818
use std::sync::{Arc, Mutex};
1919
use syntax;
2020
use syntax::source_map::{FileLoader, SourceMap};
21+
use syntax_pos::edition;
2122

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

@@ -135,6 +136,7 @@ where
135136
{
136137
let stderr = config.stderr.take();
137138
util::spawn_thread_pool(
139+
config.opts.edition,
138140
config.opts.debugging_opts.threads,
139141
&stderr,
140142
|| run_compiler_in_existing_thread_pool(config, f),
@@ -146,5 +148,5 @@ where
146148
F: FnOnce() -> R + Send,
147149
R: Send,
148150
{
149-
util::spawn_thread_pool(None, &None, f)
151+
util::spawn_thread_pool(edition::DEFAULT_EDITION, None, &None, f)
150152
}

src/librustc_interface/passes.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use syntax::util::node_count::NodeCounter;
4848
use syntax::util::lev_distance::find_best_match_for_name;
4949
use syntax::symbol::Symbol;
5050
use syntax::feature_gate::AttributeType;
51-
use syntax_pos::{FileName, hygiene};
51+
use syntax_pos::{FileName, edition::Edition, hygiene};
5252
use syntax_ext;
5353

5454
use serialize::json;
@@ -70,8 +70,6 @@ use std::ops::Generator;
7070
pub fn parse<'a>(sess: &'a Session, input: &Input) -> PResult<'a, ast::Crate> {
7171
sess.diagnostic()
7272
.set_continue_after_error(sess.opts.debugging_opts.continue_parse_after_error);
73-
hygiene::set_default_edition(sess.edition());
74-
7573
sess.profiler(|p| p.start_activity("parsing"));
7674
let krate = time(sess, "parsing", || match *input {
7775
Input::File(ref file) => parse::parse_crate_from_file(file, &sess.parse_sess),
@@ -375,7 +373,7 @@ fn configure_and_expand_inner<'a>(
375373
crate_loader,
376374
&resolver_arenas,
377375
);
378-
syntax_ext::register_builtins(&mut resolver, plugin_info.syntax_exts);
376+
syntax_ext::register_builtins(&mut resolver, plugin_info.syntax_exts, sess.edition());
379377

380378
// Expand all macros
381379
sess.profiler(|p| p.start_activity("macro expansion"));

src/librustc_interface/util.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use syntax::util::lev_distance::find_best_match_for_name;
3737
use syntax::source_map::{FileLoader, RealFileLoader, SourceMap};
3838
use syntax::symbol::{Symbol, sym};
3939
use syntax::{self, ast, attr};
40+
use syntax_pos::edition::Edition;
4041
#[cfg(not(parallel_compiler))]
4142
use std::{thread, panic};
4243

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

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

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

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

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

216-
syntax::with_globals(|| {
219+
syntax::with_globals(edition, || {
217220
syntax::GLOBALS.with(|syntax_globals| {
218221
syntax_pos::GLOBALS.with(|syntax_pos_globals| {
219222
// The main handler runs for each Rayon worker thread and sets up

src/librustc_metadata/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use syntax::ast;
3434
use syntax::attr;
3535
use syntax::source_map::Spanned;
3636
use syntax::symbol::{keywords, sym};
37-
use syntax_pos::{self, hygiene, FileName, SourceFile, Span};
37+
use syntax_pos::{self, FileName, SourceFile, Span};
3838
use log::{debug, trace};
3939

4040
use rustc::hir::{self, PatKind};
@@ -480,7 +480,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
480480
hash: tcx.crate_hash(LOCAL_CRATE),
481481
disambiguator: tcx.sess.local_crate_disambiguator(),
482482
panic_strategy: tcx.sess.panic_strategy(),
483-
edition: hygiene::default_edition(),
483+
edition: tcx.sess.edition(),
484484
has_global_allocator: has_global_allocator,
485485
has_panic_handler: has_panic_handler,
486486
has_default_lib_allocator: has_default_lib_allocator,

src/librustc_plugin/registry.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc::util::nodemap::FxHashMap;
66

77
use syntax::ext::base::{SyntaxExtension, NamedSyntaxExtension, NormalTT, IdentTT};
88
use syntax::ext::base::MacroExpanderFn;
9-
use syntax::ext::hygiene;
109
use syntax::symbol::{Symbol, sym};
1110
use syntax::ast;
1211
use syntax::feature_gate::AttributeType;
@@ -130,7 +129,7 @@ impl<'a> Registry<'a> {
130129
allow_internal_unsafe: false,
131130
local_inner_macros: false,
132131
unstable_feature: None,
133-
edition: hygiene::default_edition(),
132+
edition: self.sess.edition(),
134133
});
135134
}
136135

src/librustc_resolve/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use syntax::errors::DiagnosticBuilder;
1717
use syntax::ext::base::{self, Determinacy};
1818
use syntax::ext::base::{MacroKind, SyntaxExtension};
1919
use syntax::ext::expand::{AstFragment, Invocation, InvocationKind};
20-
use syntax::ext::hygiene::{self, Mark};
20+
use syntax::ext::hygiene::Mark;
2121
use syntax::ext::tt::macro_rules;
2222
use syntax::feature_gate::{
2323
feature_err, is_builtin_attr_name, AttributeGate, GateIssue, Stability, BUILTIN_ATTRIBUTES,
@@ -1100,7 +1100,7 @@ impl<'a> Resolver<'a> {
11001100
let def_id = self.definitions.local_def_id(item.id);
11011101
let ext = Lrc::new(macro_rules::compile(&self.session.parse_sess,
11021102
&self.session.features_untracked(),
1103-
item, hygiene::default_edition()));
1103+
item, self.session.edition()));
11041104
self.macro_map.insert(def_id, ext);
11051105

11061106
let def = match item.node { ast::ItemKind::MacroDef(ref def) => def, _ => unreachable!() };

src/librustdoc/clean/cfg.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ mod test {
418418
use syntax::attr;
419419
use syntax::source_map::dummy_spanned;
420420
use syntax::symbol::Symbol;
421-
use syntax::with_globals;
421+
use syntax::with_default_globals;
422422

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

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

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

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

589589
#[test]
590590
fn test_parse_ok() {
591-
with_globals(|| {
591+
with_default_globals(|| {
592592
let mi = dummy_meta_item_word("all");
593593
assert_eq!(Cfg::parse(&mi), Ok(word_cfg("all")));
594594

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

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

662662
#[test]
663663
fn test_render_short_html() {
664-
with_globals(|| {
664+
with_default_globals(|| {
665665
assert_eq!(
666666
word_cfg("unix").render_short_html(),
667667
"Unix"
@@ -741,7 +741,7 @@ mod test {
741741

742742
#[test]
743743
fn test_render_long_html() {
744-
with_globals(|| {
744+
with_default_globals(|| {
745745
assert_eq!(
746746
word_cfg("unix").render_long_html(),
747747
"This is supported on <strong>Unix</strong> only."

src/librustdoc/test.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc::session::config::{OutputType, OutputTypes, Externs, CodegenOptions};
88
use rustc::session::search_paths::SearchPath;
99
use rustc::util::common::ErrorReported;
1010
use syntax::ast;
11+
use syntax::with_globals;
1112
use syntax::source_map::SourceMap;
1213
use syntax::edition::Edition;
1314
use syntax::feature_gate::UnstableFeatures;
@@ -386,13 +387,11 @@ pub fn make_test(s: &str,
386387

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

394-
syntax::ext::hygiene::set_default_edition(edition);
395-
396395
let filename = FileName::anon_source_code(s);
397396
let source = crates + &everything_else;
398397

src/libsyntax/ext/base.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::attr::HasAttrs;
55
use crate::source_map::{SourceMap, Spanned, respan};
66
use crate::edition::Edition;
77
use crate::ext::expand::{self, AstFragment, Invocation};
8-
use crate::ext::hygiene::{self, Mark, SyntaxContext, Transparency};
8+
use crate::ext::hygiene::{Mark, SyntaxContext, Transparency};
99
use crate::mut_visit::{self, MutVisitor};
1010
use crate::parse::{self, parser, DirectoryOwnership};
1111
use crate::parse::token;
@@ -713,7 +713,7 @@ impl SyntaxExtension {
713713
}
714714
}
715715

716-
pub fn edition(&self) -> Edition {
716+
pub fn edition(&self, default_edition: Edition) -> Edition {
717717
match *self {
718718
SyntaxExtension::NormalTT { edition, .. } |
719719
SyntaxExtension::DeclMacro { edition, .. } |
@@ -725,7 +725,7 @@ impl SyntaxExtension {
725725
SyntaxExtension::IdentTT { .. } |
726726
SyntaxExtension::MultiDecorator(..) |
727727
SyntaxExtension::MultiModifier(..) |
728-
SyntaxExtension::BuiltinDerive(..) => hygiene::default_edition(),
728+
SyntaxExtension::BuiltinDerive(..) => default_edition,
729729
}
730730
}
731731
}
@@ -734,6 +734,7 @@ pub type NamedSyntaxExtension = (Name, SyntaxExtension);
734734

735735
pub trait Resolver {
736736
fn next_node_id(&mut self) -> ast::NodeId;
737+
737738
fn get_module_scope(&mut self, id: ast::NodeId) -> Mark;
738739

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

769770
impl Resolver for DummyResolver {
770771
fn next_node_id(&mut self) -> ast::NodeId { ast::DUMMY_NODE_ID }
772+
771773
fn get_module_scope(&mut self, _id: ast::NodeId) -> Mark { Mark::root() }
772774

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

src/libsyntax/ext/derive.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::attr::HasAttrs;
22
use crate::ast;
3-
use crate::source_map::{hygiene, ExpnInfo, ExpnFormat};
3+
use crate::source_map::{ExpnInfo, ExpnFormat};
44
use crate::ext::base::ExtCtxt;
55
use crate::ext::build::AstBuilder;
66
use crate::parse::parser::PathStyle;
@@ -64,7 +64,7 @@ pub fn add_derived_markers<T>(cx: &mut ExtCtxt<'_>, span: Span, traits: &[ast::P
6464
].into()),
6565
allow_internal_unsafe: false,
6666
local_inner_macros: false,
67-
edition: hygiene::default_edition(),
67+
edition: cx.parse_sess.edition,
6868
});
6969

7070
let span = span.with_ctxt(cx.backtrace());

0 commit comments

Comments
 (0)