Skip to content

Commit

Permalink
Add some more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjasper committed May 9, 2020
1 parent 54aa418 commit 1a19c1d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/librustc_mir_build/build/matches/test.rs
Expand Up @@ -439,7 +439,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
literal: method,
}),
args: vec![val, expect],
destination: Some((eq_result.clone(), eq_block)),
destination: Some((eq_result, eq_block)),
cleanup: None,
from_hir_call: false,
},
Expand Down
27 changes: 21 additions & 6 deletions src/librustc_mir_build/build/scope.rs
Expand Up @@ -237,6 +237,9 @@ trait DropTreeBuilder<'tcx> {

impl DropTree {
fn new() -> Self {
// The root node of the tree doesn't represent a drop, but instead
// represents the block in the tree that should be jumped to once all
// of the required drops have been performed.
let fake_source_info = SourceInfo::outermost(DUMMY_SP);
let fake_data =
DropData { source_info: fake_source_info, local: Local::MAX, kind: DropKind::Storage };
Expand All @@ -258,6 +261,10 @@ impl DropTree {
self.entry_points.push((to, from));
}

/// Builds the MIR for a given drop tree.
///
/// `blocks` should have the same length as `self.drops`, and may have its
/// first value set to some already existing block.
fn build_mir<'tcx, T: DropTreeBuilder<'tcx>>(
&mut self,
cfg: &mut CFG<'tcx>,
Expand Down Expand Up @@ -1344,10 +1351,16 @@ impl<'tcx> DropTreeBuilder<'tcx> for GeneratorDrop {
cfg.start_new_block()
}
fn add_entry(cfg: &mut CFG<'tcx>, from: BasicBlock, to: BasicBlock) {
let kind = &mut cfg.block_data_mut(from).terminator_mut().kind;
if let TerminatorKind::Yield { drop, .. } = kind {
let term = cfg.block_data_mut(from).terminator_mut();
if let TerminatorKind::Yield { ref mut drop, .. } = term.kind {
*drop = Some(to);
};
} else {
span_bug!(
term.source_info.span,
"cannot enter generator drop tree from {:?}",
term.kind
)
}
}
}

Expand All @@ -1358,8 +1371,8 @@ impl<'tcx> DropTreeBuilder<'tcx> for Unwind {
cfg.start_new_cleanup_block()
}
fn add_entry(cfg: &mut CFG<'tcx>, from: BasicBlock, to: BasicBlock) {
let term = &mut cfg.block_data_mut(from).terminator_mut().kind;
match term {
let term = &mut cfg.block_data_mut(from).terminator_mut();
match &mut term.kind {
TerminatorKind::Drop { unwind, .. }
| TerminatorKind::DropAndReplace { unwind, .. }
| TerminatorKind::FalseUnwind { unwind, .. }
Expand All @@ -1375,7 +1388,9 @@ impl<'tcx> DropTreeBuilder<'tcx> for Unwind {
| TerminatorKind::Unreachable
| TerminatorKind::Yield { .. }
| TerminatorKind::GeneratorDrop
| TerminatorKind::FalseEdges { .. } => bug!("cannot unwind from {:?}", term),
| TerminatorKind::FalseEdges { .. } => {
span_bug!(term.source_info.span, "cannot unwind from {:?}", term.kind)
}
}
}
}

0 comments on commit 1a19c1d

Please sign in to comment.