Skip to content

Add tracing to resolve-related functions #144727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions compiler/rustc_const_eval/src/interpret/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use super::{
Projectable, Provenance, ReturnAction, ReturnContinuation, Scalar, StackPopInfo, interp_ok,
throw_ub, throw_ub_custom, throw_unsup_format,
};
use crate::fluent_generated as fluent;
use crate::{enter_trace_span, fluent_generated as fluent};

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

let _span = enter_trace_span!(M, resolve::expect_resolve_for_vtable, ?def_id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we call this _span everywhere? I now realize that's confusing because usually that refers to the Span type...

let concrete_method = Instance::expect_resolve_for_vtable(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the same pattern with a nested block as everywhere else.

tcx,
self.typing_env,
Expand Down Expand Up @@ -819,7 +820,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
place
}
};
let instance = ty::Instance::resolve_drop_in_place(*self.tcx, place.layout.ty);
let instance = {
let _span = enter_trace_span!(M, resolve::resolve_drop_in_place, ty = ?place.layout.ty);
ty::Instance::resolve_drop_in_place(*self.tcx, place.layout.ty)
};
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty())?;

let arg = self.mplace_to_ref(&place)?;
Expand Down
34 changes: 20 additions & 14 deletions compiler/rustc_const_eval/src/interpret/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use super::{
FnVal, ImmTy, Immediate, InterpCx, Machine, OpTy, PlaceTy, err_inval, interp_ok, throw_ub,
throw_ub_custom,
};
use crate::fluent_generated as fluent;
use crate::interpret::Writeable;
use crate::{enter_trace_span, fluent_generated as fluent};

impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
pub fn cast(
Expand Down Expand Up @@ -81,13 +81,16 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
// The src operand does not matter, just its type
match *src.layout.ty.kind() {
ty::FnDef(def_id, args) => {
let instance = ty::Instance::resolve_for_fn_ptr(
*self.tcx,
self.typing_env,
def_id,
args,
)
.ok_or_else(|| err_inval!(TooGeneric))?;
let instance = {
let _span = enter_trace_span!(M, resolve::resolve_for_fn_ptr, ?def_id);
ty::Instance::resolve_for_fn_ptr(
*self.tcx,
self.typing_env,
def_id,
args,
)
.ok_or_else(|| err_inval!(TooGeneric))?
};

let fn_ptr = self.fn_ptr(FnVal::Instance(instance));
self.write_pointer(fn_ptr, dest)?;
Expand All @@ -114,12 +117,15 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
// The src operand does not matter, just its type
match *src.layout.ty.kind() {
ty::Closure(def_id, args) => {
let instance = ty::Instance::resolve_closure(
*self.tcx,
def_id,
args,
ty::ClosureKind::FnOnce,
);
let instance = {
let _span = enter_trace_span!(M, resolve::resolve_closure, ?def_id);
ty::Instance::resolve_closure(
*self.tcx,
def_id,
args,
ty::ClosureKind::FnOnce,
)
};
let fn_ptr = self.fn_ptr(FnVal::Instance(instance));
self.write_pointer(fn_ptr, dest)?;
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_const_eval/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
def: DefId,
args: GenericArgsRef<'tcx>,
) -> InterpResult<'tcx, ty::Instance<'tcx>> {
let _span = enter_trace_span!(M, resolve::try_resolve, def = ?def);
trace!("resolve: {:?}, {:#?}", def, args);
trace!("typing_env: {:#?}", self.typing_env);
trace!("args: {:#?}", args);
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_const_eval/src/interpret/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use super::{
FnArg, FnVal, ImmTy, Immediate, InterpCx, InterpResult, Machine, MemPlaceMeta, PlaceTy,
Projectable, Scalar, interp_ok, throw_ub, throw_unsup_format,
};
use crate::util;
use crate::{enter_trace_span, util};

struct EvaluatedCalleeAndArgs<'tcx, M: Machine<'tcx>> {
callee: FnVal<'tcx, M::ExtraFnVal>,
Expand Down Expand Up @@ -544,7 +544,11 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
"Async Drop must be expanded or reset to sync in runtime MIR"
);
let place = self.eval_place(place)?;
let instance = Instance::resolve_drop_in_place(*self.tcx, place.layout.ty);
let instance = {
let _span =
enter_trace_span!(M, resolve::resolve_drop_in_place, ty = ?place.layout.ty);
Instance::resolve_drop_in_place(*self.tcx, place.layout.ty)
};
if let ty::InstanceKind::DropGlue(_, None) = instance.def {
// This is the branch we enter if and only if the dropped type has no drop glue
// whatsoever. This can happen as a result of monomorphizing a drop of a
Expand Down
2 changes: 2 additions & 0 deletions src/tools/miri/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub enum AccessKind {
///
/// A `None` namespace indicates we are looking for a module.
fn try_resolve_did(tcx: TyCtxt<'_>, path: &[&str], namespace: Option<Namespace>) -> Option<DefId> {
let _span = enter_trace_span!(resolve::try_resolve_did, ?path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the same kind of operation as the others at all, it is using resolve to refer to something else. It's a good idea to trace this but separate from the normal resolve calls.


/// Yield all children of the given item, that have the given name.
fn find_children<'tcx: 'a, 'a>(
tcx: TyCtxt<'tcx>,
Expand Down
Loading