Skip to content

Commit 513c9b7

Browse files
committed
Add debugging instrumentation.
1 parent b6f0945 commit 513c9b7

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

compiler/rustc_mir_transform/src/coroutine.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,15 @@ impl<'tcx> MutVisitor<'tcx> for SelfArgVisitor<'tcx> {
159159
}
160160
}
161161

162+
#[tracing::instrument(level = "trace", skip(tcx))]
162163
fn replace_base<'tcx>(place: &mut Place<'tcx>, new_base: Place<'tcx>, tcx: TyCtxt<'tcx>) {
163164
place.local = new_base.local;
164165

165166
let mut new_projection = new_base.projection.to_vec();
166167
new_projection.append(&mut place.projection.to_vec());
167168

168169
place.projection = tcx.mk_place_elems(&new_projection);
170+
tracing::trace!(?place);
169171
}
170172

171173
const SELF_ARG: Local = Local::from_u32(1);
@@ -270,6 +272,7 @@ impl<'tcx> TransformVisitor<'tcx> {
270272
// `core::ops::CoroutineState` only has single element tuple variants,
271273
// so we can just write to the downcasted first field and then set the
272274
// discriminant to the appropriate variant.
275+
#[tracing::instrument(level = "trace", skip(self, statements))]
273276
fn make_state(
274277
&self,
275278
val: Operand<'tcx>,
@@ -348,6 +351,7 @@ impl<'tcx> TransformVisitor<'tcx> {
348351
}
349352

350353
// Create a Place referencing a coroutine struct field
354+
#[tracing::instrument(level = "trace", skip(self), ret)]
351355
fn make_field(&self, variant_index: VariantIdx, idx: FieldIdx, ty: Ty<'tcx>) -> Place<'tcx> {
352356
let self_place = Place::from(SELF_ARG);
353357
let base = self.tcx.mk_place_downcast_unnamed(self_place, variant_index);
@@ -358,6 +362,7 @@ impl<'tcx> TransformVisitor<'tcx> {
358362
}
359363

360364
// Create a statement which changes the discriminant
365+
#[tracing::instrument(level = "trace", skip(self))]
361366
fn set_discr(&self, state_disc: VariantIdx, source_info: SourceInfo) -> Statement<'tcx> {
362367
let self_place = Place::from(SELF_ARG);
363368
Statement::new(
@@ -370,6 +375,7 @@ impl<'tcx> TransformVisitor<'tcx> {
370375
}
371376

372377
// Create a statement which reads the discriminant into a temporary
378+
#[tracing::instrument(level = "trace", skip(self, body))]
373379
fn get_discr(&self, body: &mut Body<'tcx>) -> (Statement<'tcx>, Place<'tcx>) {
374380
let temp_decl = LocalDecl::new(self.discr_ty, body.span);
375381
let local_decls_len = body.local_decls.push(temp_decl);
@@ -389,22 +395,20 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> {
389395
self.tcx
390396
}
391397

392-
fn visit_local(&mut self, local: &mut Local, _: PlaceContext, _: Location) {
398+
#[tracing::instrument(level = "trace", skip(self), ret)]
399+
fn visit_local(&mut self, local: &mut Local, _: PlaceContext, _location: Location) {
393400
assert!(!self.remap.contains(*local));
394401
}
395402

396-
fn visit_place(
397-
&mut self,
398-
place: &mut Place<'tcx>,
399-
_context: PlaceContext,
400-
_location: Location,
401-
) {
403+
#[tracing::instrument(level = "trace", skip(self), ret)]
404+
fn visit_place(&mut self, place: &mut Place<'tcx>, _: PlaceContext, _location: Location) {
402405
// Replace an Local in the remap with a coroutine struct access
403406
if let Some(&Some((ty, variant_index, idx))) = self.remap.get(place.local) {
404407
replace_base(place, self.make_field(variant_index, idx, ty), self.tcx);
405408
}
406409
}
407410

411+
#[tracing::instrument(level = "trace", skip(self, data), ret)]
408412
fn visit_basic_block_data(&mut self, block: BasicBlock, data: &mut BasicBlockData<'tcx>) {
409413
// Remove StorageLive and StorageDead statements for remapped locals
410414
for s in &mut data.statements {
@@ -483,6 +487,7 @@ fn make_aggregate_adt<'tcx>(
483487
Rvalue::Aggregate(Box::new(AggregateKind::Adt(def_id, variant_idx, args, None, None)), operands)
484488
}
485489

490+
#[tracing::instrument(level = "trace", skip(tcx, body))]
486491
fn make_coroutine_state_argument_indirect<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
487492
let coroutine_ty = body.local_decls.raw[1].ty;
488493

@@ -495,6 +500,7 @@ fn make_coroutine_state_argument_indirect<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Bo
495500
SelfArgVisitor::new(tcx, ProjectionElem::Deref).visit_body(body);
496501
}
497502

503+
#[tracing::instrument(level = "trace", skip(tcx, body))]
498504
fn make_coroutine_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
499505
let ref_coroutine_ty = body.local_decls.raw[1].ty;
500506

@@ -553,6 +559,7 @@ fn replace_local<'tcx>(
553559
/// The async lowering step and the type / lifetime inference / checking are
554560
/// still using the `ResumeTy` indirection for the time being, and that indirection
555561
/// is removed here. After this transform, the coroutine body only knows about `&mut Context<'_>`.
562+
#[tracing::instrument(level = "trace", skip(tcx, body), ret)]
556563
fn transform_async_context<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> Ty<'tcx> {
557564
let context_mut_ref = Ty::new_task_context(tcx);
558565

@@ -606,6 +613,7 @@ fn eliminate_get_context_call<'tcx>(bb_data: &mut BasicBlockData<'tcx>) -> Local
606613
}
607614

608615
#[cfg_attr(not(debug_assertions), allow(unused))]
616+
#[tracing::instrument(level = "trace", skip(tcx, body), ret)]
609617
fn replace_resume_ty_local<'tcx>(
610618
tcx: TyCtxt<'tcx>,
611619
body: &mut Body<'tcx>,
@@ -670,6 +678,7 @@ struct LivenessInfo {
670678
/// case none exist, the local is considered to be always live.
671679
/// - a local has to be stored if it is either directly used after the
672680
/// the suspend point, or if it is live and has been previously borrowed.
681+
#[tracing::instrument(level = "trace", skip(tcx, body))]
673682
fn locals_live_across_suspend_points<'tcx>(
674683
tcx: TyCtxt<'tcx>,
675684
body: &Body<'tcx>,
@@ -945,6 +954,7 @@ impl StorageConflictVisitor<'_, '_> {
945954
}
946955
}
947956

957+
#[tracing::instrument(level = "trace", skip(liveness, body))]
948958
fn compute_layout<'tcx>(
949959
liveness: LivenessInfo,
950960
body: &Body<'tcx>,
@@ -1049,7 +1059,9 @@ fn compute_layout<'tcx>(
10491059
variant_source_info,
10501060
storage_conflicts,
10511061
};
1062+
debug!(?remap);
10521063
debug!(?layout);
1064+
debug!(?storage_liveness);
10531065

10541066
(remap, layout, storage_liveness)
10551067
}
@@ -1221,6 +1233,7 @@ fn generate_poison_block_and_redirect_unwinds_there<'tcx>(
12211233
}
12221234
}
12231235

1236+
#[tracing::instrument(level = "trace", skip(tcx, transform, body))]
12241237
fn create_coroutine_resume_function<'tcx>(
12251238
tcx: TyCtxt<'tcx>,
12261239
transform: TransformVisitor<'tcx>,
@@ -1299,7 +1312,7 @@ fn create_coroutine_resume_function<'tcx>(
12991312
}
13001313

13011314
/// An operation that can be performed on a coroutine.
1302-
#[derive(PartialEq, Copy, Clone)]
1315+
#[derive(PartialEq, Copy, Clone, Debug)]
13031316
enum Operation {
13041317
Resume,
13051318
Drop,
@@ -1314,6 +1327,7 @@ impl Operation {
13141327
}
13151328
}
13161329

1330+
#[tracing::instrument(level = "trace", skip(transform, body))]
13171331
fn create_cases<'tcx>(
13181332
body: &mut Body<'tcx>,
13191333
transform: &TransformVisitor<'tcx>,
@@ -1445,6 +1459,8 @@ impl<'tcx> crate::MirPass<'tcx> for StateTransform {
14451459
// This only applies to coroutines
14461460
return;
14471461
};
1462+
tracing::trace!(def_id = ?body.source.def_id());
1463+
14481464
let old_ret_ty = body.return_ty();
14491465

14501466
assert!(body.coroutine_drop().is_none() && body.coroutine_drop_async().is_none());

compiler/rustc_mir_transform/src/coroutine/drop.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ fn build_pin_fut<'tcx>(
126126
// Ready() => ready_block
127127
// Pending => yield_block
128128
//}
129+
#[tracing::instrument(level = "trace", skip(tcx, body), ret)]
129130
fn build_poll_switch<'tcx>(
130131
tcx: TyCtxt<'tcx>,
131132
body: &mut Body<'tcx>,
@@ -179,6 +180,7 @@ fn build_poll_switch<'tcx>(
179180
}
180181

