Skip to content

Commit fc9d1a8

Browse files
committed
Split a bool argument into two named functions
1 parent ca109af commit fc9d1a8

File tree

12 files changed

+39
-30
lines changed

12 files changed

+39
-30
lines changed

compiler/rustc_const_eval/src/interpret/cast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
153153
);
154154
}
155155

156-
self.copy_op(src, dest, /*allow_transmute*/ true)?;
156+
self.copy_op_allow_transmute(src, dest)?;
157157
}
158158
}
159159
Ok(())
@@ -441,7 +441,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
441441
if src_field.layout.is_1zst() && cast_ty_field.is_1zst() {
442442
// Skip 1-ZST fields.
443443
} else if src_field.layout.ty == cast_ty_field.ty {
444-
self.copy_op(&src_field, &dst_field, /*allow_transmute*/ false)?;
444+
self.copy_op(&src_field, &dst_field)?;
445445
} else {
446446
if found_cast_field {
447447
span_bug!(self.cur_span(), "unsize_into: more than one field to cast");

compiler/rustc_const_eval/src/interpret/eval_context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
899899
.local_to_op(self.frame(), mir::RETURN_PLACE, None)
900900
.expect("return place should always be live");
901901
let dest = self.frame().return_place.clone();
902-
let err = self.copy_op(&op, &dest, /*allow_transmute*/ true);
902+
let err = self.copy_op_allow_transmute(&op, &dest);
903903
trace!("return value: {:?}", self.dump_place(&dest));
904904
// We delay actually short-circuiting on this error until *after* the stack frame is
905905
// popped, since we want this error to be attributed to the caller, whose type defines

compiler/rustc_const_eval/src/interpret/intrinsics.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
120120
let val = self.tcx.span_as_caller_location(span);
121121
let val =
122122
self.const_val_to_op(val, self.tcx.caller_location_ty(), Some(dest.layout))?;
123-
self.copy_op(&val, dest, /* allow_transmute */ false)?;
123+
self.copy_op(&val, dest)?;
124124
}
125125

126126
sym::min_align_of_val | sym::size_of_val => {
@@ -157,7 +157,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
157157
tcx.const_eval_global_id(self.param_env, gid, Some(tcx.span))
158158
})?;
159159
let val = self.const_val_to_op(val, ty, Some(dest.layout))?;
160-
self.copy_op(&val, dest, /*allow_transmute*/ false)?;
160+
self.copy_op(&val, dest)?;
161161
}
162162

163163
sym::ctpop
@@ -391,7 +391,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
391391
} else {
392392
self.project_index(&input, i)?.into()
393393
};
394-
self.copy_op(&value, &place, /*allow_transmute*/ false)?;
394+
self.copy_op(&value, &place)?;
395395
}
396396
}
397397
sym::simd_extract => {
@@ -401,15 +401,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
401401
index < input_len,
402402
"index `{index}` must be in bounds of vector with length {input_len}"
403403
);
404-
self.copy_op(
405-
&self.project_index(&input, index)?,
406-
dest,
407-
/*allow_transmute*/ false,
408-
)?;
404+
self.copy_op(&self.project_index(&input, index)?, dest)?;
409405
}
410406
sym::likely | sym::unlikely | sym::black_box => {
411407
// These just return their argument
412-
self.copy_op(&args[0], dest, /*allow_transmute*/ false)?;
408+
self.copy_op(&args[0], dest)?;
413409
}
414410
sym::raw_eq => {
415411
let result = self.raw_eq_intrinsic(&args[0], &args[1])?;

compiler/rustc_const_eval/src/interpret/place.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -758,11 +758,32 @@ where
758758
Ok(())
759759
}
760760

