diff --git a/.gitignore b/.gitignore index 67e0dd8e795bb..d34ed114972c5 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,7 @@ __pycache__/ .project .settings/ .valgrindrc -.vscode/ +.vscode .favorites.json /*-*-*-*/ /*-*-*/ diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index b5e3c4cda0a66..4b49bde0af303 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1852,8 +1852,11 @@ pub fn rustc_optgroups() -> Vec { } // Convert strings provided as --cfg [cfgspec] into a crate_cfg -pub fn parse_cfgspecs(cfgspecs: Vec) -> FxHashSet<(String, Option)> { - syntax::with_globals(move || { +pub fn parse_cfgspecs( + driver_symbols: &[&str], + cfgspecs: Vec, +) -> FxHashSet<(String, Option)> { + syntax::with_globals(driver_symbols, move || { let cfg = cfgspecs.into_iter().map(|s| { let sess = parse::ParseSess::new(FilePathMapping::empty()); let filename = FileName::cfg_spec_source_code(&s); @@ -1918,6 +1921,7 @@ pub fn get_cmd_lint_options(matches: &getopts::Matches, } pub fn build_session_options_and_crate_config( + driver_symbols: &[&str], matches: &getopts::Matches, ) -> (Options, FxHashSet<(String, Option)>) { let color = match matches.opt_str("color").as_ref().map(|s| &s[..]) { @@ -2296,7 +2300,7 @@ pub fn build_session_options_and_crate_config( }) .collect(); - let cfg = parse_cfgspecs(matches.opt_strs("cfg")); + let cfg = parse_cfgspecs(driver_symbols, matches.opt_strs("cfg")); let test = matches.opt_present("test"); let is_unstable_enabled = nightly_options::is_unstable_enabled(matches); @@ -2735,13 +2739,13 @@ 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_globals(&[], || { let matches = &match optgroups().parse(&["--test".to_string()]) { Ok(m) => m, Err(f) => panic!("test_switch_implies_cfg_test: {}", f), }; let registry = errors::registry::Registry::new(&[]); - let (sessopts, cfg) = build_session_options_and_crate_config(matches); + let (sessopts, cfg) = build_session_options_and_crate_config(&[], matches); let sess = build_session(sessopts, None, registry); let cfg = build_configuration(&sess, to_crate_config(cfg)); assert!(cfg.contains(&(Symbol::intern("test"), None))); @@ -2753,14 +2757,14 @@ mod tests { #[test] fn test_switch_implies_cfg_test_unless_cfg_test() { use syntax::symbol::sym; - syntax::with_globals(|| { + syntax::with_globals(&[], || { let matches = &match optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]) { Ok(m) => m, Err(f) => panic!("test_switch_implies_cfg_test_unless_cfg_test: {}", f), }; let registry = errors::registry::Registry::new(&[]); - let (sessopts, cfg) = build_session_options_and_crate_config(matches); + let (sessopts, cfg) = build_session_options_and_crate_config(&[], matches); let sess = build_session(sessopts, None, registry); let cfg = build_configuration(&sess, to_crate_config(cfg)); let mut test_items = cfg.iter().filter(|&&(name, _)| name == sym::test); @@ -2771,28 +2775,28 @@ mod tests { #[test] fn test_can_print_warnings() { - syntax::with_globals(|| { + syntax::with_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 (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_globals(&[], || { let matches = optgroups() .parse(&["-Awarnings".to_string(), "-Dwarnings".to_string()]) .unwrap(); let registry = errors::registry::Registry::new(&[]); - let (sessopts, _) = build_session_options_and_crate_config(&matches); + 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_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); + let (sessopts, _) = build_session_options_and_crate_config(&[], &matches); let sess = build_session(sessopts, None, registry); assert!(sess.diagnostic().flags.can_emit_warnings); }); @@ -3390,7 +3394,7 @@ mod tests { let matches = optgroups() .parse(&["--edition=2018".to_string()]) .unwrap(); - let (sessopts, _) = build_session_options_and_crate_config(&matches); + let (sessopts, _) = build_session_options_and_crate_config(&[], &matches); assert!(sessopts.edition == Edition::Edition2018) } } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 02f8eee67b151..eb1f57995ee7e 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -122,6 +122,7 @@ impl Callbacks for DefaultCallbacks {} // The FileLoader provides a way to load files from sources other than the file system. pub fn run_compiler( args: &[String], + driver_symbols: &'static [&'static str], callbacks: &mut (dyn Callbacks + Send), file_loader: Option>, emitter: Option> @@ -135,7 +136,7 @@ pub fn run_compiler( install_panic_hook(); - let (sopts, cfg) = config::build_session_options_and_crate_config(&matches); + let (sopts, cfg) = config::build_session_options_and_crate_config(driver_symbols, &matches); let mut dummy_config = |sopts, cfg, diagnostic_output| { let mut config = interface::Config { @@ -149,6 +150,7 @@ pub fn run_compiler( diagnostic_output, stderr: None, crate_name: None, + driver_symbols, lint_caps: Default::default(), }; callbacks.config(&mut config); @@ -222,6 +224,7 @@ pub fn run_compiler( diagnostic_output, stderr: None, crate_name: None, + driver_symbols, lint_caps: Default::default(), }; @@ -1176,7 +1179,7 @@ pub fn main() { &format!("Argument {} is not valid Unicode: {:?}", i, arg)) })) .collect::>(); - run_compiler(&args, &mut DefaultCallbacks, None, None) + run_compiler(&args, &[], &mut DefaultCallbacks, None, None) }).and_then(|result| result); process::exit(match result { Ok(_) => EXIT_SUCCESS, diff --git a/src/librustc_interface/interface.rs b/src/librustc_interface/interface.rs index f2a21d61aed4a..90e1eddc78614 100644 --- a/src/librustc_interface/interface.rs +++ b/src/librustc_interface/interface.rs @@ -76,6 +76,8 @@ pub struct Config { pub file_loader: Option>, pub diagnostic_output: DiagnosticOutput, + pub driver_symbols: &'static [&'static str], + /// Set to capture stderr output during compiler execution pub stderr: Option>>>, @@ -136,15 +138,16 @@ where let stderr = config.stderr.take(); util::spawn_thread_pool( config.opts.debugging_opts.threads, + config.driver_symbols, &stderr, || run_compiler_in_existing_thread_pool(config, f), ) } -pub fn default_thread_pool(f: F) -> R +pub fn default_thread_pool(driver_symbols: &[&str], f: F) -> R where F: FnOnce() -> R + Send, R: Send, { - util::spawn_thread_pool(None, &None, f) + util::spawn_thread_pool(None, driver_symbols, &None, f) } diff --git a/src/librustc_interface/util.rs b/src/librustc_interface/util.rs index d2d0d19180783..35ad0c9ad76bf 100644 --- a/src/librustc_interface/util.rs +++ b/src/librustc_interface/util.rs @@ -168,6 +168,7 @@ pub fn scoped_thread R + Send, R: Send>(cfg: thread::Builder, f: #[cfg(not(parallel_compiler))] pub fn spawn_thread_pool R + Send, R: Send>( _threads: Option, + driver_symbols: &[&str], stderr: &Option>>>, f: F, ) -> R { @@ -178,7 +179,7 @@ pub fn spawn_thread_pool R + Send, R: Send>( } scoped_thread(cfg, || { - syntax::with_globals( || { + syntax::with_globals(driver_symbols, || { ty::tls::GCX_PTR.set(&Lock::new(0), || { if let Some(stderr) = stderr { io::set_panic(Some(box Sink(stderr.clone()))); @@ -192,6 +193,7 @@ pub fn spawn_thread_pool R + Send, R: Send>( #[cfg(parallel_compiler)] pub fn spawn_thread_pool R + Send, R: Send>( threads: Option, + driver_symbols: &[&str], stderr: &Option>>>, f: F, ) -> R { @@ -213,7 +215,7 @@ pub fn spawn_thread_pool R + Send, R: Send>( let with_pool = move |pool: &ThreadPool| pool.install(move || f()); - syntax::with_globals(|| { + syntax::with_globals(driver_symbols, || { syntax::GLOBALS.with(|syntax_globals| { syntax_pos::GLOBALS.with(|syntax_pos_globals| { // The main handler runs for each Rayon worker thread and sets up diff --git a/src/librustc_macros/src/symbols.rs b/src/librustc_macros/src/symbols.rs index a4c7daf088ff2..1d10aff3790c7 100644 --- a/src/librustc_macros/src/symbols.rs +++ b/src/librustc_macros/src/symbols.rs @@ -166,10 +166,14 @@ pub fn symbols(input: TokenStream) -> TokenStream { } impl Interner { - pub fn fresh() -> Self { - Interner::prefill(&[ - #prefill_stream - ]) + /// If your driver adds more symbols, this is the first index you may use. + /// Do not leave holes in the indexing scheme and add all symbols to the `Interner` + /// created in the closure argument to `Interner::fresh`. + pub const FIRST_DRIVER_INDEX: u32 = #counter; + /// It is the driver's responsibility to not preeintern any symbols that are already + /// in the list given to the closure. + pub fn fresh(driver_symbols: &[&str]) -> Self { + Interner::prefill(&[#prefill_stream], driver_symbols) } } }); diff --git a/src/librustdoc/clean/cfg.rs b/src/librustdoc/clean/cfg.rs index 61399e0568cb1..fdaadb71a29f2 100644 --- a/src/librustdoc/clean/cfg.rs +++ b/src/librustdoc/clean/cfg.rs @@ -466,7 +466,7 @@ mod test { #[test] fn test_cfg_not() { - with_globals(|| { + with_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_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_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_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_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_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_globals(&[], || { assert_eq!( word_cfg("unix").render_long_html(), "This is supported on Unix only." diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 428f4f328b907..17d62faf4fb2e 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -326,7 +326,8 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt let config = interface::Config { opts: sessopts, - crate_cfg: config::parse_cfgspecs(cfgs), + crate_cfg: config::parse_cfgspecs(&[], cfgs), + driver_symbols: &[], input, input_path: cpath, output_file: None, diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 5b76f6861de79..3ccbe4d013f1d 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -94,7 +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 || { + rustc_interface::interface::default_thread_pool(&[], move || { get_args().map(|args| main_args(&args)).unwrap_or(1) }) }).unwrap().join().unwrap_or(rustc_driver::EXIT_FAILURE); diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index e40dbe52ffe64..00d8ee16b0f5e 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -61,7 +61,8 @@ pub fn run(options: Options) -> i32 { let config = interface::Config { opts: sessopts, - crate_cfg: config::parse_cfgspecs(options.cfgs.clone()), + crate_cfg: config::parse_cfgspecs(&[], options.cfgs.clone()), + driver_symbols: &[], input, input_path: None, output_file: None, @@ -279,7 +280,8 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize, let config = interface::Config { opts: sessopts, - crate_cfg: config::parse_cfgspecs(cfgs), + crate_cfg: config::parse_cfgspecs(&[], cfgs), + driver_symbols: &[], input, input_path: None, output_file: Some(output_file.clone()), @@ -385,7 +387,9 @@ 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, + ) = crate::syntax::with_globals(&[],|| { use crate::syntax::{parse::{self, ParseSess}, source_map::FilePathMapping}; use errors::emitter::EmitterWriter; use errors::Handler; diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index db10ab7af5a72..e48136199e782 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -82,21 +82,23 @@ pub struct Globals { } impl Globals { - fn new() -> Globals { + /// See documentation on `syntax_pos::Globals` for information on the slice. + /// It is solely forwareded to `syntax_pos::Globals::new` + fn new(driver_symbols: &[&str]) -> Globals { Globals { // We have no idea how many attributes their will be, so just // initiate the vectors with 0 bits. We'll grow them as necessary. used_attrs: Lock::new(GrowableBitSet::new_empty()), known_attrs: Lock::new(GrowableBitSet::new_empty()), - syntax_pos_globals: syntax_pos::Globals::new(), + syntax_pos_globals: syntax_pos::Globals::new(driver_symbols), } } } -pub fn with_globals(f: F) -> R +pub fn with_globals(driver_symbols: &[&str], f: F) -> R where F: FnOnce() -> R { - let globals = Globals::new(); + let globals = Globals::new(driver_symbols); GLOBALS.set(&globals, || { syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f) }) diff --git a/src/libsyntax/mut_visit.rs b/src/libsyntax/mut_visit.rs index f587e63e12b94..8bbd546c0f6f6 100644 --- a/src/libsyntax/mut_visit.rs +++ b/src/libsyntax/mut_visit.rs @@ -1343,7 +1343,7 @@ mod tests { // make sure idents get transformed everywhere #[test] fn ident_transformation () { - with_globals(|| { + with_globals(&[], || { let mut zz_visitor = ToZzIdentMutVisitor; let mut krate = string_to_crate( "#[a] mod b {fn c (d : e, f : g) {h!(i,j,k);l;m}}".to_string()); @@ -1358,7 +1358,7 @@ mod tests { // even inside macro defs.... #[test] fn ident_transformation_in_defs () { - with_globals(|| { + with_globals(&[], || { let mut zz_visitor = ToZzIdentMutVisitor; let mut krate = string_to_crate( "macro_rules! a {(b $c:expr $(d $e:token)f+ => \ diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 47da3ee6a6c78..4424ca70d8951 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -1601,7 +1601,7 @@ mod tests { #[test] fn t1() { - with_globals(|| { + with_globals(&[], || { let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(sm.clone()); let mut string_reader = setup(&sm, @@ -1649,7 +1649,7 @@ mod tests { #[test] fn doublecolonparsing() { - with_globals(|| { + with_globals(&[], || { let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(sm.clone()); check_tokenization(setup(&sm, &sh, "a b".to_string()), @@ -1659,7 +1659,7 @@ mod tests { #[test] fn dcparsing_2() { - with_globals(|| { + with_globals(&[], || { let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(sm.clone()); check_tokenization(setup(&sm, &sh, "a::b".to_string()), @@ -1669,7 +1669,7 @@ mod tests { #[test] fn dcparsing_3() { - with_globals(|| { + with_globals(&[], || { let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(sm.clone()); check_tokenization(setup(&sm, &sh, "a ::b".to_string()), @@ -1679,7 +1679,7 @@ mod tests { #[test] fn dcparsing_4() { - with_globals(|| { + with_globals(&[], || { let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(sm.clone()); check_tokenization(setup(&sm, &sh, "a:: b".to_string()), @@ -1689,7 +1689,7 @@ mod tests { #[test] fn character_a() { - with_globals(|| { + with_globals(&[], || { let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(sm.clone()); assert_eq!(setup(&sm, &sh, "'a'".to_string()).next_token().tok, @@ -1699,7 +1699,7 @@ mod tests { #[test] fn character_space() { - with_globals(|| { + with_globals(&[], || { let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(sm.clone()); assert_eq!(setup(&sm, &sh, "' '".to_string()).next_token().tok, @@ -1709,7 +1709,7 @@ mod tests { #[test] fn character_escaped() { - with_globals(|| { + with_globals(&[], || { let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(sm.clone()); assert_eq!(setup(&sm, &sh, "'\\n'".to_string()).next_token().tok, @@ -1719,7 +1719,7 @@ mod tests { #[test] fn lifetime_name() { - with_globals(|| { + with_globals(&[], || { let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(sm.clone()); assert_eq!(setup(&sm, &sh, "'abc".to_string()).next_token().tok, @@ -1729,7 +1729,7 @@ mod tests { #[test] fn raw_string() { - with_globals(|| { + with_globals(&[], || { let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(sm.clone()); assert_eq!(setup(&sm, &sh, "r###\"\"#a\\b\x00c\"\"###".to_string()) @@ -1741,7 +1741,7 @@ mod tests { #[test] fn literal_suffixes() { - with_globals(|| { + with_globals(&[], || { let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(sm.clone()); macro_rules! test { @@ -1787,7 +1787,7 @@ mod tests { #[test] fn nested_block_comments() { - with_globals(|| { + with_globals(&[], || { let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(sm.clone()); let mut lexer = setup(&sm, &sh, "/* /* */ */'a'".to_string()); @@ -1802,7 +1802,7 @@ mod tests { #[test] fn crlf_comments() { - with_globals(|| { + with_globals(&[], || { let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(sm.clone()); let mut lexer = setup(&sm, &sh, "// test\r\n/// test\r\n".to_string()); diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 0611c1d9b42a5..48d2339d5602b 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -382,7 +382,7 @@ mod tests { #[should_panic] #[test] fn bad_path_expr_1() { - with_globals(|| { + with_globals(&[], || { string_to_expr("::abc::def::return".to_string()); }) } @@ -390,7 +390,7 @@ mod tests { // check the token-tree-ization of macros #[test] fn string_to_tts_macro () { - with_globals(|| { + with_globals(&[], || { use crate::symbol::sym; let tts: Vec<_> = @@ -447,7 +447,7 @@ mod tests { #[test] fn string_to_tts_1() { - with_globals(|| { + with_globals(&[], || { let tts = string_to_stream("fn a (b : i32) { b; }".to_string()); let expected = TokenStream::new(vec![ @@ -480,7 +480,7 @@ mod tests { } #[test] fn parse_use() { - with_globals(|| { + with_globals(&[], || { let use_s = "use foo::bar::baz;"; let vitem = string_to_item(use_s.to_string()).unwrap(); let vitem_s = item_to_string(&vitem); @@ -494,7 +494,7 @@ mod tests { } #[test] fn parse_extern_crate() { - with_globals(|| { + with_globals(&[], || { let ex_s = "extern crate foo;"; let vitem = string_to_item(ex_s.to_string()).unwrap(); let vitem_s = item_to_string(&vitem); @@ -531,7 +531,7 @@ mod tests { } #[test] fn span_of_self_arg_pat_idents_are_correct() { - with_globals(|| { + with_globals(&[], || { let srcs = ["impl z { fn a (&self, &myarg: i32) {} }", "impl z { fn a (&mut self, &myarg: i32) {} }", @@ -551,7 +551,7 @@ mod tests { } #[test] fn parse_exprs () { - with_globals(|| { + with_globals(&[], || { // just make sure that they parse.... string_to_expr("3 + 4".to_string()); string_to_expr("a::z.froob(b,&(987+3))".to_string()); @@ -559,7 +559,7 @@ mod tests { } #[test] fn attrs_fix_bug () { - with_globals(|| { + with_globals(&[], || { string_to_item("pub fn mk_file_writer(path: &Path, flags: &[FileFlag]) -> Result, String> { #[cfg(windows)] @@ -576,7 +576,7 @@ mod tests { } #[test] fn crlf_doc_comments() { - with_globals(|| { + with_globals(&[], || { use crate::symbol::sym; let sess = ParseSess::new(FilePathMapping::empty()); @@ -613,7 +613,7 @@ mod tests { new_parser_from_source_str(sess, name, source).parse_expr() } - with_globals(|| { + with_globals(&[], || { let sess = ParseSess::new(FilePathMapping::empty()); let expr = parse_expr_from_source_str(PathBuf::from("foo").into(), "foo!( fn main() { body } )".to_string(), &sess).unwrap(); @@ -637,7 +637,7 @@ mod tests { // See `recurse_into_file_modules` in the parser. #[test] fn out_of_line_mod() { - with_globals(|| { + with_globals(&[], || { let sess = ParseSess::new(FilePathMapping::empty()); let item = parse_item_from_source_str( PathBuf::from("foo").into(), diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 86db7a673d471..238e3dcb96551 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -3151,7 +3151,7 @@ mod tests { #[test] fn test_fun_to_string() { - with_globals(|| { + with_globals(&[], || { let abba_ident = ast::Ident::from_str("abba"); let decl = ast::FnDecl { @@ -3179,7 +3179,7 @@ mod tests { #[test] fn test_variant_to_string() { - with_globals(|| { + with_globals(&[], || { let ident = ast::Ident::from_str("principal_skinner"); let var = source_map::respan(syntax_pos::DUMMY_SP, ast::Variant_ { diff --git a/src/libsyntax/test_snippet.rs b/src/libsyntax/test_snippet.rs index 3cf6699538de0..459d47338fe22 100644 --- a/src/libsyntax/test_snippet.rs +++ b/src/libsyntax/test_snippet.rs @@ -39,7 +39,7 @@ impl Write for Shared { } fn test_harness(file_text: &str, span_labels: Vec, expected_output: &str) { - with_globals(|| { + with_globals(&[], || { let output = Arc::new(Mutex::new(Vec::new())); let source_map = Lrc::new(SourceMap::new(FilePathMapping::empty())); diff --git a/src/libsyntax/tokenstream.rs b/src/libsyntax/tokenstream.rs index 93b5ecadd148f..fbd11a0bd63f8 100644 --- a/src/libsyntax/tokenstream.rs +++ b/src/libsyntax/tokenstream.rs @@ -572,7 +572,7 @@ mod tests { #[test] fn test_concat() { - with_globals(|| { + with_globals(&[], || { let test_res = string_to_ts("foo::bar::baz"); let test_fst = string_to_ts("foo::bar"); let test_snd = string_to_ts("::baz"); @@ -585,7 +585,7 @@ mod tests { #[test] fn test_to_from_bijection() { - with_globals(|| { + with_globals(&[], || { let test_start = string_to_ts("foo::bar(baz)"); let test_end = test_start.trees().collect(); assert_eq!(test_start, test_end) @@ -594,7 +594,7 @@ mod tests { #[test] fn test_eq_0() { - with_globals(|| { + with_globals(&[], || { let test_res = string_to_ts("foo"); let test_eqs = string_to_ts("foo"); assert_eq!(test_res, test_eqs) @@ -603,7 +603,7 @@ mod tests { #[test] fn test_eq_1() { - with_globals(|| { + with_globals(&[], || { let test_res = string_to_ts("::bar::baz"); let test_eqs = string_to_ts("::bar::baz"); assert_eq!(test_res, test_eqs) @@ -612,7 +612,7 @@ mod tests { #[test] fn test_eq_3() { - with_globals(|| { + with_globals(&[], || { let test_res = string_to_ts(""); let test_eqs = string_to_ts(""); assert_eq!(test_res, test_eqs) @@ -621,7 +621,7 @@ mod tests { #[test] fn test_diseq_0() { - with_globals(|| { + with_globals(&[], || { let test_res = string_to_ts("::bar::baz"); let test_eqs = string_to_ts("bar::baz"); assert_eq!(test_res == test_eqs, false) @@ -630,7 +630,7 @@ mod tests { #[test] fn test_diseq_1() { - with_globals(|| { + with_globals(&[], || { let test_res = string_to_ts("(bar,baz)"); let test_eqs = string_to_ts("bar,baz"); assert_eq!(test_res == test_eqs, false) @@ -639,7 +639,7 @@ mod tests { #[test] fn test_is_empty() { - with_globals(|| { + with_globals(&[], || { let test0: TokenStream = Vec::::new().into_iter().collect(); let test1: TokenStream = TokenTree::Token(sp(0, 1), Token::Ident(Ident::from_str("a"), false)).into(); diff --git a/src/libsyntax/util/lev_distance.rs b/src/libsyntax/util/lev_distance.rs index 2f150d22159fa..2d7da19a5f0b7 100644 --- a/src/libsyntax/util/lev_distance.rs +++ b/src/libsyntax/util/lev_distance.rs @@ -102,7 +102,7 @@ fn test_lev_distance() { #[test] fn test_find_best_match_for_name() { use crate::with_globals; - with_globals(|| { + with_globals(&[], || { let input = vec![Symbol::intern("aaab"), Symbol::intern("aaabc")]; assert_eq!( find_best_match_for_name(input.iter(), "aaaa", None), diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 39859f25f97fb..df42a0614b1e3 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -55,9 +55,11 @@ pub struct Globals { } impl Globals { - pub fn new() -> Globals { + /// Takes a list of symbols to be preinterned additionally to the ones from + /// `symbol.rs`. The default rustc driver will simply pass an empty list here. + pub fn new(driver_symbols: &[&str]) -> Globals { Globals { - symbol_interner: Lock::new(symbol::Interner::fresh()), + symbol_interner: Lock::new(symbol::Interner::fresh(driver_symbols)), span_interner: Lock::new(span_encoding::SpanInterner::default()), hygiene_data: Lock::new(hygiene::HygieneData::new()), } diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index c2a18c9df83ba..7fed659a0e695 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -822,10 +822,10 @@ impl Decodable for Symbol { } } -// The `&'static str`s in this type actually point into the arena. -// -// Note that normal symbols are indexed upward from 0, and gensyms are indexed -// downward from SymbolIndex::MAX_AS_U32. +/// The `&'static str`s in this type actually point into the arena. +/// +/// Note that normal symbols are indexed upward from 0, and gensyms are indexed +/// downward from SymbolIndex::MAX_AS_U32. #[derive(Default)] pub struct Interner { arena: DroplessArena, @@ -835,17 +835,17 @@ pub struct Interner { } impl Interner { - fn prefill(init: &[&str]) -> Self { + fn prefill(init: &[&str], driver_symbols: &[&str]) -> Self { let mut this = Interner::default(); - this.names.reserve(init.len()); - this.strings.reserve(init.len()); + this.names.reserve(init.len() + driver_symbols.len()); + this.strings.reserve(init.len() + driver_symbols.len()); // We can't allocate empty strings in the arena, so handle this here. assert!(keywords::Invalid.name().as_u32() == 0 && init[0].is_empty()); this.names.insert("", keywords::Invalid.name()); this.strings.push(""); - for string in &init[1..] { + for string in init[1..].iter().chain(driver_symbols) { this.intern(string); } this @@ -1262,7 +1262,7 @@ mod tests { #[test] fn without_first_quote_test() { - GLOBALS.set(&Globals::new(), || { + GLOBALS.set(&Globals::new(&[]), || { let i = Ident::from_str("'break"); assert_eq!(i.without_first_quote().name, keywords::Break.name()); }); diff --git a/src/test/run-make-fulldeps/issue-19371/foo.rs b/src/test/run-make-fulldeps/issue-19371/foo.rs index 0cbdf40e2f908..47bd2e15b972d 100644 --- a/src/test/run-make-fulldeps/issue-19371/foo.rs +++ b/src/test/run-make-fulldeps/issue-19371/foo.rs @@ -49,6 +49,7 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf) { let config = interface::Config { opts, crate_cfg: Default::default(), + driver_symbols: &[], input, input_path: None, output_file: Some(output), diff --git a/src/test/run-pass-fulldeps/ast_stmt_expr_attr.rs b/src/test/run-pass-fulldeps/ast_stmt_expr_attr.rs index d32fafd215c07..6b37b21e183f7 100644 --- a/src/test/run-pass-fulldeps/ast_stmt_expr_attr.rs +++ b/src/test/run-pass-fulldeps/ast_stmt_expr_attr.rs @@ -105,7 +105,7 @@ fn reject_stmt_parse(es: &str) { } fn main() { - syntax::with_globals(|| run()); + syntax::with_globals(&[], || run()); } fn run() { diff --git a/src/test/run-pass-fulldeps/compiler-calls.rs b/src/test/run-pass-fulldeps/compiler-calls.rs index b4731bbaeb5ca..f8c6f60192866 100644 --- a/src/test/run-pass-fulldeps/compiler-calls.rs +++ b/src/test/run-pass-fulldeps/compiler-calls.rs @@ -24,7 +24,9 @@ fn main() { let mut count = 1; let args = vec!["compiler-calls".to_string(), "foo.rs".to_string()]; rustc_driver::report_ices_to_stderr_if_any(|| { - rustc_driver::run_compiler(&args, &mut TestCalls { count: &mut count }, None, None).ok(); + rustc_driver::run_compiler( + &args, &[], &mut TestCalls { count: &mut count }, None, None, + ).ok(); }).ok(); assert_eq!(count, 2); } diff --git a/src/test/run-pass-fulldeps/mod_dir_path_canonicalized.rs b/src/test/run-pass-fulldeps/mod_dir_path_canonicalized.rs index 22a76a3d968aa..e053b9fb7e1c0 100644 --- a/src/test/run-pass-fulldeps/mod_dir_path_canonicalized.rs +++ b/src/test/run-pass-fulldeps/mod_dir_path_canonicalized.rs @@ -13,7 +13,7 @@ use syntax::parse::{self, ParseSess}; mod gravy; pub fn main() { - syntax::with_globals(|| parse()); + syntax::with_globals(&[], || parse()); assert_eq!(gravy::foo(), 10); } diff --git a/src/test/run-pass-fulldeps/pprust-expr-roundtrip.rs b/src/test/run-pass-fulldeps/pprust-expr-roundtrip.rs index 80e0b0102af75..b8ff891ac0dbc 100644 --- a/src/test/run-pass-fulldeps/pprust-expr-roundtrip.rs +++ b/src/test/run-pass-fulldeps/pprust-expr-roundtrip.rs @@ -189,7 +189,7 @@ impl MutVisitor for AddParens { } fn main() { - syntax::with_globals(|| run()); + syntax::with_globals(&[], || run()); } fn run() { diff --git a/src/tools/clippy b/src/tools/clippy index 11194e3d050f4..456e4795e15e3 160000 --- a/src/tools/clippy +++ b/src/tools/clippy @@ -1 +1 @@ -Subproject commit 11194e3d050f45ff002a775f451ff6222fcd5b2c +Subproject commit 456e4795e15e3c9584a15b49586d8bfeccabe0d2 diff --git a/src/tools/error_index_generator/main.rs b/src/tools/error_index_generator/main.rs index 04986b59ea0f1..9df5bd9edc64d 100644 --- a/src/tools/error_index_generator/main.rs +++ b/src/tools/error_index_generator/main.rs @@ -264,7 +264,7 @@ fn main() { *slot.borrow_mut() = Some((None, String::from("https://play.rust-lang.org/"))); }); let (format, dst) = parse_args(); - let result = syntax::with_globals(move || { + let result = syntax::with_globals(&[], move || { main_with_result(format, &dst) }); if let Err(e) = result { diff --git a/src/tools/miri b/src/tools/miri index bc0c76d861a17..224b72d6f3575 160000 --- a/src/tools/miri +++ b/src/tools/miri @@ -1 +1 @@ -Subproject commit bc0c76d861a178911f3f506196a7404eda1e690d +Subproject commit 224b72d6f35756b086cc4b0479fb85036c7501cc diff --git a/src/tools/rls b/src/tools/rls index 5b8e99bb61958..3b7ba010ee552 160000 --- a/src/tools/rls +++ b/src/tools/rls @@ -1 +1 @@ -Subproject commit 5b8e99bb61958ca8abcb7c5eda70521726be1065 +Subproject commit 3b7ba010ee552f9c86bb03d61cd1bcab00221855 diff --git a/src/tools/rustfmt b/src/tools/rustfmt index 5274b49caa1a7..db2cc882b0fdf 160000 --- a/src/tools/rustfmt +++ b/src/tools/rustfmt @@ -1 +1 @@ -Subproject commit 5274b49caa1a7db6ac10c76bf1a3d5710ccef569 +Subproject commit db2cc882b0fdfbc99e50edcf619d40e7bbd15cc5