@@ -101,7 +101,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
101101use rustc_mir:: monomorphize:: item:: { InstantiationMode , MonoItem , MonoItemExt } ;
102102use rustc_mir:: monomorphize:: Instance ;
103103
104- use syntax_pos:: symbol:: Symbol ;
104+ use syntax_pos:: symbol:: { Symbol , InternedString } ;
105105
106106use log:: debug;
107107
@@ -110,7 +110,6 @@ use std::mem::{self, discriminant};
110110
111111pub fn provide ( providers : & mut Providers < ' _ > ) {
112112 * providers = Providers {
113- def_symbol_name,
114113 symbol_name,
115114
116115 ..* providers
@@ -222,21 +221,13 @@ fn get_symbol_hash<'a, 'tcx>(
222221 hasher. finish ( )
223222}
224223
225- fn def_symbol_name < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , def_id : DefId ) -> ty:: SymbolName {
226- SymbolPrinter {
227- tcx,
228- path : SymbolPath :: new ( ) ,
229- keep_within_component : false ,
230- } . print_def_path ( def_id, & [ ] ) . unwrap ( ) . path . into_interned ( )
231- }
232-
233- fn symbol_name < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , instance : Instance < ' tcx > ) -> ty:: SymbolName {
224+ fn symbol_name ( tcx : TyCtxt < ' _ , ' tcx , ' tcx > , instance : Instance < ' tcx > ) -> ty:: SymbolName {
234225 ty:: SymbolName {
235- name : Symbol :: intern ( & compute_symbol_name ( tcx, instance) ) . as_interned_str ( ) ,
226+ name : compute_symbol_name ( tcx, instance) ,
236227 }
237228}
238229
239- fn compute_symbol_name < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , instance : Instance < ' tcx > ) -> String {
230+ fn compute_symbol_name ( tcx : TyCtxt < ' _ , ' tcx , ' tcx > , instance : Instance < ' tcx > ) -> InternedString {
240231 let def_id = instance. def_id ( ) ;
241232 let substs = instance. substs ;
242233
@@ -247,11 +238,13 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
247238 if def_id. is_local ( ) {
248239 if tcx. plugin_registrar_fn ( LOCAL_CRATE ) == Some ( def_id) {
249240 let disambiguator = tcx. sess . local_crate_disambiguator ( ) ;
250- return tcx. sess . generate_plugin_registrar_symbol ( disambiguator) ;
241+ return Symbol :: intern ( & tcx. sess . generate_plugin_registrar_symbol ( disambiguator) )
242+ . as_interned_str ( ) ;
251243 }
252244 if tcx. proc_macro_decls_static ( LOCAL_CRATE ) == Some ( def_id) {
253245 let disambiguator = tcx. sess . local_crate_disambiguator ( ) ;
254- return tcx. sess . generate_proc_macro_decls_symbol ( disambiguator) ;
246+ return Symbol :: intern ( & tcx. sess . generate_proc_macro_decls_symbol ( disambiguator) )
247+ . as_interned_str ( ) ;
255248 }
256249 }
257250
@@ -268,20 +261,20 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
268261 let attrs = tcx. codegen_fn_attrs ( def_id) ;
269262 if is_foreign {
270263 if let Some ( name) = attrs. link_name {
271- return name. to_string ( ) ;
264+ return name. as_interned_str ( ) ;
272265 }
273266 // Don't mangle foreign items.
274- return tcx. item_name ( def_id) . to_string ( ) ;
267+ return tcx. item_name ( def_id) ;
275268 }
276269
277270 if let Some ( name) = & attrs. export_name {
278271 // Use provided name
279- return name. to_string ( ) ;
272+ return name. as_interned_str ( ) ;
280273 }
281274
282275 if attrs. flags . contains ( CodegenFnAttrFlags :: NO_MANGLE ) {
283276 // Don't mangle
284- return tcx. item_name ( def_id) . to_string ( ) ;
277+ return tcx. item_name ( def_id) ;
285278 }
286279
287280 // We want to compute the "type" of this item. Unfortunately, some
@@ -321,15 +314,15 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
321314
322315 let mut printer = SymbolPrinter {
323316 tcx,
324- path : SymbolPath :: from_interned ( tcx . def_symbol_name ( def_id ) ) ,
317+ path : SymbolPath :: new ( ) ,
325318 keep_within_component : false ,
326- } ;
319+ } . print_def_path ( def_id , & [ ] ) . unwrap ( ) ;
327320
328321 if instance. is_vtable_shim ( ) {
329322 let _ = printer. write_str ( "{{vtable-shim}}" ) ;
330323 }
331324
332- printer. path . finish ( hash)
325+ Symbol :: intern ( & printer. path . finish ( hash) ) . as_interned_str ( )
333326}
334327
335328// Follow C++ namespace-mangling style, see
@@ -361,22 +354,6 @@ impl SymbolPath {
361354 result
362355 }
363356
364- fn from_interned ( symbol : ty:: SymbolName ) -> Self {
365- let mut result = SymbolPath {
366- result : String :: with_capacity ( 64 ) ,
367- temp_buf : String :: with_capacity ( 16 ) ,
368- } ;
369- result. result . push_str ( & symbol. as_str ( ) ) ;
370- result
371- }
372-
373- fn into_interned ( mut self ) -> ty:: SymbolName {
374- self . finalize_pending_component ( ) ;
375- ty:: SymbolName {
376- name : Symbol :: intern ( & self . result ) . as_interned_str ( ) ,
377- }
378- }
379-
380357 fn finalize_pending_component ( & mut self ) {
381358 if !self . temp_buf . is_empty ( ) {
382359 let _ = write ! ( self . result, "{}{}" , self . temp_buf. len( ) , self . temp_buf) ;
0 commit comments