Skip to content

Commit 8d84b08

Browse files
authored
Merge pull request #4492 from rust-lang/rustup-2025-07-25
Automatic Rustup
2 parents da7506e + 67a73f9 commit 8d84b08

File tree

4 files changed

+11
-67
lines changed

4 files changed

+11
-67
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9748d87dc70a9a6725c5dbd76ce29d04752b4f90
1+
b56aaec52bc0fa35591a872fb4aac81f606e265c

src/machine.rs

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use std::any::Any;
55
use std::borrow::Cow;
66
use std::cell::{Cell, RefCell};
7-
use std::collections::hash_map::Entry;
87
use std::path::Path;
98
use std::rc::Rc;
109
use std::{fmt, process};
@@ -70,32 +69,19 @@ pub struct FrameExtra<'tcx> {
7069
/// This is used by `MiriMachine::current_span` and `MiriMachine::caller_span`
7170
pub is_user_relevant: bool,
7271

73-
/// We have a cache for the mapping from [`mir::Const`] to resulting [`AllocId`].
74-
/// However, we don't want all frames to always get the same result, so we insert
75-
/// an additional bit of "salt" into the cache key. This salt is fixed per-frame
76-
/// so that within a call, a const will have a stable address.
77-
salt: usize,
78-
7972
/// Data race detector per-frame data.
8073
pub data_race: Option<data_race::FrameState>,
8174
}
8275

8376
impl<'tcx> std::fmt::Debug for FrameExtra<'tcx> {
8477
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
8578
// Omitting `timing`, it does not support `Debug`.
86-
let FrameExtra {
87-
borrow_tracker,
88-
catch_unwind,
89-
timing: _,
90-
is_user_relevant,
91-
salt,
92-
data_race,
93-
} = self;
79+
let FrameExtra { borrow_tracker, catch_unwind, timing: _, is_user_relevant, data_race } =
80+
self;
9481
f.debug_struct("FrameData")
9582
.field("borrow_tracker", borrow_tracker)
9683
.field("catch_unwind", catch_unwind)
9784
.field("is_user_relevant", is_user_relevant)
98-
.field("salt", salt)
9985
.field("data_race", data_race)
10086
.finish()
10187
}
@@ -108,7 +94,6 @@ impl VisitProvenance for FrameExtra<'_> {
10894
borrow_tracker,
10995
timing: _,
11096
is_user_relevant: _,
111-
salt: _,
11297
data_race: _,
11398
} = self;
11499

@@ -578,11 +563,6 @@ pub struct MiriMachine<'tcx> {
578563
/// diagnostics.
579564
pub(crate) allocation_spans: RefCell<FxHashMap<AllocId, (Span, Option<Span>)>>,
580565

