Skip to content

Commit 035e767

Browse files
committed
Add tracing to resolve-related functions
1 parent adcb3d3 commit 035e767

File tree

5 files changed

+35
-18
lines changed

5 files changed

+35
-18
lines changed

compiler/rustc_const_eval/src/interpret/call.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use super::{
1818
Projectable, Provenance, ReturnAction, ReturnContinuation, Scalar, StackPopInfo, interp_ok,
1919
throw_ub, throw_ub_custom, throw_unsup_format,
2020
};
21-
use crate::fluent_generated as fluent;
21+
use crate::{enter_trace_span, fluent_generated as fluent};
2222

2323
/// An argument passed to a function.
2424
#[derive(Clone, Debug)]
@@ -730,6 +730,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
730730
let existential_trait_ref = ty::ExistentialTraitRef::erase_self_ty(tcx, virtual_trait_ref);
731731
let concrete_trait_ref = existential_trait_ref.with_self_ty(tcx, dyn_ty);
732732

733+
let _span = enter_trace_span!(M, resolve::expect_resolve_for_vtable, ?def_id);
733734
let concrete_method = Instance::expect_resolve_for_vtable(
734735
tcx,
735736
self.typing_env,
@@ -819,7 +820,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
819820
place
820821
}
821822
};
822-
let instance = ty::Instance::resolve_drop_in_place(*self.tcx, place.layout.ty);
823+
let instance = {
824+
let _span = enter_trace_span!(M, resolve::resolve_drop_in_place, ty = ?place.layout.ty);
825+
ty::Instance::resolve_drop_in_place(*self.tcx, place.layout.ty)
826+
};
823827
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty())?;
824828

825829
let arg = self.mplace_to_ref(&place)?;

compiler/rustc_const_eval/src/interpret/cast.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use super::{
1616
FnVal, ImmTy, Immediate, InterpCx, Machine, OpTy, PlaceTy, err_inval, interp_ok, throw_ub,
1717
throw_ub_custom,
1818
};
19-
use crate::fluent_generated as fluent;
2019
use crate::interpret::Writeable;
20+
use crate::{enter_trace_span, fluent_generated as fluent};
2121

2222
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
2323
pub fn cast(
@@ -81,13 +81,16 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
8181
// The src operand does not matter, just its type
8282
match *src.layout.ty.kind() {
8383
ty::FnDef(def_id, args) => {
84-
let instance = ty::Instance::resolve_for_fn_ptr(
85-
*self.tcx,
86-
self.typing_env,
87-
def_id,
88-
args,
89-
)
90-
.ok_or_else(|| err_inval!(TooGeneric))?;
84+
let instance = {
85+
let _span = enter_trace_span!(M, resolve::resolve_for_fn_ptr, ?def_id);
86+
ty::Instance::resolve_for_fn_ptr(
87+
*self.tcx,
88+
self.typing_env,
89+
def_id,
90+
args,
91+
)
92+
.ok_or_else(|| err_inval!(TooGeneric))?
93+
};
9194

9295
let fn_ptr = self.fn_ptr(FnVal::Instance(instance));
9396
self.write_pointer(fn_ptr, dest)?;
@@ -114,12 +117,15 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
114117
// The src operand does not matter, just its type
115118
match *src.layout.ty.kind() {
116119
ty::Closure(def_id, args) => {
117-
let instance = ty::Instance::resolve_closure(
118-
*self.tcx,
119-
def_id,
120-
args,
121-
ty::ClosureKind::FnOnce,
122-
);
120+
let instance = {
121+
let _span = enter_trace_span!(M, resolve::resolve_closure, ?def_id);
122+
ty::Instance::resolve_closure(
123+
*self.tcx,
124+
def_id,
125+
args,
126+
ty::ClosureKind::FnOnce,
127+
)
128+
};
123129
let fn_ptr = self.fn_ptr(FnVal::Instance(instance));
124130
self.write_pointer(fn_ptr, dest)?;
125131
}

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
344344
def: DefId,
345345
args: GenericArgsRef<'tcx>,
346346
) -> InterpResult<'tcx, ty::Instance<'tcx>> {
347+
let _span = enter_trace_span!(M, resolve::try_resolve, def = ?def);
347348
trace!("resolve: {:?}, {:#?}", def, args);
348349
trace!("typing_env: {:#?}", self.typing_env);
349350
trace!("args: {:#?}", args);

compiler/rustc_const_eval/src/interpret/step.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use super::{
1515
FnArg, FnVal, ImmTy, Immediate, InterpCx, InterpResult, Machine, MemPlaceMeta, PlaceTy,
1616
Projectable, Scalar, interp_ok, throw_ub, throw_unsup_format,
1717
};
18-
use crate::util;
18+
use crate::{enter_trace_span, util};
1919

2020
struct EvaluatedCalleeAndArgs<'tcx, M: Machine<'tcx>> {
2121
callee: FnVal<'tcx, M::ExtraFnVal>,
@@ -544,7 +544,11 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
544544
"Async Drop must be expanded or reset to sync in runtime MIR"
545545
);
546546
let place = self.eval_place(place)?;
547-
let instance = Instance::resolve_drop_in_place(*self.tcx, place.layout.ty);
547+
let instance = {
548+
let _span =
549+
enter_trace_span!(M, resolve::resolve_drop_in_place, ty = ?place.layout.ty);
550+
Instance::resolve_drop_in_place(*self.tcx, place.layout.ty)
551+
};
548552
if let ty::InstanceKind::DropGlue(_, None) = instance.def {
549553
// This is the branch we enter if and only if the dropped type has no drop glue
550554
// whatsoever. This can happen as a result of monomorphizing a drop of a

src/tools/miri/src/helpers.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ pub enum AccessKind {
3232
///
3333
/// A `None` namespace indicates we are looking for a module.
3434
fn try_resolve_did(tcx: TyCtxt<'_>, path: &[&str], namespace: Option<Namespace>) -> Option<DefId> {
35+
let _span = enter_trace_span!(resolve::try_resolve_did, ?path);
36+
3537
/// Yield all children of the given item, that have the given name.
3638
fn find_children<'tcx: 'a, 'a>(
3739
tcx: TyCtxt<'tcx>,

0 commit comments

Comments
 (0)