mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
interpret, codegen: tweak some comments and checks regarding Box with custom allocator
This commit is contained in:
parent
fa72f0763d
commit
d0aedfbb90
@ -216,6 +216,8 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
|
|||||||
// need to make sure that we don't break existing debuginfo consumers
|
// need to make sure that we don't break existing debuginfo consumers
|
||||||
// by doing that (at least not without a warning period).
|
// by doing that (at least not without a warning period).
|
||||||
let layout_type = if ptr_type.is_box() {
|
let layout_type = if ptr_type.is_box() {
|
||||||
|
// The assertion at the start of this function ensures we have a ZST allocator.
|
||||||
|
// We'll make debuginfo "skip" all ZST allocators, not just the default allocator.
|
||||||
Ty::new_mut_ptr(cx.tcx, pointee_type)
|
Ty::new_mut_ptr(cx.tcx, pointee_type)
|
||||||
} else {
|
} else {
|
||||||
ptr_type
|
ptr_type
|
||||||
|
@ -438,14 +438,16 @@ where
|
|||||||
&self,
|
&self,
|
||||||
src: &impl Readable<'tcx, M::Provenance>,
|
src: &impl Readable<'tcx, M::Provenance>,
|
||||||
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
|
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
|
||||||
|
if src.layout().ty.is_box() {
|
||||||
|
// Derefer should have removed all Box derefs.
|
||||||
|
// Some `Box` are not immediates (if they have a custom allocator)
|
||||||
|
// so the code below would fail.
|
||||||
|
bug!("dereferencing {}", src.layout().ty);
|
||||||
|
}
|
||||||
|
|
||||||
let val = self.read_immediate(src)?;
|
let val = self.read_immediate(src)?;
|
||||||
trace!("deref to {} on {:?}", val.layout.ty, *val);
|
trace!("deref to {} on {:?}", val.layout.ty, *val);
|
||||||
|
|
||||||
if val.layout.ty.is_box() {
|
|
||||||
// Derefer should have removed all Box derefs
|
|
||||||
bug!("dereferencing {}", val.layout.ty);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mplace = self.ref_to_mplace(&val)?;
|
let mplace = self.ref_to_mplace(&val)?;
|
||||||
Ok(mplace)
|
Ok(mplace)
|
||||||
}
|
}
|
||||||
|
@ -1149,7 +1149,10 @@ impl<'tcx> Ty<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tests whether this is a Box using the global allocator.
|
/// Tests whether this is a Box definitely using the global allocator.
|
||||||
|
///
|
||||||
|
/// If the allocator is still generic, the answer is `false`, but it may
|
||||||
|
/// later turn out that it does use the global allocator.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_box_global(self, tcx: TyCtxt<'tcx>) -> bool {
|
pub fn is_box_global(self, tcx: TyCtxt<'tcx>) -> bool {
|
||||||
match self.kind() {
|
match self.kind() {
|
||||||
|
@ -137,6 +137,8 @@ impl<'tcx> MirPass<'tcx> for AddRetag {
|
|||||||
// Using `is_box_global` here is a bit sketchy: if this code is
|
// Using `is_box_global` here is a bit sketchy: if this code is
|
||||||
// generic over the allocator, we'll not add a retag! This is a hack
|
// generic over the allocator, we'll not add a retag! This is a hack
|
||||||
// to make Stacked Borrows compatible with custom allocator code.
|
// to make Stacked Borrows compatible with custom allocator code.
|
||||||
|
// It means the raw pointer inherits the tag of the box, which mostly works
|
||||||
|
// but can sometimes lead to unexpected aliasing errors.
|
||||||
// Long-term, we'll want to move to an aliasing model where "cast to
|
// Long-term, we'll want to move to an aliasing model where "cast to
|
||||||
// raw pointer" is a complete NOP, and then this will no longer be
|
// raw pointer" is a complete NOP, and then this will no longer be
|
||||||
// an issue.
|
// an issue.
|
||||||
|
Loading…
Reference in New Issue
Block a user