@@ -29,10 +29,15 @@ pub enum InstanceDef<'tcx> {
29
29
30
30
/// `fn()` pointer where the function itself cannot be turned into a pointer.
31
31
///
32
- /// One example in the compiler today is functions annotated with `#[track_caller]`, which
33
- /// must have their implicit caller location argument populated for a call. Because this is a
34
- /// required part of the function's ABI but can't be tracked as a property of the function
35
- /// pointer, we create a single "caller location" at the site where the function is reified.
32
+ /// One example is `<dyn Trait as Trait>::fn`, where the shim contains
33
+ /// a virtual call, which codegen supports only via a direct call to the
34
+ /// `<dyn Trait as Trait>::fn` instance (an `InstanceDef::Virtual`).
35
+ ///
36
+ /// Another example is functions annotated with `#[track_caller]`, which
37
+ /// must have their implicit caller location argument populated for a call.
38
+ /// Because this is a required part of the function's ABI but can't be tracked
39
+ /// as a property of the function pointer, we use a single "caller location"
40
+ /// (the definition of the function itself).
36
41
ReifyShim ( DefId ) ,
37
42
38
43
/// `<fn() as FnTrait>::call_*`
@@ -194,7 +199,7 @@ impl<'tcx> fmt::Display for Instance<'tcx> {
194
199
write ! ( f, " - intrinsic" )
195
200
}
196
201
InstanceDef :: Virtual ( _, num) => {
197
- write ! ( f, " - shim( #{}) " , num)
202
+ write ! ( f, " - virtual #{}" , num)
198
203
}
199
204
InstanceDef :: FnPtrShim ( _, ty) => {
200
205
write ! ( f, " - shim({:?})" , ty)
@@ -309,20 +314,23 @@ impl<'tcx> Instance<'tcx> {
309
314
substs : SubstsRef < ' tcx > ,
310
315
) -> Option < Instance < ' tcx > > {
311
316
debug ! ( "resolve(def_id={:?}, substs={:?})" , def_id, substs) ;
312
- Instance :: resolve ( tcx, param_env, def_id, substs) . map ( |resolved| {
317
+ Instance :: resolve ( tcx, param_env, def_id, substs) . map ( |mut resolved| {
313
318
let has_track_caller = |def| tcx. codegen_fn_attrs ( def) . flags
314
319
. contains ( CodegenFnAttrFlags :: TRACK_CALLER ) ;
315
320
316
321
match resolved. def {
317
322
InstanceDef :: Item ( def_id) if has_track_caller ( def_id) => {
318
323
debug ! ( " => fn pointer created for function with #[track_caller]" ) ;
319
- Instance {
320
- def : InstanceDef :: ReifyShim ( def_id) ,
321
- substs,
322
- }
323
- } ,
324
- _ => resolved,
324
+ resolved. def = InstanceDef :: ReifyShim ( def_id) ;
325
+ }
326
+ InstanceDef :: Virtual ( def_id, _) => {
327
+ debug ! ( " => fn pointer created for virtual call" ) ;
328
+ resolved. def = InstanceDef :: ReifyShim ( def_id) ;
329
+ }
330
+ _ => { }
325
331
}
332
+
333
+ resolved
326
334
} )
327
335
}
328
336
0 commit comments