Skip to content

Commit 1d45658

Browse files
committed
Some tracing changes
1 parent c06b2b9 commit 1d45658

File tree

3 files changed

+35
-56
lines changed

3 files changed

+35
-56
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,14 +504,13 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
504504

505505
/// Checks that the types internal to the `place` match up with
506506
/// what would be expected.
507+
#[instrument(level = "debug", skip(self, location), ret)]
507508
fn sanitize_place(
508509
&mut self,
509510
place: &Place<'tcx>,
510511
location: Location,
511512
context: PlaceContext,
512513
) -> PlaceTy<'tcx> {
513-
debug!("sanitize_place: {:?}", place);
514-
515514
let mut place_ty = PlaceTy::from_ty(self.body().local_decls[place.local].ty);
516515

517516
for elem in place.projection.iter() {
@@ -614,7 +613,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
614613
}
615614
}
616615

617-
#[instrument(skip(self), level = "debug")]
616+
#[instrument(skip(self, location), ret, level = "debug")]
618617
fn sanitize_projection(
619618
&mut self,
620619
base: PlaceTy<'tcx>,
@@ -623,7 +622,6 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
623622
location: Location,
624623
context: PlaceContext,
625624
) -> PlaceTy<'tcx> {
626-
debug!("sanitize_projection: {:?} {:?} {:?}", base, pi, place);
627625
let tcx = self.tcx();
628626
let base_ty = base.ty;
629627
match pi {

compiler/rustc_hir_typeck/src/mem_categorization.rs

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,14 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
198198
}
199199

200200
/// Like `pat_ty`, but ignores implicit `&` patterns.
201+
#[instrument(level = "debug", skip(self), ret)]
201202
fn pat_ty_unadjusted(&self, pat: &hir::Pat<'_>) -> McResult<Ty<'tcx>> {
202203
let base_ty = self.node_ty(pat.hir_id)?;
203-
debug!("pat_ty(pat={:?}) base_ty={:?}", pat, base_ty);
204+
trace!(?base_ty);
204205

205206
// This code detects whether we are looking at a `ref x`,
206207
// and if so, figures out what the type *being borrowed* is.
207-
let ret_ty = match pat.kind {
208+
match pat.kind {
208209
PatKind::Binding(..) => {
209210
let bm = *self
210211
.typeck_results
@@ -217,21 +218,18 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
217218
// but what we want here is the type of the underlying value being borrowed.
218219
// So peel off one-level, turning the &T into T.
219220
match base_ty.builtin_deref(false) {
220-
Some(t) => t.ty,
221+
Some(t) => Ok(t.ty),
221222
None => {
222-
debug!("By-ref binding of non-derefable type {:?}", base_ty);
223-
return Err(());
223+
debug!("By-ref binding of non-derefable type");
224+
Err(())
224225
}
225226
}
226227
} else {
227-
base_ty
228+
Ok(base_ty)
228229
}
229230
}
230-
_ => base_ty,
231-
};
232-
debug!("pat_ty(pat={:?}) ret_ty={:?}", pat, ret_ty);
233-
234-
Ok(ret_ty)
231+
_ => Ok(base_ty),
232+
}
235233
}
236234

237235
pub(crate) fn cat_expr(&self, expr: &hir::Expr<'_>) -> McResult<PlaceWithHirId<'tcx>> {
@@ -299,13 +297,11 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
299297
}
300298
}
301299

