Skip to content

Commit 302d357

Browse files
committed
interpret: make write functions generic over the place type
1 parent 22008f1 commit 302d357

File tree

16 files changed

+71
-71
lines changed

16 files changed

+71
-71
lines changed

src/concurrency/data_race.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> {
490490
this.atomic_access_check(dest)?;
491491

492492
this.validate_overlapping_atomic(dest)?;
493-
this.allow_data_races_mut(move |this| this.write_scalar(val, &dest.into()))?;
493+
this.allow_data_races_mut(move |this| this.write_scalar(val, dest))?;
494494
this.validate_atomic_store(dest, atomic)?;
495495
// FIXME: it's not possible to get the value before write_scalar. A read_scalar will cause
496496
// side effects from a read the program did not perform. So we have to initialise
@@ -518,7 +518,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> {
518518
// Atomics wrap around on overflow.
519519
let val = this.binary_op(op, &old, rhs)?;
520520
let val = if neg { this.unary_op(mir::UnOp::Not, &val)? } else { val };
521-
this.allow_data_races_mut(|this| this.write_immediate(*val, &place.into()))?;
521+
this.allow_data_races_mut(|this| this.write_immediate(*val, place))?;
522522

523523
this.validate_atomic_rmw(place, atomic)?;
524524

@@ -539,7 +539,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> {
539539

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

544544
this.validate_atomic_rmw(place, atomic)?;
545545

@@ -569,7 +569,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> {
569569
if lt { &rhs } else { &old }
570570
};
571571

572-
this.allow_data_races_mut(|this| this.write_immediate(**new_val, &place.into()))?;
572+
this.allow_data_races_mut(|this| this.write_immediate(**new_val, place))?;
573573

574574
this.validate_atomic_rmw(place, atomic)?;
575575

@@ -621,7 +621,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> {
621621
// if successful, perform a full rw-atomic validation
622622
// otherwise treat this as an atomic load with the fail ordering.
623623
if cmpxchg_success {
624-
this.allow_data_races_mut(|this| this.write_scalar(new, &place.into()))?;
624+
this.allow_data_races_mut(|this| this.write_scalar(new, place))?;
625625
this.validate_atomic_rmw(place, success)?;
626626
this.buffered_atomic_rmw(new, place, success, old.to_scalar())?;
627627
} else {

src/concurrency/thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
834834
if let Some(thread_info_place) = thread {
835835
this.write_scalar(
836836
Scalar::from_uint(new_thread_id.to_u32(), thread_info_place.layout.size),
837-
&thread_info_place.into(),
837+
&thread_info_place,
838838
)?;
839839
}
840840

src/eval.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
321321
let argvs_place = ecx.allocate(argvs_layout, MiriMemoryKind::Machine.into())?;
322322
for (idx, arg) in argvs.into_iter().enumerate() {
323323
let place = ecx.project_field(&argvs_place, idx)?;
324-
ecx.write_immediate(arg, &place.into())?;
324+
ecx.write_immediate(arg, &place)?;
325325
}
326326
ecx.mark_immutable(&argvs_place);
327327
// A pointer to that place is the 3rd argument for main.
@@ -330,15 +330,15 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
330330
{
331331
let argc_place =
332332
ecx.allocate(ecx.machine.layouts.isize, MiriMemoryKind::Machine.into())?;
333-
ecx.write_scalar(argc, &argc_place.into())?;
333+
ecx.write_scalar(argc, &argc_place)?;
334334
ecx.mark_immutable(&argc_place);
335335
ecx.machine.argc = Some(*argc_place);
336336

337337
let argv_place = ecx.allocate(
338338
ecx.layout_of(Ty::new_imm_ptr(tcx, tcx.types.unit))?,
339339
MiriMemoryKind::Machine.into(),
340340
)?;
341-
ecx.write_immediate(argv, &argv_place.into())?;
341+
ecx.write_immediate(argv, &argv_place)?;
342342
ecx.mark_immutable(&argv_place);
343343
ecx.machine.argv = Some(*argv_place);
344344
}
@@ -355,7 +355,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
355355
// Store the UTF-16 string. We just allocated so we know the bounds are fine.
356356
for (idx, &c) in cmd_utf16.iter().enumerate() {
357357
let place = ecx.project_field(&cmd_place, idx)?;
358-
ecx.write_scalar(Scalar::from_u16(c), &place.into())?;
358+
ecx.write_scalar(Scalar::from_u16(c), &place)?;
359359
}
360360
ecx.mark_immutable(&cmd_place);
361361
}

src/helpers.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
231231
}
232232

233233
/// Project to the given *named* field (which must be a struct or union type).
234-
fn project_field_named<P: Projectable<'mir, 'tcx, Provenance>>(
234+
fn project_field_named<P: Projectable<'tcx, Provenance>>(
235235
&self,
236236
base: &P,
237237
name: &str,
@@ -252,13 +252,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
252252
fn write_int(
253253
&mut self,
254254
i: impl Into<i128>,
255-
dest: &PlaceTy<'tcx, Provenance>,
255+
dest: &impl Writeable<'tcx, Provenance>,
256256
) -> InterpResult<'tcx> {
257-
assert!(dest.layout.abi.is_scalar(), "write_int on non-scalar type {}", dest.layout.ty);
258-
let val = if dest.layout.abi.is_signed() {
259-
Scalar::from_int(i, dest.layout.size)
257+
assert!(dest.layout().abi.is_scalar(), "write_int on non-scalar type {}", dest.layout().ty);
258+
let val = if dest.layout().abi.is_signed() {
259+
Scalar::from_int(i, dest.layout().size)
260260
} else {
261-
Scalar::from_uint(u64::try_from(i.into()).unwrap(), dest.layout.size)
261+
Scalar::from_uint(u64::try_from(i.into()).unwrap(), dest.layout().size)
262262
};
263263
self.eval_context_mut().write_scalar(val, dest)
264264
}
@@ -267,12 +267,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
267267
fn write_int_fields(
268268
&mut self,
269269
values: &[i128],
270-
dest: &MPlaceTy<'tcx, Provenance>,
270+
dest: &impl Writeable<'tcx, Provenance>,
271271
) -> InterpResult<'tcx> {
272272
let this = self.eval_context_mut();
273273
for (idx, &val) in values.iter().enumerate() {
274274
let field = this.project_field(dest, idx)?;
275-
this.write_int(val, &field.into())?;
275+
this.write_int(val, &field)?;
276276
}
277277
Ok(())
278278
}
@@ -281,18 +281,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
281281
fn write_int_fields_named(
282282
&mut self,
283283
values: &[(&str, i128)],
284-
dest: &MPlaceTy<'tcx, Provenance>,
284+
dest: &impl Writeable<'tcx, Provenance>,
285285
) -> InterpResult<'tcx> {
286286
let this = self.eval_context_mut();
287287
for &(name, val) in values.iter() {
288288
let field = this.project_field_named(dest, name)?;
289-
this.write_int(val, &field.into())?;
289+
this.write_int(val, &field)?;
290290
}
291291
Ok(())
292292
}
293293

294294
/// Write a 0 of the appropriate size to `dest`.
295-
fn write_null(&mut self, dest: &PlaceTy<'tcx, Provenance>) -> InterpResult<'tcx> {
295+
fn write_null(&mut self, dest: &impl Writeable<'tcx, Provenance>) -> InterpResult<'tcx> {
296296
self.write_int(0, dest)
297297
}
298298

@@ -606,7 +606,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
606606
// Allocate new place, set initial value to 0.
607607
let errno_layout = this.machine.layouts.u32;
608608
let errno_place = this.allocate(errno_layout, MiriMemoryKind::Machine.into())?;
609-
this.write_scalar(Scalar::from_u32(0), &errno_place.into())?;
609+
this.write_scalar(Scalar::from_u32(0), &errno_place)?;
610610
this.active_thread_mut().last_error = Some(errno_place);
611611
Ok(errno_place)
612612
}
@@ -616,7 +616,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
616616
fn set_last_error(&mut self, scalar: Scalar<Provenance>) -> InterpResult<'tcx> {
617617
let this = self.eval_context_mut();
618618
let errno_place = this.last_error_place()?;
619-
this.write_scalar(scalar, &errno_place.into())
619+
this.write_scalar(scalar, &errno_place)
620620
}
621621

622622
/// Gets the last error variable.
@@ -785,7 +785,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
785785
) -> InterpResult<'tcx, ()> {
786786
let this = self.eval_context_mut();
787787
let value_place = this.deref_operand_and_offset(op, offset, base_layout, value_layout)?;
788-
this.write_scalar(value, &value_place.into())
788+
this.write_scalar(value, &value_place)
789789
}
790790

791791
/// Parse a `timespec` struct and return it as a `std::time::Duration`. It returns `None`

src/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
651651
val: ImmTy<'tcx, Provenance>,
652652
) -> InterpResult<'tcx> {
653653
let place = this.allocate(val.layout, MiriMemoryKind::ExternStatic.into())?;
654-
this.write_immediate(*val, &place.into())?;
654+
this.write_immediate(*val, &place)?;
655655
Self::add_extern_static(this, name, place.ptr);
656656
Ok(())
657657
}

