@@ -28,17 +28,22 @@ pub enum InstanceDef<'tcx> {
2828
2929 /// `fn()` pointer where the function itself cannot be turned into a pointer.
3030 ///
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).
3540 ReifyShim ( DefId ) ,
3641
3742 /// `<fn() as FnTrait>::call_*`
3843 /// `DefId` is `FnTrait::call_*`
3944 FnPtrShim ( DefId , Ty < ' tcx > ) ,
4045
41- /// `<Trait as Trait>::fn`
46+ /// `<dyn Trait as Trait>::fn`
4247 Virtual ( DefId , usize ) ,
4348
4449 /// `<[mut closure] as FnOnce>::call_once`
@@ -193,7 +198,7 @@ impl<'tcx> fmt::Display for Instance<'tcx> {
193198 write ! ( f, " - intrinsic" )
194199 }
195200 InstanceDef :: Virtual ( _, num) => {
196- write ! ( f, " - shim( #{}) " , num)
201+ write ! ( f, " - virtual #{}" , num)
197202 }
198203 InstanceDef :: FnPtrShim ( _, ty) => {
199204 write ! ( f, " - shim({:?})" , ty)
@@ -308,20 +313,23 @@ impl<'tcx> Instance<'tcx> {
308313 substs : SubstsRef < ' tcx > ,
309314 ) -> Option < Instance < ' tcx > > {
310315 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| {
312317 let has_track_caller = |def| tcx. codegen_fn_attrs ( def) . flags
313318 . contains ( CodegenFnAttrFlags :: TRACK_CALLER ) ;
314319
315320 match resolved. def {
316321 InstanceDef :: Item ( def_id) if has_track_caller ( def_id) => {
317322 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+ _ => { }
324330 }
331+
332+ resolved
325333 } )
326334 }
327335
0 commit comments