Skip to content

Commit 713b7e5

Browse files
committed
start handling drop for PreloadMut
1 parent fae2f07 commit 713b7e5

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
591591
bx.ret(llval);
592592
}
593593

594+
fn is_preload_mut_type<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
595+
let ty::Adt(adt_def, _) = ty.kind() else {
596+
return false;
597+
};
598+
599+
Some(adt_def.did()) == tcx.lang_items().preload_mut_type()
600+
}
601+
594602
#[tracing::instrument(level = "trace", skip(self, helper, bx))]
595603
fn codegen_drop_terminator(
596604
&mut self,
@@ -604,6 +612,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
604612
) -> MergingSucc {
605613
let ty = location.ty(self.mir, bx.tcx()).ty;
606614
let ty = self.monomorphize(ty);
615+
616+
if is_preload_mut_type(bx.tcx(), ty) {
617+
let place = self.codegen_place(bx, location.as_ref());
618+
619+
bx.codegen_offload_preload_mut_drop(ty, place);
620+
}
607621
let drop_fn = Instance::resolve_drop_glue(bx.tcx(), ty);
608622

609623
if let ty::InstanceKind::DropGlue(_, None) = drop_fn.def {

compiler/rustc_codegen_ssa/src/traits/intrinsic.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ pub trait IntrinsicCallBuilderMethods<'tcx>: BackendTypes {
3838
is_mut: bool,
3939
);
4040

41+
fn codegen_offload_preload_mut_drop(
42+
&mut self,
43+
preload_ty: Ty<'tcx>,
44+
place: PlaceRef<'tcx, Self::Value>,
45+
);
46+
4147
fn codegen_llvm_intrinsic_call(
4248
&mut self,
4349
instance: ty::Instance<'tcx>,

library/core/src/offload/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,13 @@ pub fn preload<'a, T: ?Sized>(x: &'a T) -> Preload<'a, T> {
3131
pub fn preload_mut<'a, T: ?Sized>(x: &'a mut T) -> PreloadMut<'a, T> {
3232
PreloadMut { cpu_ptr: x as *mut T, _marker: PhantomData }
3333
}
34+
35+
impl<T: ?Sized> Drop for PreloadMut<'_, T> {
36+
fn drop(&mut self) {
37+
// Intentionally empty.
38+
//
39+
// This exists so MIR creates Drop terminators for PreloadMut.
40+
// rustc codegen intercepts those terminators and emits the
41+
// offload return mapper.
42+
}
43+
}

0 commit comments

Comments
 (0)