Skip to content

Commit

Permalink
Auto merge of #61035 - nnethercote:avoid-more-symbol-interning, r=<try>
Browse files Browse the repository at this point in the history
Avoid more symbol interning

r? @ghost
  • Loading branch information
bors committed May 22, 2019
2 parents 1cc822c + 899720f commit 87c7099
Show file tree
Hide file tree
Showing 38 changed files with 165 additions and 162 deletions.
8 changes: 2 additions & 6 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1145,9 +1145,7 @@ impl<'a> LoweringContext<'a> {
let unstable_span = self.sess.source_map().mark_span_with_reason(
CompilerDesugaringKind::Async,
span,
Some(vec![
Symbol::intern("gen_future"),
].into()),
Some(vec![sym::gen_future].into()),
);
let gen_future = self.expr_std_path(
unstable_span, &[sym::future, sym::from_generator], None, ThinVec::new());
Expand Down Expand Up @@ -4179,9 +4177,7 @@ impl<'a> LoweringContext<'a> {
let unstable_span = this.sess.source_map().mark_span_with_reason(
CompilerDesugaringKind::TryBlock,
body.span,
Some(vec![
Symbol::intern("try_trait"),
].into()),
Some(vec![sym::try_trait].into()),
);
let mut block = this.lower_block(body, true).into_inner();
let tail = block.expr.take().map_or_else(
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {
pub fn extract(attrs: &[ast::Attribute]) -> Option<(Symbol, Span)> {
attrs.iter().find_map(|attr| Some(match attr {
_ if attr.check_name(sym::lang) => (attr.value_str()?, attr.span),
_ if attr.check_name(sym::panic_handler) => (Symbol::intern("panic_impl"), attr.span),
_ if attr.check_name(sym::alloc_error_handler) => (Symbol::intern("oom"), attr.span),
_ if attr.check_name(sym::panic_handler) => (sym::panic_impl, attr.span),
_ if attr.check_name(sym::alloc_error_handler) => (sym::oom, attr.span),
_ => return None,
}))
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ impl<'a, 'tcx> Index<'tcx> {
reason: Some(Symbol::intern(reason)),
issue: 27812,
},
feature: Symbol::intern("rustc_private"),
feature: sym::rustc_private,
rustc_depr: None,
const_stability: None,
promotable: false,
Expand Down Expand Up @@ -880,7 +880,7 @@ pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
// FIXME: only remove `libc` when `stdbuild` is active.
// FIXME: remove special casing for `test`.
remaining_lib_features.remove(&Symbol::intern("libc"));
remaining_lib_features.remove(&Symbol::intern("test"));
remaining_lib_features.remove(&sym::test);

let check_features =
|remaining_lib_features: &mut FxHashMap<_, _>, defined_features: &Vec<_>| {
Expand Down
19 changes: 9 additions & 10 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use syntax::source_map::{FileName, FilePathMapping};
use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION};
use syntax::parse::token;
use syntax::parse;
use syntax::symbol::Symbol;
use syntax::symbol::{Symbol, sym};
use syntax::feature_gate::UnstableFeatures;
use errors::emitter::HumanReadableErrorType;

Expand Down Expand Up @@ -1503,31 +1503,31 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
Some(Symbol::intern(vendor)),
));
if sess.target.target.options.has_elf_tls {
ret.insert((Symbol::intern("target_thread_local"), None));
ret.insert((sym::target_thread_local, None));
}
for &i in &[8, 16, 32, 64, 128] {
if i >= min_atomic_width && i <= max_atomic_width {
let s = i.to_string();
ret.insert((
Symbol::intern("target_has_atomic"),
sym::target_has_atomic,
Some(Symbol::intern(&s)),
));
if &s == wordsz {
ret.insert((
Symbol::intern("target_has_atomic"),
sym::target_has_atomic,
Some(Symbol::intern("ptr")),
));
}
}
}
if atomic_cas {
ret.insert((Symbol::intern("target_has_atomic"), Some(Symbol::intern("cas"))));
ret.insert((sym::target_has_atomic, Some(Symbol::intern("cas"))));
}
if sess.opts.debug_assertions {
ret.insert((Symbol::intern("debug_assertions"), None));
}
if sess.opts.crate_types.contains(&CrateType::ProcMacro) {
ret.insert((Symbol::intern("proc_macro"), None));
ret.insert((sym::proc_macro, None));
}
ret
}
Expand All @@ -1547,7 +1547,7 @@ pub fn build_configuration(sess: &Session, mut user_cfg: ast::CrateConfig) -> as
let default_cfg = default_configuration(sess);
// If the user wants a test runner, then add the test cfg
if sess.opts.test {
user_cfg.insert((Symbol::intern("test"), None));
user_cfg.insert((sym::test, None));
}
user_cfg.extend(default_cfg.iter().cloned());
user_cfg
Expand Down Expand Up @@ -2702,7 +2702,7 @@ mod tests {
use std::path::PathBuf;
use super::{Externs, OutputType, OutputTypes};
use rustc_target::spec::{MergeFunctions, PanicStrategy, RelroLevel};
use syntax::symbol::Symbol;
use syntax::symbol::sym;
use syntax::edition::{Edition, DEFAULT_EDITION};
use syntax;
use super::Options;
Expand Down Expand Up @@ -2744,15 +2744,14 @@ mod tests {
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)));
assert!(cfg.contains(&(sym::test, None)));
});
}

