Skip to content

Commit a10089a

Browse files
committed
Translate drop glue shim
1 parent d49b50f commit a10089a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

frontend/exporter/src/types/new/full_def.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,27 @@ pub enum FullDefKind<Body> {
188188
param_env: ParamEnv,
189189
#[value(s.base().tcx.adt_def(s.owner_id()).sinto(s))]
190190
def: AdtDef,
191+
/// MIR body of the builtin `drop` impl.
192+
#[value(drop_glue_shim(s.base().tcx, s.owner_id()).and_then(|body| Body::from_mir(s, body)))]
193+
drop_glue: Option<Body>,
191194
},
192195
Union {
193196
#[value(get_param_env(s, s.owner_id()))]
194197
param_env: ParamEnv,
195198
#[value(s.base().tcx.adt_def(s.owner_id()).sinto(s))]
196199
def: AdtDef,
200+
/// MIR body of the builtin `drop` impl.
201+
#[value(drop_glue_shim(s.base().tcx, s.owner_id()).and_then(|body| Body::from_mir(s, body)))]
202+
drop_glue: Option<Body>,
197203
},
198204
Enum {
199205
#[value(get_param_env(s, s.owner_id()))]
200206
param_env: ParamEnv,
201207
#[value(s.base().tcx.adt_def(s.owner_id()).sinto(s))]
202208
def: AdtDef,
209+
/// MIR body of the builtin `drop` impl.
210+
#[value(drop_glue_shim(s.base().tcx, s.owner_id()).and_then(|body| Body::from_mir(s, body)))]
211+
drop_glue: Option<Body>,
203212
},
204213
/// Type alias: `type Foo = Bar;`
205214
TyAlias {
@@ -359,6 +368,9 @@ pub enum FullDefKind<Body> {
359368
opt_body.and_then(|body| Body::from_mir(s, body))
360369
})]
361370
once_shim: Option<Body>,
371+
/// MIR body of the builtin `drop` impl.
372+
#[value(drop_glue_shim(s.base().tcx, s.owner_id()).and_then(|body| Body::from_mir(s, body)))]
373+
drop_glue: Option<Body>,
362374
},
363375

364376
// Constants
@@ -947,6 +959,20 @@ fn closure_once_shim<'tcx>(
947959
Some(mir)
948960
}
949961

962+
#[cfg(feature = "rustc")]
963+
fn drop_glue_shim<'tcx>(tcx: ty::TyCtxt<'tcx>, def_id: RDefId) -> Option<mir::Body<'tcx>> {
964+
let drop_in_place = tcx.require_lang_item(rustc_hir::LangItem::DropInPlace, None);
965+
if !tcx.generics_of(def_id).is_empty() {
966+
// Hack: layout code panics if it can't fully normalize types, which can happen e.g. with a
967+
// trait associated type. For now we only translate the glue for monomorphic types.
968+
return None;
969+
}
970+
let ty = tcx.type_of(def_id).instantiate_identity();
971+
let instance_kind = ty::InstanceKind::DropGlue(drop_in_place, Some(ty));
972+
let mir = tcx.instance_mir(instance_kind).clone();
973+
Some(mir)
974+
}
975+
950976
#[cfg(feature = "rustc")]
951977
fn get_param_env<'tcx, S: BaseState<'tcx>>(s: &S, def_id: RDefId) -> ParamEnv {
952978
let tcx = s.base().tcx;

0 commit comments

Comments
 (0)