Skip to content

Commit dba6c8b

Browse files
committed
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
2 parents 1362c5f + a3aa5b3 commit dba6c8b

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/concurrency/init_once.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::collections::VecDeque;
22

33
use rustc_index::Idx;
44

5+
use super::thread::DynUnblockCallback;
56
use super::vector_clock::VClock;
67
use crate::*;
78

@@ -34,11 +35,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
3435

3536
/// Put the thread into the queue waiting for the initialization.
3637
#[inline]
37-
fn init_once_enqueue_and_block(
38-
&mut self,
39-
id: InitOnceId,
40-
callback: impl UnblockCallback<'tcx> + 'tcx,
41-
) {
38+
fn init_once_enqueue_and_block(&mut self, id: InitOnceId, callback: DynUnblockCallback<'tcx>) {
4239
let this = self.eval_context_mut();
4340
let thread = this.active_thread();
4441
let init_once = &mut this.machine.sync.init_onces[id];

src/concurrency/thread.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub trait UnblockCallback<'tcx>: VisitProvenance {
5050
fn timeout(self: Box<Self>, _ecx: &mut InterpCx<'tcx, MiriMachine<'tcx>>)
5151
-> InterpResult<'tcx>;
5252
}
53-
type DynUnblockCallback<'tcx> = Box<dyn UnblockCallback<'tcx> + 'tcx>;
53+
pub type DynUnblockCallback<'tcx> = Box<dyn UnblockCallback<'tcx> + 'tcx>;
5454

5555
#[macro_export]
5656
macro_rules! callback {
@@ -101,7 +101,7 @@ macro_rules! callback {
101101
}
102102
}
103103

104-
Callback { $($name,)* _phantom: std::marker::PhantomData }
104+
Box::new(Callback { $($name,)* _phantom: std::marker::PhantomData })
105105
}}
106106
}
107107

@@ -715,11 +715,11 @@ impl<'tcx> ThreadManager<'tcx> {
715715
&mut self,
716716
reason: BlockReason,
717717
timeout: Option<Timeout>,
718-
callback: impl UnblockCallback<'tcx> + 'tcx,
718+
callback: DynUnblockCallback<'tcx>,
719719
) {
720720
let state = &mut self.threads[self.active_thread].state;
721721
assert!(state.is_enabled());
722-
*state = ThreadState::Blocked { reason, timeout, callback: Box::new(callback) }
722+
*state = ThreadState::Blocked { reason, timeout, callback }
723723
}
724724

725725
/// Change the active thread to some enabled thread.
@@ -1032,7 +1032,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
10321032
&mut self,
10331033
reason: BlockReason,
10341034
timeout: Option<(TimeoutClock, TimeoutAnchor, Duration)>,
1035-
callback: impl UnblockCallback<'tcx> + 'tcx,
1035+
callback: DynUnblockCallback<'tcx>,
10361036
) {
10371037
let this = self.eval_context_mut();
10381038
let timeout = timeout.map(|(clock, anchor, duration)| {

0 commit comments

Comments
 (0)