Split a bool argument into two named functions

This commit is contained in:
Oli Scherer 2024-01-03 12:05:48 +00:00
parent ca109af2ac
commit fc9d1a8133
12 changed files with 39 additions and 30 deletions

View File

@ -153,7 +153,7 @@ pub fn cast(
);
}
self.copy_op(src, dest, /*allow_transmute*/ true)?;
self.copy_op_allow_transmute(src, dest)?;
}
}
Ok(())
@ -441,7 +441,7 @@ pub fn unsize_into(
if src_field.layout.is_1zst() && cast_ty_field.is_1zst() {
// Skip 1-ZST fields.
} else if src_field.layout.ty == cast_ty_field.ty {
self.copy_op(&src_field, &dst_field, /*allow_transmute*/ false)?;
self.copy_op(&src_field, &dst_field)?;
} else {
if found_cast_field {
span_bug!(self.cur_span(), "unsize_into: more than one field to cast");

View File

@ -899,7 +899,7 @@ pub(super) fn pop_stack_frame(&mut self, unwinding: bool) -> InterpResult<'tcx>
.local_to_op(self.frame(), mir::RETURN_PLACE, None)
.expect("return place should always be live");
let dest = self.frame().return_place.clone();
let err = self.copy_op(&op, &dest, /*allow_transmute*/ true);
let err = self.copy_op_allow_transmute(&op, &dest);
trace!("return value: {:?}", self.dump_place(&dest));
// We delay actually short-circuiting on this error until *after* the stack frame is
// popped, since we want this error to be attributed to the caller, whose type defines

View File

@ -120,7 +120,7 @@ pub fn emulate_intrinsic(
let val = self.tcx.span_as_caller_location(span);
let val =
self.const_val_to_op(val, self.tcx.caller_location_ty(), Some(dest.layout))?;
self.copy_op(&val, dest, /* allow_transmute */ false)?;
self.copy_op(&val, dest)?;
}
sym::min_align_of_val | sym::size_of_val => {
@ -157,7 +157,7 @@ pub fn emulate_intrinsic(
tcx.const_eval_global_id(self.param_env, gid, Some(tcx.span))
})?;
let val = self.const_val_to_op(val, ty, Some(dest.layout))?;
self.copy_op(&val, dest, /*allow_transmute*/ false)?;
self.copy_op(&val, dest)?;
}
sym::ctpop
@ -391,7 +391,7 @@ pub fn emulate_intrinsic(
} else {
self.project_index(&input, i)?.into()
};
self.copy_op(&value, &place, /*allow_transmute*/ false)?;
self.copy_op(&value, &place)?;
}
}
sym::simd_extract => {
@ -401,15 +401,11 @@ pub fn emulate_intrinsic(
index < input_len,
"index `{index}` must be in bounds of vector with length {input_len}"
);
self.copy_op(
&self.project_index(&input, index)?,
dest,
/*allow_transmute*/ false,
)?;
self.copy_op(&self.project_index(&input, index)?, dest)?;
}
sym::likely | sym::unlikely | sym::black_box => {
// These just return their argument
self.copy_op(&args[0], dest, /*allow_transmute*/ false)?;
self.copy_op(&args[0], dest)?;
}
sym::raw_eq => {
let result = self.raw_eq_intrinsic(&args[0], &args[1])?;

View File

@ -758,11 +758,32 @@ pub fn write_uninit(
Ok(())
}
/// Copies the data from an operand to a place.
/// The layouts of the `src` and `dest` may disagree.
#[inline(always)]
pub fn copy_op_allow_transmute(
&mut self,
src: &impl Readable<'tcx, M::Provenance>,
dest: &impl Writeable<'tcx, M::Provenance>,
) -> InterpResult<'tcx> {
self.copy_op_inner(src, dest, /* allow_transmute */ true)
}
/// Copies the data from an operand to a place.
#[inline(always)]
pub fn copy_op(
&mut self,
src: &impl Readable<'tcx, M::Provenance>,
dest: &impl Writeable<'tcx, M::Provenance>,
) -> InterpResult<'tcx> {
self.copy_op_inner(src, dest, /* allow_transmute */ false)
}
/// Copies the data from an operand to a place.
/// `allow_transmute` indicates whether the layouts may disagree.
#[inline(always)]
#[instrument(skip(self), level = "debug")]
pub fn copy_op(
fn copy_op_inner(
&mut self,
src: &impl Readable<'tcx, M::Provenance>,
dest: &impl Writeable<'tcx, M::Provenance>,

View File

@ -151,12 +151,12 @@ pub fn eval_rvalue_into_place(
Use(ref operand) => {
// Avoid recomputing the layout
let op = self.eval_operand(operand, Some(dest.layout))?;
self.copy_op(&op, &dest, /*allow_transmute*/ false)?;
self.copy_op(&op, &dest)?;
}
CopyForDeref(place) => {
let op = self.eval_place_to_op(place, Some(dest.layout))?;
self.copy_op(&op, &dest, /* allow_transmute*/ false)?;
self.copy_op(&op, &dest)?;
}
BinaryOp(bin_op, box (ref left, ref right)) => {
@ -316,7 +316,7 @@ fn write_aggregate(
let field_index = active_field_index.unwrap_or(field_index);
let field_dest = self.project_field(&variant_dest, field_index.as_usize())?;
let op = self.eval_operand(operand, Some(field_dest.layout))?;
self.copy_op(&op, &field_dest, /*allow_transmute*/ false)?;
self.copy_op(&op, &field_dest)?;
}
self.write_discriminant(variant_index, dest)
}
@ -339,7 +339,7 @@ fn write_repeat(
} else {
// Write the src to the first element.
let first = self.project_index(&dest, 0)?;
self.copy_op(&src, &first, /*allow_transmute*/ false)?;
self.copy_op(&src, &first)?;
// This is performance-sensitive code for big static/const arrays! So we
// avoid writing each operand individually and instead just make many copies

View File

@ -481,7 +481,7 @@ fn pass_argument<'x, 'y>(
// FIXME: Depending on the PassMode, this should reset some padding to uninitialized. (This
// is true for all `copy_op`, but there are a lot of special cases for argument passing
// specifically.)
self.copy_op(&caller_arg_copy, &callee_arg, /*allow_transmute*/ true)?;
self.copy_op_allow_transmute(&caller_arg_copy, &callee_arg)?;
// If this was an in-place pass, protect the place it comes from for the duration of the call.
if let FnArg::InPlace(place) = caller_arg {
M::protect_in_place_function_argument(self, place)?;

View File

@ -399,7 +399,7 @@ fn eval_to_const(&mut self, value: VnIndex) -> Option<OpTy<'tcx>> {
};
for (field_index, op) in fields.into_iter().enumerate() {
let field_dest = self.ecx.project_field(&variant_dest, field_index).ok()?;
self.ecx.copy_op(op, &field_dest, /*allow_transmute*/ false).ok()?;
self.ecx.copy_op(op, &field_dest).ok()?;
}
self.ecx.write_discriminant(variant.unwrap_or(FIRST_VARIANT), &dest).ok()?;
self.ecx
@ -1181,8 +1181,7 @@ fn op_to_prop_const<'tcx>(
}
// Everything failed: create a new allocation to hold the data.
let alloc_id =
ecx.intern_with_temp_alloc(op.layout, |ecx, dest| ecx.copy_op(op, dest, false)).ok()?;
let alloc_id = ecx.intern_with_temp_alloc(op.layout, |ecx, dest| ecx.copy_op(op, dest)).ok()?;
let value = ConstValue::Indirect { alloc_id, offset: Size::ZERO };
// Check that we do not leak a pointer.

View File

@ -108,12 +108,12 @@ fn emulate_intrinsic_by_name(
"volatile_load" => {
let [place] = check_arg_count(args)?;
let place = this.deref_pointer(place)?;
this.copy_op(&place, dest, /*allow_transmute*/ false)?;
this.copy_op(&place, dest)?;
}
"volatile_store" => {
let [place, dest] = check_arg_count(args)?;
let place = this.deref_pointer(place)?;
this.copy_op(dest, &place, /*allow_transmute*/ false)?;
this.copy_op(dest, &place)?;
}
"write_bytes" | "volatile_set_memory" => {

View File

@ -299,7 +299,6 @@ fn bin_op_simd_float_first<'tcx, F: rustc_apfloat::Float>(
this.copy_op(
&this.project_index(&left, i)?,
&this.project_index(&dest, i)?,
/*allow_transmute*/ false,
)?;
}
@ -424,7 +423,6 @@ fn unary_op_ss<'tcx>(
this.copy_op(
&this.project_index(&op, i)?,
&this.project_index(&dest, i)?,
/*allow_transmute*/ false,
)?;
}
@ -484,7 +482,6 @@ fn round_first<'tcx, F: rustc_apfloat::Float>(
this.copy_op(
&this.project_index(&left, i)?,
&this.project_index(&dest, i)?,
/*allow_transmute*/ false,
)?;
}

View File

@ -211,7 +211,6 @@ fn emulate_x86_sse_intrinsic(
this.copy_op(
&this.project_index(&left, i)?,
&this.project_index(&dest, i)?,
/*allow_transmute*/ false,
)?;
}
}

View File

@ -443,7 +443,6 @@ enum ShiftOp {
this.copy_op(
&this.project_index(&op, i)?,
&this.project_index(&dest, i)?,
/*allow_transmute*/ false,
)?;
}
}
@ -584,7 +583,6 @@ enum ShiftOp {
this.copy_op(
&this.project_index(&left, i)?,
&this.project_index(&dest, i)?,
/*allow_transmute*/ false,
)?;
}
}

View File

@ -60,7 +60,6 @@ fn emulate_x86_sse41_intrinsic(
this.copy_op(
&this.project_index(&left, i)?,
&dest,
/*allow_transmute*/ false,
)?;
}
}