// When the user supplies --test and --cfg test, don't implicitly add
// another --cfg test
#[test]
fn test_switch_implies_cfg_test_unless_cfg_test() {
use syntax::symbol::sym;
syntax::with_default_globals(|| {
let matches = &match optgroups().parse(&["--test".to_string(),
"--cfg=test".to_string()]) {
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_allocator/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> {
call_site: item.span, // use the call site of the static
def_site: None,
format: MacroAttribute(Symbol::intern(name)),
allow_internal_unstable: Some(vec![
Symbol::intern("rustc_attrs"),
].into()),
allow_internal_unstable: Some(vec![sym::rustc_attrs].into()),
allow_internal_unsafe: false,
local_inner_macros: false,
edition: self.sess.edition,
Expand Down Expand Up @@ -224,7 +222,7 @@ impl AllocFnFactory<'_> {
}

fn attrs(&self) -> Vec<Attribute> {
let special = Symbol::intern("rustc_std_internal_symbol");
let special = sym::rustc_std_internal_symbol;
let special = self.cx.meta_word(self.span, special);
vec![self.cx.attribute(self.span, special)]
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_interface/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn add_configuration(
sess: &Session,
codegen_backend: &dyn CodegenBackend,
) {
let tf = Symbol::intern("target_feature");
let tf = sym::target_feature;

cfg.extend(
codegen_backend
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_metadata/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,7 @@ impl cstore::CStore {
let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
let ext = SyntaxExtension::ProcMacro {
expander: Box::new(BangProcMacro { client }),
allow_internal_unstable: Some(vec![
Symbol::intern("proc_macro_def_site"),
].into()),
allow_internal_unstable: Some(vec![sym::proc_macro_def_site].into()),
edition: data.root.edition,
};
return LoadedMacro::ProcMacro(Lrc::new(ext));
Expand Down
16 changes: 6 additions & 10 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2698,16 +2698,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {

fn resolve_place_op(&self, op: PlaceOp, is_mut: bool) -> (Option<DefId>, ast::Ident) {
let (tr, name) = match (op, is_mut) {
(PlaceOp::Deref, false) =>
(self.tcx.lang_items().deref_trait(), "deref"),
(PlaceOp::Deref, true) =>
(self.tcx.lang_items().deref_mut_trait(), "deref_mut"),
(PlaceOp::Index, false) =>
(self.tcx.lang_items().index_trait(), "index"),
(PlaceOp::Index, true) =>
(self.tcx.lang_items().index_mut_trait(), "index_mut"),
(PlaceOp::Deref, false) => (self.tcx.lang_items().deref_trait(), sym::deref),
(PlaceOp::Deref, true) => (self.tcx.lang_items().deref_mut_trait(), sym::deref_mut),
(PlaceOp::Index, false) => (self.tcx.lang_items().index_trait(), sym::index),
(PlaceOp::Index, true) => (self.tcx.lang_items().index_mut_trait(), sym::index_mut),
};
(tr, ast::Ident::from_str(name))
(tr, ast::Ident::with_empty_ctxt(name))
}

fn try_overloaded_place_op(&self,
Expand Down Expand Up @@ -4949,7 +4945,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// This is less than ideal, it will not suggest a return type span on any
// method called `main`, regardless of whether it is actually the entry point,
// but it will still present it as the reason for the expected type.
Some((decl, ident, ident.name != Symbol::intern("main")))
Some((decl, ident, ident.name != sym::main))
}),
Node::TraitItem(&hir::TraitItem {
ident, node: hir::TraitItemKind::Method(hir::MethodSig {
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -969,10 +969,10 @@ impl<'a> ExtCtxt<'a> {
pub fn ident_of(&self, st: &str) -> ast::Ident {
ast::Ident::from_str(st)
}
pub fn std_path(&self, components: &[&str]) -> Vec<ast::Ident> {
pub fn std_path(&self, components: &[Symbol]) -> Vec<ast::Ident> {
let def_site = DUMMY_SP.apply_mark(self.current_expansion.mark);
iter::once(Ident::new(keywords::DollarCrate.name(), def_site))
.chain(components.iter().map(|s| self.ident_of(s)))
.chain(components.iter().map(|&s| Ident::with_empty_ctxt(s)))
.collect()
}
pub fn name_of(&self, st: &str) -> ast::Name {
Expand Down
28 changes: 14 additions & 14 deletions src/libsyntax/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::attr;
use crate::source_map::{dummy_spanned, respan, Spanned};
use crate::ext::base::ExtCtxt;
use crate::ptr::P;
use crate::symbol::{Symbol, keywords};
use crate::symbol::{Symbol, keywords, sym};
use crate::ThinVec;

use rustc_target::spec::abi::Abi;
Expand Down Expand Up @@ -429,7 +429,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
self.ty_path(
self.path_all(DUMMY_SP,
true,
self.std_path(&["option", "Option"]),
self.std_path(&[sym::option, sym::Option]),
vec![ast::GenericArg::Type(ty)],
Vec::new()))
}
Expand Down Expand Up @@ -735,7 +735,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
self.expr(sp, ast::ExprKind::Array(exprs))
}
fn expr_vec_ng(&self, sp: Span) -> P<ast::Expr> {
self.expr_call_global(sp, self.std_path(&["vec", "Vec", "new"]),
self.expr_call_global(sp, self.std_path(&[sym::vec, sym::Vec, sym::new]),
Vec::new())
}
fn expr_vec_slice(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> {
Expand All @@ -751,12 +751,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> {


fn expr_some(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
let some = self.std_path(&["option", "Option", "Some"]);
let some = self.std_path(&[sym::option, sym::Option, sym::Some]);
self.expr_call_global(sp, some, vec![expr])
}

fn expr_none(&self, sp: Span) -> P<ast::Expr> {
let none = self.std_path(&["option", "Option", "None"]);
let none = self.std_path(&[sym::option, sym::Option, sym::None]);
let none = self.path_global(sp, none);
self.expr_path(none)
}
Expand All @@ -780,7 +780,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
let expr_loc_ptr = self.expr_addr_of(span, expr_loc_tuple);
self.expr_call_global(
span,
self.std_path(&["rt", "begin_panic"]),
self.std_path(&[sym::rt, sym::begin_panic]),
vec![
self.expr_str(span, msg),
expr_loc_ptr])
Expand All @@ -791,19 +791,19 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
}

fn expr_ok(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
let ok = self.std_path(&["result", "Result", "Ok"]);
let ok = self.std_path(&[sym::result, sym::Result, sym::Ok]);
self.expr_call_global(sp, ok, vec![expr])
}

fn expr_err(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
let err = self.std_path(&["result", "Result", "Err"]);
let err = self.std_path(&[sym::result, sym::Result, sym::Err]);
self.expr_call_global(sp, err, vec![expr])
}

fn expr_try(&self, sp: Span, head: P<ast::Expr>) -> P<ast::Expr> {
let ok = self.std_path(&["result", "Result", "Ok"]);
let ok = self.std_path(&[sym::result, sym::Result, sym::Ok]);
let ok_path = self.path_global(sp, ok);
let err = self.std_path(&["result", "Result", "Err"]);
let err = self.std_path(&[sym::result, sym::Result, sym::Err]);
let err_path = self.path_global(sp, err);

let binding_variable = self.ident_of("__try_var");
Expand Down Expand Up @@ -867,25 +867,25 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
}

fn pat_some(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
let some = self.std_path(&["option", "Option", "Some"]);
let some = self.std_path(&[sym::option, sym::Option, sym::Some]);
let path = self.path_global(span, some);
self.pat_tuple_struct(span, path, vec![pat])
}

fn pat_none(&self, span: Span) -> P<ast::Pat> {
let some = self.std_path(&["option", "Option", "None"]);
let some = self.std_path(&[sym::option, sym::Option, sym::None]);
let path = self.path_global(span, some);
self.pat_path(span, path)
}

fn pat_ok(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
let some = self.std_path(&["result", "Result", "Ok"]);
let some = self.std_path(&[sym::result, sym::Result, sym::Ok]);
let path = self.path_global(span, some);
self.pat_tuple_struct(span, path, vec![pat])
}

fn pat_err(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
let some = self.std_path(&["result", "Result", "Err"]);
let some = self.std_path(&[sym::result, sym::Result, sym::Err]);
let path = self.path_global(span, some);
self.pat_tuple_struct(span, path, vec![pat])
}
Expand Down
7 changes: 2 additions & 5 deletions src/libsyntax/ext/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ pub fn add_derived_markers<T>(cx: &mut ExtCtxt<'_>, span: Span, traits: &[ast::P
call_site: span,
def_site: None,
format: ExpnFormat::MacroAttribute(Symbol::intern(&pretty_name)),
allow_internal_unstable: Some(vec![
Symbol::intern("rustc_attrs"),
Symbol::intern("structural_match"),
].into()),
allow_internal_unstable: Some(vec![sym::rustc_attrs, sym::structural_match].into()),
allow_internal_unsafe: false,
local_inner_macros: false,
edition: cx.parse_sess.edition,
Expand All @@ -74,7 +71,7 @@ pub fn add_derived_markers<T>(cx: &mut ExtCtxt<'_>, span: Span, traits: &[ast::P
attrs.push(cx.attribute(span, meta));
}
if names.contains(&Symbol::intern("Copy")) {
let meta = cx.meta_word(span, Symbol::intern("rustc_copy_clone_marker"));
let meta = cx.meta_word(span, sym::rustc_copy_clone_marker);
attrs.push(cx.attribute(span, meta));
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
}
BuiltinDerive(func) => {
expn_info.allow_internal_unstable = Some(vec![
Symbol::intern("rustc_attrs"),
sym::rustc_attrs,
Symbol::intern("derive_clone_copy"),
Symbol::intern("derive_eq"),
Symbol::intern("libstd_sys_internals"), // RustcDeserialize and RustcSerialize
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/tt/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ pub fn compile(
future this will become a hard error. Please use `allow_internal_unstable(\
foo, bar)` to only allow the `foo` and `bar` features",
);
vec![Symbol::intern("allow_internal_unstable_backcompat_hack")].into()
vec![sym::allow_internal_unstable_backcompat_hack].into()
})
);
let allow_internal_unsafe = attr::contains_name(&def.attrs, sym::allow_internal_unsafe);
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/parse/lexer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::ast::{self, Ident};
use crate::parse::{token, ParseSess};
use crate::symbol::Symbol;
use crate::symbol::{Symbol, sym};
use crate::parse::unescape;
use crate::parse::unescape_error_reporting::{emit_unescape_error, push_escaped_char};

Expand Down Expand Up @@ -753,7 +753,7 @@ impl<'a> StringReader<'a> {
}
_ => {
// just a 0
return token::Integer(self.name_from(start_bpos));
return token::Integer(sym::n0);
}
}
} else if c.is_digit(10) {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6336,7 +6336,7 @@ impl<'a> Parser<'a> {
VisibilityKind::Inherited => {}
_ => {
let is_macro_rules: bool = match self.token {
token::Ident(sid, _) => sid.name == Symbol::intern("macro_rules"),
token::Ident(sid, _) => sid.name == sym::macro_rules,
_ => false,
};
let mut err = if is_macro_rules {
Expand Down
Loading

0 comments on commit 87c7099

Please sign in to comment.