Skip to content

Commit 4f84ad2

Browse files
authored
Rollup merge of rust-lang#70891 - lcnr:replace-rvalue_aggregate, r=eddyb
unit rvalue, use constant `()` instead of tuple fixes rust-lang#70886 r? @eddyb
2 parents 02e1a74 + 647f810 commit 4f84ad2

File tree

90 files changed

+869
-198
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+869
-198
lines changed

src/librustc_mir/transform/promote_consts.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,11 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
835835
if self.keep_original {
836836
rhs.clone()
837837
} else {
838-
let unit = Rvalue::Aggregate(box AggregateKind::Tuple, vec![]);
838+
let unit = Rvalue::Use(Operand::Constant(box Constant {
839+
span: statement.source_info.span,
840+
user_ty: None,
841+
literal: ty::Const::zero_sized(self.tcx, self.tcx.types.unit),
842+
}));
839843
mem::replace(rhs, unit)
840844
},
841845
statement.source_info,

src/librustc_mir_build/build/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
187187
if destination_ty.is_unit() {
188188
// We only want to assign an implicit `()` as the return value of the block if the
189189
// block does not diverge. (Otherwise, we may try to assign a unit to a `!`-type.)
190-
this.cfg.push_assign_unit(block, source_info, destination);
190+
this.cfg.push_assign_unit(block, source_info, destination, this.hir.tcx());
191191
}
192192
}
193193
// Finally, we pop all the let scopes before exiting out from the scope of block

src/librustc_mir_build/build/cfg.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use crate::build::CFG;
44
use rustc_middle::mir::*;
5+
use rustc_middle::ty::{self, TyCtxt};
56

67
impl<'tcx> CFG<'tcx> {
78
crate fn block_data(&self, blk: BasicBlock) -> &BasicBlockData<'tcx> {
@@ -58,12 +59,17 @@ impl<'tcx> CFG<'tcx> {
5859
block: BasicBlock,
5960
source_info: SourceInfo,
6061
place: Place<'tcx>,
62+
tcx: TyCtxt<'tcx>,
6163
) {
6264
self.push_assign(
6365
block,
6466
source_info,
6567
place,
66-
Rvalue::Aggregate(box AggregateKind::Tuple, vec![]),
68+
Rvalue::Use(Operand::Constant(box Constant {
69+
span: source_info.span,
70+
user_ty: None,
71+
literal: ty::Const::zero_sized(tcx, tcx.types.unit),
72+
})),
6773
);
6874
}
6975

src/librustc_mir_build/build/expr/as_rvalue.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
225225
}
226226
ExprKind::Assign { .. } | ExprKind::AssignOp { .. } => {
227227
block = unpack!(this.stmt_expr(block, expr, None));
228-
block.and(this.unit_rvalue())
228+
block.and(Rvalue::Use(Operand::Constant(box Constant {
229+
span: expr_span,
230+
user_ty: None,
231+
literal: ty::Const::zero_sized(this.hir.tcx(), this.hir.tcx().types.unit),
232+
})))
229233
}
230234
ExprKind::Yield { .. }
231235
| ExprKind::Literal { .. }

src/librustc_mir_build/build/expr/into.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
331331
| ExprKind::LlvmInlineAsm { .. }
332332
| ExprKind::Return { .. } => {
333333
unpack!(block = this.stmt_expr(block, expr, None));
334-
this.cfg.push_assign_unit(block, source_info, destination);
334+
this.cfg.push_assign_unit(block, source_info, destination, this.hir.tcx());
335335
block.unit()
336336
}
337337

src/librustc_mir_build/build/misc.rs

-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
3232
Operand::Constant(constant)
3333
}
3434

