Skip to content

Commit a09f605

Browse files
committed
Move cached_block out of DropKind
1 parent 7d4d205 commit a09f605

File tree

4 files changed

+35
-50
lines changed

4 files changed

+35
-50
lines changed

src/librustc_mir/build/expr/as_temp.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! See docs in build/expr/mod.rs
22
33
use crate::build::{BlockAnd, BlockAndExtension, Builder};
4-
use crate::build::scope::{CachedBlock, DropKind};
4+
use crate::build::scope::DropKind;
55
use crate::hair::*;
66
use rustc::middle::region;
77
use rustc::mir::*;
@@ -103,9 +103,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
103103
temp_lifetime,
104104
temp_place,
105105
expr_ty,
106-
DropKind::Value {
107-
cached_block: CachedBlock::default(),
108-
},
106+
DropKind::Value,
109107
);
110108
}
111109

src/librustc_mir/build/matches/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! This also includes code for pattern bindings in `let` statements and
66
//! function parameters.
77
8-
use crate::build::scope::{CachedBlock, DropKind};
8+
use crate::build::scope::DropKind;
99
use crate::build::ForGuard::{self, OutsideGuard, RefWithinGuard};
1010
use crate::build::{BlockAnd, BlockAndExtension, Builder};
1111
use crate::build::{GuardFrame, GuardFrameLocal, LocalsForNode};
@@ -544,7 +544,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
544544
let place = Place::Base(PlaceBase::Local(local_id));
545545
let var_ty = self.local_decls[local_id].ty;
546546
let region_scope = self.hir.region_scope_tree.var_scope(var.local_id);
547-
self.schedule_drop(span, region_scope, &place, var_ty, DropKind::Storage { cached_block: CachedBlock::default() });
547+
self.schedule_drop(span, region_scope, &place, var_ty, DropKind::Storage);
548548
place
549549
}
550550

@@ -557,9 +557,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
557557
region_scope,
558558
&Place::Base(PlaceBase::Local(local_id)),
559559
var_ty,
560-
DropKind::Value {
561-
cached_block: CachedBlock::default(),
562-
},
560+
DropKind::Value,
563561
);
564562
}
565563

src/librustc_mir/build/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::build;
2-
use crate::build::scope::{CachedBlock, DropKind};
2+
use crate::build::scope::DropKind;
33
use crate::hair::cx::Cx;
44
use crate::hair::{LintLevel, BindingMode, PatternKind};
55
use crate::shim;
@@ -923,8 +923,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
923923
// Make sure we drop (parts of) the argument even when not matched on.
924924
self.schedule_drop(
925925
pattern.as_ref().map_or(ast_body.span, |pat| pat.span),
926-
argument_scope, &place, ty,
927-
DropKind::Value { cached_block: CachedBlock::default() },
926+
argument_scope, &place, ty, DropKind::Value,
928927
);
929928

930929
if let Some(pattern) = pattern {

src/librustc_mir/build/scope.rs

+28-38
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,13 @@ struct DropData<'tcx> {
143143

144144
/// Whether this is a value Drop or a StorageDead.
145145
kind: DropKind,
146+
147+
/// The cached blocks for unwinds.
148+
cached_block: CachedBlock,
146149
}
147150

