Auto merge of #3972 - rust-lang:eager_dyn, r=RalfJung

Avoid some needless monomorphizations

All code paths always end up boxing the type, so let's do it eagerly in the `callback!` macro instead
This commit is contained in:
bors 2024-10-14 18:03:05 +00:00
commit d3c1036255
2 changed files with 7 additions and 10 deletions

View File

@ -2,6 +2,7 @@ use std::collections::VecDeque;
use rustc_index::Idx; use rustc_index::Idx;
use super::thread::DynUnblockCallback;
use super::vector_clock::VClock; use super::vector_clock::VClock;
use crate::*; use crate::*;
@ -34,11 +35,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
/// Put the thread into the queue waiting for the initialization. /// Put the thread into the queue waiting for the initialization.
#[inline] #[inline]
fn init_once_enqueue_and_block( fn init_once_enqueue_and_block(&mut self, id: InitOnceId, callback: DynUnblockCallback<'tcx>) {
&mut self,
id: InitOnceId,
callback: impl UnblockCallback<'tcx> + 'tcx,
) {
let this = self.eval_context_mut(); let this = self.eval_context_mut();
let thread = this.active_thread(); let thread = this.active_thread();
let init_once = &mut this.machine.sync.init_onces[id]; let init_once = &mut this.machine.sync.init_onces[id];

View File

@ -50,7 +50,7 @@ pub trait UnblockCallback<'tcx>: VisitProvenance {
fn timeout(self: Box<Self>, _ecx: &mut InterpCx<'tcx, MiriMachine<'tcx>>) fn timeout(self: Box<Self>, _ecx: &mut InterpCx<'tcx, MiriMachine<'tcx>>)
-> InterpResult<'tcx>; -> InterpResult<'tcx>;
} }
type DynUnblockCallback<'tcx> = Box<dyn UnblockCallback<'tcx> + 'tcx>; pub type DynUnblockCallback<'tcx> = Box<dyn UnblockCallback<'tcx> + 'tcx>;
#[macro_export] #[macro_export]
macro_rules! callback { macro_rules! callback {
@ -101,7 +101,7 @@ macro_rules! callback {
} }
} }
Callback { $($name,)* _phantom: std::marker::PhantomData } Box::new(Callback { $($name,)* _phantom: std::marker::PhantomData })
}} }}
} }
@ -715,11 +715,11 @@ impl<'tcx> ThreadManager<'tcx> {
&mut self, &mut self,
reason: BlockReason, reason: BlockReason,
timeout: Option<Timeout>, timeout: Option<Timeout>,
callback: impl UnblockCallback<'tcx> + 'tcx, callback: DynUnblockCallback<'tcx>,
) { ) {
let state = &mut self.threads[self.active_thread].state; let state = &mut self.threads[self.active_thread].state;
assert!(state.is_enabled()); assert!(state.is_enabled());
*state = ThreadState::Blocked { reason, timeout, callback: Box::new(callback) } *state = ThreadState::Blocked { reason, timeout, callback }
} }
/// Change the active thread to some enabled thread. /// Change the active thread to some enabled thread.
@ -1032,7 +1032,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
&mut self, &mut self,
reason: BlockReason, reason: BlockReason,
timeout: Option<(TimeoutClock, TimeoutAnchor, Duration)>, timeout: Option<(TimeoutClock, TimeoutAnchor, Duration)>,
callback: impl UnblockCallback<'tcx> + 'tcx, callback: DynUnblockCallback<'tcx>,
) { ) {
let this = self.eval_context_mut(); let this = self.eval_context_mut();
let timeout = timeout.map(|(clock, anchor, duration)| { let timeout = timeout.map(|(clock, anchor, duration)| {