Fix has_body() and change resolve_drop_in_place() sig
Fixed the `has_body()` function operator. Before that, this function was returning false for all shims. Change resolve_drop_in_place() to also return an instance for empty shims, since they may still be required for vtable construction.
This commit is contained in:
parent
4c00aa3d74
commit
8e81fc0087
@ -19,9 +19,17 @@ impl<'tcx> BodyBuilder<'tcx> {
|
||||
BodyBuilder { tcx, instance }
|
||||
}
|
||||
|
||||
/// Build a stable monomorphic body for a given instance based on the MIR body.
|
||||
///
|
||||
/// Note that we skip instantiation for static and constants. Trying to do so can cause ICE.
|
||||
///
|
||||
/// We do monomorphize non-generic functions to eval unevaluated constants.
|
||||
pub fn build(mut self, tables: &mut Tables<'tcx>) -> stable_mir::mir::Body {
|
||||
let mut body = self.tcx.instance_mir(self.instance.def).clone();
|
||||
if self.tcx.def_kind(self.instance.def_id()).is_fn_like() || !self.instance.args.is_empty()
|
||||
{
|
||||
self.visit_body(&mut body);
|
||||
}
|
||||
body.stable(tables)
|
||||
}
|
||||
|
||||
|
@ -267,15 +267,11 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_drop_in_place(
|
||||
&self,
|
||||
ty: stable_mir::ty::Ty,
|
||||
) -> Option<stable_mir::mir::mono::Instance> {
|
||||
fn resolve_drop_in_place(&self, ty: stable_mir::ty::Ty) -> stable_mir::mir::mono::Instance {
|
||||
let mut tables = self.0.borrow_mut();
|
||||
let internal_ty = ty.internal(&mut *tables);
|
||||
let instance = Instance::resolve_drop_in_place(tables.tcx, internal_ty);
|
||||
matches!(instance.def, ty::InstanceDef::DropGlue(_, Some(_)))
|
||||
.then(|| instance.stable(&mut *tables))
|
||||
instance.stable(&mut *tables)
|
||||
}
|
||||
|
||||
fn resolve_for_fn_ptr(
|
||||
@ -328,9 +324,11 @@ impl<'tcx> Tables<'tcx> {
|
||||
fn has_body(&self, instance: Instance<'tcx>) -> bool {
|
||||
let def_id = instance.def_id();
|
||||
self.tcx.is_mir_available(def_id)
|
||||
&& !matches!(
|
||||
|| !matches!(
|
||||
instance.def,
|
||||
ty::InstanceDef::Virtual(..) | ty::InstanceDef::Intrinsic(..)
|
||||
ty::InstanceDef::Virtual(..)
|
||||
| ty::InstanceDef::Intrinsic(..)
|
||||
| ty::InstanceDef::Item(..)
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -364,15 +362,12 @@ fn new_item_kind(kind: DefKind) -> ItemKind {
|
||||
| DefKind::OpaqueTy
|
||||
| DefKind::Field
|
||||
| DefKind::LifetimeParam
|
||||
| DefKind::Impl { .. }
|
||||
| DefKind::Ctor(_, _)
|
||||
| DefKind::GlobalAsm => {
|
||||
unreachable!("Not a valid item kind: {kind:?}");
|
||||
}
|
||||
DefKind::Closure
|
||||
| DefKind::Coroutine
|
||||
| DefKind::Ctor(_, _)
|
||||
| DefKind::AssocFn
|
||||
| DefKind::Impl { .. }
|
||||
| DefKind::Fn => ItemKind::Fn,
|
||||
DefKind::Closure | DefKind::Coroutine | DefKind::AssocFn | DefKind::Fn => ItemKind::Fn,
|
||||
DefKind::Const | DefKind::InlineConst | DefKind::AssocConst | DefKind::AnonConst => {
|
||||
ItemKind::Const
|
||||
}
|
||||
|
@ -253,7 +253,7 @@ pub trait Context {
|
||||
fn resolve_instance(&self, def: FnDef, args: &GenericArgs) -> Option<Instance>;
|
||||
|
||||
/// Resolve an instance for drop_in_place for the given type.
|
||||
fn resolve_drop_in_place(&self, ty: Ty) -> Option<Instance>;
|
||||
fn resolve_drop_in_place(&self, ty: Ty) -> Instance;
|
||||
|
||||
/// Resolve instance for a function pointer.
|
||||
fn resolve_for_fn_ptr(&self, def: FnDef, args: &GenericArgs) -> Option<Instance>;
|
||||
|
@ -56,8 +56,7 @@ impl Instance {
|
||||
}
|
||||
|
||||
/// Resolve the drop in place for a given type.
|
||||
/// Return `None` if the drop is a no-op.
|
||||
pub fn resolve_drop_in_place(ty: Ty) -> Option<Instance> {
|
||||
pub fn resolve_drop_in_place(ty: Ty) -> Instance {
|
||||
with(|cx| cx.resolve_drop_in_place(ty))
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user