Make Miri's enter_trace_span! call const_eval's

This commit is contained in:
Stypox
2025-07-31 15:36:44 +02:00
parent e1f674cfa9
commit bb08a4dfc7
3 changed files with 9 additions and 26 deletions

View File

@@ -114,11 +114,11 @@ impl EnteredTraceSpan for tracing::span::EnteredSpan {}
/// ```
#[macro_export]
macro_rules! enter_trace_span {
($machine:ident, $name:ident :: $subname:ident $($tt:tt)*) => {{
($machine:ty, $name:ident :: $subname:ident $($tt:tt)*) => {
$crate::enter_trace_span!($machine, stringify!($name), $name = %stringify!($subname) $($tt)*)
}};
};
($machine:ident, $($tt:tt)*) => {
($machine:ty, $($tt:tt)*) => {
<$machine as $crate::interpret::Machine>::enter_trace_span(|| tracing::info_span!($($tt)*))
}
};
}

View File

@@ -1245,29 +1245,14 @@ impl ToU64 for usize {
}
}
/// This struct is needed to enforce `#[must_use]` on values produced by [enter_trace_span] even
/// when the "tracing" feature is not enabled.
#[must_use]
pub struct MaybeEnteredTraceSpan {
#[cfg(feature = "tracing")]
pub _entered_span: tracing::span::EnteredSpan,
}
/// Enters a [tracing::info_span] only if the "tracing" feature is enabled, otherwise does nothing.
/// This is like [rustc_const_eval::enter_trace_span] except that it does not depend on the
/// [Machine] trait to check if tracing is enabled, because from the Miri codebase we can directly
/// check whether the "tracing" feature is enabled, unlike from the rustc_const_eval codebase.
/// This calls [rustc_const_eval::enter_trace_span] with [MiriMachine] as the first argument, which
/// will in turn call [MiriMachine::enter_trace_span], which takes care of determining at compile
/// time whether to trace or not (and supposedly the call is compiled out if tracing is disabled).
/// Look at [rustc_const_eval::enter_trace_span] for complete documentation, examples and tips.
#[macro_export]
macro_rules! enter_trace_span {
($name:ident :: $subname:ident $($tt:tt)*) => {{
$crate::enter_trace_span!(stringify!($name), $name = %stringify!($subname) $($tt)*)
}};
($($tt:tt)*) => {
$crate::MaybeEnteredTraceSpan {
#[cfg(feature = "tracing")]
_entered_span: tracing::info_span!($($tt)*).entered()
}
rustc_const_eval::enter_trace_span!($crate::MiriMachine<'static>, $($tt)*)
};
}

View File

@@ -143,9 +143,7 @@ pub use crate::eval::{
AlignmentCheck, BacktraceStyle, IsolatedOp, MiriConfig, MiriEntryFnType, RejectOpWith,
ValidationMode, create_ecx, eval_entry,
};
pub use crate::helpers::{
AccessKind, EvalContextExt as _, MaybeEnteredTraceSpan, ToU64 as _, ToUsize as _,
};
pub use crate::helpers::{AccessKind, EvalContextExt as _, ToU64 as _, ToUsize as _};
pub use crate::intrinsics::EvalContextExt as _;
pub use crate::machine::{
AllocExtra, DynMachineCallback, FrameExtra, MachineCallback, MemoryKind, MiriInterpCx,