src/shims/backtrace.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
8585
for (i, ptr) in ptrs.into_iter().enumerate() {
8686
let place = this.project_index(&alloc, i as u64)?;
8787

88-
this.write_pointer(ptr, &place.into())?;
88+
this.write_pointer(ptr, &place)?;
8989
}
9090

9191
this.write_immediate(
@@ -106,7 +106,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
106106

107107
let op_place = buf_place.offset(offset, ptr_layout, this)?;
108108

109-
this.write_pointer(ptr, &op_place.into())?;
109+
this.write_pointer(ptr, &op_place)?;
110110
}
111111
}
112112
_ => throw_unsup_format!("unknown `miri_get_backtrace` flags {}", flags),
@@ -196,33 +196,33 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
196196

197197
this.write_immediate(
198198
name_alloc.to_ref(this),
199-
&this.project_field(&dest, 0)?.into(),
199+
&this.project_field(&dest, 0)?,
200200
)?;
201201
this.write_immediate(
202202
filename_alloc.to_ref(this),
203-
&this.project_field(&dest, 1)?.into(),
203+
&this.project_field(&dest, 1)?,
204204
)?;
205205
}
206206
1 => {
207207
this.write_scalar(
208208
Scalar::from_target_usize(name.len().try_into().unwrap(), this),
209-
&this.project_field(&dest, 0)?.into(),
209+
&this.project_field(&dest, 0)?,
210210
)?;
211211
this.write_scalar(
212212
Scalar::from_target_usize(filename.len().try_into().unwrap(), this),
213-
&this.project_field(&dest, 1)?.into(),
213+
&this.project_field(&dest, 1)?,
214214
)?;
215215
}
216216
_ => throw_unsup_format!("unknown `miri_resolve_frame` flags {}", flags),
217217
}
218218

