Skip to content

Commit 99d7064

Browse files
committed
Auto merge of #2994 - RalfJung:rustup, r=RalfJung
Rustup
2 parents ab619d5 + b8da978 commit 99d7064

19 files changed

+131
-151
lines changed

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
98db99f5f6273d95497dd83d1b3a62c2c00292b1
1+
d150dbb067e66f351a0b33a54e7d4b464ef51e47

src/concurrency/data_race.rs

+10-10
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)
@@ -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
@@ -513,12 +513,12 @@ 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)?;
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

@@ -538,8 +538,8 @@ 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()))?;
542-
this.allow_data_races_mut(|this| this.write_scalar(new, &place.into()))?;
541+
let old = this.allow_data_races_mut(|this| this.read_scalar(place))?;
542+
this.allow_data_races_mut(|this| this.write_scalar(new, place))?;
543543

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

@@ -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 {
@@ -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

@@ -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
@@ -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

+1-1
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

+5-5
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()?;
@@ -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

+23-23
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

@@ -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

@@ -600,14 +600,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
600600
/// necessary.
601601
fn last_error_place(&mut self) -> InterpResult<'tcx, MPlaceTy<'tcx, Provenance>> {
602602
let this = self.eval_context_mut();
603-
if let Some(errno_place) = this.active_thread_ref().last_error {
604-
Ok(errno_place)
603+
if let Some(errno_place) = this.active_thread_ref().last_error.as_ref() {
604+
Ok(errno_place.clone())
605605
} else {
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())?;
610-
this.active_thread_mut().last_error = Some(errno_place);
609+
this.write_scalar(Scalar::from_u32(0), &errno_place)?;
610+
this.active_thread_mut().last_error = Some(errno_place.clone());
611611
Ok(errno_place)
612612
}
613613
}
@@ -616,14 +616,14 @@ 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.
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`
@@ -725,7 +725,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
725725

726726
let mplace = MPlaceTy::from_aligned_ptr(ptr, layout);
727727

728-
this.check_mplace(mplace)?;
728+
this.check_mplace(&mplace)?;
729729

730730
Ok(mplace)
731731
}
@@ -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(
@@ -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`
@@ -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/machine.rs

+3-3
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
}
@@ -668,7 +668,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
668668
Self::add_extern_static(
669669
this,
670670
"environ",
671-
this.machine.env_vars.environ.unwrap().ptr,
671+
this.machine.env_vars.environ.as_ref().unwrap().ptr,
672672
);
673673
// A couple zero-initialized pointer-sized extern statics.
674674
// Most of them are for weak symbols, which we all set to null (indicating that the
@@ -685,7 +685,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
685685
Self::add_extern_static(
686686
this,
687687
"environ",
688-
this.machine.env_vars.environ.unwrap().ptr,
688+
this.machine.env_vars.environ.as_ref().unwrap().ptr,
689689
);
690690
}
691691
"android" => {

src/shims/backtrace.rs

+9-15
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),
@@ -194,35 +194,29 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
194194
let filename_alloc =
195195
this.allocate_str(&filename, MiriMemoryKind::Rust.into(), Mutability::Mut)?;
196196

197-
this.write_immediate(
198-
name_alloc.to_ref(this),
199-
&this.project_field(&dest, 0)?.into(),
200-
)?;
201-
this.write_immediate(
202-
filename_alloc.to_ref(this),
203-
&this.project_field(&dest, 1)?.into(),
204-
)?;
197+
this.write_immediate(name_alloc.to_ref(this), &this.project_field(&dest, 0)?)?;
198+
this.write_immediate(filename_alloc.to_ref(this), &this.project_field(&dest, 1)?)?;
205199
}
206200
1 => {
207201
this.write_scalar(
208202
Scalar::from_target_usize(name.len().try_into().unwrap(), this),
209-
&this.project_field(&dest, 0)?.into(),
203+
&this.project_field(&dest, 0)?,
210204
)?;
211205
this.write_scalar(
212206
Scalar::from_target_usize(filename.len().try_into().unwrap(), this),
213-
&this.project_field(&dest, 1)?.into(),
207+
&this.project_field(&dest, 1)?,
214208
)?;
215209
}
216210
_ => throw_unsup_format!("unknown `miri_resolve_frame` flags {}", flags),
217211
}
218212

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())?;
213+
this.write_scalar(Scalar::from_u32(lineno), &this.project_field(&dest, 2)?)?;
214+
this.write_scalar(Scalar::from_u32(colno), &this.project_field(&dest, 3)?)?;
221215

222216
// Support a 4-field struct for now - this is deprecated
223217
// and slated for removal.
224218
if num_fields == 5 {
225-
this.write_pointer(fn_ptr, &this.project_field(&dest, 4)?.into())?;
219+
this.write_pointer(fn_ptr, &this.project_field(&dest, 4)?)?;
226220
}
227221

228222
Ok(())

0 commit comments

Comments
 (0)