302-
#[instrument(level = "debug", skip(self))]
300+
#[instrument(level = "debug", skip(self), ret)]
303301
pub(crate) fn cat_expr_unadjusted(
304302
&self,
305303
expr: &hir::Expr<'_>,
306304
) -> McResult<PlaceWithHirId<'tcx>> {
307-
debug!("cat_expr: id={} expr={:?}", expr.hir_id, expr);
308-
309305
let expr_ty = self.expr_ty(expr)?;
310306
match expr.kind {
311307
hir::ExprKind::Unary(hir::UnOp::Deref, ref e_base) => {
@@ -319,7 +315,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
319315

320316
hir::ExprKind::Field(ref base, _) => {
321317
let base = self.cat_expr(base)?;
322-
debug!("cat_expr(cat_field): id={} expr={:?} base={:?}", expr.hir_id, expr, base);
318+
debug!(?base);
323319

324320
let field_idx = self
325321
.typeck_results
@@ -389,7 +385,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
389385
}
390386
}
391387

392-
#[instrument(level = "debug", skip(self, span))]
388+
#[instrument(level = "debug", skip(self, span), ret)]
393389
pub(crate) fn cat_res(
394390
&self,
395391
hir_id: hir::HirId,
@@ -430,6 +426,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
430426
/// Note: the actual upvar access contains invisible derefs of closure
431427
/// environment and upvar reference as appropriate. Only regionck cares
432428
/// about these dereferences, so we let it compute them as needed.
429+
#[instrument(level = "debug", skip(self), ret)]
433430
fn cat_upvar(&self, hir_id: hir::HirId, var_id: hir::HirId) -> McResult<PlaceWithHirId<'tcx>> {
434431
let closure_expr_def_id = self.body_owner;
435432

@@ -439,24 +436,20 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
439436
};
440437
let var_ty = self.node_ty(var_id)?;
441438

442-
let ret = PlaceWithHirId::new(hir_id, var_ty, PlaceBase::Upvar(upvar_id), Vec::new());
443-
444-
debug!("cat_upvar ret={:?}", ret);
445-
Ok(ret)
439+
Ok(PlaceWithHirId::new(hir_id, var_ty, PlaceBase::Upvar(upvar_id), Vec::new()))
446440
}
447441

442+
#[instrument(level = "debug", skip(self), ret)]
448443
pub(crate) fn cat_rvalue(
449444
&self,
450445
hir_id: hir::HirId,
451446
span: Span,
452447
expr_ty: Ty<'tcx>,
453448
) -> PlaceWithHirId<'tcx> {
454-
debug!("cat_rvalue hir_id={:?}, expr_ty={:?}, span={:?}", hir_id, expr_ty, span);
455-
let ret = PlaceWithHirId::new(hir_id, expr_ty, PlaceBase::Rvalue, Vec::new());
456-
debug!("cat_rvalue ret={:?}", ret);
457-
ret
449+
PlaceWithHirId::new(hir_id, expr_ty, PlaceBase::Rvalue, Vec::new())
458450
}
459451

452+
#[instrument(level = "debug", skip(self, node), ret)]
460453
pub(crate) fn cat_projection<N: HirNode>(
461454
&self,
462455
node: &N,
@@ -466,14 +459,12 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
466459
) -> PlaceWithHirId<'tcx> {
467460
let mut projections = base_place.place.projections;
468461
projections.push(Projection { kind, ty });
469-
let ret = PlaceWithHirId::new(
462+
PlaceWithHirId::new(
470463
node.hir_id(),
471464
base_place.place.base_ty,
472465
base_place.place.base,
473466
projections,
474-
);
475-
debug!("cat_field ret {:?}", ret);
476-
ret
467+
)
477468
}
478469

479470
#[instrument(level = "debug", skip(self))]
@@ -497,7 +488,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
497488
self.cat_deref(expr, base)
498489
}
499490

500-
#[instrument(level = "debug", skip(self, node))]
491+
#[instrument(level = "debug", skip(self, node), ret)]
501492
fn cat_deref(
502493
&self,
503494
node: &impl HirNode,
@@ -514,14 +505,12 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
514505
let mut projections = base_place.place.projections;
515506
projections.push(Projection { kind: ProjectionKind::Deref, ty: deref_ty });
516507

517-
let ret = PlaceWithHirId::new(
508+
Ok(PlaceWithHirId::new(
518509
node.hir_id(),
519510
base_place.place.base_ty,
520511
base_place.place.base,
521512
projections,
522-
);
523-
debug!("cat_deref ret {:?}", ret);
524-
Ok(ret)
513+
))
525514
}
526515

