Skip to content

Commit e23a86f

Browse files
committed
Revert "Use record_operands_moved more aggresively"
This reverts commit 7f3e855.
1 parent f5a06a4 commit e23a86f

11 files changed

+190
-115
lines changed

compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ use rustc_middle::mir::*;
1212
use rustc_middle::ty::{self, Ty, UpvarSubsts};
1313
use rustc_span::Span;
1414

15-
use std::slice;
16-
1715
impl<'a, 'tcx> Builder<'a, 'tcx> {
1816
/// Returns an rvalue suitable for use until the end of the current
1917
/// scope expression.
@@ -120,9 +118,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
120118
block =
121119
this.into(this.hir.tcx().mk_place_deref(Place::from(result)), block, value)
122120
);
123-
let result_operand = Operand::Move(Place::from(result));
124-
this.record_operands_moved(slice::from_ref(&result_operand));
125-
block.and(Rvalue::Use(result_operand))
121+
block.and(Rvalue::Use(Operand::Move(Place::from(result))))
126122
}
127123
ExprKind::Cast { source } => {
128124
let source = unpack!(block = this.as_operand(block, scope, source));
@@ -166,7 +162,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
166162
.map(|f| unpack!(block = this.as_operand(block, scope, f)))
167163
.collect();
168164

169-
this.record_operands_moved(&fields);
170165
block.and(Rvalue::Aggregate(box AggregateKind::Array(el_ty), fields))
171166
}
172167
ExprKind::Tuple { fields } => {
@@ -177,7 +172,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
177172
.map(|f| unpack!(block = this.as_operand(block, scope, f)))
178173
.collect();
179174

180-
this.record_operands_moved(&fields);
181175
block.and(Rvalue::Aggregate(box AggregateKind::Tuple, fields))
182176
}
183177
ExprKind::Closure { closure_id, substs, upvars, movability } => {
@@ -229,7 +223,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
229223
}
230224
UpvarSubsts::Closure(substs) => box AggregateKind::Closure(closure_id, substs),
231225
};
232-
this.record_operands_moved(&operands);
233226
block.and(Rvalue::Aggregate(result, operands))
234227
}
235228
ExprKind::Assign { .. } | ExprKind::AssignOp { .. } => {

compiler/rustc_mir_build/src/build/expr/into.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ use rustc_hir as hir;
1010
use rustc_middle::mir::*;
1111
use rustc_middle::ty::{CanonicalUserTypeAnnotation};
1212

13-
use std::slice;
14-
1513
impl<'a, 'tcx> Builder<'a, 'tcx> {
1614
/// Compile `expr`, storing the result into `destination`, which
1715
/// is assumed to be uninitialized.
@@ -268,7 +266,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
268266

269267
let field_names = this.hir.all_fields(adt_def, variant_index);
270268

271-
let fields: Vec<_> = if let Some(FruInfo { base, field_types }) = base {
269+
let fields = if let Some(FruInfo { base, field_types }) = base {
272270
let base = unpack!(block = this.as_place(block, base));
273271

274272
// MIR does not natively support FRU, so for each
@@ -303,7 +301,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
303301
user_ty,
304302
active_field_index,
305303
);
306-
this.record_operands_moved(&fields);
307304
this.cfg.push_assign(
308305
block,
309306
source_info,
@@ -430,7 +427,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
430427
let scope = this.local_scope();
431428
let value = unpack!(block = this.as_operand(block, Some(scope), value));
432429
let resume = this.cfg.start_new_block();
433-
this.record_operands_moved(slice::from_ref(&value));
434430
this.cfg.terminate(
435431
block,
436432
source_info,

compiler/rustc_mir_build/src/build/expr/stmt.rs

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder};
33
use crate::thir::*;
44
use rustc_middle::middle::region;
55
use rustc_middle::mir::*;
6-
use std::slice;
76

87
impl<'a, 'tcx> Builder<'a, 'tcx> {
98
/// Builds a block of MIR statements to evaluate the THIR `expr`.
@@ -47,7 +46,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
4746
if this.hir.needs_drop(lhs.ty) {
4847
let rhs = unpack!(block = this.as_local_operand(block, rhs));
4948
let lhs = unpack!(block = this.as_place(block, lhs));
50-
this.record_operands_moved(slice::from_ref(&rhs));
5149
unpack!(block = this.build_drop_and_replace(block, lhs_span, lhs, rhs));
5250
} else {
5351
let rhs = unpack!(block = this.as_local_rvalue(block, rhs));

compiler/rustc_mir_build/src/build/scope.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ impl<'tcx> DropTreeBuilder<'tcx> for Unwind {
13551355
| TerminatorKind::Yield { .. }
13561356
| TerminatorKind::GeneratorDrop
13571357
| TerminatorKind::FalseEdge { .. }
1358-
| TerminatorKind::InlineAsm { .. } => {
1358+
| TerminatorKind::InlineAsm {.. } => {
13591359
span_bug!(term.source_info.span, "cannot unwind from {:?}", term.kind)
13601360
}
13611361
}

src/test/mir-opt/basic_assignment.main.SimplifyCfg-initial.after.mir

+18-10
Original file line numberDiff line numberDiff line change
@@ -41,36 +41,44 @@ fn main() -> () {
4141
StorageLive(_5); // scope 3 at $DIR/basic_assignment.rs:19:9: 19:15
4242
StorageLive(_6); // scope 4 at $DIR/basic_assignment.rs:23:14: 23:20
4343
_6 = move _4; // scope 4 at $DIR/basic_assignment.rs:23:14: 23:20
44-
replace(_5 <- move _6) -> [return: bb1, unwind: bb4]; // scope 4 at $DIR/basic_assignment.rs:23:5: 23:11
44+
replace(_5 <- move _6) -> [return: bb1, unwind: bb5]; // scope 4 at $DIR/basic_assignment.rs:23:5: 23:11
4545
}
4646

4747
bb1: {
48+
drop(_6) -> [return: bb2, unwind: bb6]; // scope 4 at $DIR/basic_assignment.rs:23:19: 23:20
49+
}
50+
51+
bb2: {
4852
StorageDead(_6); // scope 4 at $DIR/basic_assignment.rs:23:19: 23:20
4953
_0 = const (); // scope 0 at $DIR/basic_assignment.rs:10:11: 24:2
50-
drop(_5) -> [return: bb2, unwind: bb5]; // scope 3 at $DIR/basic_assignment.rs:24:1: 24:2
54+
drop(_5) -> [return: bb3, unwind: bb7]; // scope 3 at $DIR/basic_assignment.rs:24:1: 24:2
5155
}
5256

53-
bb2: {
57+
bb3: {
5458
StorageDead(_5); // scope 3 at $DIR/basic_assignment.rs:24:1: 24:2
55-
drop(_4) -> [return: bb3, unwind: bb6]; // scope 2 at $DIR/basic_assignment.rs:24:1: 24:2
59+
drop(_4) -> [return: bb4, unwind: bb8]; // scope 2 at $DIR/basic_assignment.rs:24:1: 24:2
5660
}
5761

58-
bb3: {
62+
bb4: {
5963
StorageDead(_4); // scope 2 at $DIR/basic_assignment.rs:24:1: 24:2
6064
StorageDead(_2); // scope 1 at $DIR/basic_assignment.rs:24:1: 24:2
6165
StorageDead(_1); // scope 0 at $DIR/basic_assignment.rs:24:1: 24:2
6266
return; // scope 0 at $DIR/basic_assignment.rs:24:2: 24:2
6367
}
6468

65-
bb4 (cleanup): {
66-
drop(_5) -> bb5; // scope 3 at $DIR/basic_assignment.rs:24:1: 24:2
67-
}
68-
6969
bb5 (cleanup): {
70-
drop(_4) -> bb6; // scope 2 at $DIR/basic_assignment.rs:24:1: 24:2
70+
drop(_6) -> bb6; // scope 4 at $DIR/basic_assignment.rs:23:19: 23:20
7171
}
7272

7373
bb6 (cleanup): {
74+
drop(_5) -> bb7; // scope 3 at $DIR/basic_assignment.rs:24:1: 24:2
75+
}
76+
77+
bb7 (cleanup): {
78+
drop(_4) -> bb8; // scope 2 at $DIR/basic_assignment.rs:24:1: 24:2
79+
}
80+
81+
bb8 (cleanup): {
7482
resume; // scope 0 at $DIR/basic_assignment.rs:10:1: 24:2
7583
}
7684
}

src/test/mir-opt/box_expr.main.ElaborateDrops.before.mir

+14-10
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,49 @@ fn main() -> () {
1414
StorageLive(_1); // scope 0 at $DIR/box_expr.rs:7:9: 7:10
1515
StorageLive(_2); // scope 0 at $DIR/box_expr.rs:7:13: 7:25
1616
_2 = Box(S); // scope 0 at $DIR/box_expr.rs:7:13: 7:25
17-
(*_2) = S::new() -> [return: bb1, unwind: bb5]; // scope 0 at $DIR/box_expr.rs:7:17: 7:25
17+
(*_2) = S::new() -> [return: bb1, unwind: bb6]; // scope 0 at $DIR/box_expr.rs:7:17: 7:25
1818
// mir::Constant
1919
// + span: $DIR/box_expr.rs:7:17: 7:23
2020
// + literal: Const { ty: fn() -> S {S::new}, val: Value(Scalar(<ZST>)) }
2121
}
2222

2323
bb1: {
2424
_1 = move _2; // scope 0 at $DIR/box_expr.rs:7:13: 7:25
25+
drop(_2) -> bb2; // scope 0 at $DIR/box_expr.rs:7:24: 7:25
26+
}
27+
28+
bb2: {
2529
StorageDead(_2); // scope 0 at $DIR/box_expr.rs:7:24: 7:25
2630
StorageLive(_3); // scope 1 at $DIR/box_expr.rs:8:5: 8:12
2731
StorageLive(_4); // scope 1 at $DIR/box_expr.rs:8:10: 8:11
2832
_4 = move _1; // scope 1 at $DIR/box_expr.rs:8:10: 8:11
29-
_3 = std::mem::drop::<Box<S>>(move _4) -> [return: bb2, unwind: bb4]; // scope 1 at $DIR/box_expr.rs:8:5: 8:12
33+
_3 = std::mem::drop::<Box<S>>(move _4) -> [return: bb3, unwind: bb5]; // scope 1 at $DIR/box_expr.rs:8:5: 8:12
3034
// mir::Constant
3135
// + span: $DIR/box_expr.rs:8:5: 8:9
3236
// + literal: Const { ty: fn(std::boxed::Box<S>) {std::mem::drop::<std::boxed::Box<S>>}, val: Value(Scalar(<ZST>)) }
3337
}
3438

35-
bb2: {
39+
bb3: {
3640
StorageDead(_4); // scope 1 at $DIR/box_expr.rs:8:11: 8:12
3741
StorageDead(_3); // scope 1 at $DIR/box_expr.rs:8:12: 8:13
3842
_0 = const (); // scope 0 at $DIR/box_expr.rs:6:11: 9:2
39-
drop(_1) -> bb3; // scope 0 at $DIR/box_expr.rs:9:1: 9:2
43+
drop(_1) -> bb4; // scope 0 at $DIR/box_expr.rs:9:1: 9:2
4044
}
4145

42-
bb3: {
46+
bb4: {
4347
StorageDead(_1); // scope 0 at $DIR/box_expr.rs:9:1: 9:2
4448
return; // scope 0 at $DIR/box_expr.rs:9:2: 9:2
4549
}
4650

47-
bb4 (cleanup): {
48-
drop(_1) -> bb6; // scope 0 at $DIR/box_expr.rs:9:1: 9:2
49-
}
50-
5151
bb5 (cleanup): {
52-
drop(_2) -> bb6; // scope 0 at $DIR/box_expr.rs:7:24: 7:25
52+
drop(_1) -> bb7; // scope 0 at $DIR/box_expr.rs:9:1: 9:2
5353
}
5454

5555
bb6 (cleanup): {
56+
drop(_2) -> bb7; // scope 0 at $DIR/box_expr.rs:7:24: 7:25
57+
}
58+
59+
bb7 (cleanup): {
5660
resume; // scope 0 at $DIR/box_expr.rs:6:1: 9:2
5761
}
5862
}

src/test/mir-opt/issue_41110.test.ElaborateDrops.after.mir

+26-18
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn test() -> () {
2525
StorageLive(_3); // scope 2 at $DIR/issue-41110.rs:17:5: 17:12
2626
StorageLive(_4); // scope 2 at $DIR/issue-41110.rs:17:10: 17:11
2727
_4 = move _2; // scope 2 at $DIR/issue-41110.rs:17:10: 17:11
28-
_3 = std::mem::drop::<S>(move _4) -> [return: bb1, unwind: bb5]; // scope 2 at $DIR/issue-41110.rs:17:5: 17:12
28+
_3 = std::mem::drop::<S>(move _4) -> [return: bb1, unwind: bb7]; // scope 2 at $DIR/issue-41110.rs:17:5: 17:12
2929
// mir::Constant
3030
// + span: $DIR/issue-41110.rs:17:5: 17:9
3131
// + literal: Const { ty: fn(S) {std::mem::drop::<S>}, val: Value(Scalar(<ZST>)) }
@@ -37,53 +37,61 @@ fn test() -> () {
3737
StorageLive(_5); // scope 2 at $DIR/issue-41110.rs:18:9: 18:10
3838
_6 = const false; // scope 2 at $DIR/issue-41110.rs:18:9: 18:10
3939
_5 = move _1; // scope 2 at $DIR/issue-41110.rs:18:9: 18:10
40-
goto -> bb9; // scope 2 at $DIR/issue-41110.rs:18:5: 18:6
40+
goto -> bb11; // scope 2 at $DIR/issue-41110.rs:18:5: 18:6
4141
}
4242

4343
bb2: {
44+
goto -> bb3; // scope 2 at $DIR/issue-41110.rs:18:9: 18:10
45+
}
46+
47+
bb3: {
4448
StorageDead(_5); // scope 2 at $DIR/issue-41110.rs:18:9: 18:10
4549
_0 = const (); // scope 0 at $DIR/issue-41110.rs:14:15: 19:2
46-
drop(_2) -> [return: bb3, unwind: bb6]; // scope 1 at $DIR/issue-41110.rs:19:1: 19:2
50+
drop(_2) -> [return: bb4, unwind: bb8]; // scope 1 at $DIR/issue-41110.rs:19:1: 19:2
4751
}
4852

49-
bb3: {
53+
bb4: {
5054
StorageDead(_2); // scope 1 at $DIR/issue-41110.rs:19:1: 19:2
51-
goto -> bb4; // scope 0 at $DIR/issue-41110.rs:19:1: 19:2
55+
goto -> bb5; // scope 0 at $DIR/issue-41110.rs:19:1: 19:2
5256
}
5357

54-
bb4: {
58+
bb5: {
5559
_6 = const false; // scope 0 at $DIR/issue-41110.rs:19:1: 19:2
5660
StorageDead(_1); // scope 0 at $DIR/issue-41110.rs:19:1: 19:2
5761
return; // scope 0 at $DIR/issue-41110.rs:19:2: 19:2
5862
}
5963

60-
bb5 (cleanup): {
61-
goto -> bb6; // scope 1 at $DIR/issue-41110.rs:19:1: 19:2
62-
}
63-
6464
bb6 (cleanup): {
65-
goto -> bb11; // scope 0 at $DIR/issue-41110.rs:19:1: 19:2
65+
goto -> bb7; // scope 2 at $DIR/issue-41110.rs:18:9: 18:10
6666
}
6767

6868
bb7 (cleanup): {
69-
resume; // scope 0 at $DIR/issue-41110.rs:14:1: 19:2
69+
goto -> bb8; // scope 1 at $DIR/issue-41110.rs:19:1: 19:2
7070
}
7171

7272
bb8 (cleanup): {
73+
goto -> bb13; // scope 0 at $DIR/issue-41110.rs:19:1: 19:2
74+
}
75+
76+
bb9 (cleanup): {
77+
resume; // scope 0 at $DIR/issue-41110.rs:14:1: 19:2
78+
}
79+
80+
bb10 (cleanup): {
7381
_2 = move _5; // scope 2 at $DIR/issue-41110.rs:18:5: 18:6
74-
goto -> bb5; // scope 2 at $DIR/issue-41110.rs:18:5: 18:6
82+
goto -> bb6; // scope 2 at $DIR/issue-41110.rs:18:5: 18:6
7583
}
7684

77-
bb9: {
85+
bb11: {
7886
_2 = move _5; // scope 2 at $DIR/issue-41110.rs:18:5: 18:6
7987
goto -> bb2; // scope 2 at $DIR/issue-41110.rs:18:5: 18:6
8088
}
8189

82-
bb10 (cleanup): {
83-
drop(_1) -> bb7; // scope 0 at $DIR/issue-41110.rs:19:1: 19:2
90+
bb12 (cleanup): {
91+
drop(_1) -> bb9; // scope 0 at $DIR/issue-41110.rs:19:1: 19:2
8492
}
8593

86-
bb11 (cleanup): {
87-
switchInt(_6) -> [false: bb7, otherwise: bb10]; // scope 0 at $DIR/issue-41110.rs:19:1: 19:2
94+
bb13 (cleanup): {
95+
switchInt(_6) -> [false: bb9, otherwise: bb12]; // scope 0 at $DIR/issue-41110.rs:19:1: 19:2
8896
}
8997
}

0 commit comments

Comments
 (0)