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