@@ -225,9 +225,20 @@ impl<'ll> CodegenCx<'ll, '_> {
225
225
}
226
226
}
227
227
228
+ #[ instrument( level = "debug" , skip( self ) ) ]
228
229
pub ( crate ) fn get_static ( & self , def_id : DefId ) -> & ' ll Value {
229
230
let instance = Instance :: mono ( self . tcx , def_id) ;
231
+ trace ! ( ?instance) ;
232
+ let ty = instance. ty ( self . tcx , ty:: ParamEnv :: reveal_all ( ) ) ;
233
+ trace ! ( ?ty) ;
234
+ let llty = self . layout_of ( ty) . llvm_type ( self ) ;
235
+ self . get_static_inner ( def_id, llty)
236
+ }
237
+
238
+ #[ instrument( level = "debug" , skip( self , llty) ) ]
239
+ pub ( crate ) fn get_static_inner ( & self , def_id : DefId , llty : & ' ll Type ) -> & ' ll Value {
230
240
if let Some ( & g) = self . statics . borrow ( ) . get ( & def_id) {
241
+ trace ! ( "used cached value" ) ;
231
242
return g;
232
243
}
233
244
@@ -239,12 +250,10 @@ impl<'ll> CodegenCx<'ll, '_> {
239
250
statics defined in the same CGU, but did not for `{def_id:?}`"
240
251
) ;
241
252
242
- let ty = instance. ty ( self . tcx , ty:: ParamEnv :: reveal_all ( ) ) ;
243
- let sym = self . tcx . symbol_name ( instance) . name ;
253
+ let sym = self . tcx . symbol_name ( Instance :: mono ( self . tcx , def_id) ) . name ;
244
254
let fn_attrs = self . tcx . codegen_fn_attrs ( def_id) ;
245
255
246
- debug ! ( "get_static: sym={} instance={:?} fn_attrs={:?}" , sym, instance, fn_attrs) ;
247
- let llty = self . layout_of ( ty) . llvm_type ( self ) ;
256
+ debug ! ( ?sym, ?fn_attrs) ;
248
257
249
258
let g = if def_id. is_local ( ) && !self . tcx . is_foreign_item ( def_id) {
250
259
if let Some ( g) = self . get_declared_value ( sym) {
@@ -367,13 +376,14 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
367
376
} ;
368
377
let alloc = alloc. inner ( ) ;
369
378
370
- let g = self . get_static ( def_id) ;
371
-
372
379
let val_llty = self . val_ty ( v) ;
373
380
374
381
let instance = Instance :: mono ( self . tcx , def_id) ;
375
382
let ty = instance. ty ( self . tcx , ty:: ParamEnv :: reveal_all ( ) ) ;
376
383
let llty = self . layout_of ( ty) . llvm_type ( self ) ;
384
+
385
+ let g = self . get_static_inner ( def_id, llty) ;
386
+
377
387
let g = if val_llty == llty {
378
388
g
379
389
} else {
0 commit comments