527516
pub(crate) fn cat_pattern<F>(
@@ -603,6 +592,13 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
603592
}
604593
}
605594

595+
/// Here, `place` is the `PlaceWithHirId` being matched and pat is the pattern it
596+
/// is being matched against.
597+
///
598+
/// In general, the way that this works is that we walk down the pattern,
599+
/// constructing a `PlaceWithHirId` that represents the path that will be taken
600+
/// to reach the value being matched.
601+
#[instrument(skip(self, op), ret, level = "debug")]
606602
fn cat_pattern_<F>(
607603
&self,
608604
mut place_with_id: PlaceWithHirId<'tcx>,
@@ -612,15 +608,6 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
612608
where
613609
F: FnMut(&PlaceWithHirId<'tcx>, &hir::Pat<'_>),
614610
{
615-
// Here, `place` is the `PlaceWithHirId` being matched and pat is the pattern it
616-
// is being matched against.
617-
//
618-
// In general, the way that this works is that we walk down the pattern,
619-
// constructing a `PlaceWithHirId` that represents the path that will be taken
620-
// to reach the value being matched.
621-
622-
debug!("cat_pattern(pat={:?}, place_with_id={:?})", pat, place_with_id);
623-
624611
// If (pattern) adjustments are active for this pattern, adjust the `PlaceWithHirId` correspondingly.
625612
// `PlaceWithHirId`s are constructed differently from patterns. For example, in
626613
//
@@ -654,11 +641,11 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
654641
// `deref { deref { place_foo }}` instead of `place_foo` since the pattern is now `Some(x,)`
655642
// and not `&&Some(x,)`, even though its assigned type is that of `&&Some(x,)`.
656643
for _ in 0..self.typeck_results.pat_adjustments().get(pat.hir_id).map_or(0, |v| v.len()) {
657-
debug!("cat_pattern: applying adjustment to place_with_id={:?}", place_with_id);
644+
debug!("applying adjustment to place_with_id={:?}", place_with_id);
658645
place_with_id = self.cat_deref(pat, place_with_id)?;
659646
}
660647
let place_with_id = place_with_id; // lose mutability
661-
debug!("cat_pattern: applied adjustment derefs to get place_with_id={:?}", place_with_id);
648+
debug!("applied adjustment derefs to get place_with_id={:?}", place_with_id);
662649

663650
// Invoke the callback, but only now, after the `place_with_id` has adjusted.
664651
//

compiler/rustc_hir_typeck/src/upvar.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
294294

295295
// Equate the type variables for the upvars with the actual types.
296296
let final_upvar_tys = self.final_upvar_tys(closure_def_id);
297-
debug!(
298-
"analyze_closure: id={:?} args={:?} final_upvar_tys={:?}",
299-
closure_hir_id, args, final_upvar_tys
300-
);
297+
debug!(?closure_hir_id, ?args, ?final_upvar_tys);
301298

302299
// Build a tuple (U0..Un) of the final upvar types U0..Un
303300
// and unify the upvar tuple type in the closure with it:
@@ -338,10 +335,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
338335
let upvar_ty = captured_place.place.ty();
339336
let capture = captured_place.info.capture_kind;
340337

341-
debug!(
342-
"final_upvar_tys: place={:?} upvar_ty={:?} capture={:?}, mutability={:?}",
343-
captured_place.place, upvar_ty, capture, captured_place.mutability,
344-
);
338+
debug!(?captured_place.place, ?upvar_ty, ?capture, ?captured_place.mutability);
345339

346340
apply_capture_kind_on_capture_ty(self.tcx, upvar_ty, capture, captured_place.region)
347341
})

0 commit comments

Comments
 (0)