Skip to content

Commit d9ad25e

Browse files
committed
Auto merge of rust-lang#2548 - RalfJung:remove-tls-diagnostics-hack, r=RalfJung
avoid thread-local var indirection for non-halting diagnostics This hack used to be necessary because Stacked Borrows did not have access to enough parts of the machine. But that got fixed a while ago, so now we can just emit diagnostics directly, which is a lot more reliable. Needs rust-lang#101985 Fixes rust-lang/miri#2538
2 parents 4b9463c + 7687b7e commit d9ad25e

Some content is hidden

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

47 files changed

+362
-410
lines changed

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2019147c5642c08cdb9ad4cacd97dd1fa4ffa701
1+
acb8934fd57b3c2740c4abac0a5728c2c9b1423b

src/concurrency/data_race.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,8 @@ impl MemoryCellClocks {
438438
}
439439

440440
/// Evaluation context extensions.
441-
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for MiriEvalContext<'mir, 'tcx> {}
442-
pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
441+
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for MiriInterpCx<'mir, 'tcx> {}
442+
pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> {
443443
/// Atomic variant of read_scalar_at_offset.
444444
fn read_scalar_at_offset_atomic(
445445
&self,
@@ -940,8 +940,8 @@ impl VClockAlloc {
940940
}
941941
}
942942

943-
impl<'mir, 'tcx: 'mir> EvalContextPrivExt<'mir, 'tcx> for MiriEvalContext<'mir, 'tcx> {}
944-
trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
943+
impl<'mir, 'tcx: 'mir> EvalContextPrivExt<'mir, 'tcx> for MiriInterpCx<'mir, 'tcx> {}
944+
trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> {
945945
/// Temporarily allow data-races to occur. This should only be used in
946946
/// one of these cases:
947947
/// - One of the appropriate `validate_atomic` functions will be called to
@@ -950,7 +950,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
950950
/// cannot be accessed by the interpreted program.
951951
/// - Execution of the interpreted program execution has halted.
952952
#[inline]
953-
fn allow_data_races_ref<R>(&self, op: impl FnOnce(&MiriEvalContext<'mir, 'tcx>) -> R) -> R {
953+
fn allow_data_races_ref<R>(&self, op: impl FnOnce(&MiriInterpCx<'mir, 'tcx>) -> R) -> R {
954954
let this = self.eval_context_ref();
955955
if let Some(data_race) = &this.machine.data_race {
956956
let old = data_race.ongoing_action_data_race_free.replace(true);
@@ -969,7 +969,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
969969
#[inline]
970970
fn allow_data_races_mut<R>(
971971
&mut self,
972-
op: impl FnOnce(&mut MiriEvalContext<'mir, 'tcx>) -> R,
972+
op: impl FnOnce(&mut MiriInterpCx<'mir, 'tcx>) -> R,
973973
) -> R {
974974
let this = self.eval_context_mut();
975975
if let Some(data_race) = &this.machine.data_race {

src/concurrency/sync.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ pub(crate) struct SynchronizationState {
159159
}
160160

161161
// Private extension trait for local helper methods
162-
impl<'mir, 'tcx: 'mir> EvalContextExtPriv<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
163-
trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
162+
impl<'mir, 'tcx: 'mir> EvalContextExtPriv<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
163+
trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
164164
/// Take a reader out of the queue waiting for the lock.
165165
/// Returns `true` if some thread got the rwlock.
166166
#[inline]
@@ -208,8 +208,8 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
208208
// cases, the function calls are infallible and it is the client's (shim
209209
// implementation's) responsibility to detect and deal with erroneous
210210
// situations.
211-
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
212-
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
211+
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
212+
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
213213
#[inline]
214214
/// Create state for a new mutex.
215215
fn mutex_create(&mut self) -> MutexId {
@@ -222,7 +222,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
222222
/// otherwise returns the value from the closure
223223
fn mutex_get_or_create<F>(&mut self, existing: F) -> InterpResult<'tcx, MutexId>
224224
where
225-
F: FnOnce(&mut MiriEvalContext<'mir, 'tcx>, MutexId) -> InterpResult<'tcx, Option<MutexId>>,
225+
F: FnOnce(&mut MiriInterpCx<'mir, 'tcx>, MutexId) -> InterpResult<'tcx, Option<MutexId>>,
226226
{
227227
let this = self.eval_context_mut();
228228
let next_index = this.machine.threads.sync.mutexes.next_index();
@@ -322,10 +322,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
322322
/// otherwise returns the value from the closure
323323
fn rwlock_get_or_create<F>(&mut self, existing: F) -> InterpResult<'tcx, RwLockId>
324324
where
325-
F: FnOnce(
326-
&mut MiriEvalContext<'mir, 'tcx>,
327-
RwLockId,
328-
) -> InterpResult<'tcx, Option<RwLockId>>,
325+
F: FnOnce(&mut MiriInterpCx<'mir, 'tcx>, RwLockId) -> InterpResult<'tcx, Option<RwLockId>>,
329326
{
330327
let this = self.eval_context_mut();
331328
let next_index = this.machine.threads.sync.rwlocks.next_index();
@@ -492,7 +489,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
492489
fn condvar_get_or_create<F>(&mut self, existing: F) -> InterpResult<'tcx, CondvarId>
493490
where
494491
F: FnOnce(
495-
&mut MiriEvalContext<'mir, 'tcx>,
492+
&mut MiriInterpCx<'mir, 'tcx>,
496493
CondvarId,
497494
) -> InterpResult<'tcx, Option<CondvarId>>,
498495
{

src/concurrency/thread.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ pub enum SchedulingAction {
3232

3333
/// Timeout callbacks can be created by synchronization primitives to tell the
3434
/// scheduler that they should be called once some period of time passes.
35-
type TimeoutCallback<'mir, 'tcx> =
36-
Box<dyn FnOnce(&mut InterpCx<'mir, 'tcx, Evaluator<'mir, 'tcx>>) -> InterpResult<'tcx> + 'tcx>;
35+
type TimeoutCallback<'mir, 'tcx> = Box<
36+
dyn FnOnce(&mut InterpCx<'mir, 'tcx, MiriMachine<'mir, 'tcx>>) -> InterpResult<'tcx> + 'tcx,
37+
>;
3738

3839
/// A thread identifier.
3940
#[derive(Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Hash)]
@@ -253,7 +254,7 @@ impl<'mir, 'tcx> Default for ThreadManager<'mir, 'tcx> {
253254
}
254255

255256
impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> {
256-
pub(crate) fn init(ecx: &mut MiriEvalContext<'mir, 'tcx>) {
257+
pub(crate) fn init(ecx: &mut MiriInterpCx<'mir, 'tcx>) {
257258
if ecx.tcx.sess.target.os.as_ref() != "windows" {
258259
// The main thread can *not* be joined on except on windows.
259260
ecx.machine.threads.threads[ThreadId::new(0)].join_status = ThreadJoinStatus::Detached;
@@ -628,8 +629,8 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> {
628629
}
629630

630631
// Public interface to thread management.
631-
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
632-
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
632+
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
633+
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
633634
/// Get a thread-specific allocation id for the given thread-local static.
634635
/// If needed, allocate a new one.
635636
fn get_or_create_thread_local_alloc(

src/concurrency/weak_memory.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,9 @@ impl StoreElement {
456456
}
457457
}
458458

459-
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
459+
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
460460
pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
461-
crate::MiriEvalContextExt<'mir, 'tcx>
461+
crate::MiriInterpCxExt<'mir, 'tcx>
462462
{
463463
// If weak memory emulation is enabled, check if this atomic op imperfectly overlaps with a previous
464464
// atomic read or write. If it does, then we require it to be ordered (non-racy) with all previous atomic
@@ -502,7 +502,7 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
502502
let (alloc_id, base_offset, ..) = this.ptr_get_alloc_id(place.ptr)?;
503503
if let (
504504
crate::AllocExtra { weak_memory: Some(alloc_buffers), .. },
505-
crate::Evaluator { data_race: Some(global), threads, .. },
505+
crate::MiriMachine { data_race: Some(global), threads, .. },
506506
) = this.get_alloc_extra_mut(alloc_id)?
507507
{
508508
if atomic == AtomicRwOrd::SeqCst {
@@ -544,7 +544,7 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
544544
validate,
545545
)?;
546546
if global.track_outdated_loads && recency == LoadRecency::Outdated {
547-
register_diagnostic(NonHaltingDiagnostic::WeakMemoryOutdatedLoad);
547+
this.emit_diagnostic(NonHaltingDiagnostic::WeakMemoryOutdatedLoad);
548548
}
549549

550550
return Ok(loaded);
@@ -567,7 +567,7 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
567567
let (alloc_id, base_offset, ..) = this.ptr_get_alloc_id(dest.ptr)?;
568568
if let (
569569
crate::AllocExtra { weak_memory: Some(alloc_buffers), .. },
570-
crate::Evaluator { data_race: Some(global), threads, .. },
570+
crate::MiriMachine { data_race: Some(global), threads, .. },
571571
) = this.get_alloc_extra_mut(alloc_id)?
572572
{
573573
if atomic == AtomicWriteOrd::SeqCst {

0 commit comments

Comments
 (0)