761+
/// Copies the data from an operand to a place.
762+
/// The layouts of the `src` and `dest` may disagree.
763+
#[inline(always)]
764+
pub fn copy_op_allow_transmute(
765+
&mut self,
766+
src: &impl Readable<'tcx, M::Provenance>,
767+
dest: &impl Writeable<'tcx, M::Provenance>,
768+
) -> InterpResult<'tcx> {
769+
self.copy_op_inner(src, dest, /* allow_transmute */ true)
770+
}
771+
772+
/// Copies the data from an operand to a place.
773+
#[inline(always)]
774+
pub fn copy_op(
775+
&mut self,
776+
src: &impl Readable<'tcx, M::Provenance>,
777+
dest: &impl Writeable<'tcx, M::Provenance>,
778+
) -> InterpResult<'tcx> {
779+
self.copy_op_inner(src, dest, /* allow_transmute */ false)
780+
}
781+
761782
/// Copies the data from an operand to a place.
762783
/// `allow_transmute` indicates whether the layouts may disagree.
763784
#[inline(always)]
764785
#[instrument(skip(self), level = "debug")]
765-
pub fn copy_op(
786+
fn copy_op_inner(
766787
&mut self,
767788
src: &impl Readable<'tcx, M::Provenance>,
768789
dest: &impl Writeable<'tcx, M::Provenance>,

compiler/rustc_const_eval/src/interpret/step.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
151151
Use(ref operand) => {
152152
// Avoid recomputing the layout
153153
let op = self.eval_operand(operand, Some(dest.layout))?;
154-
self.copy_op(&op, &dest, /*allow_transmute*/ false)?;
154+
self.copy_op(&op, &dest)?;
155155
}
156156

157157
CopyForDeref(place) => {
158158
let op = self.eval_place_to_op(place, Some(dest.layout))?;
159-
self.copy_op(&op, &dest, /* allow_transmute*/ false)?;
159+
self.copy_op(&op, &dest)?;
160160
}
161161

162162
BinaryOp(bin_op, box (ref left, ref right)) => {
@@ -316,7 +316,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
316316
let field_index = active_field_index.unwrap_or(field_index);
317317
let field_dest = self.project_field(&variant_dest, field_index.as_usize())?;
318318
let op = self.eval_operand(operand, Some(field_dest.layout))?;
319-
self.copy_op(&op, &field_dest, /*allow_transmute*/ false)?;
319+
self.copy_op(&op, &field_dest)?;
320320
}
321321
self.write_discriminant(variant_index, dest)
322322
}
@@ -339,7 +339,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
339339
} else {
340340
// Write the src to the first element.
341341
let first = self.project_index(&dest, 0)?;
342-
self.copy_op(&src, &first, /*allow_transmute*/ false)?;
342+
self.copy_op(&src, &first)?;
343343

344344
// This is performance-sensitive code for big static/const arrays! So we
345345
// avoid writing each operand individually and instead just make many copies

compiler/rustc_const_eval/src/interpret/terminator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
481481
// FIXME: Depending on the PassMode, this should reset some padding to uninitialized. (This
482482
// is true for all `copy_op`, but there are a lot of special cases for argument passing
483483
// specifically.)
484-
self.copy_op(&caller_arg_copy, &callee_arg, /*allow_transmute*/ true)?;
484+
self.copy_op_allow_transmute(&caller_arg_copy, &callee_arg)?;
485485
// If this was an in-place pass, protect the place it comes from for the duration of the call.
486486
if let FnArg::InPlace(place) = caller_arg {
487487
M::protect_in_place_function_argument(self, place)?;

compiler/rustc_mir_transform/src/gvn.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
399399
};
400400
for (field_index, op) in fields.into_iter().enumerate() {
401401
let field_dest = self.ecx.project_field(&variant_dest, field_index).ok()?;
402-
self.ecx.copy_op(op, &field_dest, /*allow_transmute*/ false).ok()?;
402+
self.ecx.copy_op(op, &field_dest).ok()?;
403403
}
404404
self.ecx.write_discriminant(variant.unwrap_or(FIRST_VARIANT), &dest).ok()?;
405405
self.ecx
@@ -1181,8 +1181,7 @@ fn op_to_prop_const<'tcx>(
11811181
}
11821182

11831183
// Everything failed: create a new allocation to hold the data.
1184-
let alloc_id =
1185-
ecx.intern_with_temp_alloc(op.layout, |ecx, dest| ecx.copy_op(op, dest, false)).ok()?;
1184+
let alloc_id = ecx.intern_with_temp_alloc(op.layout, |ecx, dest| ecx.copy_op(op, dest)).ok()?;
11861185
let value = ConstValue::Indirect { alloc_id, offset: Size::ZERO };
11871186

11881187
// Check that we do not leak a pointer.

src/tools/miri/src/shims/intrinsics/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
108108
"volatile_load" => {
109109
let [place] = check_arg_count(args)?;
110110
let place = this.deref_pointer(place)?;
111-
this.copy_op(&place, dest, /*allow_transmute*/ false)?;
111+
this.copy_op(&place, dest)?;
112112
}
113113
"volatile_store" => {
114114
let [place, dest] = check_arg_count(args)?;
115115
let place = this.deref_pointer(place)?;
116-
this.copy_op(dest, &place, /*allow_transmute*/ false)?;
116+
this.copy_op(dest, &place)?;
117117
}
118118

119119
"write_bytes" | "volatile_set_memory" => {

src/tools/miri/src/shims/x86/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ fn bin_op_simd_float_first<'tcx, F: rustc_apfloat::Float>(
299299
this.copy_op(
300300
&this.project_index(&left, i)?,
301301
&this.project_index(&dest, i)?,
302-
/*allow_transmute*/ false,
303302
)?;
304303
}
305304

@@ -424,7 +423,6 @@ fn unary_op_ss<'tcx>(
424423
this.copy_op(
425424
&this.project_index(&op, i)?,
426425
&this.project_index(&dest, i)?,
427-
/*allow_transmute*/ false,
428426
)?;
429427
}
430428

@@ -484,7 +482,6 @@ fn round_first<'tcx, F: rustc_apfloat::Float>(
484482
this.copy_op(
485483
&this.project_index(&left, i)?,
486484
&this.project_index(&dest, i)?,
487-
/*allow_transmute*/ false,
488485
)?;
489486
}
490487

src/tools/miri/src/shims/x86/sse.rs

-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
211211
this.copy_op(
212212
&this.project_index(&left, i)?,
213213
&this.project_index(&dest, i)?,
214-
/*allow_transmute*/ false,
215214
)?;
216215
}
217216
}

src/tools/miri/src/shims/x86/sse2.rs

-2
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
443443
this.copy_op(
444444
&this.project_index(&op, i)?,
445445
&this.project_index(&dest, i)?,
446-
/*allow_transmute*/ false,
447446
)?;
448447
}
449448
}
@@ -584,7 +583,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
584583
this.copy_op(
585584
&this.project_index(&left, i)?,
586585
&this.project_index(&dest, i)?,
587-
/*allow_transmute*/ false,
588586
)?;
589587
}
590588
}

src/tools/miri/src/shims/x86/sse41.rs

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
6060
this.copy_op(
6161
&this.project_index(&left, i)?,
6262
&dest,
63-
/*allow_transmute*/ false,
6463
)?;
6564
}
6665
}

0 commit comments

Comments
 (0)