1//! This module contains the `InterpCx` methods for executing a single step of the interpreter.
2//!
3//! The main entry point is the `step` method.
45use std::iter;
67use either::Either;
8use rustc_abi::{FIRST_VARIANT, FieldIdx};
9use rustc_data_structures::fx::FxHashSet;
10use rustc_index::IndexSlice;
11use rustc_middle::mir;
12use rustc_middle::ty::{self, Instance, Ty};
13use rustc_span::{Spanned, bug, span_bug};
14use rustc_target::callconv::FnAbi;
15use tracing::field::Empty;
16use tracing::{info, instrument, trace};
1718use super::{
19EnteredTraceSpan, FnArg, FnVal, ImmTy, Immediate, InterpCx, InterpResult, Machine,
20MemPlaceMeta, PlaceTy, Projectable, RetagMode, interp_ok, throw_ub, throw_unsup_format,
21};
22use crate::{enter_trace_span, util};
2324struct EvaluatedCalleeAndArgs<'tcx, M: Machine<'tcx>> {
25 callee: FnVal<'tcx, M::ExtraFnVal>,
26 args: Vec<FnArg<'tcx, M::Provenance>>,
27 fn_sig: ty::FnSig<'tcx>,
28/// None if LLVM intrinsic
29fn_abi: Option<&'tcx FnAbi<'tcx, Ty<'tcx>>>,
30/// True if the function is marked as `#[track_caller]` ([`ty::InstanceKind::requires_caller_location`])
31with_caller_location: bool,
32}
3334impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
35/// Returns `true` as long as there are more things to do.
36 ///
37 /// This is used by [priroda](https://github.com/oli-obk/priroda)
38 ///
39 /// This is marked `#inline(always)` to work around adversarial codegen when `opt-level = 3`
40#[inline(always)]
41pub fn step(&mut self) -> InterpResult<'tcx, bool> {
42if self.stack().is_empty() {
43return interp_ok(false);
44 }
4546let Either::Left(loc) = self.frame().loc else {
47// We are unwinding and this fn has no cleanup code.
48 // Just go on unwinding.
49{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_const_eval/src/interpret/step.rs:49",
"rustc_const_eval::interpret::step",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_const_eval/src/interpret/step.rs"),
::tracing_core::__macro_support::Option::Some(49u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::step"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("unwinding: skipping frame")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};trace!("unwinding: skipping frame");
50self.return_from_current_stack_frame(/* unwinding */ true)?;
51return interp_ok(true);
52 };
53let basic_block = &self.body().basic_blocks[loc.block];
5455if let Some(stmt) = basic_block.statements.get(loc.statement_index) {
56let old_frames = self.frame_idx();
57self.eval_statement(stmt)?;
58// Make sure we are not updating `statement_index` of the wrong frame.
59{
match (&old_frames, &self.frame_idx()) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(old_frames, self.frame_idx());
60// Advance the program counter.
61self.frame_mut().loc.as_mut().left().unwrap().statement_index += 1;
62return interp_ok(true);
63 }
6465 M::before_terminator(self)?;
6667let terminator = basic_block.terminator();
68self.eval_terminator(terminator)?;
69if !self.stack().is_empty() {
70if let Either::Left(loc) = self.frame().loc {
71{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_const_eval/src/interpret/step.rs:71",
"rustc_const_eval::interpret::step", ::tracing::Level::INFO,
::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_const_eval/src/interpret/step.rs"),
::tracing_core::__macro_support::Option::Some(71u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::step"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::INFO <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::INFO <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("// executing {0:?}",
loc.block) as &dyn ::tracing::field::Value))])
});
} else { ; }
};info!("// executing {:?}", loc.block);
72 }
73 }
74interp_ok(true)
75 }
7677/// Runs the interpretation logic for the given `mir::Statement` at the current frame and
78 /// statement counter.
79 ///
80 /// This does NOT move the statement counter forward, the caller has to do that!
81pub fn eval_statement(&mut self, stmt: &mir::Statement<'tcx>) -> InterpResult<'tcx> {
82let _trace = <M as
crate::interpret::Machine>::enter_trace_span(||
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("step",
"rustc_const_eval::interpret::step", ::tracing::Level::INFO,
::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_const_eval/src/interpret/step.rs"),
::tracing_core::__macro_support::Option::Some(82u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::step"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("step")
}> =
::tracing::__macro_support::FieldName::new("step");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("stmt")
}> =
::tracing::__macro_support::FieldName::new("stmt");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("span")
}> =
::tracing::__macro_support::FieldName::new("span");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("tracing_separate_thread")
}> =
::tracing::__macro_support::FieldName::new("tracing_separate_thread");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::INFO <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::INFO <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::display(&"eval_statement")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&stmt.kind)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&stmt.source_info.span)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&Empty as
&dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
})enter_trace_span!(
83 M,
84 step::eval_statement,
85 stmt = ?stmt.kind,
86 span = ?stmt.source_info.span,
87 tracing_separate_thread = Empty,
88 )89 .or_if_tracing_disabled(|| {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_const_eval/src/interpret/step.rs:89",
"rustc_const_eval::interpret::step", ::tracing::Level::INFO,
::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_const_eval/src/interpret/step.rs"),
::tracing_core::__macro_support::Option::Some(89u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::step"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::INFO <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::INFO <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("{0:?}",
stmt.kind) as &dyn ::tracing::field::Value))])
});
} else { ; }
}info!("{:?}", stmt.kind));
9091use rustc_middle::mir::StatementKind::*;
9293match &stmt.kind {
94Assign((place, rvalue)) => self.eval_rvalue_into_place(rvalue, *place)?,
9596SetDiscriminant { place, variant_index } => {
97let dest =
98self.eval_place(**place, /* skip_validity_for_simple_deref */ false)?;
99self.write_discriminant(*variant_index, &dest)?;
100 }
101102// Mark locals as alive
103StorageLive(local) => {
104self.storage_live(*local)?;
105 }
106107// Mark locals as dead
108StorageDead(local) => {
109self.storage_dead(*local)?;
110 }
111112// No dynamic semantics attached to `FakeRead`; MIR
113 // interpreter is solely intended for borrowck'ed code.
114FakeRead(..) => {}
115116Intrinsic(intrinsic) => self.eval_nondiverging_intrinsic(intrinsic)?,
117118// Evaluate the place expression, without reading from it.
119PlaceMention(place) => {
120let _ =
121self.eval_place(**place, /* skip_validity_for_simple_deref */ false)?;
122 }
123124// This exists purely to guide borrowck lifetime inference, and does not have
125 // an operational effect.
126AscribeUserType(..) => {}
127128// Currently, Miri discards Coverage statements. Coverage statements are only injected
129 // via an optional compile time MIR pass and have no side effects. Since Coverage
130 // statements don't exist at the source level, it is safe for Miri to ignore them, even
131 // for undefined behavior (UB) checks.
132 //
133 // A coverage counter inside a const expression (for example, a counter injected in a
134 // const function) is discarded when the const is evaluated at compile time. Whether
135 // this should change, and/or how to implement a const eval counter, is a subject of the
136 // following issue:
137 //
138 // FIXME(#73156): Handle source code coverage in const eval
139Coverage(..) => {}
140141ConstEvalCounter => {
142 M::increment_const_eval_counter(self)?;
143 }
144145// Defined to do nothing. These are added by optimization passes, to avoid changing the
146 // size of MIR constantly.
147Nop => {}
148149// Only used for temporary lifetime lints
150BackwardIncompatibleDropHint { .. } => {}
151 }
152153interp_ok(())
154 }
155156/// Evaluate an assignment statement.
157 ///
158 /// There is no separate `eval_rvalue` function. Instead, the code for handling each rvalue
159 /// type writes its results directly into the memory specified by the place.
160pub fn eval_rvalue_into_place(
161&mut self,
162 rvalue: &mir::Rvalue<'tcx>,
163 place: mir::Place<'tcx>,
164 ) -> InterpResult<'tcx> {
165// We can skip validity because we'll write to the place which checks everything we care
166 // about for references, and the pointee must be sized so there's nothing to check for raw
167 // pointers.
168let dest = self.eval_place(place, /* skip_validity_for_simple_deref */ true)?;
169// FIXME: ensure some kind of non-aliasing between LHS and RHS?
170 // Also see https://github.com/rust-lang/rust/issues/68364.
171172use rustc_middle::mir::Rvalue::*;
173match *rvalue {
174ThreadLocalRef(did) => {
175let ptr = M::thread_local_static_pointer(self, did)?;
176self.write_pointer(ptr, &dest)?;
177 }
178179Use(ref operand, with_retag) => {
180// Avoid recomputing the layout
181let op = self.eval_operand(operand, Some(dest.layout))?;
182let mode = if with_retag.yes() { RetagMode::Default } else { RetagMode::None };
183 M::with_retag_mode(self, mode, |ecx| ecx.copy_op(&op, &dest))?;
184 }
185186CopyForDeref(_) => ::rustc_span::macros::bug_impl(None,
format_args!("`CopyForDeref` in runtime MIR"), Location::caller())bug!("`CopyForDeref` in runtime MIR"),
187188BinaryOp(bin_op, (ref left, ref right)) => {
189let layout = util::binop_left_homogeneous(bin_op).then_some(dest.layout);
190let left = self.read_immediate(&self.eval_operand(left, layout)?)?;
191let layout = util::binop_right_homogeneous(bin_op).then_some(left.layout);
192let right = self.read_immediate(&self.eval_operand(right, layout)?)?;
193let result = self.binary_op(bin_op, &left, &right)?;
194{
match (&result.layout, &dest.layout) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val,
::core::option::Option::Some(format_args!("layout mismatch for result of {0:?}",
bin_op)));
}
}
}
};assert_eq!(result.layout, dest.layout, "layout mismatch for result of {bin_op:?}");
195self.write_immediate(*result, &dest)?;
196 }
197198UnaryOp(un_op, ref operand) => {
199let layout = util::unop_homogeneous(un_op).then_some(dest.layout);
200let val = self.read_immediate(&self.eval_operand(operand, layout)?)?;
201let result = self.unary_op(un_op, &val)?;
202{
match (&result.layout, &dest.layout) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val,
::core::option::Option::Some(format_args!("layout mismatch for result of {0:?}",
un_op)));
}
}
}
};assert_eq!(result.layout, dest.layout, "layout mismatch for result of {un_op:?}");
203self.write_immediate(*result, &dest)?;
204 }
205206Aggregate(ref kind, ref operands) => {
207self.write_aggregate(kind, operands, &dest)?;
208 }
209210Repeat(ref operand, _) => {
211self.write_repeat(operand, &dest)?;
212 }
213214Ref(_, borrow_kind, place) => {
215// `x = &*ptr` does not need a validity check on `ptr` because we will already
216 // check `x` below.
217let src = self.eval_place(place, /* skip_validity_for_simple_deref */ true)?;
218let place = self.force_allocation(&src)?;
219let mut val = ImmTy::from_immediate(place.to_ref(self), dest.layout);
220// A fresh reference was created, make sure it gets retagged with the right mode.
221let mode = if borrow_kind.is_two_phase_borrow() {
222 RetagMode::TwoPhase223 } else {
224 RetagMode::Default225 };
226 M::with_retag_mode(self, mode, |ecx| {
227// If validation is disabled, we still want to do this retag. This is because
228 // const-eval disables validation for performance reasons but wants to retag
229 // shared references. So we add a bit of a hack here to do the retag manually
230 // if the write would not incur validation.
231if !M::enforce_validity(ecx, val.layout) {
232if let Some(new_val) = M::retag_ptr_value(ecx, &val, val.layout.ty)? {
233 val = new_val;
234 }
235 }
236// Now do the actual write.
237ecx.write_immediate(*val, &dest)
238 })?;
239 }
240241Reborrow(_, mutability, place) => {
242let op = self.eval_place_to_op(place, None)?;
243if mutability.is_not() {
244// Shared generic reborrows use `CoerceShared`: a bitwise copy into a
245 // distinct same-layout target ADT.
246self.copy_op_allow_transmute(&op, &dest)?;
247 } else {
248self.copy_op(&op, &dest)?;
249 }
250 }
251252RawPtr(kind, place) => {
253// Figure out whether this is an addr_of of an already raw place.
254let place_base_raw = if place.is_indirect_first_projection() {
255let ty = self.frame().body.local_decls[place.local].ty;
256ty.is_raw_ptr()
257 } else {
258// Not a deref, and thus not raw.
259false
260};
261262let src =
263self.eval_place(place, /* skip_validity_for_simple_deref */ false)?;
264let place = self.force_allocation(&src)?;
265let mut val = ImmTy::from_immediate(place.to_ref(self), dest.layout);
266if !place_base_raw && !kind.is_fake() {
267// If this was not already raw, it needs retagging -- except for "fake"
268 // raw borrows whose defining property is that they do not get retagged.
269val = M::with_retag_mode(self, RetagMode::Raw, |ecx| {
270 interp_ok(M::retag_ptr_value(ecx, &val, val.layout.ty)?.unwrap_or(val))
271 })?;
272 }
273// This writes a raw pointer so it will not do any retags.
274self.write_immediate(*val, &dest)?;
275 }
276277Cast(cast_kind, ref operand, cast_ty) => {
278let src = self.eval_operand(operand, None)?;
279let cast_ty =
280self.instantiate_from_current_frame_and_normalize_erasing_regions(cast_ty)?;
281self.cast(&src, cast_kind, cast_ty, &dest)?;
282 }
283284Discriminant(place) => {
285let op = self.eval_place_to_op(place, None)?;
286let variant = self.read_discriminant(&op)?;
287let discr = self.discriminant_for_variant(op.layout.ty, variant)?;
288self.write_immediate(*discr, &dest)?;
289 }
290291WrapUnsafeBinder(ref op, _ty) => {
292// Constructing an unsafe binder acts like a transmute
293 // since the operand's layout does not change.
294let op = self.eval_operand(op, None)?;
295self.copy_op_allow_transmute(&op, &dest)?;
296 }
297 }
298299{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_const_eval/src/interpret/step.rs:299",
"rustc_const_eval::interpret::step",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_const_eval/src/interpret/step.rs"),
::tracing_core::__macro_support::Option::Some(299u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::step"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("{0:?}",
self.dump_place(&dest)) as &dyn ::tracing::field::Value))])
});
} else { ; }
};trace!("{:?}", self.dump_place(&dest));
300301interp_ok(())
302 }
303304/// Writes the aggregate to the destination.
305{}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("write_aggregate",
"rustc_const_eval::interpret::step",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_const_eval/src/interpret/step.rs"),
::tracing_core::__macro_support::Option::Some(305u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::step"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("kind")
}> =
::tracing::__macro_support::FieldName::new("kind");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("operands")
}> =
::tracing::__macro_support::FieldName::new("operands");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("dest")
}> =
::tracing::__macro_support::FieldName::new("dest");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&kind)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&operands)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&dest)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: InterpResult<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let (variant_index, variant_dest, active_field_index) =
match *kind {
mir::AggregateKind::Adt(_, variant_index, _, _,
active_field_index) => {
let variant_dest =
self.project_downcast(dest, variant_index)?;
(variant_index, variant_dest, active_field_index)
}
mir::AggregateKind::RawPtr(..) => {
let [data, meta] =
&operands.raw else {
::rustc_span::macros::bug_impl(None,
format_args!("{0:?} should have 2 operands, had {1:?}",
kind, operands), Location::caller());
};
let data = self.eval_operand(data, None)?;
let data = self.read_pointer(&data)?;
let meta = self.eval_operand(meta, None)?;
let meta =
if meta.layout.is_zst() {
MemPlaceMeta::None
} else { MemPlaceMeta::Meta(self.read_scalar(&meta)?) };
let ptr_imm =
Immediate::new_pointer_with_meta(data, meta, self);
let ptr = ImmTy::from_immediate(ptr_imm, dest.layout);
self.copy_op(&ptr, dest)?;
return interp_ok(());
}
_ => (FIRST_VARIANT, dest.clone(), None),
};
if active_field_index.is_some() {
{
match (&operands.len(), &1) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
}
for (field_index, operand) in operands.iter_enumerated() {
let field_index = active_field_index.unwrap_or(field_index);
let field_dest =
self.project_field(&variant_dest, field_index)?;
let op = self.eval_operand(operand, Some(field_dest.layout))?;
self.copy_op_no_validate(&op, &field_dest, false)?;
}
self.write_discriminant(variant_index, dest)?;
if M::enforce_validity(self, dest.layout()) {
self.validate_place(dest,
M::enforce_validity_recursively(self, dest.layout()),
true)?;
}
interp_ok(())
}
}
}#[instrument(skip(self), level = "trace")]306fn write_aggregate(
307&mut self,
308 kind: &mir::AggregateKind<'tcx>,
309 operands: &IndexSlice<FieldIdx, mir::Operand<'tcx>>,
310 dest: &PlaceTy<'tcx, M::Provenance>,
311 ) -> InterpResult<'tcx> {
312let (variant_index, variant_dest, active_field_index) = match *kind {
313 mir::AggregateKind::Adt(_, variant_index, _, _, active_field_index) => {
314let variant_dest = self.project_downcast(dest, variant_index)?;
315 (variant_index, variant_dest, active_field_index)
316 }
317 mir::AggregateKind::RawPtr(..) => {
318// Pointers don't have "fields" in the normal sense, so the
319 // projection-based code below would either fail in projection
320 // or in type mismatches. Instead, build an `Immediate` from
321 // the parts and write that to the destination.
322let [data, meta] = &operands.raw else {
323bug!("{kind:?} should have 2 operands, had {operands:?}");
324 };
325let data = self.eval_operand(data, None)?;
326let data = self.read_pointer(&data)?;
327let meta = self.eval_operand(meta, None)?;
328let meta = if meta.layout.is_zst() {
329 MemPlaceMeta::None
330 } else {
331 MemPlaceMeta::Meta(self.read_scalar(&meta)?)
332 };
333let ptr_imm = Immediate::new_pointer_with_meta(data, meta, self);
334let ptr = ImmTy::from_immediate(ptr_imm, dest.layout);
335self.copy_op(&ptr, dest)?;
336return interp_ok(());
337 }
338_ => (FIRST_VARIANT, dest.clone(), None),
339 };
340if active_field_index.is_some() {
341assert_eq!(operands.len(), 1);
342 }
343for (field_index, operand) in operands.iter_enumerated() {
344let field_index = active_field_index.unwrap_or(field_index);
345let field_dest = self.project_field(&variant_dest, field_index)?;
346let op = self.eval_operand(operand, Some(field_dest.layout))?;
347// We validate manually below so we don't have to do it here.
348self.copy_op_no_validate(&op, &field_dest, /*allow_transmute*/ false)?;
349 }
350self.write_discriminant(variant_index, dest)?;
351// Validate that the entire thing is valid, and reset padding that might be in between the
352 // fields.
353if M::enforce_validity(self, dest.layout()) {
354self.validate_place(
355 dest,
356 M::enforce_validity_recursively(self, dest.layout()),
357/*reset_provenance_and_padding*/ true,
358 )?;
359 }
360 interp_ok(())
361 }
362363/// Repeats `operand` into the destination. `dest` must have array type, and that type
364 /// determines how often `operand` is repeated.
365fn write_repeat(
366&mut self,
367 operand: &mir::Operand<'tcx>,
368 dest: &PlaceTy<'tcx, M::Provenance>,
369 ) -> InterpResult<'tcx> {
370let src = self.eval_operand(operand, None)?;
371if !src.layout.is_sized() {
::core::panicking::panic("assertion failed: src.layout.is_sized()")
};assert!(src.layout.is_sized());
372let dest = self.force_allocation(&dest)?;
373let length = dest.len(self)?;
374375if length == 0 {
376// Nothing to copy... but let's still make sure that `dest` as a place is valid.
377self.get_place_alloc_mut(&dest)?;
378 } else {
379// Write the src to the first element.
380let first = self.project_index(&dest, 0)?;
381self.copy_op(&src, &first)?;
382383// This is performance-sensitive code for big static/const arrays! So we
384 // avoid writing each operand individually and instead just make many copies
385 // of the first element.
386let elem_size = first.layout.size;
387let first_ptr = first.ptr();
388let rest_ptr = first_ptr.wrapping_offset(elem_size, self);
389// No alignment requirement since `copy_op` above already checked it.
390self.mem_copy_repeatedly(
391 first_ptr,
392 rest_ptr,
393 elem_size,
394 length - 1,
395/*nonoverlapping:*/ true,
396 )?;
397 }
398399interp_ok(())
400 }
401402/// Evaluate the arguments of a function call
403fn eval_fn_call_argument(
404&mut self,
405 op: &mir::Operand<'tcx>,
406 move_definitely_disjoint: bool,
407 ) -> InterpResult<'tcx, FnArg<'tcx, M::Provenance>> {
408interp_ok(match op {
409 mir::Operand::Copy(_) | mir::Operand::Constant(_) | mir::Operand::RuntimeChecks(_) => {
410// Make a regular copy.
411let op = self.eval_operand(op, None)?;
412 FnArg::Copy(op)
413 }
414 mir::Operand::Move(place) => {
415// We will read from this place, which checks everything there is to check,
416 // so we can skip the extra validity check here.
417let place =
418self.eval_place(*place, /* skip_validity_for_simple_deref */ true)?;
419if move_definitely_disjoint {
420// We still have to ensure that no *other* pointers are used to access this place,
421 // so *if* it is in memory then we have to treat it as `InPlace`.
422 // Use `place_to_op` to guarantee that we notice it being in memory.
423let op = self.place_to_op(&place)?;
424match op.as_mplace_or_imm() {
425 Either::Left(mplace) => FnArg::InPlace(mplace),
426 Either::Right(_imm) => FnArg::Copy(op),
427 }
428 } else {
429// We have to force this into memory to detect aliasing among `Move` arguments.
430FnArg::InPlace(self.force_allocation(&place)?)
431 }
432 }
433 })
434 }
435436/// Shared part of `Call` and `TailCall` implementation — finding and evaluating all the
437 /// necessary information about callee and arguments to make a call.
438fn eval_callee_and_args(
439&mut self,
440 terminator: &mir::Terminator<'tcx>,
441 func: &mir::Operand<'tcx>,
442 args: &[Spanned<mir::Operand<'tcx>>],
443 dest: &mir::Place<'tcx>,
444 ) -> InterpResult<'tcx, EvaluatedCalleeAndArgs<'tcx, M>> {
445let func = self.eval_operand(func, None)?;
446447// Evaluating function call arguments. The tricky part here is dealing with `Move`
448 // arguments: we have to ensure no two such arguments alias. This would be most easily done
449 // by just forcing them all into memory and then doing the usual in-place argument
450 // protection, but then we'd force *a lot* of arguments into memory. So we do some syntactic
451 // pre-processing here where if all `move` arguments are syntactically distinct local
452 // variables (and none is indirect), we can skip the in-memory forcing.
453 // We have to include `dest` in that list so that we can detect aliasing of an in-place
454 // argument with the return place.
455let move_definitely_disjoint = 'move_definitely_disjoint: {
456let mut previous_locals = FxHashSet::<mir::Local>::default();
457for place in args
458 .iter()
459 .filter_map(|a| {
460// We only have to care about `Move` arguments.
461if let mir::Operand::Move(place) = &a.node { Some(place) } else { None }
462 })
463 .chain(iter::once(dest))
464 {
465if place.is_indirect_first_projection() {
466// An indirect in-place argument could alias with anything else...
467break 'move_definitely_disjoint false;
468 }
469if !previous_locals.insert(place.local) {
470// This local is the base for two arguments! They might overlap.
471break 'move_definitely_disjoint false;
472 }
473 }
474// We found no violation so they are all definitely disjoint.
475true
476};
477let args = args
478 .iter()
479 .map(|arg| self.eval_fn_call_argument(&arg.node, move_definitely_disjoint))
480 .collect::<InterpResult<'tcx, Vec<_>>>()?;
481482let fn_sig_binder = {
483let _trace = <M as
crate::interpret::Machine>::enter_trace_span(||
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("fn_sig",
"rustc_const_eval::interpret::step", ::tracing::Level::INFO,
::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_const_eval/src/interpret/step.rs"),
::tracing_core::__macro_support::Option::Some(483u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::step"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ty")
}> =
::tracing::__macro_support::FieldName::new("ty");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::INFO <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::INFO <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&func.layout.ty.kind())
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
})enter_trace_span!(M, "fn_sig", ty = ?func.layout.ty.kind());
484func.layout.ty.fn_sig(*self.tcx)
485 };
486let fn_sig = self.tcx.normalize_erasing_late_bound_regions(self.typing_env, fn_sig_binder);
487let extra_args = &args[fn_sig.inputs().len()..];
488let extra_args =
489self.tcx.mk_type_list_from_iter(extra_args.iter().map(|arg| arg.layout().ty));
490491let (callee, fn_abi, with_caller_location) = match *func.layout.ty.kind() {
492 ty::FnPtr(..) => {
493let fn_ptr = self.read_pointer(&func)?;
494let fn_val = self.get_ptr_fn(fn_ptr)?;
495 (fn_val, Some(self.fn_abi_of_fn_ptr(fn_sig_binder, extra_args)?), false)
496 }
497 ty::FnDef(def_id, args) => {
498let instance = self.resolve(def_id, args.no_bound_vars().unwrap())?;
499let fn_abi =
500match instance.def {
501// Don't compute FnAbi for LLVM intrinsics. Trying to do that would panic.
502ty::InstanceKind::LlvmIntrinsic(_) => None,
503// Rust intrinsics don't really have a normal ABI, except for the case
504 // where we call the fallback body like a regular function.
505 // So, we compute the ABI based on the fallback body.
506 // We can't compute the ABI based on the `instance` directly,
507 // because `#[track_caller]` affects the ABI of the fallback body,
508 // but not affect the "ABI" of the intrinsic itself.
509 // Even if there is no fallback body, this computes a valid ABI
510 // (that we then mostly ignore).
511ty::InstanceKind::Intrinsic(def_id) => {
512let fallback_instance = ty::Instance {
513 def: ty::InstanceKind::Item(def_id),
514 args: instance.args,
515 };
516Some(self.fn_abi_of_instance_no_deduced_attrs(
517 fallback_instance,
518 extra_args,
519 )?)
520 }
521_ => Some(self.fn_abi_of_instance_no_deduced_attrs(instance, extra_args)?),
522 };
523 (
524 FnVal::Instance(instance),
525fn_abi,
526instance.def.requires_caller_location(*self.tcx),
527 )
528 }
529_ => {
530::rustc_span::macros::bug_impl(Some(terminator.source_info.span),
format_args!("invalid callee of type {0}", func.layout.ty),
Location::caller())span_bug!(terminator.source_info.span, "invalid callee of type {}", func.layout.ty)531 }
532 };
533534interp_ok(EvaluatedCalleeAndArgs { callee, args, fn_sig, fn_abi, with_caller_location })
535 }
536537fn eval_terminator(&mut self, terminator: &mir::Terminator<'tcx>) -> InterpResult<'tcx> {
538let _trace = <M as
crate::interpret::Machine>::enter_trace_span(||
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("step",
"rustc_const_eval::interpret::step", ::tracing::Level::INFO,
::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_const_eval/src/interpret/step.rs"),
::tracing_core::__macro_support::Option::Some(538u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::step"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("step")
}> =
::tracing::__macro_support::FieldName::new("step");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("terminator")
}> =
::tracing::__macro_support::FieldName::new("terminator");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("span")
}> =
::tracing::__macro_support::FieldName::new("span");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("tracing_separate_thread")
}> =
::tracing::__macro_support::FieldName::new("tracing_separate_thread");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::INFO <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::INFO <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::display(&"eval_terminator")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&terminator.kind)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&terminator.source_info.span)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&Empty as
&dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
})enter_trace_span!(
539 M,
540 step::eval_terminator,
541 terminator = ?terminator.kind,
542 span = ?terminator.source_info.span,
543 tracing_separate_thread = Empty,
544 )545 .or_if_tracing_disabled(|| {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_const_eval/src/interpret/step.rs:545",
"rustc_const_eval::interpret::step", ::tracing::Level::INFO,
::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_const_eval/src/interpret/step.rs"),
::tracing_core::__macro_support::Option::Some(545u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::step"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::INFO <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::INFO <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("{0:?}",
terminator.kind) as &dyn ::tracing::field::Value))])
});
} else { ; }
}info!("{:?}", terminator.kind));
546547use rustc_middle::mir::TerminatorKind::*;
548match terminator.kind {
549Return => {
550self.return_from_current_stack_frame(/* unwinding */ false)?
551}
552553Goto { target, loop_hint_attrs: _ } => self.go_to_block(target),
554555SwitchInt { ref discr, ref targets } => {
556let discr = self.read_immediate(&self.eval_operand(discr, None)?)?;
557{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_const_eval/src/interpret/step.rs:557",
"rustc_const_eval::interpret::step",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_const_eval/src/interpret/step.rs"),
::tracing_core::__macro_support::Option::Some(557u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::step"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("SwitchInt({0:?})",
*discr) as &dyn ::tracing::field::Value))])
});
} else { ; }
};trace!("SwitchInt({:?})", *discr);
558559// Branch to the `otherwise` case by default, if no match is found.
560let mut target_block = targets.otherwise();
561562for (const_int, target) in targets.iter() {
563// Compare using MIR BinOp::Eq, to also support pointer values.
564 // (Avoiding `self.binary_op` as that does some redundant layout computation.)
565let res = self.binary_op(
566 mir::BinOp::Eq,
567&discr,
568&ImmTy::from_uint(const_int, discr.layout),
569 )?;
570if res.to_scalar().to_bool()? {
571 target_block = target;
572break;
573 }
574 }
575576self.go_to_block(target_block);
577 }
578579Call {
580ref func,
581ref args,
582 destination,
583 target,
584 unwind,
585 call_source: _,
586 fn_span: _,
587 } => {
588let old_stack = self.frame_idx();
589let old_loc = self.frame().loc;
590591// Evaluation order consistent with assignment: destination first.
592let dest_place =
593self.eval_place(destination, /* skip_validity_for_simple_deref */ false)?;
594let EvaluatedCalleeAndArgs { callee, args, fn_sig, fn_abi, with_caller_location } =
595self.eval_callee_and_args(terminator, func, args, &destination)?;
596597self.init_fn_call(
598 callee,
599 (fn_sig.abi(), fn_abi),
600&args,
601 with_caller_location,
602&dest_place,
603 target,
604if fn_abi.is_some_and(|fn_abi| fn_abi.can_unwind) {
605 unwind
606 } else {
607 mir::UnwindAction::Unreachable
608 },
609 )?;
610611// Sanity-check that `eval_fn_call` either pushed a new frame or
612 // did a jump to another block. We disable the sanity check for functions that
613 // can't return, since Miri sometimes does have to keep the location the same
614 // for those (which is fine since execution will continue on a different thread).
615if target.is_some() && self.frame_idx() == old_stack && self.frame().loc == old_loc616 {
617::rustc_span::macros::bug_impl(Some(terminator.source_info.span),
format_args!("evaluating this call made no progress"),
Location::caller());span_bug!(terminator.source_info.span, "evaluating this call made no progress");
618 }
619 }
620621TailCall { ref func, ref args, fn_span: _ } => {
622let old_frame_idx = self.frame_idx();
623624let EvaluatedCalleeAndArgs { callee, args, fn_sig, fn_abi, with_caller_location } =
625self.eval_callee_and_args(terminator, func, args, &mir::Place::return_place())?;
626627self.init_fn_tail_call(
628 callee,
629 (fn_sig.abi(), fn_abi),
630&args,
631 with_caller_location,
632 )?;
633634if self.frame_idx() != old_frame_idx {
635::rustc_span::macros::bug_impl(Some(terminator.source_info.span),
format_args!("evaluating this tail call pushed a new stack frame"),
Location::caller());span_bug!(
636 terminator.source_info.span,
637"evaluating this tail call pushed a new stack frame"
638);
639 }
640 }
641642Drop { place, target, unwind, replace: _, drop } => {
643if !drop.is_none() {
{
::core::panicking::panic_fmt(format_args!("Async Drop must be expanded or reset to sync in runtime MIR"));
}
};assert!(
644 drop.is_none(),
645"Async Drop must be expanded or reset to sync in runtime MIR"
646);
647let place =
648self.eval_place(place, /* skip_validity_for_simple_deref */ false)?;
649let instance = {
650let _trace =
651<M as
crate::interpret::Machine>::enter_trace_span(||
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("resolve",
"rustc_const_eval::interpret::step", ::tracing::Level::INFO,
::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_const_eval/src/interpret/step.rs"),
::tracing_core::__macro_support::Option::Some(651u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::step"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("resolve")
}> =
::tracing::__macro_support::FieldName::new("resolve");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ty")
}> =
::tracing::__macro_support::FieldName::new("ty");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::INFO <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::INFO <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::display(&"resolve_drop_glue")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&place.layout.ty)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
})enter_trace_span!(M, resolve::resolve_drop_glue, ty = ?place.layout.ty);
652Instance::resolve_drop_glue(*self.tcx, place.layout.ty)
653 };
654if let ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_, None)) = instance.def {
655// This is the branch we enter if and only if the dropped type has no drop glue
656 // whatsoever. This can happen as a result of monomorphizing a drop of a
657 // generic. In order to make sure that generic and non-generic code behaves
658 // roughly the same (and in keeping with Mir semantics) we do nothing here.
659self.go_to_block(target);
660return interp_ok(());
661 }
662{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_const_eval/src/interpret/step.rs:662",
"rustc_const_eval::interpret::step",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_const_eval/src/interpret/step.rs"),
::tracing_core::__macro_support::Option::Some(662u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::step"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("TerminatorKind::drop: {0:?}, type {1}",
place, place.layout.ty) as &dyn ::tracing::field::Value))])
});
} else { ; }
};trace!("TerminatorKind::drop: {:?}, type {}", place, place.layout.ty);
663self.init_drop_in_place_call(&place, instance, target, unwind)?;
664 }
665666Assert { ref cond, expected, ref msg, target, unwind } => {
667let ignored =
668 M::ignore_optional_overflow_checks(self) && msg.is_optional_overflow_check();
669let cond_val = self.read_scalar(&self.eval_operand(cond, None)?)?.to_bool()?;
670if ignored || expected == cond_val {
671self.go_to_block(target);
672 } else {
673 M::assert_panic(self, msg, unwind)?;
674 }
675 }
676677UnwindTerminate(reason) => {
678 M::unwind_terminate(self, reason)?;
679 }
680681// When we encounter Resume, we've finished unwinding
682 // cleanup for the current stack frame. We pop it in order
683 // to continue unwinding the next frame
684UnwindResume => {
685{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_const_eval/src/interpret/step.rs:685",
"rustc_const_eval::interpret::step",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_const_eval/src/interpret/step.rs"),
::tracing_core::__macro_support::Option::Some(685u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::step"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("unwinding: resuming from cleanup")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};trace!("unwinding: resuming from cleanup");
686// By definition, a Resume terminator means
687 // that we're unwinding
688self.return_from_current_stack_frame(/* unwinding */ true)?;
689return interp_ok(());
690 }
691692// It is UB to ever encounter this.
693Unreachable => do yeet ::rustc_middle::mir::interpret::InterpErrorKind::UndefinedBehavior(::rustc_middle::mir::interpret::UndefinedBehaviorInfo::Unreachable)throw_ub!(Unreachable),
694695// These should never occur for MIR we actually run.
696FalseEdge { .. } | FalseUnwind { .. } | Yield { .. } | CoroutineDrop => ::rustc_span::macros::bug_impl(Some(terminator.source_info.span),
format_args!("{0:#?} should have been eliminated by MIR pass",
terminator.kind), Location::caller())span_bug!(
697 terminator.source_info.span,
698"{:#?} should have been eliminated by MIR pass",
699 terminator.kind
700 ),
701702InlineAsm { .. } => {
703do yeet ::rustc_middle::mir::interpret::InterpErrorKind::Unsupported(::rustc_middle::mir::interpret::UnsupportedOpInfo::Unsupported(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("inline assembly is not supported"))
})));throw_unsup_format!("inline assembly is not supported");
704 }
705 }
706707interp_ok(())
708 }
709}