1
Fork 0

Replace Symbol::intern calls with preinterned symbols

This commit is contained in:
clubby789 2024-11-27 17:52:57 +00:00
parent 72d2db7bf4
commit 71b698c0b8
15 changed files with 40 additions and 35 deletions

View file

@ -4,9 +4,9 @@ use rustc_ast::{NodeId, PatKind, attr, token};
use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute, Features, GateIssue}; use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute, Features, GateIssue};
use rustc_session::Session; use rustc_session::Session;
use rustc_session::parse::{feature_err, feature_err_issue, feature_warn}; use rustc_session::parse::{feature_err, feature_err_issue, feature_warn};
use rustc_span::Span;
use rustc_span::source_map::Spanned; use rustc_span::source_map::Spanned;
use rustc_span::symbol::sym; use rustc_span::symbol::{Symbol, sym};
use rustc_span::{Span, Symbol};
use rustc_target::spec::abi; use rustc_target::spec::abi;
use thin_vec::ThinVec; use thin_vec::ThinVec;
@ -690,6 +690,7 @@ fn check_new_solver_banned_features(sess: &Session, features: &Features) {
.find(|feat| feat.gate_name == sym::generic_const_exprs) .find(|feat| feat.gate_name == sym::generic_const_exprs)
.map(|feat| feat.attr_sp) .map(|feat| feat.attr_sp)
{ {
#[cfg_attr(not(bootstrap), allow(rustc::symbol_intern_string_literal))]
sess.dcx().emit_err(errors::IncompatibleFeatures { sess.dcx().emit_err(errors::IncompatibleFeatures {
spans: vec![gce_span], spans: vec![gce_span],
f1: Symbol::intern("-Znext-solver=globally"), f1: Symbol::intern("-Znext-solver=globally"),

View file

@ -33,8 +33,8 @@ use rustc_middle::ty::{
TyCtxt, TypeVisitableExt, TyCtxt, TypeVisitableExt,
}; };
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
use rustc_span::ErrorGuaranteed;
use rustc_span::symbol::{kw, sym}; use rustc_span::symbol::{kw, sym};
use rustc_span::{ErrorGuaranteed, Symbol};
use tracing::{debug, instrument}; use tracing::{debug, instrument};
use crate::BorrowckInferCtxt; use crate::BorrowckInferCtxt;
@ -524,7 +524,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
let reg_vid = self let reg_vid = self
.infcx .infcx
.next_nll_region_var(FR, || RegionCtxt::Free(Symbol::intern("c-variadic"))) .next_nll_region_var(FR, || RegionCtxt::Free(sym::c_dash_variadic))
.as_var(); .as_var();
let region = ty::Region::new_var(self.infcx.tcx, reg_vid); let region = ty::Region::new_var(self.infcx.tcx, reg_vid);
@ -540,10 +540,8 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
} }
} }
let fr_fn_body = self let fr_fn_body =
.infcx self.infcx.next_nll_region_var(FR, || RegionCtxt::Free(sym::fn_body)).as_var();
.next_nll_region_var(FR, || RegionCtxt::Free(Symbol::intern("fn_body")))
.as_var();
let num_universals = self.infcx.num_region_vars(); let num_universals = self.infcx.num_region_vars();

View file

@ -74,7 +74,7 @@ fn create_jit_module(
jit_builder.symbol("__clif_jit_fn", clif_jit_fn as *const u8); jit_builder.symbol("__clif_jit_fn", clif_jit_fn as *const u8);
let mut jit_module = UnwindModule::new(JITModule::new(jit_builder), false); let mut jit_module = UnwindModule::new(JITModule::new(jit_builder), false);
let cx = crate::CodegenCx::new(tcx, jit_module.isa(), false, Symbol::intern("dummy_cgu_name")); let cx = crate::CodegenCx::new(tcx, jit_module.isa(), false, sym::dummy_cgu_name);
crate::allocator::codegen(tcx, &mut jit_module); crate::allocator::codegen(tcx, &mut jit_module);
@ -276,12 +276,7 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) ->
jit_module.module.prepare_for_function_redefine(func_id).unwrap(); jit_module.module.prepare_for_function_redefine(func_id).unwrap();
let mut cx = crate::CodegenCx::new( let mut cx = crate::CodegenCx::new(tcx, jit_module.isa(), false, sym::dummy_cgu_name);
tcx,
jit_module.isa(),
false,
Symbol::intern("dummy_cgu_name"),
);
codegen_and_compile_fn(tcx, &mut cx, &mut Context::new(), jit_module, instance); codegen_and_compile_fn(tcx, &mut cx, &mut Context::new(), jit_module, instance);
assert!(cx.global_asm.is_empty()); assert!(cx.global_asm.is_empty());

View file

@ -189,18 +189,13 @@ impl CodegenBackend for CraneliftCodegenBackend {
// FIXME return the actually used target features. this is necessary for #[cfg(target_feature)] // FIXME return the actually used target features. this is necessary for #[cfg(target_feature)]
if sess.target.arch == "x86_64" && sess.target.os != "none" { if sess.target.arch == "x86_64" && sess.target.os != "none" {
// x86_64 mandates SSE2 support // x86_64 mandates SSE2 support
vec![Symbol::intern("fxsr"), sym::sse, Symbol::intern("sse2")] vec![sym::fsxr, sym::sse, sym::sse2]
} else if sess.target.arch == "aarch64" { } else if sess.target.arch == "aarch64" {
match &*sess.target.os { match &*sess.target.os {
"none" => vec![], "none" => vec![],
// On macOS the aes, sha2 and sha3 features are enabled by default and ring // On macOS the aes, sha2 and sha3 features are enabled by default and ring
// fails to compile on macOS when they are not present. // fails to compile on macOS when they are not present.
"macos" => vec![ "macos" => vec![sym::neon, sym::aes, sym::sha2, sym::sha3],
sym::neon,
Symbol::intern("aes"),
Symbol::intern("sha2"),
Symbol::intern("sha3"),
],
// AArch64 mandates Neon support // AArch64 mandates Neon support
_ => vec![sym::neon], _ => vec![sym::neon],
} }

View file

@ -419,7 +419,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
if let Node::ConstBlock(_) = node { if let Node::ConstBlock(_) = node {
own_params.push(ty::GenericParamDef { own_params.push(ty::GenericParamDef {
index: next_index(), index: next_index(),
name: Symbol::intern("<const_ty>"), name: rustc_span::sym::const_ty_placeholder,
def_id: def_id.to_def_id(), def_id: def_id.to_def_id(),
pure_wrt_drop: false, pure_wrt_drop: false,
kind: ty::GenericParamDefKind::Type { has_default: false, synthetic: false }, kind: ty::GenericParamDefKind::Type { has_default: false, synthetic: false },

View file

@ -664,7 +664,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let is_write = sugg_span.ctxt().outer_expn_data().macro_def_id.is_some_and(|def_id| { let is_write = sugg_span.ctxt().outer_expn_data().macro_def_id.is_some_and(|def_id| {
tcx.is_diagnostic_item(sym::write_macro, def_id) tcx.is_diagnostic_item(sym::write_macro, def_id)
|| tcx.is_diagnostic_item(sym::writeln_macro, def_id) || tcx.is_diagnostic_item(sym::writeln_macro, def_id)
}) && item_name.name == Symbol::intern("write_fmt"); }) && item_name.name == sym::write_fmt;
let mut err = if is_write && let SelfSource::MethodCall(rcvr_expr) = source { let mut err = if is_write && let SelfSource::MethodCall(rcvr_expr) = source {
self.suggest_missing_writer(rcvr_ty, rcvr_expr) self.suggest_missing_writer(rcvr_ty, rcvr_expr)
} else { } else {

View file

@ -1563,7 +1563,7 @@ impl UnusedImportBraces {
} }
rename.unwrap_or(orig_ident).name rename.unwrap_or(orig_ident).name
} }
ast::UseTreeKind::Glob => Symbol::intern("*"), ast::UseTreeKind::Glob => sym::asterisk,
ast::UseTreeKind::Nested { .. } => return, ast::UseTreeKind::Nested { .. } => return,
}; };

View file

@ -861,8 +861,10 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
// First up we check for global allocators. Look at the crate graph here // First up we check for global allocators. Look at the crate graph here
// and see what's a global allocator, including if we ourselves are a // and see what's a global allocator, including if we ourselves are a
// global allocator. // global allocator.
let mut global_allocator = #[cfg_attr(not(bootstrap), allow(rustc::symbol_intern_string_literal))]
self.cstore.has_global_allocator.then(|| Symbol::intern("this crate")); let this_crate = Symbol::intern("this crate");
let mut global_allocator = self.cstore.has_global_allocator.then_some(this_crate);
for (_, data) in self.cstore.iter_crate_data() { for (_, data) in self.cstore.iter_crate_data() {
if data.has_global_allocator() { if data.has_global_allocator() {
match global_allocator { match global_allocator {
@ -876,8 +878,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
} }
} }
} }
let mut alloc_error_handler = let mut alloc_error_handler = self.cstore.has_alloc_error_handler.then_some(this_crate);
self.cstore.has_alloc_error_handler.then(|| Symbol::intern("this crate"));
for (_, data) in self.cstore.iter_crate_data() { for (_, data) in self.cstore.iter_crate_data() {
if data.has_alloc_error_handler() { if data.has_alloc_error_handler() {
match alloc_error_handler { match alloc_error_handler {

View file

@ -872,6 +872,7 @@ impl MetadataBlob {
let def_kind = root.tables.def_kind.get(blob, item).unwrap(); let def_kind = root.tables.def_kind.get(blob, item).unwrap();
let def_key = root.tables.def_keys.get(blob, item).unwrap().decode(blob); let def_key = root.tables.def_keys.get(blob, item).unwrap().decode(blob);
#[cfg_attr(not(bootstrap), allow(rustc::symbol_intern_string_literal))]
let def_name = if item == CRATE_DEF_INDEX { let def_name = if item == CRATE_DEF_INDEX {
rustc_span::symbol::kw::Crate rustc_span::symbol::kw::Crate
} else { } else {

View file

@ -9,7 +9,7 @@ use rustc_ast::{
}; };
use rustc_errors::{Applicability, PResult}; use rustc_errors::{Applicability, PResult};
use rustc_span::symbol::{Ident, kw, sym}; use rustc_span::symbol::{Ident, kw, sym};
use rustc_span::{ErrorGuaranteed, Span, Symbol}; use rustc_span::{ErrorGuaranteed, Span};
use thin_vec::{ThinVec, thin_vec}; use thin_vec::{ThinVec, thin_vec};
use super::{Parser, PathStyle, SeqSep, TokenType, Trailing}; use super::{Parser, PathStyle, SeqSep, TokenType, Trailing};
@ -1139,7 +1139,7 @@ impl<'a> Parser<'a> {
Some(ast::Path { Some(ast::Path {
span: fn_token_span.to(self.prev_token.span), span: fn_token_span.to(self.prev_token.span),
segments: thin_vec![ast::PathSegment { segments: thin_vec![ast::PathSegment {
ident: Ident::new(Symbol::intern("Fn"), fn_token_span), ident: Ident::new(sym::Fn, fn_token_span),
id: DUMMY_NODE_ID, id: DUMMY_NODE_ID,
args: Some(P(ast::GenericArgs::Parenthesized(ast::ParenthesizedArgs { args: Some(P(ast::GenericArgs::Parenthesized(ast::ParenthesizedArgs {
span: args_lo.to(self.prev_token.span), span: args_lo.to(self.prev_token.span),

View file

@ -3113,6 +3113,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
} }
} }
#[cfg_attr(not(bootstrap), allow(rustc::symbol_intern_string_literal))]
let existing_name = match &in_scope_lifetimes[..] { let existing_name = match &in_scope_lifetimes[..] {
[] => Symbol::intern("'a"), [] => Symbol::intern("'a"),
[(existing, _)] => existing.name, [(existing, _)] => existing.name,

View file

@ -2270,7 +2270,7 @@ fn module_to_string(module: Module<'_>) -> Option<String> {
collect_mod(names, parent); collect_mod(names, parent);
} }
} else { } else {
names.push(Symbol::intern("<opaque>")); names.push(sym::opaque_module_name_placeholder);
collect_mod(names, module.parent.unwrap()); collect_mod(names, module.parent.unwrap());
} }
} }

View file

@ -87,7 +87,7 @@ pub fn find_crate_name(sess: &Session, attrs: &[ast::Attribute]) -> Symbol {
} }
} }
Symbol::intern("rust_out") sym::rust_out
} }
pub fn validate_crate_name(sess: &Session, s: Symbol, sp: Option<Span>) { pub fn validate_crate_name(sess: &Session, s: Symbol, sp: Option<Span>) {

View file

@ -297,6 +297,7 @@ symbols! {
Return, Return,
Right, Right,
Rust, Rust,
RustaceansAreAwesome,
RustcDecodable, RustcDecodable,
RustcEncodable, RustcEncodable,
RwLock, RwLock,
@ -377,6 +378,7 @@ symbols! {
adt_const_params, adt_const_params,
advanced_slice_patterns, advanced_slice_patterns,
adx_target_feature, adx_target_feature,
aes,
aggregate_raw_ptr, aggregate_raw_ptr,
alias, alias,
align, align,
@ -439,6 +441,7 @@ symbols! {
associated_types, associated_types,
assume, assume,
assume_init, assume_init,
asterisk: "*",
async_await, async_await,
async_call, async_call,
async_call_mut, async_call_mut,
@ -519,6 +522,7 @@ symbols! {
btreeset_iter, btreeset_iter,
builtin_syntax, builtin_syntax,
c, c,
c_dash_variadic,
c_str, c_str,
c_str_literals, c_str_literals,
c_unwind, c_unwind,
@ -649,6 +653,7 @@ symbols! {
const_trait_bound_opt_out, const_trait_bound_opt_out,
const_trait_impl, const_trait_impl,
const_try, const_try,
const_ty_placeholder: "<const_ty>",
constant, constant,
constructor, constructor,
convert_identity, convert_identity,
@ -778,6 +783,7 @@ symbols! {
drop_types_in_const, drop_types_in_const,
dropck_eyepatch, dropck_eyepatch,
dropck_parametricity, dropck_parametricity,
dummy_cgu_name,
dylib, dylib,
dyn_compatible_for_dispatch, dyn_compatible_for_dispatch,
dyn_metadata, dyn_metadata,
@ -921,6 +927,7 @@ symbols! {
fmuladdf32, fmuladdf32,
fmuladdf64, fmuladdf64,
fn_align, fn_align,
fn_body,
fn_delegation, fn_delegation,
fn_must_use, fn_must_use,
fn_mut, fn_mut,
@ -961,6 +968,7 @@ symbols! {
fs_create_dir, fs_create_dir,
fsub_algebraic, fsub_algebraic,
fsub_fast, fsub_fast,
fsxr,
full, full,
fundamental, fundamental,
fused_iterator, fused_iterator,
@ -1384,6 +1392,7 @@ symbols! {
on, on,
on_unimplemented, on_unimplemented,
opaque, opaque,
opaque_module_name_placeholder: "<opaque>",
open_options_new, open_options_new,
ops, ops,
opt_out_copy, opt_out_copy,
@ -1652,6 +1661,7 @@ symbols! {
rust_eh_catch_typeinfo, rust_eh_catch_typeinfo,
rust_eh_personality, rust_eh_personality,
rust_logo, rust_logo,
rust_out,
rustc, rustc,
rustc_abi, rustc_abi,
rustc_allocator, rustc_allocator,
@ -1774,6 +1784,8 @@ symbols! {
self_in_typedefs, self_in_typedefs,
self_struct_ctor, self_struct_ctor,
semitransparent, semitransparent,
sha2,
sha3,
sha512_sm_x86, sha512_sm_x86,
shadow_call_stack, shadow_call_stack,
shallow, shallow,
@ -1887,6 +1899,7 @@ symbols! {
sreg, sreg,
sreg_low16, sreg_low16,
sse, sse,
sse2,
sse4a_target_feature, sse4a_target_feature,
stable, stable,
staged_api, staged_api,
@ -2173,6 +2186,7 @@ symbols! {
wrapping_sub, wrapping_sub,
wreg, wreg,
write_bytes, write_bytes,
write_fmt,
write_macro, write_macro,
write_str, write_str,
write_via_move, write_via_move,

View file

@ -18,7 +18,6 @@ use rustc_middle::ty::{
TypeVisitableExt, TypeVisitor, TypingMode, Upcast, TypeVisitableExt, TypeVisitor, TypingMode, Upcast,
}; };
use rustc_span::Span; use rustc_span::Span;
use rustc_span::symbol::Symbol;
use smallvec::SmallVec; use smallvec::SmallVec;
use tracing::{debug, instrument}; use tracing::{debug, instrument};
@ -679,7 +678,7 @@ fn receiver_is_dispatchable<'tcx>(
// FIXME(mikeyhew) this is a total hack. Once dyn_compatible_for_dispatch is stabilized, we can // FIXME(mikeyhew) this is a total hack. Once dyn_compatible_for_dispatch is stabilized, we can
// replace this with `dyn Trait` // replace this with `dyn Trait`
let unsized_self_ty: Ty<'tcx> = let unsized_self_ty: Ty<'tcx> =
Ty::new_param(tcx, u32::MAX, Symbol::intern("RustaceansAreAwesome")); Ty::new_param(tcx, u32::MAX, rustc_span::sym::RustaceansAreAwesome);
// `Receiver[Self => U]` // `Receiver[Self => U]`
let unsized_receiver_ty = let unsized_receiver_ty =