Skip to content

Add tracing instrumentation to method typeck #80995

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

Merged
merged 1 commit into from
Jan 18, 2021
Merged
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
1 change: 1 addition & 0 deletions compiler/rustc_typeck/src/check/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl<'a, 'tcx> Deref for ConfirmContext<'a, 'tcx> {
}
}

#[derive(Debug)]
pub struct ConfirmResult<'tcx> {
pub callee: MethodCallee<'tcx>,
pub illegal_sized_bound: Option<Span>,
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_typeck/src/check/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ pub enum CandidateSource {

impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Determines whether the type `self_ty` supports a method name `method_name` or not.
#[instrument(level = "debug", skip(self))]
pub fn method_exists(
&self,
method_name: Ident,
Expand Down Expand Up @@ -129,6 +130,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}

/// Adds a suggestion to call the given method to the provided diagnostic.
#[instrument(level = "debug", skip(self, err, call_expr))]
crate fn suggest_method_call(
&self,
err: &mut DiagnosticBuilder<'a>,
Expand Down Expand Up @@ -177,6 +179,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// * `span`: the span for the method call
/// * `call_expr`: the complete method call: (`foo.bar::<T1,...Tn>(...)`)
/// * `self_expr`: the self expression (`foo`)
#[instrument(level = "debug", skip(self, call_expr, self_expr))]
pub fn lookup_method(
&self,
self_ty: Ty<'tcx>,
Expand Down Expand Up @@ -204,6 +207,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

let result =
self.confirm_method(span, self_expr, call_expr, self_ty, pick.clone(), segment);
debug!("result = {:?}", result);

if let Some(span) = result.illegal_sized_bound {
let mut needs_mut = false;
Expand Down Expand Up @@ -256,6 +260,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Ok(result.callee)
}

#[instrument(level = "debug", skip(self, call_expr))]
pub fn lookup_probe(
&self,
span: Span,
Expand Down Expand Up @@ -286,6 +291,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// FIXME(#18741): it seems likely that we can consolidate some of this
// code with the other method-lookup code. In particular, the second half
// of this method is basically the same as confirmation.
#[instrument(level = "debug", skip(self, span, opt_input_types))]
pub fn lookup_method_in_trait(
&self,
span: Span,
Expand Down Expand Up @@ -409,6 +415,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Some(InferOk { obligations, value: callee })
}

#[instrument(level = "debug", skip(self))]
pub fn resolve_ufcs(
&self,
span: Span,
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_typeck/src/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub use self::PickKind::*;

/// Boolean flag used to indicate if this search is for a suggestion
/// or not. If true, we can allow ambiguity and so forth.
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct IsSuggestion(pub bool);

struct ProbeContext<'a, 'tcx> {
Expand Down Expand Up @@ -219,6 +219,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// would result in an error (basically, the same criteria we
/// would use to decide if a method is a plausible fit for
/// ambiguity purposes).
#[instrument(level = "debug", skip(self, scope_expr_id))]
pub fn probe_for_return_type(
&self,
span: Span,
Expand Down Expand Up @@ -264,6 +265,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.collect()
}

#[instrument(level = "debug", skip(self, scope_expr_id))]
pub fn probe_for_name(
&self,
span: Span,
Expand Down Expand Up @@ -770,7 +772,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
// will be reported by `object_safety.rs` if the method refers to the
// `Self` type anywhere other than the receiver. Here, we use a
// substitution that replaces `Self` with the object type itself. Hence,
// a `&self` method will wind up with an argument type like `&Trait`.
// a `&self` method will wind up with an argument type like `&dyn Trait`.
let trait_ref = principal.with_self_ty(self.tcx, self_ty);
self.elaborate_bounds(iter::once(trait_ref), |this, new_trait_ref, item| {
let new_trait_ref = this.erase_late_bound_regions(new_trait_ref);
Expand Down