@@ -29,10 +29,15 @@ pub enum InstanceDef<'tcx> {
2929
3030 /// `fn()` pointer where the function itself cannot be turned into a pointer.
3131 ///
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).
3641 ReifyShim ( DefId ) ,
3742
3843 /// `<fn() as FnTrait>::call_*`
@@ -194,7 +199,7 @@ impl<'tcx> fmt::Display for Instance<'tcx> {
194199 write ! ( f, " - intrinsic" )
195200 }
196201 InstanceDef :: Virtual ( _, num) => {
197- write ! ( f, " - shim( #{}) " , num)
202+ write ! ( f, " - virtual #{}" , num)
198203 }
199204 InstanceDef :: FnPtrShim ( _, ty) => {
200205 write ! ( f, " - shim({:?})" , ty)
@@ -309,20 +314,23 @@ impl<'tcx> Instance<'tcx> {
309314 substs : SubstsRef < ' tcx > ,
310315 ) -> Option < Instance < ' tcx > > {
311316 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| {
313318 let has_track_caller = |def| tcx. codegen_fn_attrs ( def) . flags
314319 . contains ( CodegenFnAttrFlags :: TRACK_CALLER ) ;
315320
316321 match resolved. def {
317322 InstanceDef :: Item ( def_id) if has_track_caller ( def_id) => {
318323 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+ _ => { }
325331 }
332+
333+ resolved
326334 } )
327335 }
328336
0 commit comments