Skip to content

Commit 7a21ea8

Browse files
committed
interpret: make read functions generic over operand type
1 parent 302d357 commit 7a21ea8

File tree

9 files changed

+45
-45
lines changed

9 files changed

+45
-45
lines changed

src/concurrency/data_race.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> {
472472
// This is fine with StackedBorrow and race checks because they don't concern metadata on
473473
// the *value* (including the associated provenance if this is an AtomicPtr) at this location.
474474
// Only metadata on the location itself is used.
475-
let scalar = this.allow_data_races_ref(move |this| this.read_scalar(&place.into()))?;
475+
let scalar = this.allow_data_races_ref(move |this| this.read_scalar(place))?;
476476
this.validate_overlapping_atomic(place)?;
477477
this.buffered_atomic_read(place, atomic, scalar, || {
478478
this.validate_atomic_load(place, atomic)
@@ -513,7 +513,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> {
513513
this.atomic_access_check(place)?;
514514

515515
this.validate_overlapping_atomic(place)?;
516-
let old = this.allow_data_races_mut(|this| this.read_immediate(&place.into()))?;
516+
let old = this.allow_data_races_mut(|this| this.read_immediate(place))?;
517517

518518
// Atomics wrap around on overflow.
519519
let val = this.binary_op(op, &old, rhs)?;
@@ -538,7 +538,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> {
538538
this.atomic_access_check(place)?;
539539

540540
this.validate_overlapping_atomic(place)?;
541-
let old = this.allow_data_races_mut(|this| this.read_scalar(&place.into()))?;
541+
let old = this.allow_data_races_mut(|this| this.read_scalar(place))?;
542542
this.allow_data_races_mut(|this| this.write_scalar(new, place))?;
543543

544544
this.validate_atomic_rmw(place, atomic)?;
@@ -560,7 +560,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> {
560560
this.atomic_access_check(place)?;
561561

562562
this.validate_overlapping_atomic(place)?;
563-
let old = this.allow_data_races_mut(|this| this.read_immediate(&place.into()))?;
563+
let old = this.allow_data_races_mut(|this| this.read_immediate(place))?;
564564
let lt = this.binary_op(mir::BinOp::Lt, &old, &rhs)?.to_scalar().to_bool()?;
565565

566566
let new_val = if min {
@@ -603,7 +603,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> {
603603
// to read with the failure ordering and if successful then try again with the success
604604
// read ordering and write in the success case.
605605
// Read as immediate for the sake of `binary_op()`
606-
let old = this.allow_data_races_mut(|this| this.read_immediate(&(place.into())))?;
606+
let old = this.allow_data_races_mut(|this| this.read_immediate(place))?;
607607
// `binary_op` will bail if either of them is not a scalar.
608608
let eq = this.binary_op(mir::BinOp::Eq, &old, expect_old)?;
609609
// If the operation would succeed, but is "weak", fail some portion

src/eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl MainThreadState {
246246
this.machine.main_fn_ret_place.unwrap().ptr,
247247
this.machine.layouts.isize,
248248
);
249-
let exit_code = this.read_target_isize(&ret_place.into())?;
249+
let exit_code = this.read_target_isize(&ret_place)?;
250250
// Need to call this ourselves since we are not going to return to the scheduler
251251
// loop, and we want the main thread TLS to not show up as memory leaks.
252252
this.terminate_active_thread()?;

src/helpers.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
166166
let const_val = this.eval_global(cid, None).unwrap_or_else(|err| {
167167
panic!("failed to evaluate required Rust item: {path:?}\n{err:?}")
168168
});
169-
this.read_scalar(&const_val.into())
169+
this.read_scalar(&const_val)
170170
.unwrap_or_else(|err| panic!("failed to read required Rust item: {path:?}\n{err:?}"))
171171
}
172172

@@ -623,7 +623,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
623623
fn get_last_error(&mut self) -> InterpResult<'tcx, Scalar<Provenance>> {
624624
let this = self.eval_context_mut();
625625
let errno_place = this.last_error_place()?;
626-
this.read_scalar(&errno_place.into())
626+
this.read_scalar(&errno_place)
627627
}
628628

629629
/// This function tries to produce the most similar OS error from the `std::io::ErrorKind`
@@ -772,7 +772,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
772772
) -> InterpResult<'tcx, Scalar<Provenance>> {
773773
let this = self.eval_context_ref();
774774
let value_place = this.deref_operand_and_offset(op, offset, base_layout, value_layout)?;
775-
this.read_scalar(&value_place.into())
775+
this.read_scalar(&value_place)
776776
}
777777

778778
fn write_scalar_at_offset(
@@ -797,10 +797,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
797797
) -> InterpResult<'tcx, Option<Duration>> {
798798
let this = self.eval_context_mut();
799799
let seconds_place = this.project_field(tp, 0)?;
800-
let seconds_scalar = this.read_scalar(&seconds_place.into())?;
800+
let seconds_scalar = this.read_scalar(&seconds_place)?;
801801
let seconds = seconds_scalar.to_target_isize(this)?;
802802
let nanoseconds_place = this.project_field(tp, 1)?;
803-
let nanoseconds_scalar = this.read_scalar(&nanoseconds_place.into())?;
803+
let nanoseconds_scalar = this.read_scalar(&nanoseconds_place)?;
804804
let nanoseconds = nanoseconds_scalar.to_target_isize(this)?;
805805

806806
Ok(try {

src/shims/env.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl<'tcx> EnvVars<'tcx> {
8888
}
8989
// Deallocate environ var list.
9090
let environ = ecx.machine.env_vars.environ.unwrap();
91-
let old_vars_ptr = ecx.read_pointer(&environ.into())?;
91+
let old_vars_ptr = ecx.read_pointer(&environ)?;
9292
ecx.deallocate_ptr(old_vars_ptr, None, MiriMemoryKind::Runtime.into())?;
9393
Ok(())
9494
}
@@ -432,7 +432,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
432432
let this = self.eval_context_mut();
433433
// Deallocate the old environ list, if any.
434434
if let Some(environ) = this.machine.env_vars.environ {
435-
let old_vars_ptr = this.read_pointer(&environ.into())?;
435+
let old_vars_ptr = this.read_pointer(&environ)?;
436436
this.deallocate_ptr(old_vars_ptr, None, MiriMemoryKind::Runtime.into())?;
437437
} else {
438438
// No `environ` allocated yet, let's do that.

src/shims/intrinsics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
9797
"volatile_load" => {
9898
let [place] = check_arg_count(args)?;
9999
let place = this.deref_operand(place)?;
100-
this.copy_op(&place.into(), dest, /*allow_transmute*/ false)?;
100+
this.copy_op(&place, dest, /*allow_transmute*/ false)?;
101101
}
102102
"volatile_store" => {
103103
let [place, dest] = check_arg_count(args)?;

src/shims/intrinsics/simd.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
5757
};
5858

5959
for i in 0..dest_len {
60-
let op = this.read_immediate(&this.project_index(&op, i)?.into())?;
60+
let op = this.read_immediate(&this.project_index(&op, i)?)?;
6161
let dest = this.project_index(&dest, i)?;
6262
let val = match which {
6363
Op::MirOp(mir_op) => this.unary_op(mir_op, &op)?.to_scalar(),
@@ -172,8 +172,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
172172
};
173173

174174
for i in 0..dest_len {
175-
let left = this.read_immediate(&this.project_index(&left, i)?.into())?;
176-
let right = this.read_immediate(&this.project_index(&right, i)?.into())?;
175+
let left = this.read_immediate(&this.project_index(&left, i)?)?;
176+
let right = this.read_immediate(&this.project_index(&right, i)?)?;
177177
let dest = this.project_index(&dest, i)?;
178178
let val = match which {
179179
Op::MirOp(mir_op) => {
@@ -232,9 +232,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
232232
assert_eq!(dest_len, c_len);
233233

234234
for i in 0..dest_len {
235-
let a = this.read_scalar(&this.project_index(&a, i)?.into())?;
236-
let b = this.read_scalar(&this.project_index(&b, i)?.into())?;
237-
let c = this.read_scalar(&this.project_index(&c, i)?.into())?;
235+
let a = this.read_scalar(&this.project_index(&a, i)?)?;
236+
let b = this.read_scalar(&this.project_index(&b, i)?)?;
237+
let c = this.read_scalar(&this.project_index(&c, i)?)?;
238238
let dest = this.project_index(&dest, i)?;
239239

240240
// Works for f32 and f64.
@@ -295,13 +295,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
295295
};
296296

297297
// Initialize with first lane, then proceed with the rest.
298-
let mut res = this.read_immediate(&this.project_index(&op, 0)?.into())?;
298+
let mut res = this.read_immediate(&this.project_index(&op, 0)?)?;
299299
if matches!(which, Op::MirOpBool(_)) {
300300
// Convert to `bool` scalar.
301301
res = imm_from_bool(simd_element_to_bool(res)?);
302302
}
303303
for i in 1..op_len {
304-
let op = this.read_immediate(&this.project_index(&op, i)?.into())?;
304+
let op = this.read_immediate(&this.project_index(&op, i)?)?;
305305
res = match which {
306306
Op::MirOp(mir_op) => {
307307
this.binary_op(mir_op, &res, &op)?
@@ -355,7 +355,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
355355

356356
let mut res = init;
357357
for i in 0..op_len {
358-
let op = this.read_immediate(&this.project_index(&op, i)?.into())?;
358+
let op = this.read_immediate(&this.project_index(&op, i)?)?;
359359
res = this.binary_op(mir_op, &res, &op)?;
360360
}
361361
this.write_immediate(*res, dest)?;
@@ -372,9 +372,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
372372
assert_eq!(dest_len, no_len);
373373

374374
for i in 0..dest_len {
375-
let mask = this.read_immediate(&this.project_index(&mask, i)?.into())?;
376-
let yes = this.read_immediate(&this.project_index(&yes, i)?.into())?;
377-
let no = this.read_immediate(&this.project_index(&no, i)?.into())?;
375+
let mask = this.read_immediate(&this.project_index(&mask, i)?)?;
376+
let yes = this.read_immediate(&this.project_index(&yes, i)?)?;
377+
let no = this.read_immediate(&this.project_index(&no, i)?)?;
378378
let dest = this.project_index(&dest, i)?;
379379

380380
let val = if simd_element_to_bool(mask)? { yes } else { no };
@@ -403,8 +403,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
403403
& 1u64
404404
.checked_shl(simd_bitmask_index(i, dest_len, this.data_layout().endian))
405405
.unwrap();
406-
let yes = this.read_immediate(&this.project_index(&yes, i.into())?.into())?;
407-
let no = this.read_immediate(&this.project_index(&no, i.into())?.into())?;
406+
let yes = this.read_immediate(&this.project_index(&yes, i.into())?)?;
407+
let no = this.read_immediate(&this.project_index(&no, i.into())?)?;
408408
let dest = this.project_index(&dest, i.into())?;
409409

410410
let val = if mask != 0 { yes } else { no };
@@ -435,7 +435,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
435435
let from_exposed_cast = intrinsic_name == "from_exposed_addr";
436436

437437
for i in 0..dest_len {
438-
let op = this.read_immediate(&this.project_index(&op, i)?.into())?;
438+
let op = this.read_immediate(&this.project_index(&op, i)?)?;
439439
let dest = this.project_index(&dest, i)?;
440440

441441
let val = match (op.layout.ty.kind(), dest.layout.ty.kind()) {
@@ -503,10 +503,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
503503
let dest = this.project_index(&dest, i)?;
504504

505505
let val = if src_index < left_len {
506-
this.read_immediate(&this.project_index(&left, src_index)?.into())?
506+
this.read_immediate(&this.project_index(&left, src_index)?)?
507507
} else if src_index < left_len.checked_add(right_len).unwrap() {
508508
let right_idx = src_index.checked_sub(left_len).unwrap();
509-
this.read_immediate(&this.project_index(&right, right_idx)?.into())?
509+
this.read_immediate(&this.project_index(&right, right_idx)?)?
510510
} else {
511511
span_bug!(
512512
this.cur_span(),
@@ -528,14 +528,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
528528
assert_eq!(dest_len, mask_len);
529529

530530
for i in 0..dest_len {
531-
let passthru = this.read_immediate(&this.project_index(&passthru, i)?.into())?;
532-
let ptr = this.read_immediate(&this.project_index(&ptrs, i)?.into())?;
533-
let mask = this.read_immediate(&this.project_index(&mask, i)?.into())?;
531+
let passthru = this.read_immediate(&this.project_index(&passthru, i)?)?;
532+
let ptr = this.read_immediate(&this.project_index(&ptrs, i)?)?;
533+
let mask = this.read_immediate(&this.project_index(&mask, i)?)?;
534534
let dest = this.project_index(&dest, i)?;
535535

536536
let val = if simd_element_to_bool(mask)? {
537-
let place = this.deref_operand(&ptr.into())?;
538-
this.read_immediate(&place.into())?
537+
let place = this.deref_operand(&ptr)?;
538+
this.read_immediate(&place)?
539539
} else {
540540
passthru
541541
};
@@ -552,12 +552,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
552552
assert_eq!(ptrs_len, mask_len);
553553

554554
for i in 0..ptrs_len {
555-
let value = this.read_immediate(&this.project_index(&value, i)?.into())?;
556-
let ptr = this.read_immediate(&this.project_index(&ptrs, i)?.into())?;
557-
let mask = this.read_immediate(&this.project_index(&mask, i)?.into())?;
555+
let value = this.read_immediate(&this.project_index(&value, i)?)?;
556+
let ptr = this.read_immediate(&this.project_index(&ptrs, i)?)?;
557+
let mask = this.read_immediate(&this.project_index(&mask, i)?)?;
558558

559559
if simd_element_to_bool(mask)? {
560-
let place = this.deref_operand(&ptr.into())?;
560+
let place = this.deref_operand(&ptr)?;
561561
this.write_immediate(*value, &place)?;
562562
}
563563
}
@@ -578,7 +578,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
578578

579579
let mut res = 0u64;
580580
for i in 0..op_len {
581-
let op = this.read_immediate(&this.project_index(&op, i.into())?.into())?;
581+
let op = this.read_immediate(&this.project_index(&op, i.into())?)?;
582582
if simd_element_to_bool(op)? {
583583
res |= 1u64
584584
.checked_shl(simd_bitmask_index(i, op_len, this.data_layout().endian))

src/shims/unix/linux/fd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
7474
let event = this.deref_operand_as(event, this.libc_ty_layout("epoll_event"))?;
7575

7676
let events = this.project_field(&event, 0)?;
77-
let events = this.read_scalar(&events.into())?.to_u32()?;
77+
let events = this.read_scalar(&events)?.to_u32()?;
7878
let data = this.project_field(&event, 1)?;
79-
let data = this.read_scalar(&data.into())?;
79+
let data = this.read_scalar(&data)?;
8080
let event = EpollEvent { events, data };
8181

8282
if let Some(epfd) = this.machine.file_handler.handles.get_mut(&epfd) {

src/shims/unix/macos/foreign_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
133133
let (written, size_needed) = this.write_path_to_c_str(
134134
&path,
135135
buf_ptr,
136-
this.read_scalar(&bufsize.into())?.to_u32()?.into(),
136+
this.read_scalar(&bufsize)?.to_u32()?.into(),
137137
)?;
138138

139139
if written {

src/shims/windows/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
323323
let layout = this.machine.layouts.uint(size).unwrap();
324324
let futex_val = this
325325
.read_scalar_atomic(&MPlaceTy::from_aligned_ptr(ptr, layout), AtomicReadOrd::Relaxed)?;
326-
let compare_val = this.read_scalar(&MPlaceTy::from_aligned_ptr(compare, layout).into())?;
326+
let compare_val = this.read_scalar(&MPlaceTy::from_aligned_ptr(compare, layout))?;
327327

328328
if futex_val == compare_val {
329329
// If the values are the same, we have to block.

0 commit comments

Comments
 (0)