181182
// Gather blocks, reachable through 'drop' targets of Yield and Drop terminators (chained)
183+
#[tracing::instrument(level = "trace", skip(body), ret)]
182184
fn gather_dropline_blocks<'tcx>(body: &mut Body<'tcx>) -> DenseBitSet<BasicBlock> {
183185
let mut dropline: DenseBitSet<BasicBlock> = DenseBitSet::new_empty(body.basic_blocks.len());
184186
for (bb, data) in traversal::reverse_postorder(body) {
@@ -249,6 +251,7 @@ pub(super) fn has_expandable_async_drops<'tcx>(
249251
}
250252

251253
/// Expand Drop terminator for async drops into mainline poll-switch and dropline poll-switch
254+
#[tracing::instrument(level = "trace", skip(tcx, body), ret)]
252255
pub(super) fn expand_async_drops<'tcx>(
253256
tcx: TyCtxt<'tcx>,
254257
body: &mut Body<'tcx>,
@@ -259,6 +262,7 @@ pub(super) fn expand_async_drops<'tcx>(
259262
let dropline = gather_dropline_blocks(body);
260263
// Clean drop and async_fut fields if potentially async drop is not expanded (stays sync)
261264
let remove_asyncness = |block: &mut BasicBlockData<'tcx>| {
265+
tracing::trace!("remove_asyncness");
262266
if let TerminatorKind::Drop {
263267
place: _,
264268
target: _,
@@ -461,6 +465,7 @@ pub(super) fn expand_async_drops<'tcx>(
461465
}
462466
}
463467