35-
crate fn unit_rvalue(&mut self) -> Rvalue<'tcx> {
36-
Rvalue::Aggregate(box AggregateKind::Tuple, vec![])
37-
}
38-
3935
// Returns a zero literal operand for the appropriate type, works for
4036
// bool, char and integers.
4137
crate fn zero_literal(&mut self, span: Span, ty: Ty<'tcx>) -> Operand<'tcx> {

src/librustc_mir_build/build/scope.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
523523
unpack!(block = self.into(destination, block, value));
524524
self.block_context.pop();
525525
} else {
526-
self.cfg.push_assign_unit(block, source_info, destination)
526+
self.cfg.push_assign_unit(block, source_info, destination, self.hir.tcx())
527527
}
528528
} else {
529529
assert!(value.is_none(), "`return` and `break` should have a destination");

src/test/mir-opt/address-of/rustc.address_of_reborrow.SimplifyCfg-initial.after.mir

+7-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,13 @@ fn address_of_reborrow() -> () {
298298
StorageDead(_48); // bb0[157]: scope 13 at $DIR/address-of.rs:36:25: 36:26
299299
FakeRead(ForLet, _47); // bb0[158]: scope 13 at $DIR/address-of.rs:36:9: 36:10
300300
AscribeUserType(_47, o, UserTypeProjection { base: UserType(29), projs: [] }); // bb0[159]: scope 13 at $DIR/address-of.rs:36:12: 36:22
301-
_0 = (); // bb0[160]: scope 0 at $DIR/address-of.rs:3:26: 37:2
301+
_0 = const (); // bb0[160]: scope 0 at $DIR/address-of.rs:3:26: 37:2
302+
// ty::Const
303+
// + ty: ()
304+
// + val: Value(Scalar(<ZST>))
305+
// mir::Constant
306+
// + span: $DIR/address-of.rs:3:26: 37:2
307+
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
302308
StorageDead(_47); // bb0[161]: scope 13 at $DIR/address-of.rs:37:1: 37:2
303309
StorageDead(_45); // bb0[162]: scope 12 at $DIR/address-of.rs:37:1: 37:2
304310
StorageDead(_44); // bb0[163]: scope 11 at $DIR/address-of.rs:37:1: 37:2

src/test/mir-opt/address-of/rustc.borrow_and_cast.SimplifyCfg-initial.after.mir

+7-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ fn borrow_and_cast(_1: i32) -> () {
3838
_6 = &raw mut (*_7); // bb0[15]: scope 2 at $DIR/address-of.rs:44:13: 44:19
3939
FakeRead(ForLet, _6); // bb0[16]: scope 2 at $DIR/address-of.rs:44:9: 44:10
4040
StorageDead(_7); // bb0[17]: scope 2 at $DIR/address-of.rs:44:31: 44:32
41-
_0 = (); // bb0[18]: scope 0 at $DIR/address-of.rs:41:32: 45:2
41+
_0 = const (); // bb0[18]: scope 0 at $DIR/address-of.rs:41:32: 45:2
42+
// ty::Const
43+
// + ty: ()
44+
// + val: Value(Scalar(<ZST>))
45+
// mir::Constant
46+
// + span: $DIR/address-of.rs:41:32: 45:2
47+
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
4248
StorageDead(_6); // bb0[19]: scope 2 at $DIR/address-of.rs:45:1: 45:2
4349
StorageDead(_4); // bb0[20]: scope 1 at $DIR/address-of.rs:45:1: 45:2
4450
StorageDead(_2); // bb0[21]: scope 0 at $DIR/address-of.rs:45:1: 45:2

src/test/mir-opt/array-index-is-temporary/32bit/rustc.main.SimplifyCfg-elaborate-drops.after.mir

+7-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,13 @@ fn main() -> () {
8282
_1[_7] = move _5; // bb2[0]: scope 3 at $DIR/array-index-is-temporary.rs:16:5: 16:29
8383
StorageDead(_5); // bb2[1]: scope 3 at $DIR/array-index-is-temporary.rs:16:28: 16:29
8484
StorageDead(_7); // bb2[2]: scope 3 at $DIR/array-index-is-temporary.rs:16:29: 16:30
85-
_0 = (); // bb2[3]: scope 0 at $DIR/array-index-is-temporary.rs:12:11: 17:2
85+
_0 = const (); // bb2[3]: scope 0 at $DIR/array-index-is-temporary.rs:12:11: 17:2
86+
// ty::Const
87+
// + ty: ()
88+
// + val: Value(Scalar(<ZST>))
89+
// mir::Constant
90+
// + span: $DIR/array-index-is-temporary.rs:12:11: 17:2
91+
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
8692
StorageDead(_3); // bb2[4]: scope 2 at $DIR/array-index-is-temporary.rs:17:1: 17:2
8793
StorageDead(_2); // bb2[5]: scope 1 at $DIR/array-index-is-temporary.rs:17:1: 17:2
8894
StorageDead(_1); // bb2[6]: scope 0 at $DIR/array-index-is-temporary.rs:17:1: 17:2

src/test/mir-opt/array-index-is-temporary/64bit/rustc.main.SimplifyCfg-elaborate-drops.after.mir

+7-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,13 @@ fn main() -> () {
8282
_1[_7] = move _5; // bb2[0]: scope 3 at $DIR/array-index-is-temporary.rs:16:5: 16:29
8383
StorageDead(_5); // bb2[1]: scope 3 at $DIR/array-index-is-temporary.rs:16:28: 16:29
8484
StorageDead(_7); // bb2[2]: scope 3 at $DIR/array-index-is-temporary.rs:16:29: 16:30
85-
_0 = (); // bb2[3]: scope 0 at $DIR/array-index-is-temporary.rs:12:11: 17:2
85+
_0 = const (); // bb2[3]: scope 0 at $DIR/array-index-is-temporary.rs:12:11: 17:2
86+
// ty::Const
87+
// + ty: ()
88+
// + val: Value(Scalar(<ZST>))
89+
// mir::Constant
90+
// + span: $DIR/array-index-is-temporary.rs:12:11: 17:2
91+
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
8692
StorageDead(_3); // bb2[4]: scope 2 at $DIR/array-index-is-temporary.rs:17:1: 17:2
8793
StorageDead(_2); // bb2[5]: scope 1 at $DIR/array-index-is-temporary.rs:17:1: 17:2
8894
StorageDead(_1); // bb2[6]: scope 0 at $DIR/array-index-is-temporary.rs:17:1: 17:2

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ fn main() -> () {
7272

7373
bb6: {
7474
StorageDead(_6); // bb6[0]: scope 4 at $DIR/basic_assignment.rs:23:19: 23:20
75-
_0 = (); // bb6[1]: scope 0 at $DIR/basic_assignment.rs:10:11: 24:2
75+
_0 = const (); // bb6[1]: scope 0 at $DIR/basic_assignment.rs:10:11: 24:2
76+
// ty::Const
77+
// + ty: ()
78+
// + val: Value(Scalar(<ZST>))
79+
// mir::Constant
80+
// + span: $DIR/basic_assignment.rs:10:11: 24:2
81+
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
7682
drop(_5) -> [return: bb7, unwind: bb3]; // bb6[2]: scope 3 at $DIR/basic_assignment.rs:24:1: 24:2
7783
}
7884

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ fn main() -> () {
5353
bb5: {
5454
StorageDead(_4); // bb5[0]: scope 1 at $DIR/box_expr.rs:8:11: 8:12
5555
StorageDead(_3); // bb5[1]: scope 1 at $DIR/box_expr.rs:8:12: 8:13
56-
_0 = (); // bb5[2]: scope 0 at $DIR/box_expr.rs:6:11: 9:2
56+
_0 = const (); // bb5[2]: scope 0 at $DIR/box_expr.rs:6:11: 9:2
57+
// ty::Const
58+
// + ty: ()
59+
// + val: Value(Scalar(<ZST>))
60+
// mir::Constant
61+
// + span: $DIR/box_expr.rs:6:11: 9:2
62+
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
5763
drop(_1) -> bb8; // bb5[3]: scope 0 at $DIR/box_expr.rs:9:1: 9:2
5864
}
5965

src/test/mir-opt/byte_slice/rustc.main.SimplifyCfg-elaborate-drops.after.mir

+7-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ fn main() -> () {
3434
// mir::Constant
3535
// + span: $DIR/byte_slice.rs:6:19: 6:23
3636
// + literal: Const { ty: u8, val: Value(Scalar(0x78)) }
37-
_0 = (); // bb0[4]: scope 0 at $DIR/byte_slice.rs:4:11: 7:2
37+
_0 = const (); // bb0[4]: scope 0 at $DIR/byte_slice.rs:4:11: 7:2
38+
// ty::Const
39+
// + ty: ()
40+
// + val: Value(Scalar(<ZST>))
41+
// mir::Constant
42+
// + span: $DIR/byte_slice.rs:4:11: 7:2
43+
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
3844
StorageDead(_2); // bb0[5]: scope 1 at $DIR/byte_slice.rs:7:1: 7:2
3945
StorageDead(_1); // bb0[6]: scope 0 at $DIR/byte_slice.rs:7:1: 7:2
4046
return; // bb0[7]: scope 0 at $DIR/byte_slice.rs:7:2: 7:2

src/test/mir-opt/const_allocation/32bit/rustc.main.ConstProp.after.mir

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ fn main() -> () {
1818
_1 = (*_2); // bb0[3]: scope 0 at $DIR/const_allocation.rs:8:5: 8:8
1919
StorageDead(_2); // bb0[4]: scope 0 at $DIR/const_allocation.rs:8:8: 8:9
2020
StorageDead(_1); // bb0[5]: scope 0 at $DIR/const_allocation.rs:8:8: 8:9
21-
_0 = (); // bb0[6]: scope 0 at $DIR/const_allocation.rs:7:11: 9:2
21+
_0 = const (); // bb0[6]: scope 0 at $DIR/const_allocation.rs:7:11: 9:2
22+
// ty::Const
23+
// + ty: ()
24+
// + val: Value(Scalar(<ZST>))
25+
// mir::Constant
26+
// + span: $DIR/const_allocation.rs:7:11: 9:2
27+
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
2228
return; // bb0[7]: scope 0 at $DIR/const_allocation.rs:9:2: 9:2
2329
}
2430
}

src/test/mir-opt/const_allocation/64bit/rustc.main.ConstProp.after.mir

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ fn main() -> () {
1818
_1 = (*_2); // bb0[3]: scope 0 at $DIR/const_allocation.rs:8:5: 8:8
1919
StorageDead(_2); // bb0[4]: scope 0 at $DIR/const_allocation.rs:8:8: 8:9
2020
StorageDead(_1); // bb0[5]: scope 0 at $DIR/const_allocation.rs:8:8: 8:9
21-
_0 = (); // bb0[6]: scope 0 at $DIR/const_allocation.rs:7:11: 9:2
21+
_0 = const (); // bb0[6]: scope 0 at $DIR/const_allocation.rs:7:11: 9:2
22+
// ty::Const
23+
// + ty: ()
24+
// + val: Value(Scalar(<ZST>))
25+
// mir::Constant
26+
// + span: $DIR/const_allocation.rs:7:11: 9:2
27+
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
2228
return; // bb0[7]: scope 0 at $DIR/const_allocation.rs:9:2: 9:2
2329
}
2430
}

src/test/mir-opt/const_allocation2/32bit/rustc.main.ConstProp.after.mir

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ fn main() -> () {
1818
_1 = (*_2); // bb0[3]: scope 0 at $DIR/const_allocation2.rs:5:5: 5:8
1919
StorageDead(_2); // bb0[4]: scope 0 at $DIR/const_allocation2.rs:5:8: 5:9
2020
StorageDead(_1); // bb0[5]: scope 0 at $DIR/const_allocation2.rs:5:8: 5:9
21-
_0 = (); // bb0[6]: scope 0 at $DIR/const_allocation2.rs:4:11: 6:2
21+
_0 = const (); // bb0[6]: scope 0 at $DIR/const_allocation2.rs:4:11: 6:2
22+
// ty::Const
23+
// + ty: ()
24+
// + val: Value(Scalar(<ZST>))
25+
// mir::Constant
26+
// + span: $DIR/const_allocation2.rs:4:11: 6:2
27+
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
2228
return; // bb0[7]: scope 0 at $DIR/const_allocation2.rs:6:2: 6:2
2329
}
2430
}

src/test/mir-opt/const_allocation2/64bit/rustc.main.ConstProp.after.mir

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ fn main() -> () {
1818
_1 = (*_2); // bb0[3]: scope 0 at $DIR/const_allocation2.rs:5:5: 5:8
1919
StorageDead(_2); // bb0[4]: scope 0 at $DIR/const_allocation2.rs:5:8: 5:9
2020
StorageDead(_1); // bb0[5]: scope 0 at $DIR/const_allocation2.rs:5:8: 5:9
21-
_0 = (); // bb0[6]: scope 0 at $DIR/const_allocation2.rs:4:11: 6:2
21+
_0 = const (); // bb0[6]: scope 0 at $DIR/const_allocation2.rs:4:11: 6:2
22+
// ty::Const
23+
// + ty: ()
24+
// + val: Value(Scalar(<ZST>))
25+
// mir::Constant
26+
// + span: $DIR/const_allocation2.rs:4:11: 6:2
27+
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
2228
return; // bb0[7]: scope 0 at $DIR/const_allocation2.rs:6:2: 6:2
2329
}
2430
}

src/test/mir-opt/const_allocation3/32bit/rustc.main.ConstProp.after.mir

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ fn main() -> () {
1818
_1 = (*_2); // bb0[3]: scope 0 at $DIR/const_allocation3.rs:5:5: 5:8
1919
StorageDead(_2); // bb0[4]: scope 0 at $DIR/const_allocation3.rs:5:8: 5:9
2020
StorageDead(_1); // bb0[5]: scope 0 at $DIR/const_allocation3.rs:5:8: 5:9
21-
_0 = (); // bb0[6]: scope 0 at $DIR/const_allocation3.rs:4:11: 6:2
21+
_0 = const (); // bb0[6]: scope 0 at $DIR/const_allocation3.rs:4:11: 6:2
22+
// ty::Const
23+
// + ty: ()
24+
// + val: Value(Scalar(<ZST>))
25+
// mir::Constant
26+
// + span: $DIR/const_allocation3.rs:4:11: 6:2
27+
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
2228
return; // bb0[7]: scope 0 at $DIR/const_allocation3.rs:6:2: 6:2
2329
}
2430
}

src/test/mir-opt/const_allocation3/64bit/rustc.main.ConstProp.after.mir

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ fn main() -> () {
1818
_1 = (*_2); // bb0[3]: scope 0 at $DIR/const_allocation3.rs:5:5: 5:8
1919
StorageDead(_2); // bb0[4]: scope 0 at $DIR/const_allocation3.rs:5:8: 5:9
2020
StorageDead(_1); // bb0[5]: scope 0 at $DIR/const_allocation3.rs:5:8: 5:9
21-
_0 = (); // bb0[6]: scope 0 at $DIR/const_allocation3.rs:4:11: 6:2
21+
_0 = const (); // bb0[6]: scope 0 at $DIR/const_allocation3.rs:4:11: 6:2
22+
// ty::Const
23+
// + ty: ()
24+
// + val: Value(Scalar(<ZST>))
25+
// mir::Constant
26+
// + span: $DIR/const_allocation3.rs:4:11: 6:2
27+
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
2228
return; // bb0[7]: scope 0 at $DIR/const_allocation3.rs:6:2: 6:2
2329
}
2430
}

src/test/mir-opt/const_prop/aggregate/rustc.main.ConstProp.diff

+7-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@
5454
+ // + literal: Const { ty: i32, val: Value(Scalar(0x00000001)) }
5555
StorageDead(_2); // bb0[6]: scope 0 at $DIR/aggregate.rs:5:27: 5:28
5656
StorageDead(_3); // bb0[7]: scope 0 at $DIR/aggregate.rs:5:28: 5:29
57-
_0 = (); // bb0[8]: scope 0 at $DIR/aggregate.rs:4:11: 6:2
57+
_0 = const (); // bb0[8]: scope 0 at $DIR/aggregate.rs:4:11: 6:2
58+
// ty::Const
59+
// + ty: ()
60+
// + val: Value(Scalar(<ZST>))
61+
// mir::Constant
62+
// + span: $DIR/aggregate.rs:4:11: 6:2
63+
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
5864
StorageDead(_1); // bb0[9]: scope 0 at $DIR/aggregate.rs:6:1: 6:2
5965
return; // bb0[10]: scope 0 at $DIR/aggregate.rs:6:2: 6:2
6066
}

0 commit comments

Comments
 (0)