Skip to content

Commit c352eda

Browse files
committed
Add InstanceDef::ReifyShim for track_caller functions.
1 parent 0a87757 commit c352eda

File tree

8 files changed

+27
-1
lines changed

8 files changed

+27
-1
lines changed

src/librustc/mir/mono.rs

+1
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ impl<'tcx> CodegenUnit<'tcx> {
386386
tcx.hir().as_local_hir_id(def_id)
387387
}
388388
InstanceDef::VtableShim(..) |
389+
InstanceDef::ReifyShim(..) |
389390
InstanceDef::Intrinsic(..) |
390391
InstanceDef::FnPtrShim(..) |
391392
InstanceDef::Virtual(..) |

src/librustc/ty/instance.rs

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ pub enum InstanceDef<'tcx> {
2525
/// `<T as Trait>::method` where `method` receives unsizeable `self: Self`.
2626
VtableShim(DefId),
2727

28+
/// `fn()` where the function is annotated with `#[track_caller]`.
29+
ReifyShim(DefId),
30+
2831
/// `<fn() as FnTrait>::call_*`
2932
/// `DefId` is `FnTrait::call_*`
3033
FnPtrShim(DefId, Ty<'tcx>),
@@ -123,6 +126,7 @@ impl<'tcx> InstanceDef<'tcx> {
123126
match *self {
124127
InstanceDef::Item(def_id) |
125128
InstanceDef::VtableShim(def_id) |
129+
InstanceDef::ReifyShim(def_id) |
126130
InstanceDef::FnPtrShim(def_id, _) |
127131
InstanceDef::Virtual(def_id, _) |
128132
InstanceDef::Intrinsic(def_id, ) |
@@ -178,6 +182,9 @@ impl<'tcx> fmt::Display for Instance<'tcx> {
178182
InstanceDef::VtableShim(_) => {
179183
write!(f, " - shim(vtable)")
180184
}
185+
InstanceDef::ReifyShim(_) => {
186+
write!(f, " - shim(reify)")
187+
}
181188
InstanceDef::Intrinsic(_) => {
182189
write!(f, " - intrinsic")
183190
}

src/librustc/ty/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3026,6 +3026,7 @@ impl<'tcx> TyCtxt<'tcx> {
30263026
self.optimized_mir(did)
30273027
}
30283028
ty::InstanceDef::VtableShim(..) |
3029+
ty::InstanceDef::ReifyShim(..) |
30293030
ty::InstanceDef::Intrinsic(..) |
30303031
ty::InstanceDef::FnPtrShim(..) |
30313032
ty::InstanceDef::Virtual(..) |

src/librustc/ty/structural_impls.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::InstanceDef<'a> {
761761
Some(ty::InstanceDef::Item(def_id)),
762762
ty::InstanceDef::VtableShim(def_id) =>
763763
Some(ty::InstanceDef::VtableShim(def_id)),
764+
ty::InstanceDef::ReifyShim(def_id) =>
765+
Some(ty::InstanceDef::ReifyShim(def_id)),
764766
ty::InstanceDef::Intrinsic(def_id) =>
765767
Some(ty::InstanceDef::Intrinsic(def_id)),
766768
ty::InstanceDef::FnPtrShim(def_id, ref ty) =>
@@ -966,6 +968,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> {
966968
def: match self.def {
967969
Item(did) => Item(did.fold_with(folder)),
968970
VtableShim(did) => VtableShim(did.fold_with(folder)),
971+
ReifyShim(did) => ReifyShim(did.fold_with(folder)),
969972
Intrinsic(did) => Intrinsic(did.fold_with(folder)),
970973
FnPtrShim(did, ty) => FnPtrShim(
971974
did.fold_with(folder),
@@ -994,7 +997,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> {
994997
use crate::ty::InstanceDef::*;
995998
self.substs.visit_with(visitor) ||
996999
match self.def {
997-
Item(did) | VtableShim(did) | Intrinsic(did) | Virtual(did, _) => {
1000+
Item(did) | VtableShim(did) | ReifyShim(did) | Intrinsic(did) | Virtual(did, _) => {
9981001
did.visit_with(visitor)
9991002
},
10001003
FnPtrShim(did, ty) | CloneShim(did, ty) => {

src/librustc_mir/interpret/terminator.rs

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
263263
Ok(())
264264
}
265265
ty::InstanceDef::VtableShim(..) |
266+
ty::InstanceDef::ReifyShim(..) |
266267
ty::InstanceDef::ClosureOnceShim { .. } |
267268
ty::InstanceDef::FnPtrShim(..) |
268269
ty::InstanceDef::DropGlue(..) |

src/librustc_mir/monomorphize/collector.rs

+2
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@ fn visit_instance_use<'tcx>(
740740
}
741741
}
742742
ty::InstanceDef::VtableShim(..) |
743+
ty::InstanceDef::ReifyShim(..) |
743744
ty::InstanceDef::Virtual(..) |
744745
ty::InstanceDef::DropGlue(_, None) => {
745746
// don't need to emit shim if we are calling directly.
@@ -766,6 +767,7 @@ fn should_monomorphize_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: &Instance<'tcx
766767
let def_id = match instance.def {
767768
ty::InstanceDef::Item(def_id) => def_id,
768769
ty::InstanceDef::VtableShim(..) |
770+
ty::InstanceDef::ReifyShim(..) |
769771
ty::InstanceDef::ClosureOnceShim { .. } |
770772
ty::InstanceDef::Virtual(..) |
771773
ty::InstanceDef::FnPtrShim(..) |

src/librustc_mir/monomorphize/partitioning.rs

+2
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ fn mono_item_visibility(
329329

330330
// These are all compiler glue and such, never exported, always hidden.
331331
InstanceDef::VtableShim(..) |
332+
InstanceDef::ReifyShim(..) |
332333
InstanceDef::FnPtrShim(..) |
333334
InstanceDef::Virtual(..) |
334335
InstanceDef::Intrinsic(..) |
@@ -664,6 +665,7 @@ fn characteristic_def_id_of_mono_item<'tcx>(
664665
let def_id = match instance.def {
665666
ty::InstanceDef::Item(def_id) => def_id,
666667
ty::InstanceDef::VtableShim(..) |
668+
ty::InstanceDef::ReifyShim(..) |
667669
ty::InstanceDef::FnPtrShim(..) |
668670
ty::InstanceDef::ClosureOnceShim { .. } |
669671
ty::InstanceDef::Intrinsic(..) |

src/librustc_mir/shim.rs

+9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx
4141
None,
4242
)
4343
}
44+
ty::InstanceDef::ReifyShim(def_id) => {
45+
build_call_shim(
46+
tcx,
47+
def_id,
48+
Adjustment::DerefMove,
49+
CallKind::Direct(def_id),
50+
None,
51+
)
52+
}
4453
ty::InstanceDef::FnPtrShim(def_id, ty) => {
4554
let trait_ = tcx.trait_of_item(def_id).unwrap();
4655
let adjustment = match tcx.lang_items().fn_trait_kind(trait_) {

0 commit comments

Comments
 (0)