From 6af831ace693ed380c3dba78cf133ffdd6d460de Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Thu, 14 Jan 2021 01:37:50 +0000 Subject: [PATCH] Add tracing instrumentation to method typeck I was recently digging into how this code works, and this instrumentation was helpful. --- compiler/rustc_typeck/src/check/method/confirm.rs | 1 + compiler/rustc_typeck/src/check/method/mod.rs | 7 +++++++ compiler/rustc_typeck/src/check/method/probe.rs | 6 ++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_typeck/src/check/method/confirm.rs b/compiler/rustc_typeck/src/check/method/confirm.rs index 8ef723d59028..76ab7304d5d5 100644 --- a/compiler/rustc_typeck/src/check/method/confirm.rs +++ b/compiler/rustc_typeck/src/check/method/confirm.rs @@ -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, diff --git a/compiler/rustc_typeck/src/check/method/mod.rs b/compiler/rustc_typeck/src/check/method/mod.rs index 8e13b3746992..4ea1888ad2eb 100644 --- a/compiler/rustc_typeck/src/check/method/mod.rs +++ b/compiler/rustc_typeck/src/check/method/mod.rs @@ -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, @@ -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>, @@ -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::(...)`) /// * `self_expr`: the self expression (`foo`) + #[instrument(level = "debug", skip(self, call_expr, self_expr))] pub fn lookup_method( &self, self_ty: Ty<'tcx>, @@ -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; @@ -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, @@ -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, @@ -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, diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs index d4631c465a3a..ccf13030ac18 100644 --- a/compiler/rustc_typeck/src/check/method/probe.rs +++ b/compiler/rustc_typeck/src/check/method/probe.rs @@ -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> { @@ -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, @@ -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, @@ -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);