@@ -106,6 +106,8 @@ use syntax_pos::symbol::Symbol;
106
106
use std:: fmt:: { self , Write } ;
107
107
use std:: mem:: { self , discriminant} ;
108
108
109
+ mod new;
110
+
109
111
pub fn provide ( providers : & mut Providers ) {
110
112
* providers = Providers {
111
113
def_symbol_name,
@@ -118,9 +120,6 @@ pub fn provide(providers: &mut Providers) {
118
120
fn get_symbol_hash < ' a , ' tcx > (
119
121
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
120
122
121
- // the DefId of the item this name is for
122
- def_id : DefId ,
123
-
124
123
// instance this name will be for
125
124
instance : Instance < ' tcx > ,
126
125
@@ -129,11 +128,9 @@ fn get_symbol_hash<'a, 'tcx>(
129
128
// included in the hash as a kind of
130
129
// safeguard.
131
130
item_type : Ty < ' tcx > ,
132
-
133
- // values for generic type parameters,
134
- // if any.
135
- substs : & ' tcx Substs < ' tcx > ,
136
131
) -> u64 {
132
+ let def_id = instance. def_id ( ) ;
133
+ let substs = instance. substs ;
137
134
debug ! (
138
135
"get_symbol_hash(def_id={:?}, parameters={:?})" ,
139
136
def_id, substs
@@ -170,42 +167,7 @@ fn get_symbol_hash<'a, 'tcx>(
170
167
assert ! ( !substs. needs_subst( ) ) ;
171
168
substs. hash_stable ( & mut hcx, & mut hasher) ;
172
169
173
- let is_generic = substs. types ( ) . next ( ) . is_some ( ) ;
174
- let avoid_cross_crate_conflicts =
175
- // If this is an instance of a generic function, we also hash in
176
- // the ID of the instantiating crate. This avoids symbol conflicts
177
- // in case the same instances is emitted in two crates of the same
178
- // project.
179
- is_generic ||
180
-
181
- // If we're dealing with an instance of a function that's inlined from
182
- // another crate but we're marking it as globally shared to our
183
- // compliation (aka we're not making an internal copy in each of our
184
- // codegen units) then this symbol may become an exported (but hidden
185
- // visibility) symbol. This means that multiple crates may do the same
186
- // and we want to be sure to avoid any symbol conflicts here.
187
- match MonoItem :: Fn ( instance) . instantiation_mode ( tcx) {
188
- InstantiationMode :: GloballyShared { may_conflict : true } => true ,
189
- _ => false ,
190
- } ;
191
-
192
- if avoid_cross_crate_conflicts {
193
- let instantiating_crate = if is_generic {
194
- if !def_id. is_local ( ) && tcx. sess . opts . share_generics ( ) {
195
- // If we are re-using a monomorphization from another crate,
196
- // we have to compute the symbol hash accordingly.
197
- let upstream_monomorphizations = tcx. upstream_monomorphizations_for ( def_id) ;
198
-
199
- upstream_monomorphizations
200
- . and_then ( |monos| monos. get ( & substs) . cloned ( ) )
201
- . unwrap_or ( LOCAL_CRATE )
202
- } else {
203
- LOCAL_CRATE
204
- }
205
- } else {
206
- LOCAL_CRATE
207
- } ;
208
-
170
+ if let Some ( instantiating_crate) = instantiating_crate ( tcx, instance) {
209
171
( & tcx. original_crate_name ( instantiating_crate) . as_str ( ) [ ..] )
210
172
. hash_stable ( & mut hcx, & mut hasher) ;
211
173
( & tcx. crate_disambiguator ( instantiating_crate) ) . hash_stable ( & mut hcx, & mut hasher) ;
@@ -220,6 +182,53 @@ fn get_symbol_hash<'a, 'tcx>(
220
182
hasher. finish ( )
221
183
}
222
184
185
+ fn instantiating_crate (
186
+ tcx : TyCtxt < ' _ , ' tcx , ' tcx > ,
187
+ instance : Instance < ' tcx > ,
188
+ ) -> Option < CrateNum > {
189
+ let def_id = instance. def_id ( ) ;
190
+ let substs = instance. substs ;
191
+
192
+ let is_generic = substs. types ( ) . next ( ) . is_some ( ) ;
193
+ let avoid_cross_crate_conflicts =
194
+ // If this is an instance of a generic function, we also hash in
195
+ // the ID of the instantiating crate. This avoids symbol conflicts
196
+ // in case the same instances is emitted in two crates of the same
197
+ // project.
198
+ is_generic ||
199
+
200
+ // If we're dealing with an instance of a function that's inlined from
201
+ // another crate but we're marking it as globally shared to our
202
+ // compliation (aka we're not making an internal copy in each of our
203
+ // codegen units) then this symbol may become an exported (but hidden
204
+ // visibility) symbol. This means that multiple crates may do the same
205
+ // and we want to be sure to avoid any symbol conflicts here.
206
+ match MonoItem :: Fn ( instance) . instantiation_mode ( tcx) {
207
+ InstantiationMode :: GloballyShared { may_conflict : true } => true ,
208
+ _ => false ,
209
+ } ;
210
+
211
+ if avoid_cross_crate_conflicts {
212
+ Some ( if is_generic {
213
+ if !def_id. is_local ( ) && tcx. sess . opts . share_generics ( ) {
214
+ // If we are re-using a monomorphization from another crate,
215
+ // we have to compute the symbol hash accordingly.
216
+ let upstream_monomorphizations = tcx. upstream_monomorphizations_for ( def_id) ;
217
+
218
+ upstream_monomorphizations
219
+ . and_then ( |monos| monos. get ( & substs) . cloned ( ) )
220
+ . unwrap_or ( LOCAL_CRATE )
221
+ } else {
222
+ LOCAL_CRATE
223
+ }
224
+ } else {
225
+ LOCAL_CRATE
226
+ } )
227
+ } else {
228
+ None
229
+ }
230
+ }
231
+
223
232
fn def_symbol_name < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , def_id : DefId ) -> ty:: SymbolName {
224
233
SymbolPrinter {
225
234
tcx,
@@ -282,6 +291,12 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
282
291
return tcx. item_name ( def_id) . to_string ( ) ;
283
292
}
284
293
294
+ compute_mangled_symbol_name ( tcx, instance)
295
+ }
296
+
297
+ fn compute_mangled_symbol_name ( tcx : TyCtxt < ' _ , ' tcx , ' tcx > , instance : Instance < ' tcx > ) -> String {
298
+ let def_id = instance. def_id ( ) ;
299
+
285
300
// We want to compute the "type" of this item. Unfortunately, some
286
301
// kinds of items (e.g., closures) don't have an entry in the
287
302
// item-type array. So walk back up the find the closest parent
@@ -315,7 +330,7 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
315
330
// and should not matter anyhow.
316
331
let instance_ty = tcx. erase_regions ( & instance_ty) ;
317
332
318
- let hash = get_symbol_hash ( tcx, def_id , instance, instance_ty, substs ) ;
333
+ let hash = get_symbol_hash ( tcx, instance, instance_ty) ;
319
334
320
335
let mut buf = SymbolPath :: from_interned ( tcx. def_symbol_name ( def_id) ) ;
321
336
0 commit comments