148151
#[derive(Debug, Default, Clone, Copy)]
149-
pub(crate) struct CachedBlock {
152+
struct CachedBlock {
150153
/// The cached block for the cleanups-on-diverge path. This block
151154
/// contains code to run the current drop and all the preceding
152155
/// drops (i.e., those having lower index in Drop’s Scope drop
@@ -164,8 +167,8 @@ pub(crate) struct CachedBlock {
164167

165168
#[derive(Debug)]
166169
pub(crate) enum DropKind {
167-
Value { cached_block: CachedBlock },
168-
Storage { cached_block: CachedBlock },
170+
Value,
171+
Storage,
169172
}
170173

171174
#[derive(Clone, Debug)]
@@ -208,8 +211,8 @@ impl CachedBlock {
208211
impl DropKind {
209212
fn may_panic(&self) -> bool {
210213
match *self {
211-
DropKind::Value { .. } => true,
212-
DropKind::Storage { .. } => false
214+
DropKind::Value => true,
215+
DropKind::Storage => false
213216
}
214217
}
215218
}
@@ -240,11 +243,7 @@ impl<'tcx> Scope<'tcx> {
240243

241244
if !ignore_unwinds && !this_scope_only {
242245
for drop_data in &mut self.drops {
243-
let cached_block = match drop_data.kind {
244-
DropKind::Storage { ref mut cached_block } => cached_block,
245-
DropKind::Value { ref mut cached_block } => cached_block,
246-
};
247-
cached_block.invalidate();
246+
drop_data.cached_block.invalidate();
248247
}
249248
}
250249
}
@@ -642,18 +641,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
642641
place: &Place<'tcx>,
643642
place_ty: Ty<'tcx>,
644643
) {
645-
self.schedule_drop(
646-
span, region_scope, place, place_ty,
647-
DropKind::Storage {
648-
cached_block: CachedBlock::default(),
649-
},
650-
);
651-
self.schedule_drop(
652-
span, region_scope, place, place_ty,
653-
DropKind::Value {
654-
cached_block: CachedBlock::default(),
655-
},
656-
);
644+
self.schedule_drop(span, region_scope, place, place_ty, DropKind::Storage);
645+
self.schedule_drop(span, region_scope, place, place_ty, DropKind::Value);
657646
}
658647

659648
// Scheduling drops
@@ -673,8 +662,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
673662
) {
674663
let needs_drop = self.hir.needs_drop(place_ty);
675664
match drop_kind {
676-
DropKind::Value { .. } => if !needs_drop { return },
677-
DropKind::Storage { .. } => {
665+
DropKind::Value => if !needs_drop { return },
666+
DropKind::Storage => {
678667
match *place {
679668
Place::Base(PlaceBase::Local(index)) => if index.index() <= self.arg_count {
680669
span_bug!(
@@ -740,7 +729,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
740729
// cache of outer scpoe stays intact.
741730
scope.invalidate_cache(!needs_drop, self.is_generator, this_scope);
742731
if this_scope {
743-
if let DropKind::Value { .. } = drop_kind {
732+
if let DropKind::Value = drop_kind {
744733
scope.needs_cleanup = true;
745734
}
746735

@@ -752,7 +741,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
752741
scope.drops.push(DropData {
753742
span: scope_end,
754743
location: place.clone(),
755-
kind: drop_kind
744+
kind: drop_kind,
745+
cached_block: CachedBlock::default(),
756746
});
757747
return;
758748
}
@@ -984,7 +974,7 @@ fn build_scope_drops<'tcx>(
984974
let drop_data = &scope.drops[drop_idx];
985975
let source_info = scope.source_info(drop_data.span);
986976
match drop_data.kind {
987-
DropKind::Value { .. } => {
977+
DropKind::Value => {
988978
let unwind_to = get_unwind_to(scope, is_generator, drop_idx, generator_drop)
989979
.unwrap_or(last_unwind_to);
990980

@@ -996,7 +986,7 @@ fn build_scope_drops<'tcx>(
996986
});
997987
block = next;
998988
}
999-
DropKind::Storage { .. } => {
989+
DropKind::Storage => {
1000990
// Drop the storage for both value and storage drops.
1001991
// Only temps and vars need their storage dead.
1002992
match drop_data.location {
@@ -1022,14 +1012,14 @@ fn get_unwind_to<'tcx>(
10221012
) -> Option<BasicBlock> {
10231013
for drop_idx in (0..unwind_from).rev() {
10241014
let drop_data = &scope.drops[drop_idx];
1025-
match drop_data.kind {
1026-
DropKind::Storage { cached_block } if is_generator => {
1027-
return Some(cached_block.get(generator_drop).unwrap_or_else(|| {
1015+
match (is_generator, &drop_data.kind) {
1016+
(true, DropKind::Storage) => {
1017+
return Some(drop_data.cached_block.get(generator_drop).unwrap_or_else(|| {
10281018
span_bug!(drop_data.span, "cached block not present for {:?}", drop_data)
10291019
}));
10301020
}
1031-
DropKind::Value { cached_block } if !is_generator => {
1032-
return Some(cached_block.get(generator_drop).unwrap_or_else(|| {
1021+
(false, DropKind::Value) => {
1022+
return Some(drop_data.cached_block.get(generator_drop).unwrap_or_else(|| {
10331023
span_bug!(drop_data.span, "cached block not present for {:?}", drop_data)
10341024
}));
10351025
}
@@ -1084,7 +1074,7 @@ fn build_diverge_scope<'tcx>(cfg: &mut CFG<'tcx>,
10841074
// match the behavior of clang, but on inspection eddyb says
10851075
// this is not what clang does.
10861076
match drop_data.kind {
1087-
DropKind::Storage { ref mut cached_block } if is_generator => {
1077+
DropKind::Storage if is_generator => {
10881078
// Only temps and vars need their storage dead.
10891079
match drop_data.location {
10901080
Place::Base(PlaceBase::Local(index)) => {
@@ -1105,11 +1095,11 @@ fn build_diverge_scope<'tcx>(cfg: &mut CFG<'tcx>,
11051095
}
11061096
_ => unreachable!(),
11071097
};
1108-
*cached_block.ref_mut(generator_drop) = Some(target);
1098+
*drop_data.cached_block.ref_mut(generator_drop) = Some(target);
11091099
}
1110-
DropKind::Storage { .. } => {}
1111-
DropKind::Value { ref mut cached_block } => {
1112-
let cached_block = cached_block.ref_mut(generator_drop);
1100+
DropKind::Storage => {}
1101+
DropKind::Value => {
1102+
let cached_block = drop_data.cached_block.ref_mut(generator_drop);
11131103
target = if let Some(cached_block) = *cached_block {
11141104
storage_deads.clear();
11151105
target_built_by_us = false;

0 commit comments

Comments
 (0)