Auto merge of #80995 - tmandry:instrument-method-checker, r=lcnr

Add tracing instrumentation to method typeck

I was recently digging into how this code works, and this instrumentation was helpful.
This commit is contained in:
bors 2021-01-18 08:39:31 +00:00
commit 86e0ff47a0
3 changed files with 12 additions and 2 deletions

View file

@ -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>,

View file

@ -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::<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>,
@ -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,

View file

@ -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);