Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7516912

Browse files
committedMay 29, 2024
Auto merge of rust-lang#125691 - jieyouxu:rollup-0i3wrc4, r=jieyouxu
Rollup of 8 pull requests Successful merges: - rust-lang#124251 (Add an intrinsic for `ptr::metadata`) - rust-lang#124320 (Add `--print=check-cfg` to get the expected configs) - rust-lang#125226 (Make more of the test suite run on Mac Catalyst) - rust-lang#125381 (Silence some resolve errors when there have been glob import errors) - rust-lang#125633 (miri: avoid making a full copy of all new allocations) - rust-lang#125638 (Rewrite `lto-smoke`, `simple-rlib` and `mixing-deps` `run-make` tests in `rmake.rs` format) - rust-lang#125639 (Support `./x doc run-make-support --open`) - rust-lang#125664 (Tweak relations to no longer rely on `TypeTrace`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents da159eb + 4c12282 commit 7516912

File tree

140 files changed

+1278
-465
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+1278
-465
lines changed
 

‎compiler/rustc_const_eval/src/interpret/memory.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
239239

240240
pub fn allocate_raw_ptr(
241241
&mut self,
242-
alloc: Allocation,
242+
alloc: Allocation<M::Provenance, (), M::Bytes>,
243243
kind: MemoryKind<M::MemoryKind>,
244244
) -> InterpResult<'tcx, Pointer<M::Provenance>> {
245245
let id = self.tcx.reserve_alloc_id();
@@ -248,8 +248,11 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
248248
M::GLOBAL_KIND.map(MemoryKind::Machine),
249249
"dynamically allocating global memory"
250250
);
251-
let alloc = M::adjust_allocation(self, id, Cow::Owned(alloc), Some(kind))?;
252-
self.memory.alloc_map.insert(id, (kind, alloc.into_owned()));
251+
// We have set things up so we don't need to call `adjust_from_tcx` here,
252+
// so we avoid copying the entire allocation contents.
253+
let extra = M::init_alloc_extra(self, id, kind, alloc.size(), alloc.align)?;
254+
let alloc = alloc.with_extra(extra);
255+
self.memory.alloc_map.insert(id, (kind, alloc));
253256
M::adjust_alloc_root_pointer(self, Pointer::from(id), Some(kind))
254257
}
255258

@@ -583,11 +586,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
583586
};
584587
M::before_access_global(self.tcx, &self.machine, id, alloc, def_id, is_write)?;
585588
// We got tcx memory. Let the machine initialize its "extra" stuff.
586-
M::adjust_allocation(
589+
M::adjust_global_allocation(
587590
self,
588591
id, // always use the ID we got as input, not the "hidden" one.
589-
Cow::Borrowed(alloc.inner()),
590-
M::GLOBAL_KIND.map(MemoryKind::Machine),
592+
alloc.inner(),
591593
)
592594
}
593595

‎compiler/rustc_const_eval/src/interpret/operator.rs

+24-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_middle::{bug, span_bug};
99
use rustc_span::symbol::sym;
1010
use tracing::trace;
1111

12-
use super::{err_ub, throw_ub, ImmTy, InterpCx, Machine};
12+
use super::{err_ub, throw_ub, ImmTy, InterpCx, Machine, MemPlaceMeta};
1313

1414
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
1515
fn three_way_compare<T: Ord>(&self, lhs: T, rhs: T) -> ImmTy<'tcx, M::Provenance> {
@@ -415,11 +415,11 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
415415
use rustc_middle::mir::UnOp::*;
416416

417417
let layout = val.layout;
418-
let val = val.to_scalar();
419418
trace!("Running unary op {:?}: {:?} ({})", un_op, val, layout.ty);
420419

421420
match layout.ty.kind() {
422421
ty::Bool => {
422+
let val = val.to_scalar();
423423
let val = val.to_bool()?;
424424
let res = match un_op {
425425
Not => !val,
@@ -428,6 +428,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
428428
Ok(ImmTy::from_bool(res, *self.tcx))
429429
}
430430
ty::Float(fty) => {
431+
let val = val.to_scalar();
431432
// No NaN adjustment here, `-` is a bitwise operation!
432433
let res = match (un_op, fty) {
433434
(Neg, FloatTy::F32) => Scalar::from_f32(-val.to_f32()?),
@@ -436,8 +437,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
436437
};
437438
Ok(ImmTy::from_scalar(res, layout))
438439
}
439-
_ => {
440-
assert!(layout.ty.is_integral());
440+
_ if layout.ty.is_integral() => {
441+
let val = val.to_scalar();
441442
let val = val.to_bits(layout.size)?;
442443
let res = match un_op {
443444
Not => self.truncate(!val, layout), // bitwise negation, then truncate
@@ -450,9 +451,28 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
450451
// Truncate to target type.
451452
self.truncate(res, layout)
452453
}
454+
_ => span_bug!(self.cur_span(), "Invalid integer op {:?}", un_op),
453455
};
454456
Ok(ImmTy::from_uint(res, layout))
455457
}
458+
ty::RawPtr(..) => {
459+
assert_eq!(un_op, PtrMetadata);
460+
let (_, meta) = val.to_scalar_and_meta();
461+
Ok(match meta {
462+
MemPlaceMeta::Meta(scalar) => {
463+
let ty = un_op.ty(*self.tcx, val.layout.ty);
464+
let layout = self.layout_of(ty)?;
465+
ImmTy::from_scalar(scalar, layout)
466+
}
467+
MemPlaceMeta::None => {
468+
let unit_layout = self.layout_of(self.tcx.types.unit)?;
469+
ImmTy::uninit(unit_layout)
470+
}
471+
})
472+
}
473+
_ => {
474+
bug!("Unexpected unary op argument {val:?}")
475+
}
456476
}
457477
}
458478
}
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.