Skip to content

Commit

Permalink
More review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tmandry committed Jun 11, 2019
1 parent 9f3ad88 commit aeefbc4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 39 deletions.
7 changes: 0 additions & 7 deletions src/librustc/mir/mod.rs
Expand Up @@ -1501,13 +1501,6 @@ impl<'tcx> BasicBlockData<'tcx> {
self.terminator.as_mut().expect("invalid terminator state")
}

pub fn is_unreachable(&self) -> bool {
match self.terminator().kind {
TerminatorKind::Unreachable => true,
_ => false,
}
}

pub fn retain_statements<F>(&mut self, mut f: F)
where
F: FnMut(&mut Statement<'_>) -> bool,
Expand Down
42 changes: 13 additions & 29 deletions src/librustc/ty/layout.rs
Expand Up @@ -1311,7 +1311,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
) -> Result<&'tcx LayoutDetails, LayoutError<'tcx>> {
use SavedLocalEligibility::*;
let tcx = self.tcx;
let recompute_memory_index = |offsets: &Vec<u32>| -> Vec<u32> {
let recompute_memory_index = |offsets: &[Size]| -> Vec<u32> {
debug!("recompute_memory_index({:?})", offsets);
let mut inverse_index = (0..offsets.len() as u32).collect::<Vec<_>>();
inverse_index.sort_unstable_by_key(|i| offsets[*i as usize]);
Expand Down Expand Up @@ -1349,19 +1349,14 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
// get included in each variant that requested them in
// GeneratorLayout.
debug!("prefix = {:#?}", prefix);
let (outer_fields, promoted_offsets, promoted_memory_index) = match prefix.fields {
FieldPlacement::Arbitrary { offsets, memory_index } => {
let (offsets_a, offsets_b) =
offsets.split_at(discr_index + 1);
let (memory_index_a, memory_index_b) =
memory_index.split_at(discr_index + 1);
let outer_fields = FieldPlacement::Arbitrary {
offsets: offsets_a.to_vec(),
memory_index: recompute_memory_index(&memory_index_a.to_vec())
};
(outer_fields,
offsets_b.to_vec(),
recompute_memory_index(&memory_index_b.to_vec()))
let (outer_fields, promoted_offsets) = match prefix.fields {
FieldPlacement::Arbitrary { mut offsets, .. } => {
let offsets_b = offsets.split_off(discr_index + 1);
let offsets_a = offsets;

let memory_index = recompute_memory_index(&offsets_a);
let outer_fields = FieldPlacement::Arbitrary { offsets: offsets_a, memory_index };
(outer_fields, offsets_b)
}
_ => bug!(),
};
Expand Down Expand Up @@ -1391,41 +1386,30 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
StructKind::Prefixed(prefix_size, prefix_align.abi))?;
variant.variants = Variants::Single { index };

let (offsets, memory_index) = match variant.fields {
FieldPlacement::Arbitrary { offsets, memory_index } => (offsets, memory_index),
let offsets = match variant.fields {
FieldPlacement::Arbitrary { offsets, .. } => offsets,
_ => bug!(),
};

// Now, stitch the promoted and variant-only fields back together in
// the order they are mentioned by our GeneratorLayout.
let mut next_variant_field = 0;
let mut combined_offsets = Vec::new();
let mut combined_memory_index = Vec::new();
for local in variant_fields.iter() {
match assignments[*local] {
Unassigned => bug!(),
Assigned(_) => {
combined_offsets.push(offsets[next_variant_field]);
// Shift memory indices by the number of promoted
// fields, which all come first. We may not use all
// promoted fields in our variant but that's okay; we'll
// renumber them below.
combined_memory_index.push(
promoted_memory_index.len() as u32 +
memory_index[next_variant_field]);
next_variant_field += 1;
}
Ineligible(field_idx) => {
let field_idx = field_idx.unwrap() as usize;
combined_offsets.push(promoted_offsets[field_idx]);
combined_memory_index.push(promoted_memory_index[field_idx]);
}
}
}
variant.fields = FieldPlacement::Arbitrary {
offsets: combined_offsets,
memory_index: recompute_memory_index(&combined_memory_index),
};
let memory_index = recompute_memory_index(&combined_offsets);
variant.fields = FieldPlacement::Arbitrary { offsets: combined_offsets, memory_index };

size = size.max(variant.size);
align = align.max(variant.align);
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_mir/transform/generator.rs
Expand Up @@ -660,9 +660,10 @@ impl<'body, 'tcx: 'body, 's> StorageConflictVisitor<'body, 'tcx, 's> {
flow_state: &FlowAtLocation<'tcx, MaybeStorageLive<'body, 'tcx>>,
loc: Location) {
// Ignore unreachable blocks.
if self.body.basic_blocks()[loc.block].is_unreachable() {
return;
}
match self.body.basic_blocks()[loc.block].terminator().kind {
TerminatorKind::Unreachable => return,
_ => (),
};

let mut eligible_storage_live = flow_state.as_dense().clone();
eligible_storage_live.intersect(&self.stored_locals);
Expand Down

0 comments on commit aeefbc4

Please sign in to comment.