Skip to content

Commit 251b92a

Browse files
committed
Add some comments to generator clone shim code
1 parent cf91768 commit 251b92a

File tree

1 file changed

+12
-0
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+12
-0
lines changed

compiler/rustc_mir_transform/src/shim.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,18 @@ impl<'tcx> CloneShimBuilder<'tcx> {
473473
where
474474
I: IntoIterator<Item = Ty<'tcx>>,
475475
{
476+
// For an iterator of length n, create 2*n + 1 blocks.
476477
for (i, ity) in tys.into_iter().enumerate() {
478+
// Each iteration creates two blocks, referred to here as block 2*i and block 2*i + 1.
479+
//
480+
// Block 2*i attempts to clone the field. If successful it branches to 2*i + 2 (the
481+
// next clone block). If unsuccessful it branches to the previous unwind block, which
482+
// is initially the `unwind` argument passed to this function.
483+
//
484+
// Block 2*i + 1 is the unwind block for this iteration. It drops the cloned value
485+
// created by block 2*i. We store this block in `unwind` so that the next clone block
486+
// will unwind to it if cloning fails.
487+
477488
let field = Field::new(i);
478489
let src_field = self.tcx.mk_place_field(src, field, ity);
479490

@@ -489,6 +500,7 @@ impl<'tcx> CloneShimBuilder<'tcx> {
489500
);
490501
unwind = next_unwind;
491502
}
503+
// If all clones succeed then we end up here.
492504
self.block(vec![], TerminatorKind::Goto { target }, false);
493505
unwind
494506
}

0 commit comments

Comments
 (0)