Skip to content

Commit a034446

Browse files
committed
Add some tracing instrumentation
1 parent 84a444a commit a034446

File tree

8 files changed

+29
-27
lines changed

8 files changed

+29
-27
lines changed

compiler/rustc_mir_build/src/build/expr/as_temp.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2323
ensure_sufficient_stack(|| self.as_temp_inner(block, temp_lifetime, expr, mutability))
2424
}
2525

26+
#[instrument(skip(self), level = "debug")]
2627
fn as_temp_inner(
2728
&mut self,
2829
mut block: BasicBlock,
2930
temp_lifetime: Option<region::Scope>,
3031
expr: &Expr<'tcx>,
3132
mutability: Mutability,
3233
) -> BlockAnd<Local> {
33-
debug!(
34-
"as_temp(block={:?}, temp_lifetime={:?}, expr={:?}, mutability={:?})",
35-
block, temp_lifetime, expr, mutability
36-
);
3734
let this = self;
3835

3936
let expr_span = expr.span;

compiler/rustc_mir_build/src/build/expr/into.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ use std::iter;
1515
impl<'a, 'tcx> Builder<'a, 'tcx> {
1616
/// Compile `expr`, storing the result into `destination`, which
1717
/// is assumed to be uninitialized.
18+
#[instrument(level = "debug", skip(self))]
1819
pub(crate) fn expr_into_dest(
1920
&mut self,
2021
destination: Place<'tcx>,
2122
mut block: BasicBlock,
2223
expr: &Expr<'tcx>,
2324
) -> BlockAnd<()> {
24-
debug!("expr_into_dest(destination={:?}, block={:?}, expr={:?})", destination, block, expr);
25-
2625
// since we frequently have to reference `self` from within a
2726
// closure, where `self` would be shadowed, it's easier to
2827
// just use the name `this` uniformly

compiler/rustc_mir_build/src/build/matches/mod.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
654654
/// scope for the bindings in these patterns, if such a scope had to be
655655
/// created. NOTE: Declaring the bindings should always be done in their
656656
/// drop scope.
657+
#[instrument(skip(self), level = "debug")]
657658
pub(crate) fn declare_bindings(
658659
&mut self,
659660
mut visibility_scope: Option<SourceScope>,
@@ -662,7 +663,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
662663
has_guard: ArmHasGuard,
663664
opt_match_place: Option<(Option<&Place<'tcx>>, Span)>,
664665
) -> Option<SourceScope> {
665-
debug!("declare_bindings: pattern={:?}", pattern);
666666
self.visit_primary_bindings(
667667
&pattern,
668668
UserTypeProjections::none(),
@@ -1048,6 +1048,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10481048
/// if `x.0` matches `false` (for the third arm). In the (impossible at
10491049
/// runtime) case when `x.0` is now `true`, we branch to
10501050
/// `otherwise_block`.
1051+
#[instrument(skip(self, fake_borrows), level = "debug")]
10511052
fn match_candidates<'pat>(
10521053
&mut self,
10531054
span: Span,
@@ -1057,11 +1058,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10571058
candidates: &mut [&mut Candidate<'pat, 'tcx>],
10581059
fake_borrows: &mut Option<FxIndexSet<Place<'tcx>>>,
10591060
) {
1060-
debug!(
1061-
"matched_candidate(span={:?}, candidates={:?}, start_block={:?}, otherwise_block={:?})",
1062-
span, candidates, start_block, otherwise_block,
1063-
);
1064-
10651061
// Start by simplifying candidates. Once this process is complete, all
10661062
// the match pairs which remain require some form of test, whether it
10671063
// be a switch or pattern comparison.
@@ -1380,6 +1376,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
13801376
)
13811377
}
13821378

1379+
#[instrument(
1380+
skip(self, otherwise, or_span, place, fake_borrows, candidate, pats),
1381+
level = "debug"
1382+
)]
13831383
fn test_or_pattern<'pat>(
13841384
&mut self,
13851385
candidate: &mut Candidate<'pat, 'tcx>,
@@ -1389,7 +1389,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
13891389
place: PlaceBuilder<'tcx>,
13901390
fake_borrows: &mut Option<FxIndexSet<Place<'tcx>>>,
13911391
) {
1392-
debug!("test_or_pattern:\ncandidate={:#?}\npats={:#?}", candidate, pats);
1392+
debug!("candidate={:#?}\npats={:#?}", candidate, pats);
13931393
let mut or_candidates: Vec<_> = pats
13941394
.iter()
13951395
.map(|pat| Candidate::new(place.clone(), pat, candidate.has_guard))
@@ -1634,9 +1634,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
16341634
candidates = rest;
16351635
}
16361636
// at least the first candidate ought to be tested
1637-
assert!(total_candidate_count > candidates.len());
1638-
debug!("test_candidates: tested_candidates: {}", total_candidate_count - candidates.len());
1639-
debug!("test_candidates: untested_candidates: {}", candidates.len());
1637+
assert!(
1638+
total_candidate_count > candidates.len(),
1639+
"{}, {:#?}",
1640+
total_candidate_count,
1641+
candidates
1642+
);
1643+
debug!("tested_candidates: {}", total_candidate_count - candidates.len());
1644+
debug!("untested_candidates: {}", candidates.len());
16401645

16411646
// HACK(matthewjasper) This is a closure so that we can let the test
16421647
// create its blocks before the rest of the match. This currently
@@ -2195,6 +2200,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
21952200
/// first local is a binding for occurrences of `var` in the guard, which
21962201
/// will have type `&T`. The second local is a binding for occurrences of
21972202
/// `var` in the arm body, which will have type `T`.
2203+
#[instrument(skip(self), level = "debug")]
21982204
fn declare_binding(
21992205
&mut self,
22002206
source_info: SourceInfo,
@@ -2209,19 +2215,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
22092215
opt_match_place: Option<(Option<Place<'tcx>>, Span)>,
22102216
pat_span: Span,
22112217
) {
2212-
debug!(
2213-
"declare_binding(var_id={:?}, name={:?}, mode={:?}, var_ty={:?}, \
2214-
visibility_scope={:?}, source_info={:?})",
2215-
var_id, name, mode, var_ty, visibility_scope, source_info
2216-
);
2217-
22182218
let tcx = self.tcx;
22192219
let debug_source_info = SourceInfo { span: source_info.span, scope: visibility_scope };
22202220
let binding_mode = match mode {
22212221
BindingMode::ByValue => ty::BindingMode::BindByValue(mutability),
22222222
BindingMode::ByRef(_) => ty::BindingMode::BindByReference(mutability),
22232223
};
2224-
debug!("declare_binding: user_ty={:?}", user_ty);
22252224
let local = LocalDecl::<'tcx> {
22262225
mutability,
22272226
ty: var_ty,
@@ -2271,7 +2270,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
22712270
} else {
22722271
LocalsForNode::One(for_arm_body)
22732272
};
2274-
debug!("declare_binding: vars={:?}", locals);
2273+
debug!(?locals);
22752274
self.var_indices.insert(var_id, locals);
22762275
}
22772276

