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 Feb 29, 2020
1 parent 9a926f9 commit ba989b2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/librustc_mir_build/build/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_hir as hir;
use rustc_span::Span;

impl<'a, 'tcx> Builder<'a, 'tcx> {
pub fn ast_block(
crate fn ast_block(
&mut self,
destination: &Place<'tcx>,
scope: Option<region::Scope>,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir_build/build/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub(in crate::build) trait EvalInto<'tcx> {
}

impl<'a, 'tcx> Builder<'a, 'tcx> {
pub fn into<E>(
crate fn into<E>(
&mut self,
destination: &Place<'tcx>,
scope: Option<region::Scope>,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir_build/build/matches/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,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
31 changes: 22 additions & 9 deletions src/librustc_mir_build/build/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,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 { span: DUMMY_SP, scope: OUTERMOST_SOURCE_SCOPE };
let fake_data =
DropData { source_info: fake_source_info, local: Local::MAX, kind: DropKind::Storage };
Expand All @@ -256,12 +259,17 @@ 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>,
blocks: &mut IndexVec<DropIdx, Option<BasicBlock>>,
) {
debug!("DropTree::lower_to_mir(drops = {:#?})", self);
debug_assert_eq!(blocks.len(), self.drops.len());

self.assign_blocks::<T>(cfg, blocks);
self.link_blocks(cfg, blocks)
Expand Down Expand Up @@ -1105,7 +1113,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
return self.cfg.start_new_block().unit();
}
let mut first_arm = true;
let cached_unwind_block = self.diverge_cleanup();
let arm_end_blocks: Vec<_> = arm_candidates
.into_iter()
.map(|(arm, candidate)| {
Expand All @@ -1115,8 +1122,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
destination_scope.map(|scope| {
self.unschedule_drop(scope, destination.as_local().unwrap());
});
let top_scope = &mut self.scopes.scopes.last_mut().unwrap();
top_scope.cached_unwind_block = Some(cached_unwind_block);
}

let arm_source_info = self.source_info(arm.span);
Expand Down Expand Up @@ -1394,10 +1399,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 @@ -1408,8 +1419,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 @@ -1425,7 +1436,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 ba989b2

Please sign in to comment.