219-
this.write_scalar(Scalar::from_u32(lineno), &this.project_field(&dest, 2)?.into())?;
220-
this.write_scalar(Scalar::from_u32(colno), &this.project_field(&dest, 3)?.into())?;
219+
this.write_scalar(Scalar::from_u32(lineno), &this.project_field(&dest, 2)?)?;
220+
this.write_scalar(Scalar::from_u32(colno), &this.project_field(&dest, 3)?)?;
221221

222222
// Support a 4-field struct for now - this is deprecated
223223
// and slated for removal.
224224
if num_fields == 5 {
225-
this.write_pointer(fn_ptr, &this.project_field(&dest, 4)?.into())?;
225+
this.write_pointer(fn_ptr, &this.project_field(&dest, 4)?)?;
226226
}
227227

228228
Ok(())

src/shims/env.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
457457
let vars_place = this.allocate(vars_layout, MiriMemoryKind::Runtime.into())?;
458458
for (idx, var) in vars.into_iter().enumerate() {
459459
let place = this.project_field(&vars_place, idx)?;
460-
this.write_pointer(var, &place.into())?;
460+
this.write_pointer(var, &place)?;
461461
}
462-
this.write_pointer(vars_place.ptr, &this.machine.env_vars.environ.unwrap().into())?;
462+
this.write_pointer(vars_place.ptr, &this.machine.env_vars.environ.unwrap())?;
463463

