1
Fork 0

Add some more comments

This commit is contained in:
Matthew Jasper 2020-02-29 17:48:09 +00:00 committed by Aaron Hill
parent f810e600cd
commit 1e71862046
No known key found for this signature in database
GPG key ID: B4087E510E98B164
2 changed files with 22 additions and 7 deletions

View file

@ -434,7 +434,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
literal: method, literal: method,
}), }),
args: vec![val, expect], args: vec![val, expect],
destination: Some((eq_result.clone(), eq_block)), destination: Some((eq_result, eq_block)),
cleanup: None, cleanup: None,
from_hir_call: false, from_hir_call: false,
fn_span: source_info.span, fn_span: source_info.span,

View file

@ -238,6 +238,9 @@ trait DropTreeBuilder<'tcx> {
impl DropTree { impl DropTree {
fn new() -> Self { 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_source_info = SourceInfo::outermost(DUMMY_SP);
let fake_data = let fake_data =
DropData { source_info: fake_source_info, local: Local::MAX, kind: DropKind::Storage }; DropData { source_info: fake_source_info, local: Local::MAX, kind: DropKind::Storage };
@ -259,6 +262,10 @@ impl DropTree {
self.entry_points.push((to, from)); 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>>( fn build_mir<'tcx, T: DropTreeBuilder<'tcx>>(
&mut self, &mut self,
cfg: &mut CFG<'tcx>, cfg: &mut CFG<'tcx>,
@ -1345,10 +1352,16 @@ impl<'tcx> DropTreeBuilder<'tcx> for GeneratorDrop {
cfg.start_new_block() cfg.start_new_block()
} }
fn add_entry(cfg: &mut CFG<'tcx>, from: BasicBlock, to: BasicBlock) { fn add_entry(cfg: &mut CFG<'tcx>, from: BasicBlock, to: BasicBlock) {
let kind = &mut cfg.block_data_mut(from).terminator_mut().kind; let term = cfg.block_data_mut(from).terminator_mut();
if let TerminatorKind::Yield { drop, .. } = kind { if let TerminatorKind::Yield { ref mut drop, .. } = term.kind {
*drop = Some(to); *drop = Some(to);
}; } else {
span_bug!(
term.source_info.span,
"cannot enter generator drop tree from {:?}",
term.kind
)
}
} }
} }
@ -1359,8 +1372,8 @@ impl<'tcx> DropTreeBuilder<'tcx> for Unwind {
cfg.start_new_cleanup_block() cfg.start_new_cleanup_block()
} }
fn add_entry(cfg: &mut CFG<'tcx>, from: BasicBlock, to: BasicBlock) { fn add_entry(cfg: &mut CFG<'tcx>, from: BasicBlock, to: BasicBlock) {
let term = &mut cfg.block_data_mut(from).terminator_mut().kind; let term = &mut cfg.block_data_mut(from).terminator_mut();
match term { match &mut term.kind {
TerminatorKind::Drop { unwind, .. } TerminatorKind::Drop { unwind, .. }
| TerminatorKind::DropAndReplace { unwind, .. } | TerminatorKind::DropAndReplace { unwind, .. }
| TerminatorKind::FalseUnwind { unwind, .. } | TerminatorKind::FalseUnwind { unwind, .. }
@ -1376,7 +1389,9 @@ impl<'tcx> DropTreeBuilder<'tcx> for Unwind {
| TerminatorKind::Unreachable | TerminatorKind::Unreachable
| TerminatorKind::Yield { .. } | TerminatorKind::Yield { .. }
| TerminatorKind::GeneratorDrop | TerminatorKind::GeneratorDrop
| TerminatorKind::FalseEdges { .. } => bug!("cannot unwind from {:?}", term), | TerminatorKind::FalseEdges { .. } => {
span_bug!(term.source_info.span, "cannot unwind from {:?}", term.kind)
}
} }
} }
} }