compiler/rustc_mir_build/src/build/matches/simplify.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
3737
///
3838
/// only generates a single switch. If this happens this method returns
3939
/// `true`.
40+
#[instrument(skip(self, candidate), level = "debug")]
4041
pub(super) fn simplify_candidate<'pat>(
4142
&mut self,
4243
candidate: &mut Candidate<'pat, 'tcx>,
4344
) -> bool {
4445
// repeatedly simplify match pairs until fixed point is reached
45-
debug!(?candidate, "simplify_candidate");
46+
debug!("{:#?}", candidate);
4647

4748
// existing_bindings and new_bindings exists to keep the semantics in order.
4849
// Reversing the binding order for bindings after `@` changes the binding order in places

compiler/rustc_mir_build/src/build/matches/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
144144
}
145145
}
146146

147+
#[instrument(skip(self, make_target_blocks, place_builder), level = "debug")]
147148
pub(super) fn perform_test(
148149
&mut self,
149150
match_start_span: Span,

compiler/rustc_mir_build/src/build/scope.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
553553

554554
/// Convenience wrapper that pushes a scope and then executes `f`
555555
/// to build its contents, popping the scope afterwards.
556+
#[instrument(skip(self, f), level = "debug")]
556557
pub(crate) fn in_scope<F, R>(
557558
&mut self,
558559
region_scope: (region::Scope, SourceInfo),
@@ -562,7 +563,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
562563
where
563564
F: FnOnce(&mut Builder<'a, 'tcx>) -> BlockAnd<R>,
564565
{
565-
debug!("in_scope(region_scope={:?})", region_scope);
566566
let source_scope = self.source_scope;
567567
let tcx = self.tcx;
568568
if let LintLevel::Explicit(current_hir_id) = lint_level {
@@ -589,7 +589,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
589589
let rv = unpack!(block = f(self));
590590
unpack!(block = self.pop_scope(region_scope, block));
591591
self.source_scope = source_scope;
592-
debug!("in_scope: exiting region_scope={:?} block={:?}", region_scope, block);
592+
debug!(?block);
593593
block.and(rv)
594594
}
595595

compiler/rustc_mir_build/src/thir/cx/expr.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ impl<'tcx> Cx<'tcx> {
4848
_ => None,
4949
};
5050

51+
trace!(?expr.ty);
52+
5153
// Now apply adjustments, if any.
5254
for adjustment in self.typeck_results.expr_adjustments(hir_expr) {
5355
trace!(?expr, ?adjustment);
@@ -56,6 +58,8 @@ impl<'tcx> Cx<'tcx> {
5658
self.apply_adjustment(hir_expr, expr, adjustment, adjustment_span.unwrap_or(span));
5759
}
5860

61+
trace!(?expr.ty, "after adjustments");
62+
5963
// Next, wrap this up in the expr's scope.
6064
expr = Expr {
6165
temp_lifetime,

compiler/rustc_mir_build/src/thir/pattern/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
196196
}
197197
}
198198

199+
#[instrument(skip(self), level = "debug")]
199200
fn lower_pattern_unadjusted(&mut self, pat: &'tcx hir::Pat<'tcx>) -> Pat<'tcx> {
200201
let mut ty = self.typeck_results.node_type(pat.hir_id);
201202

0 commit comments

Comments
 (0)