581-
/// Maps MIR consts to their evaluated result. We combine the const with a "salt" (`usize`)
582-
/// that is fixed per stack frame; this lets us have sometimes different results for the
583-
/// same const while ensuring consistent results within a single call.
584-
const_cache: RefCell<FxHashMap<(mir::Const<'tcx>, usize), OpTy<'tcx>>>,
585-
586566
/// For each allocation, an offset inside that allocation that was deemed aligned even for
587567
/// symbolic alignment checks. This cannot be stored in `AllocExtra` since it needs to be
588568
/// tracked for vtables and function allocations as well as regular allocations.
@@ -764,7 +744,6 @@ impl<'tcx> MiriMachine<'tcx> {
764744
stack_size,
765745
collect_leak_backtraces: config.collect_leak_backtraces,
766746
allocation_spans: RefCell::new(FxHashMap::default()),
767-
const_cache: RefCell::new(FxHashMap::default()),
768747
symbolic_alignment: RefCell::new(FxHashMap::default()),
769748
union_data_ranges: FxHashMap::default(),
770749
pthread_mutex_sanity: Cell::new(false),
@@ -941,7 +920,6 @@ impl VisitProvenance for MiriMachine<'_> {
941920
stack_size: _,
942921
collect_leak_backtraces: _,
943922
allocation_spans: _,
944-
const_cache: _,
945923
symbolic_alignment: _,
946924
union_data_ranges: _,
947925
pthread_mutex_sanity: _,
@@ -1578,7 +1556,6 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
15781556
catch_unwind: None,
15791557
timing,
15801558
is_user_relevant: ecx.machine.is_user_relevant(&frame),
1581-
salt: ecx.machine.rng.borrow_mut().random_range(0..ADDRS_PER_ANON_GLOBAL),
15821559
data_race: ecx
15831560
.machine
15841561
.data_race
@@ -1737,33 +1714,6 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
17371714
interp_ok(())
17381715
}
17391716

1740-
fn eval_mir_constant<F>(
1741-
ecx: &InterpCx<'tcx, Self>,
1742-
val: mir::Const<'tcx>,
1743-
span: Span,
1744-
layout: Option<TyAndLayout<'tcx>>,
1745-
eval: F,
1746-
) -> InterpResult<'tcx, OpTy<'tcx>>
1747-
where
1748-
F: Fn(
1749-
&InterpCx<'tcx, Self>,
1750-
mir::Const<'tcx>,
1751-
Span,
1752-
Option<TyAndLayout<'tcx>>,
1753-
) -> InterpResult<'tcx, OpTy<'tcx>>,
1754-
{
1755-
let frame = ecx.active_thread_stack().last().unwrap();
1756-
let mut cache = ecx.machine.const_cache.borrow_mut();
1757-
match cache.entry((val, frame.extra.salt)) {
1758-
Entry::Vacant(ve) => {
1759-
let op = eval(ecx, val, span, layout)?;
1760-
ve.insert(op.clone());
1761-
interp_ok(op)
1762-
}
1763-
Entry::Occupied(oe) => interp_ok(oe.get().clone()),
1764-
}
1765-
}
1766-
17671717
fn get_global_alloc_salt(
17681718
ecx: &InterpCx<'tcx, Self>,
17691719
instance: Option<ty::Instance<'tcx>>,

tests/pass/const-addrs.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
1-
// The const fn interpreter creates a new AllocId every time it evaluates any const.
2-
// If we do that in Miri, repeatedly evaluating a const causes unbounded memory use
3-
// we need to keep track of the base address for that AllocId, and the allocation is never
4-
// deallocated.
5-
// In Miri we explicitly store previously-assigned AllocIds for each const and ensure
6-
// that we only hand out a finite number of AllocIds per const.
7-
// MIR inlining will put every evaluation of the const we're repeatedly evaluating into the same
8-
// stack frame, breaking this test.
1+
// The interpreter used to create a new AllocId every time it evaluates any const.
2+
// This caused unbounded memory use in Miri.
3+
// This test verifies that we only create a bounded amount of addresses for any given const.
4+
// In practice, the interpreter always returns the same address, but we *do not guarantee* that.
95
//@compile-flags: -Zinline-mir=no
106

11-
const EVALS: usize = 256;
7+
const EVALS: usize = 64;
128

139
use std::collections::HashSet;
1410
fn main() {
1511
let mut addrs = HashSet::new();
1612
for _ in 0..EVALS {
1713
addrs.insert(const_addr());
1814
}
19-
// Check that the const allocation has multiple base addresses
20-
assert!(addrs.len() > 1);
21-
// But also that we get a limited number of unique base addresses
22-
assert!(addrs.len() < EVALS);
15+
// Check that we always return the same base address for the const allocation.
16+
assert_eq!(addrs.len(), 1);
2317

2418
// Check that within a call we always produce the same address
2519
let mut prev = 0;

tests/x86_64-unknown-kernel.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"llvm-target": "x86_64-unknown-none",
33
"target-endian": "little",
44
"target-pointer-width": "64",
5-
"target-c-int-width": "32",
5+
"target-c-int-width": 32,
66
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
77
"arch": "x86_64",
88
"os": "none",

0 commit comments

Comments
 (0)