@@ -101,7 +101,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
101
101
use rustc_mir:: monomorphize:: item:: { InstantiationMode , MonoItem , MonoItemExt } ;
102
102
use rustc_mir:: monomorphize:: Instance ;
103
103
104
- use syntax_pos:: symbol:: Symbol ;
104
+ use syntax_pos:: symbol:: { Symbol , InternedString } ;
105
105
106
106
use log:: debug;
107
107
@@ -110,7 +110,6 @@ use std::mem::{self, discriminant};
110
110
111
111
pub fn provide ( providers : & mut Providers < ' _ > ) {
112
112
* providers = Providers {
113
- def_symbol_name,
114
113
symbol_name,
115
114
116
115
..* providers
@@ -222,21 +221,13 @@ fn get_symbol_hash<'a, 'tcx>(
222
221
hasher. finish ( )
223
222
}
224
223
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 {
234
225
ty:: SymbolName {
235
- name : Symbol :: intern ( & compute_symbol_name ( tcx, instance) ) . as_interned_str ( ) ,
226
+ name : compute_symbol_name ( tcx, instance) ,
236
227
}
237
228
}
238
229
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 {
240
231
let def_id = instance. def_id ( ) ;
241
232
let substs = instance. substs ;
242
233
@@ -247,11 +238,13 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
247
238
if def_id. is_local ( ) {
248
239
if tcx. plugin_registrar_fn ( LOCAL_CRATE ) == Some ( def_id) {
249
240
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 ( ) ;
251
243
}
252
244
if tcx. proc_macro_decls_static ( LOCAL_CRATE ) == Some ( def_id) {
253
245
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 ( ) ;
255
248
}
256
249
}
257
250
@@ -268,20 +261,20 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
268
261
let attrs = tcx. codegen_fn_attrs ( def_id) ;
269
262
if is_foreign {
270
263
if let Some ( name) = attrs. link_name {
271
- return name. to_string ( ) ;
264
+ return name. as_interned_str ( ) ;
272
265
}
273
266
// Don't mangle foreign items.
274
- return tcx. item_name ( def_id) . to_string ( ) ;
267
+ return tcx. item_name ( def_id) ;
275
268
}
276
269
277
270
if let Some ( name) = & attrs. export_name {
278
271
// Use provided name
279
- return name. to_string ( ) ;
272
+ return name. as_interned_str ( ) ;
280
273
}
281
274
282
275
if attrs. flags . contains ( CodegenFnAttrFlags :: NO_MANGLE ) {
283
276
// Don't mangle
284
- return tcx. item_name ( def_id) . to_string ( ) ;
277
+ return tcx. item_name ( def_id) ;
285
278
}
286
279
287
280
// 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
321
314
322
315
let mut printer = SymbolPrinter {
323
316
tcx,
324
- path : SymbolPath :: from_interned ( tcx . def_symbol_name ( def_id ) ) ,
317
+ path : SymbolPath :: new ( ) ,
325
318
keep_within_component : false ,
326
- } ;
319
+ } . print_def_path ( def_id , & [ ] ) . unwrap ( ) ;
327
320
328
321
if instance. is_vtable_shim ( ) {
329
322
let _ = printer. write_str ( "{{vtable-shim}}" ) ;
330
323
}
331
324
332
- printer. path . finish ( hash)
325
+ Symbol :: intern ( & printer. path . finish ( hash) ) . as_interned_str ( )
333
326
}
334
327
335
328
// Follow C++ namespace-mangling style, see
@@ -361,22 +354,6 @@ impl SymbolPath {
361
354
result
362
355
}
363
356
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
-
380
357
fn finalize_pending_component ( & mut self ) {
381
358
if !self . temp_buf . is_empty ( ) {
382
359
let _ = write ! ( self . result, "{}{}" , self . temp_buf. len( ) , self . temp_buf) ;
0 commit comments