468+
#[tracing::instrument(level = "trace", skip(tcx, body))]
464469
pub(super) fn elaborate_coroutine_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
465470
use crate::elaborate_drop::{Unwind, elaborate_drop};
466471
use crate::patch::MirPatch;
@@ -519,6 +524,7 @@ pub(super) fn elaborate_coroutine_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body
519524
elaborator.patch.apply(body);
520525
}
521526

527+
#[tracing::instrument(level = "trace", skip(tcx, body), ret)]
522528
pub(super) fn insert_clean_drop<'tcx>(
523529
tcx: TyCtxt<'tcx>,
524530
body: &mut Body<'tcx>,
@@ -550,6 +556,7 @@ pub(super) fn insert_clean_drop<'tcx>(
550556
.push(BasicBlockData::new(Some(Terminator { source_info, kind: term }), false))
551557
}
552558

559+
#[tracing::instrument(level = "trace", skip(tcx, transform, body))]
553560
pub(super) fn create_coroutine_drop_shim<'tcx>(
554561
tcx: TyCtxt<'tcx>,
555562
transform: &TransformVisitor<'tcx>,
@@ -621,6 +628,7 @@ pub(super) fn create_coroutine_drop_shim<'tcx>(
621628
}
622629

623630
// Create async drop shim function to drop coroutine itself
631+
#[tracing::instrument(level = "trace", skip(tcx, transform, body))]
624632
pub(super) fn create_coroutine_drop_shim_async<'tcx>(
625633
tcx: TyCtxt<'tcx>,
626634
transform: &TransformVisitor<'tcx>,

0 commit comments

Comments
 (0)