Skip to content

Commit 7721c73

Browse files
authored
Rollup merge of #110962 - cjgillot:no-hash-drops, r=compiler-errors
Make drop_flags an IndexVec. Fixes #91943
2 parents 339786e + 7f26191 commit 7721c73

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

compiler/rustc_mir_transform/src/elaborate_drops.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::deref_separator::deref_finder;
22
use crate::MirPass;
3-
use rustc_data_structures::fx::FxHashMap;
43
use rustc_index::bit_set::BitSet;
4+
use rustc_index::IndexVec;
55
use rustc_middle::mir::patch::MirPatch;
66
use rustc_middle::mir::*;
77
use rustc_middle::ty::{self, TyCtxt};
@@ -84,12 +84,13 @@ impl<'tcx> MirPass<'tcx> for ElaborateDrops {
8484

8585
let reachable = traversal::reachable_as_bitset(body);
8686

87+
let drop_flags = IndexVec::from_elem(None, &env.move_data.move_paths);
8788
ElaborateDropsCtxt {
8889
tcx,
8990
body,
9091
env: &env,
9192
init_data: InitializationData { inits, uninits },
92-
drop_flags: Default::default(),
93+
drop_flags,
9394
patch: MirPatch::new(body),
9495
un_derefer: un_derefer,
9596
reachable,
@@ -293,7 +294,7 @@ struct ElaborateDropsCtxt<'a, 'tcx> {
293294
body: &'a Body<'tcx>,
294295
env: &'a MoveDataParamEnv<'tcx>,
295296
init_data: InitializationData<'a, 'tcx>,
296-
drop_flags: FxHashMap<MovePathIndex, Local>,
297+
drop_flags: IndexVec<MovePathIndex, Option<Local>>,
297298
patch: MirPatch<'tcx>,
298299
un_derefer: UnDerefer<'tcx>,
299300
reachable: BitSet<BasicBlock>,
@@ -312,11 +313,11 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
312313
let tcx = self.tcx;
313314
let patch = &mut self.patch;
314315
debug!("create_drop_flag({:?})", self.body.span);
315-
self.drop_flags.entry(index).or_insert_with(|| patch.new_internal(tcx.types.bool, span));
316+
self.drop_flags[index].get_or_insert_with(|| patch.new_internal(tcx.types.bool, span));
316317
}
317318

318319
fn drop_flag(&mut self, index: MovePathIndex) -> Option<Place<'tcx>> {
319-
self.drop_flags.get(&index).map(|t| Place::from(*t))
320+
self.drop_flags[index].map(Place::from)
320321
}
321322

322323
/// create a patch that elaborates all drops in the input
@@ -463,7 +464,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
463464
}
464465

465466
fn set_drop_flag(&mut self, loc: Location, path: MovePathIndex, val: DropFlagState) {
466-
if let Some(&flag) = self.drop_flags.get(&path) {
467+
if let Some(flag) = self.drop_flags[path] {
467468
let span = self.patch.source_info_for_location(self.body, loc).span;
468469
let val = self.constant_bool(span, val.value());
469470
self.patch.add_assign(loc, Place::from(flag), val);
@@ -474,7 +475,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
474475
let loc = Location::START;
475476
let span = self.patch.source_info_for_location(self.body, loc).span;
476477
let false_ = self.constant_bool(span, false);
477-
for flag in self.drop_flags.values() {
478+
for flag in self.drop_flags.iter().flatten() {
478479
self.patch.add_assign(loc, Place::from(*flag), false_.clone());
479480
}
480481
}

tests/mir-opt/issue_41888.main.ElaborateDrops.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
}
2323

2424
bb0: {
25-
+ _9 = const false; // scope 0 at $DIR/issue_41888.rs:+1:9: +1:10
2625
+ _7 = const false; // scope 0 at $DIR/issue_41888.rs:+1:9: +1:10
2726
+ _8 = const false; // scope 0 at $DIR/issue_41888.rs:+1:9: +1:10
27+
+ _9 = const false; // scope 0 at $DIR/issue_41888.rs:+1:9: +1:10
2828
StorageLive(_1); // scope 0 at $DIR/issue_41888.rs:+1:9: +1:10
2929
StorageLive(_2); // scope 1 at $DIR/issue_41888.rs:+2:8: +2:14
3030
_2 = cond() -> [return: bb1, unwind: bb11]; // scope 1 at $DIR/issue_41888.rs:+2:8: +2:14

0 commit comments

Comments
 (0)