Skip to content

Commit 6af831a

Browse files
committed
Add tracing instrumentation to method typeck
I was recently digging into how this code works, and this instrumentation was helpful.
1 parent 9775ffe commit 6af831a

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

Diff for: compiler/rustc_typeck/src/check/method/confirm.rs

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ impl<'a, 'tcx> Deref for ConfirmContext<'a, 'tcx> {
3131
}
3232
}
3333

34+
#[derive(Debug)]
3435
pub struct ConfirmResult<'tcx> {
3536
pub callee: MethodCallee<'tcx>,
3637
pub illegal_sized_bound: Option<Span>,

Diff for: compiler/rustc_typeck/src/check/method/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ pub enum CandidateSource {
102102

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

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

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

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

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

418+
#[instrument(level = "debug", skip(self))]
412419
pub fn resolve_ufcs(
413420
&self,
414421
span: Span,

Diff for: compiler/rustc_typeck/src/check/method/probe.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub use self::PickKind::*;
4848

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

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

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

0 commit comments

Comments
 (0)