464464
Ok(())
465465
}

src/shims/intrinsics/mod.rs

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

108108
"write_bytes" | "volatile_set_memory" => {

src/shims/intrinsics/simd.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
104104

105105
}
106106
};
107-
this.write_scalar(val, &dest.into())?;
107+
this.write_scalar(val, &dest)?;
108108
}
109109
}
110110
#[rustfmt::skip]
@@ -217,7 +217,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
217217
fmin_op(&left, &right)?
218218
}
219219
};
220-
this.write_scalar(val, &dest.into())?;
220+
this.write_scalar(val, &dest)?;
221221
}
222222
}
223223
"fma" => {
@@ -258,7 +258,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
258258
Scalar::from_u64(res.to_bits())
259259
}
260260
};
261-
this.write_scalar(val, &dest.into())?;
261+
this.write_scalar(val, &dest)?;
262262
}
263263
}
264264
#[rustfmt::skip]
@@ -378,7 +378,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
378378
let dest = this.project_index(&dest, i)?;
379379

380380
let val = if simd_element_to_bool(mask)? { yes } else { no };
381-
this.write_immediate(*val, &dest.into())?;
381+
this.write_immediate(*val, &dest)?;
382382
}
383383
}
384384
"select_bitmask" => {
@@ -408,7 +408,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
408408
let dest = this.project_index(&dest, i.into())?;
409409

410410
let val = if mask != 0 { yes } else { no };
411-
this.write_immediate(*val, &dest.into())?;
411+
this.write_immediate(*val, &dest)?;
412412
}
413413
for i in dest_len..bitmask_len {
414414
// If the mask is "padded", ensure that padding is all-zero.
@@ -472,7 +472,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
472472
to_ty = dest.layout.ty,
473473
),
474474
};
475-
this.write_immediate(val, &dest.into())?;
475+
this.write_immediate(val, &dest)?;
476476
}
477477
}
478478
"shuffle" => {
@@ -513,7 +513,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
513513
"simd_shuffle index {src_index} is out of bounds for 2 vectors of size {left_len}",
514514
);
515515
};
516-
this.write_immediate(*val, &dest.into())?;
516+
this.write_immediate(*val, &dest)?;
517517
}
518518
}
519519
"gather" => {
@@ -539,7 +539,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
539539
} else {
540540
passthru
541541
};
542-
this.write_immediate(*val, &dest.into())?;
542+
this.write_immediate(*val, &dest)?;
543543
}
544544
}
545545
"scatter" => {
@@ -558,7 +558,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
558558

559559
if simd_element_to_bool(mask)? {
560560
let place = this.deref_operand(&ptr.into())?;
561-
this.write_immediate(*value, &place.into())?;
561+
this.write_immediate(*value, &place)?;
562562
}
563563
}
564564
}
@@ -588,7 +588,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
588588
// We have to force the place type to be an int so that we can write `res` into it.
589589
let mut dest = this.force_allocation(dest)?;
590590
dest.layout = this.machine.layouts.uint(dest.layout.size).unwrap();
591-
this.write_int(res, &dest.into())?;
591+
this.write_int(res, &dest)?;
592592
}
593593

594594
name => throw_unsup_format!("unimplemented intrinsic: `simd_{name}`"),

src/shims/time.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
158158
})?;
159159
this.write_scalar(
160160
Scalar::from_i64(qpc),
161-
&this.deref_operand(lpPerformanceCount_op)?.into(),
161+
&this.deref_operand(lpPerformanceCount_op)?,
162162
)?;
163163
Ok(Scalar::from_i32(-1)) // return non-zero on success
164164
}
@@ -179,7 +179,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
179179
// and thus 10^9 counts per second.
180180
this.write_scalar(
181181
Scalar::from_i64(1_000_000_000),
182-
&this.deref_operand_as(lpFrequency_op, this.machine.layouts.u64)?.into(),
182+
&this.deref_operand_as(lpFrequency_op, this.machine.layouts.u64)?,
183183
)?;
184184
Ok(Scalar::from_i32(-1)) // Return non-zero on success
185185
}

0 commit comments

Comments
 (0)