Auto merge of #108096 - matthiaskrgr:rollup-ncexzf6, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #107034 (Migrating rustc_infer to session diagnostics (part 4)) - #107972 (Fix unintentional UB in ui tests) - #108010 (Make `InferCtxt::can_eq` and `InferCtxt::can_sub` return booleans) - #108021 (make x look for x.py if shell script does not exist) - #108047 (Use `target` instead of `machine` for mir interpreter integer handling.) - #108049 (Don't suggest `#[doc(hidden)]` trait methods with matching return type) - #108066 (Better names for illegal impl trait positions) - #108076 (rustdoc: Use more let chain) - #108088 (clarify correctness of `black_box`) - #108094 (Demonstrate I/O in File examples) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
dc7a676778
109 changed files with 1126 additions and 784 deletions
|
@ -186,7 +186,7 @@ pub(super) fn op_to_const<'tcx>(
|
|||
0,
|
||||
),
|
||||
};
|
||||
let len = b.to_machine_usize(ecx).unwrap();
|
||||
let len = b.to_target_usize(ecx).unwrap();
|
||||
let start = start.try_into().unwrap();
|
||||
let len: usize = len.try_into().unwrap();
|
||||
ConstValue::Slice { data, start, end: start + len }
|
||||
|
|
|
@ -244,7 +244,7 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> {
|
|||
assert_eq!(args.len(), 2);
|
||||
|
||||
let ptr = self.read_pointer(&args[0])?;
|
||||
let target_align = self.read_scalar(&args[1])?.to_machine_usize(self)?;
|
||||
let target_align = self.read_scalar(&args[1])?.to_target_usize(self)?;
|
||||
|
||||
if !target_align.is_power_of_two() {
|
||||
throw_ub_format!("`align_offset` called with non-power-of-two align: {}", target_align);
|
||||
|
@ -276,7 +276,7 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> {
|
|||
Ok(ControlFlow::Break(()))
|
||||
} else {
|
||||
// Not alignable in const, return `usize::MAX`.
|
||||
let usize_max = Scalar::from_machine_usize(self.machine_usize_max(), self);
|
||||
let usize_max = Scalar::from_target_usize(self.target_usize_max(), self);
|
||||
self.write_scalar(usize_max, dest)?;
|
||||
self.return_to_block(ret)?;
|
||||
Ok(ControlFlow::Break(()))
|
||||
|
@ -470,8 +470,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
|
|||
ecx.write_scalar(Scalar::from_u8(cmp), dest)?;
|
||||
}
|
||||
sym::const_allocate => {
|
||||
let size = ecx.read_scalar(&args[0])?.to_machine_usize(ecx)?;
|
||||
let align = ecx.read_scalar(&args[1])?.to_machine_usize(ecx)?;
|
||||
let size = ecx.read_scalar(&args[0])?.to_target_usize(ecx)?;
|
||||
let align = ecx.read_scalar(&args[1])?.to_target_usize(ecx)?;
|
||||
|
||||
let align = match Align::from_bytes(align) {
|
||||
Ok(a) => a,
|
||||
|
@ -487,8 +487,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
|
|||
}
|
||||
sym::const_deallocate => {
|
||||
let ptr = ecx.read_pointer(&args[0])?;
|
||||
let size = ecx.read_scalar(&args[1])?.to_machine_usize(ecx)?;
|
||||
let align = ecx.read_scalar(&args[2])?.to_machine_usize(ecx)?;
|
||||
let size = ecx.read_scalar(&args[1])?.to_target_usize(ecx)?;
|
||||
let align = ecx.read_scalar(&args[2])?.to_target_usize(ecx)?;
|
||||
|
||||
let size = Size::from_bytes(size);
|
||||
let align = match Align::from_bytes(align) {
|
||||
|
|
|
@ -155,7 +155,7 @@ pub(crate) fn deref_mir_constant<'tcx>(
|
|||
// In case of unsized types, figure out the real type behind.
|
||||
MemPlaceMeta::Meta(scalar) => match mplace.layout.ty.kind() {
|
||||
ty::Str => bug!("there's no sized equivalent of a `str`"),
|
||||
ty::Slice(elem_ty) => tcx.mk_array(*elem_ty, scalar.to_machine_usize(&tcx).unwrap()),
|
||||
ty::Slice(elem_ty) => tcx.mk_array(*elem_ty, scalar.to_target_usize(&tcx).unwrap()),
|
||||
_ => bug!(
|
||||
"type {} should not have metadata, but had {:?}",
|
||||
mplace.layout.ty,
|
||||
|
|
|
@ -239,7 +239,7 @@ fn create_pointee_place<'tcx>(
|
|||
MPlaceTy::from_aligned_ptr_with_meta(
|
||||
ptr.into(),
|
||||
layout,
|
||||
MemPlaceMeta::Meta(Scalar::from_machine_usize(num_elems as u64, &tcx)),
|
||||
MemPlaceMeta::Meta(Scalar::from_target_usize(num_elems as u64, &tcx)),
|
||||
)
|
||||
} else {
|
||||
create_mplace_from_layout(ecx, ty)
|
||||
|
@ -355,7 +355,7 @@ fn valtree_into_mplace<'tcx>(
|
|||
let imm = match inner_ty.kind() {
|
||||
ty::Slice(_) | ty::Str => {
|
||||
let len = valtree.unwrap_branch().len();
|
||||
let len_scalar = Scalar::from_machine_usize(len as u64, &tcx);
|
||||
let len_scalar = Scalar::from_target_usize(len as u64, &tcx);
|
||||
|
||||
Immediate::ScalarPair(
|
||||
Scalar::from_maybe_pointer((*pointee_place).ptr, &tcx),
|
||||
|
@ -426,7 +426,7 @@ fn valtree_into_mplace<'tcx>(
|
|||
place
|
||||
.offset_with_meta(
|
||||
offset,
|
||||
MemPlaceMeta::Meta(Scalar::from_machine_usize(
|
||||
MemPlaceMeta::Meta(Scalar::from_target_usize(
|
||||
num_elems as u64,
|
||||
&tcx,
|
||||
)),
|
||||
|
|
|
@ -231,7 +231,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
// First cast to usize.
|
||||
let scalar = src.to_scalar();
|
||||
let addr = self.cast_from_int_like(scalar, src.layout, self.tcx.types.usize)?;
|
||||
let addr = addr.to_machine_usize(self)?;
|
||||
let addr = addr.to_target_usize(self)?;
|
||||
|
||||
// Then turn address into pointer.
|
||||
let ptr = M::ptr_from_addr_cast(&self, addr)?;
|
||||
|
|
|
@ -639,7 +639,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
}
|
||||
|
||||
ty::Slice(_) | ty::Str => {
|
||||
let len = metadata.unwrap_meta().to_machine_usize(self)?;
|
||||
let len = metadata.unwrap_meta().to_target_usize(self)?;
|
||||
let elem = layout.field(self, 0);
|
||||
|
||||
// Make sure the slice is not too big.
|
||||
|
|
|
@ -71,7 +71,7 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>(
|
|||
sym::pref_align_of => {
|
||||
// Correctly handles non-monomorphic calls, so there is no need for ensure_monomorphic_enough.
|
||||
let layout = tcx.layout_of(param_env.and(tp_ty)).map_err(|e| err_inval!(Layout(e)))?;
|
||||
ConstValue::from_machine_usize(layout.align.pref.bytes(), &tcx)
|
||||
ConstValue::from_target_usize(layout.align.pref.bytes(), &tcx)
|
||||
}
|
||||
sym::type_id => {
|
||||
ensure_monomorphic_enough(tcx, tp_ty)?;
|
||||
|
@ -79,7 +79,7 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>(
|
|||
}
|
||||
sym::variant_count => match tp_ty.kind() {
|
||||
// Correctly handles non-monomorphic calls, so there is no need for ensure_monomorphic_enough.
|
||||
ty::Adt(adt, _) => ConstValue::from_machine_usize(adt.variants().len() as u64, &tcx),
|
||||
ty::Adt(adt, _) => ConstValue::from_target_usize(adt.variants().len() as u64, &tcx),
|
||||
ty::Alias(..) | ty::Param(_) | ty::Placeholder(_) | ty::Infer(_) => {
|
||||
throw_inval!(TooGeneric)
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>(
|
|||
| ty::GeneratorWitnessMIR(_, _)
|
||||
| ty::Never
|
||||
| ty::Tuple(_)
|
||||
| ty::Error(_) => ConstValue::from_machine_usize(0u64, &tcx),
|
||||
| ty::Error(_) => ConstValue::from_target_usize(0u64, &tcx),
|
||||
},
|
||||
other => bug!("`{}` is not a zero arg intrinsic", other),
|
||||
})
|
||||
|
@ -156,7 +156,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
_ => bug!(),
|
||||
};
|
||||
|
||||
self.write_scalar(Scalar::from_machine_usize(result, self), dest)?;
|
||||
self.write_scalar(Scalar::from_target_usize(result, self), dest)?;
|
||||
}
|
||||
|
||||
sym::pref_align_of
|
||||
|
@ -302,7 +302,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
}
|
||||
sym::offset => {
|
||||
let ptr = self.read_pointer(&args[0])?;
|
||||
let offset_count = self.read_machine_isize(&args[1])?;
|
||||
let offset_count = self.read_target_isize(&args[1])?;
|
||||
let pointee_ty = substs.type_at(0);
|
||||
|
||||
let offset_ptr = self.ptr_offset_inbounds(ptr, pointee_ty, offset_count)?;
|
||||
|
@ -310,7 +310,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
}
|
||||
sym::arith_offset => {
|
||||
let ptr = self.read_pointer(&args[0])?;
|
||||
let offset_count = self.read_machine_isize(&args[1])?;
|
||||
let offset_count = self.read_target_isize(&args[1])?;
|
||||
let pointee_ty = substs.type_at(0);
|
||||
|
||||
let pointee_size = i64::try_from(self.layout_of(pointee_ty)?.size.bytes()).unwrap();
|
||||
|
@ -376,7 +376,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
// The signed form of the intrinsic allows this. If we interpret the
|
||||
// difference as isize, we'll get the proper signed difference. If that
|
||||
// seems *positive*, they were more than isize::MAX apart.
|
||||
let dist = val.to_machine_isize(self)?;
|
||||
let dist = val.to_target_isize(self)?;
|
||||
if dist >= 0 {
|
||||
throw_ub_format!(
|
||||
"`{}` called when first pointer is too far before second",
|
||||
|
@ -386,7 +386,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
dist
|
||||
} else {
|
||||
// b >= a
|
||||
let dist = val.to_machine_isize(self)?;
|
||||
let dist = val.to_target_isize(self)?;
|
||||
// If converting to isize produced a *negative* result, we had an overflow
|
||||
// because they were more than isize::MAX apart.
|
||||
if dist < 0 {
|
||||
|
@ -411,10 +411,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
|
||||
// Perform division by size to compute return value.
|
||||
let ret_layout = if intrinsic_name == sym::ptr_offset_from_unsigned {
|
||||
assert!(0 <= dist && dist <= self.machine_isize_max());
|
||||
assert!(0 <= dist && dist <= self.target_isize_max());
|
||||
usize_layout
|
||||
} else {
|
||||
assert!(self.machine_isize_min() <= dist && dist <= self.machine_isize_max());
|
||||
assert!(self.target_isize_min() <= dist && dist <= self.target_isize_max());
|
||||
isize_layout
|
||||
};
|
||||
let pointee_layout = self.layout_of(substs.type_at(0))?;
|
||||
|
@ -531,12 +531,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
sym::vtable_size => {
|
||||
let ptr = self.read_pointer(&args[0])?;
|
||||
let (size, _align) = self.get_vtable_size_and_align(ptr)?;
|
||||
self.write_scalar(Scalar::from_machine_usize(size.bytes(), self), dest)?;
|
||||
self.write_scalar(Scalar::from_target_usize(size.bytes(), self), dest)?;
|
||||
}
|
||||
sym::vtable_align => {
|
||||
let ptr = self.read_pointer(&args[0])?;
|
||||
let (_size, align) = self.get_vtable_size_and_align(ptr)?;
|
||||
self.write_scalar(Scalar::from_machine_usize(align.bytes(), self), dest)?;
|
||||
self.write_scalar(Scalar::from_target_usize(align.bytes(), self), dest)?;
|
||||
}
|
||||
|
||||
_ => return Ok(false),
|
||||
|
@ -675,10 +675,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
count: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::Provenance>,
|
||||
nonoverlapping: bool,
|
||||
) -> InterpResult<'tcx> {
|
||||
let count = self.read_machine_usize(&count)?;
|
||||
let count = self.read_target_usize(&count)?;
|
||||
let layout = self.layout_of(src.layout.ty.builtin_deref(true).unwrap().ty)?;
|
||||
let (size, align) = (layout.size, layout.align.abi);
|
||||
// `checked_mul` enforces a too small bound (the correct one would probably be machine_isize_max),
|
||||
// `checked_mul` enforces a too small bound (the correct one would probably be target_isize_max),
|
||||
// but no actual allocation can be big enough for the difference to be noticeable.
|
||||
let size = size.checked_mul(count, self).ok_or_else(|| {
|
||||
err_ub_format!(
|
||||
|
@ -703,9 +703,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
|
||||
let dst = self.read_pointer(&dst)?;
|
||||
let byte = self.read_scalar(&byte)?.to_u8()?;
|
||||
let count = self.read_machine_usize(&count)?;
|
||||
let count = self.read_target_usize(&count)?;
|
||||
|
||||
// `checked_mul` enforces a too small bound (the correct one would probably be machine_isize_max),
|
||||
// `checked_mul` enforces a too small bound (the correct one would probably be target_isize_max),
|
||||
// but no actual allocation can be big enough for the difference to be noticeable.
|
||||
let len = layout
|
||||
.size
|
||||
|
|
|
@ -425,7 +425,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
throw_ub!(PointerOutOfBounds {
|
||||
alloc_id,
|
||||
alloc_size,
|
||||
ptr_offset: self.machine_usize_to_isize(offset.bytes()),
|
||||
ptr_offset: self.target_usize_to_isize(offset.bytes()),
|
||||
ptr_size: size,
|
||||
msg,
|
||||
})
|
||||
|
|
|
@ -52,7 +52,7 @@ impl<Prov: Provenance> Immediate<Prov> {
|
|||
}
|
||||
|
||||
pub fn new_slice(val: Scalar<Prov>, len: u64, cx: &impl HasDataLayout) -> Self {
|
||||
Immediate::ScalarPair(val, Scalar::from_machine_usize(len, cx))
|
||||
Immediate::ScalarPair(val, Scalar::from_target_usize(len, cx))
|
||||
}
|
||||
|
||||
pub fn new_dyn_trait(
|
||||
|
@ -414,12 +414,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
self.read_scalar(op)?.to_pointer(self)
|
||||
}
|
||||
/// Read a pointer-sized unsigned integer from a place.
|
||||
pub fn read_machine_usize(&self, op: &OpTy<'tcx, M::Provenance>) -> InterpResult<'tcx, u64> {
|
||||
self.read_scalar(op)?.to_machine_usize(self)
|
||||
pub fn read_target_usize(&self, op: &OpTy<'tcx, M::Provenance>) -> InterpResult<'tcx, u64> {
|
||||
self.read_scalar(op)?.to_target_usize(self)
|
||||
}
|
||||
/// Read a pointer-sized signed integer from a place.
|
||||
pub fn read_machine_isize(&self, op: &OpTy<'tcx, M::Provenance>) -> InterpResult<'tcx, i64> {
|
||||
self.read_scalar(op)?.to_machine_isize(self)
|
||||
pub fn read_target_isize(&self, op: &OpTy<'tcx, M::Provenance>) -> InterpResult<'tcx, i64> {
|
||||
self.read_scalar(op)?.to_target_isize(self)
|
||||
}
|
||||
|
||||
/// Turn the wide MPlace into a string (must already be dereferenced!)
|
||||
|
|
|
@ -229,7 +229,7 @@ impl<'tcx, Prov: Provenance> MPlaceTy<'tcx, Prov> {
|
|||
if self.layout.is_unsized() {
|
||||
// We need to consult `meta` metadata
|
||||
match self.layout.ty.kind() {
|
||||
ty::Slice(..) | ty::Str => self.mplace.meta.unwrap_meta().to_machine_usize(cx),
|
||||
ty::Slice(..) | ty::Str => self.mplace.meta.unwrap_meta().to_target_usize(cx),
|
||||
_ => bug!("len not supported on unsized type {:?}", self.layout.ty),
|
||||
}
|
||||
} else {
|
||||
|
@ -756,7 +756,7 @@ where
|
|||
mutbl: Mutability,
|
||||
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
|
||||
let ptr = self.allocate_bytes_ptr(str.as_bytes(), Align::ONE, kind, mutbl)?;
|
||||
let meta = Scalar::from_machine_usize(u64::try_from(str.len()).unwrap(), self);
|
||||
let meta = Scalar::from_target_usize(u64::try_from(str.len()).unwrap(), self);
|
||||
let mplace = MemPlace { ptr: ptr.into(), meta: MemPlaceMeta::Meta(meta) };
|
||||
|
||||
let ty = self.tcx.mk_ref(
|
||||
|
|
|
@ -319,7 +319,7 @@ where
|
|||
// implement this.
|
||||
ty::Array(inner, _) => (MemPlaceMeta::None, self.tcx.mk_array(*inner, inner_len)),
|
||||
ty::Slice(..) => {
|
||||
let len = Scalar::from_machine_usize(inner_len, self);
|
||||
let len = Scalar::from_target_usize(inner_len, self);
|
||||
(MemPlaceMeta::Meta(len), base.layout.ty)
|
||||
}
|
||||
_ => {
|
||||
|
@ -363,7 +363,7 @@ where
|
|||
Index(local) => {
|
||||
let layout = self.layout_of(self.tcx.types.usize)?;
|
||||
let n = self.local_to_op(self.frame(), local, Some(layout))?;
|
||||
let n = self.read_machine_usize(&n)?;
|
||||
let n = self.read_target_usize(&n)?;
|
||||
self.place_index(base, n)?
|
||||
}
|
||||
ConstantIndex { offset, min_length, from_end } => {
|
||||
|
@ -392,7 +392,7 @@ where
|
|||
Index(local) => {
|
||||
let layout = self.layout_of(self.tcx.types.usize)?;
|
||||
let n = self.local_to_op(self.frame(), local, Some(layout))?;
|
||||
let n = self.read_machine_usize(&n)?;
|
||||
let n = self.read_target_usize(&n)?;
|
||||
self.operand_index(base, n)?
|
||||
}
|
||||
ConstantIndex { offset, min_length, from_end } => {
|
||||
|
|
|
@ -242,7 +242,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
let src = self.eval_place(place)?;
|
||||
let op = self.place_to_op(&src)?;
|
||||
let len = op.len(self)?;
|
||||
self.write_scalar(Scalar::from_machine_usize(len, self), &dest)?;
|
||||
self.write_scalar(Scalar::from_target_usize(len, self), &dest)?;
|
||||
}
|
||||
|
||||
Ref(_, borrow_kind, place) => {
|
||||
|
@ -297,7 +297,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
mir::NullOp::SizeOf => layout.size.bytes(),
|
||||
mir::NullOp::AlignOf => layout.align.abi.bytes(),
|
||||
};
|
||||
self.write_scalar(Scalar::from_machine_usize(val, self), &dest)?;
|
||||
self.write_scalar(Scalar::from_target_usize(val, self), &dest)?;
|
||||
}
|
||||
|
||||
ShallowInitBox(ref operand, _) => {
|
||||
|
|
|
@ -348,7 +348,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
|
|||
// FIXME: check if the type/trait match what ty::Dynamic says?
|
||||
}
|
||||
ty::Slice(..) | ty::Str => {
|
||||
let _len = meta.unwrap_meta().to_machine_usize(self.ecx)?;
|
||||
let _len = meta.unwrap_meta().to_target_usize(self.ecx)?;
|
||||
// We do not check that `len * elem_size <= isize::MAX`:
|
||||
// that is only required for references, and there it falls out of the
|
||||
// "dereferenceable" check performed by Stacked Borrows.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue