Skip to content

Commit 41066e2

Browse files
committed
mir opt tests + comment
1 parent dc56653 commit 41066e2

8 files changed

+90
-491
lines changed

compiler/rustc_middle/src/mir/interpret/queries.rs

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ impl<'tcx> TyCtxt<'tcx> {
2020
let substs = InternalSubsts::identity_for_item(self, def_id);
2121
let instance = ty::Instance::new(def_id, substs);
2222
let cid = GlobalId { instance, promoted: None };
23+
// This function isn't used in the type system, so we're free to use
24+
// `param_env_reveal_all_normalized` here.
2325
let param_env = self.param_env_reveal_all_normalized(def_id);
2426
self.const_eval_global_id(param_env, cid, None)
2527
}
@@ -184,6 +186,8 @@ impl<'tcx> TyCtxtEnsure<'tcx> {
184186
let substs = InternalSubsts::identity_for_item(self.tcx, def_id);
185187
let instance = ty::Instance::new(def_id, substs);
186188
let cid = GlobalId { instance, promoted: None };
189+
// This function isn't used in the type system, so we're free to use
190+
// `param_env_reveal_all_normalized` here.
187191
let param_env = self.tcx.param_env_reveal_all_normalized(def_id).with_const();
188192
// Const-eval shouldn't depend on lifetimes at all, so we can erase them, which should
189193
// improve caching of queries.

src/test/mir-opt/inline/inline_generator.main.Inline.diff

+40-16
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
+ Deinit(_4); // scope 2 at $DIR/inline-generator.rs:15:5: 15:41
5151
+ discriminant(_4) = 0; // scope 2 at $DIR/inline-generator.rs:15:5: 15:41
5252
_3 = &mut _4; // scope 0 at $DIR/inline-generator.rs:+1:23: +1:31
53-
- _2 = Pin::<&mut [generator@$DIR/inline-generator.rs:15:5: 15:8]>::new(move _3) -> [return: bb2, unwind: bb4]; // scope 0 at $DIR/inline-generator.rs:+1:14: +1:32
53+
- _2 = Pin::<&mut [generator@$DIR/inline-generator.rs:15:5: 15:8]>::new(move _3) -> [return: bb2, unwind: bb7]; // scope 0 at $DIR/inline-generator.rs:+1:14: +1:32
5454
- // mir::Constant
5555
- // + span: $DIR/inline-generator.rs:9:14: 9:22
5656
- // + user_ty: UserType(0)
@@ -67,7 +67,7 @@
6767
+ StorageDead(_6); // scope 5 at $SRC_DIR/core/src/pin.rs:LL:COL
6868
+ StorageDead(_5); // scope 4 at $SRC_DIR/core/src/pin.rs:LL:COL
6969
StorageDead(_3); // scope 0 at $DIR/inline-generator.rs:+1:31: +1:32
70-
- _1 = <[generator@$DIR/inline-generator.rs:15:5: 15:8] as Generator<bool>>::resume(move _2, const false) -> [return: bb3, unwind: bb4]; // scope 0 at $DIR/inline-generator.rs:+1:14: +1:46
70+
- _1 = <[generator@$DIR/inline-generator.rs:15:5: 15:8] as Generator<bool>>::resume(move _2, const false) -> [return: bb3, unwind: bb7]; // scope 0 at $DIR/inline-generator.rs:+1:14: +1:46
7171
- // mir::Constant
7272
- // + span: $DIR/inline-generator.rs:9:33: 9:39
7373
- // + literal: Const { ty: for<'r> fn(Pin<&'r mut [generator@$DIR/inline-generator.rs:15:5: 15:8]>, bool) -> GeneratorState<<[generator@$DIR/inline-generator.rs:15:5: 15:8] as Generator<bool>>::Yield, <[generator@$DIR/inline-generator.rs:15:5: 15:8] as Generator<bool>>::Return> {<[generator@$DIR/inline-generator.rs:15:5: 15:8] as Generator<bool>>::resume}, val: Value(<ZST>) }
@@ -77,7 +77,7 @@
7777
+ StorageLive(_11); // scope 0 at $DIR/inline-generator.rs:+1:14: +1:46
7878
+ _13 = deref_copy (_2.0: &mut [generator@$DIR/inline-generator.rs:15:5: 15:8]); // scope 6 at $DIR/inline-generator.rs:15:5: 15:8
7979
+ _12 = discriminant((*_13)); // scope 6 at $DIR/inline-generator.rs:15:5: 15:8
80-
+ switchInt(move _12) -> [0_u32: bb3, 1_u32: bb8, 3_u32: bb7, otherwise: bb9]; // scope 6 at $DIR/inline-generator.rs:15:5: 15:8
80+
+ switchInt(move _12) -> [0_u32: bb7, 1_u32: bb12, 3_u32: bb11, otherwise: bb13]; // scope 6 at $DIR/inline-generator.rs:15:5: 15:8
8181
}
8282

8383
- bb3: {
@@ -86,36 +86,60 @@
8686
+ StorageDead(_10); // scope 0 at $DIR/inline-generator.rs:+1:14: +1:46
8787
+ StorageDead(_7); // scope 0 at $DIR/inline-generator.rs:+1:14: +1:46
8888
StorageDead(_2); // scope 0 at $DIR/inline-generator.rs:+1:45: +1:46
89+
- drop(_4) -> [return: bb4, unwind: bb6]; // scope 0 at $DIR/inline-generator.rs:+1:46: +1:47
90+
+ drop(_4) -> [return: bb2, unwind: bb4]; // scope 0 at $DIR/inline-generator.rs:+1:46: +1:47
91+
}
92+
93+
- bb4: {
94+
+ bb2: {
8995
StorageDead(_4); // scope 0 at $DIR/inline-generator.rs:+1:46: +1:47
9096
_0 = const (); // scope 0 at $DIR/inline-generator.rs:+0:11: +2:2
97+
- drop(_1) -> [return: bb5, unwind: bb8]; // scope 0 at $DIR/inline-generator.rs:+2:1: +2:2
98+
+ drop(_1) -> [return: bb3, unwind: bb6]; // scope 0 at $DIR/inline-generator.rs:+2:1: +2:2
99+
}
100+
101+
- bb5: {
102+
+ bb3: {
91103
StorageDead(_1); // scope 0 at $DIR/inline-generator.rs:+2:1: +2:2
92104
return; // scope 0 at $DIR/inline-generator.rs:+2:2: +2:2
93105
}
94106

95-
- bb4 (cleanup): {
96-
+ bb2 (cleanup): {
107+
- bb6 (cleanup): {
108+
- drop(_1) -> bb8; // scope 0 at $DIR/inline-generator.rs:+2:1: +2:2
109+
+ bb4 (cleanup): {
110+
+ drop(_1) -> bb6; // scope 0 at $DIR/inline-generator.rs:+2:1: +2:2
111+
}
112+
113+
- bb7 (cleanup): {
114+
- drop(_4) -> bb8; // scope 0 at $DIR/inline-generator.rs:+1:46: +1:47
115+
+ bb5 (cleanup): {
116+
+ drop(_4) -> bb6; // scope 0 at $DIR/inline-generator.rs:+1:46: +1:47
117+
}
118+
119+
- bb8 (cleanup): {
120+
+ bb6 (cleanup): {
97121
resume; // scope 0 at $DIR/inline-generator.rs:+0:1: +2:2
98122
+ }
99123
+
100-
+ bb3: {
124+
+ bb7: {
101125
+ _11 = move _7; // scope 6 at $DIR/inline-generator.rs:15:5: 15:8
102126
+ StorageLive(_8); // scope 6 at $DIR/inline-generator.rs:15:17: 15:39
103127
+ StorageLive(_9); // scope 6 at $DIR/inline-generator.rs:15:20: 15:21
104128
+ _9 = _11; // scope 6 at $DIR/inline-generator.rs:15:20: 15:21
105-
+ switchInt(move _9) -> [false: bb5, otherwise: bb4]; // scope 6 at $DIR/inline-generator.rs:15:20: 15:21
129+
+ switchInt(move _9) -> [false: bb9, otherwise: bb8]; // scope 6 at $DIR/inline-generator.rs:15:20: 15:21
106130
+ }
107131
+
108-
+ bb4: {
132+
+ bb8: {
109133
+ _8 = const 7_i32; // scope 6 at $DIR/inline-generator.rs:15:24: 15:25
110-
+ goto -> bb6; // scope 6 at $DIR/inline-generator.rs:15:17: 15:39
134+
+ goto -> bb10; // scope 6 at $DIR/inline-generator.rs:15:17: 15:39
111135
+ }
112136
+
113-
+ bb5: {
137+
+ bb9: {
114138
+ _8 = const 13_i32; // scope 6 at $DIR/inline-generator.rs:15:35: 15:37
115-
+ goto -> bb6; // scope 6 at $DIR/inline-generator.rs:15:17: 15:39
139+
+ goto -> bb10; // scope 6 at $DIR/inline-generator.rs:15:17: 15:39
116140
+ }
117141
+
118-
+ bb6: {
142+
+ bb10: {
119143
+ StorageDead(_9); // scope 6 at $DIR/inline-generator.rs:15:38: 15:39
120144
+ Deinit(_1); // scope 6 at $DIR/inline-generator.rs:15:11: 15:39
121145
+ ((_1 as Yielded).0: i32) = move _8; // scope 6 at $DIR/inline-generator.rs:15:11: 15:39
@@ -125,7 +149,7 @@
125149
+ goto -> bb1; // scope 0 at $DIR/inline-generator.rs:15:11: 15:39
126150
+ }
127151
+
128-
+ bb7: {
152+
+ bb11: {
129153
+ StorageLive(_8); // scope 6 at $DIR/inline-generator.rs:15:5: 15:8
130154
+ _10 = move _7; // scope 6 at $DIR/inline-generator.rs:15:5: 15:8
131155
+ StorageDead(_8); // scope 6 at $DIR/inline-generator.rs:15:38: 15:39
@@ -137,11 +161,11 @@
137161
+ goto -> bb1; // scope 0 at $DIR/inline-generator.rs:15:8: 15:8
138162
+ }
139163
+
140-
+ bb8: {
141-
+ assert(const false, "generator resumed after completion") -> [success: bb8, unwind: bb2]; // scope 6 at $DIR/inline-generator.rs:15:5: 15:8
164+
+ bb12: {
165+
+ assert(const false, "generator resumed after completion") -> [success: bb12, unwind: bb5]; // scope 6 at $DIR/inline-generator.rs:15:5: 15:8
142166
+ }
143167
+
144-
+ bb9: {
168+
+ bb13: {
145169
+ unreachable; // scope 6 at $DIR/inline-generator.rs:15:5: 15:8
146170
}
147171
}

src/test/mir-opt/inline/issue_78442.bar.Inline.diff

+30-21
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
StorageLive(_2); // scope 0 at $DIR/issue-78442.rs:+4:5: +4:17
1616
StorageLive(_3); // scope 0 at $DIR/issue-78442.rs:+4:5: +4:15
1717
StorageLive(_4); // scope 0 at $DIR/issue-78442.rs:+4:5: +4:15
18-
- _4 = hide_foo() -> [return: bb1, unwind: bb4]; // scope 0 at $DIR/issue-78442.rs:+4:5: +4:15
19-
+ _4 = hide_foo() -> [return: bb1, unwind: bb3]; // scope 0 at $DIR/issue-78442.rs:+4:5: +4:15
18+
- _4 = hide_foo() -> [return: bb1, unwind: bb6]; // scope 0 at $DIR/issue-78442.rs:+4:5: +4:15
19+
+ _4 = hide_foo() -> [return: bb1, unwind: bb5]; // scope 0 at $DIR/issue-78442.rs:+4:5: +4:15
2020
// mir::Constant
2121
// + span: $DIR/issue-78442.rs:11:5: 11:13
2222
// + literal: Const { ty: fn() -> impl Fn() {hide_foo}, val: Value(<ZST>) }
@@ -26,43 +26,52 @@
2626
_3 = &_4; // scope 0 at $DIR/issue-78442.rs:+4:5: +4:15
2727
StorageLive(_5); // scope 0 at $DIR/issue-78442.rs:+4:5: +4:17
2828
Deinit(_5); // scope 0 at $DIR/issue-78442.rs:+4:5: +4:17
29-
- _2 = <fn() {foo} as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind: bb4]; // scope 0 at $DIR/issue-78442.rs:+4:5: +4:17
29+
- _2 = <fn() {foo} as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind: bb5]; // scope 0 at $DIR/issue-78442.rs:+4:5: +4:17
3030
- // mir::Constant
3131
- // + span: $DIR/issue-78442.rs:11:5: 11:15
3232
- // + literal: Const { ty: for<'r> extern "rust-call" fn(&'r fn() {foo}, ()) -> <fn() {foo} as FnOnce<()>>::Output {<fn() {foo} as Fn<()>>::call}, val: Value(<ZST>) }
33-
+ _2 = move (*_3)() -> [return: bb5, unwind: bb3]; // scope 1 at $SRC_DIR/core/src/ops/function.rs:LL:COL
33+
+ _2 = move (*_3)() -> [return: bb7, unwind: bb4]; // scope 1 at $SRC_DIR/core/src/ops/function.rs:LL:COL
3434
}
3535

3636
bb2: {
3737
- StorageDead(_5); // scope 0 at $DIR/issue-78442.rs:+4:16: +4:17
3838
- StorageDead(_3); // scope 0 at $DIR/issue-78442.rs:+4:16: +4:17
39-
- StorageDead(_4); // scope 0 at $DIR/issue-78442.rs:+4:17: +4:18
40-
- StorageDead(_2); // scope 0 at $DIR/issue-78442.rs:+4:17: +4:18
41-
- _0 = const (); // scope 0 at $DIR/issue-78442.rs:+3:3: +5:2
42-
- drop(_1) -> [return: bb3, unwind: bb5]; // scope 0 at $DIR/issue-78442.rs:+5:1: +5:2
43-
+ return; // scope 0 at $DIR/issue-78442.rs:+5:2: +5:2
39+
- drop(_4) -> [return: bb3, unwind: bb6]; // scope 0 at $DIR/issue-78442.rs:+4:17: +4:18
40+
- }
41+
-
42+
- bb3: {
43+
StorageDead(_4); // scope 0 at $DIR/issue-78442.rs:+4:17: +4:18
44+
StorageDead(_2); // scope 0 at $DIR/issue-78442.rs:+4:17: +4:18
45+
_0 = const (); // scope 0 at $DIR/issue-78442.rs:+3:3: +5:2
46+
- drop(_1) -> [return: bb4, unwind: bb7]; // scope 0 at $DIR/issue-78442.rs:+5:1: +5:2
47+
+ drop(_1) -> [return: bb3, unwind: bb6]; // scope 0 at $DIR/issue-78442.rs:+5:1: +5:2
4448
}
4549

46-
- bb3: {
47-
- return; // scope 0 at $DIR/issue-78442.rs:+5:2: +5:2
48-
+ bb3 (cleanup): {
49-
+ drop(_1) -> bb4; // scope 0 at $DIR/issue-78442.rs:+5:1: +5:2
50+
- bb4: {
51+
+ bb3: {
52+
return; // scope 0 at $DIR/issue-78442.rs:+5:2: +5:2
53+
}
54+
55+
+ bb4 (cleanup): {
56+
+ drop(_4) -> bb5; // scope 0 at $DIR/issue-78442.rs:+4:17: +4:18
57+
+ }
58+
+
59+
bb5 (cleanup): {
60+
- drop(_4) -> bb6; // scope 0 at $DIR/issue-78442.rs:+4:17: +4:18
61+
+ drop(_1) -> bb6; // scope 0 at $DIR/issue-78442.rs:+5:1: +5:2
5062
}
5163

52-
bb4 (cleanup): {
53-
- drop(_1) -> bb5; // scope 0 at $DIR/issue-78442.rs:+5:1: +5:2
64+
bb6 (cleanup): {
65+
- drop(_1) -> bb7; // scope 0 at $DIR/issue-78442.rs:+5:1: +5:2
5466
+ resume; // scope 0 at $DIR/issue-78442.rs:+0:1: +5:2
5567
}
5668

57-
- bb5 (cleanup): {
69+
- bb7 (cleanup): {
5870
- resume; // scope 0 at $DIR/issue-78442.rs:+0:1: +5:2
59-
+ bb5: {
71+
+ bb7: {
6072
+ StorageDead(_5); // scope 0 at $DIR/issue-78442.rs:+4:16: +4:17
6173
+ StorageDead(_3); // scope 0 at $DIR/issue-78442.rs:+4:16: +4:17
62-
+ StorageDead(_4); // scope 0 at $DIR/issue-78442.rs:+4:17: +4:18
63-
+ StorageDead(_2); // scope 0 at $DIR/issue-78442.rs:+4:17: +4:18
64-
+ _0 = const (); // scope 0 at $DIR/issue-78442.rs:+3:3: +5:2
65-
+ drop(_1) -> [return: bb2, unwind: bb4]; // scope 0 at $DIR/issue-78442.rs:+5:1: +5:2
74+
+ drop(_4) -> [return: bb2, unwind: bb5]; // scope 0 at $DIR/issue-78442.rs:+4:17: +4:18
6675
}
6776
}
6877

src/test/mir-opt/inline/issue_78442.bar.RevealAll.diff

+16-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
StorageLive(_2); // scope 0 at $DIR/issue-78442.rs:+4:5: +4:17
1616
StorageLive(_3); // scope 0 at $DIR/issue-78442.rs:+4:5: +4:15
1717
StorageLive(_4); // scope 0 at $DIR/issue-78442.rs:+4:5: +4:15
18-
_4 = hide_foo() -> [return: bb1, unwind: bb4]; // scope 0 at $DIR/issue-78442.rs:+4:5: +4:15
18+
_4 = hide_foo() -> [return: bb1, unwind: bb6]; // scope 0 at $DIR/issue-78442.rs:+4:5: +4:15
1919
// mir::Constant
2020
// + span: $DIR/issue-78442.rs:11:5: 11:13
2121
// + literal: Const { ty: fn() -> impl Fn() {hide_foo}, val: Value(<ZST>) }
@@ -25,8 +25,8 @@
2525
_3 = &_4; // scope 0 at $DIR/issue-78442.rs:+4:5: +4:15
2626
StorageLive(_5); // scope 0 at $DIR/issue-78442.rs:+4:5: +4:17
2727
Deinit(_5); // scope 0 at $DIR/issue-78442.rs:+4:5: +4:17
28-
- _2 = <impl Fn() as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind: bb4]; // scope 0 at $DIR/issue-78442.rs:+4:5: +4:17
29-
+ _2 = <fn() {foo} as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind: bb4]; // scope 0 at $DIR/issue-78442.rs:+4:5: +4:17
28+
- _2 = <impl Fn() as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind: bb5]; // scope 0 at $DIR/issue-78442.rs:+4:5: +4:17
29+
+ _2 = <fn() {foo} as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind: bb5]; // scope 0 at $DIR/issue-78442.rs:+4:5: +4:17
3030
// mir::Constant
3131
// + span: $DIR/issue-78442.rs:11:5: 11:15
3232
- // + literal: Const { ty: for<'r> extern "rust-call" fn(&'r impl Fn(), ()) -> <impl Fn() as FnOnce<()>>::Output {<impl Fn() as Fn<()>>::call}, val: Value(<ZST>) }
@@ -36,21 +36,29 @@
3636
bb2: {
3737
StorageDead(_5); // scope 0 at $DIR/issue-78442.rs:+4:16: +4:17
3838
StorageDead(_3); // scope 0 at $DIR/issue-78442.rs:+4:16: +4:17
39+
drop(_4) -> [return: bb3, unwind: bb6]; // scope 0 at $DIR/issue-78442.rs:+4:17: +4:18
40+
}
41+
42+
bb3: {
3943
StorageDead(_4); // scope 0 at $DIR/issue-78442.rs:+4:17: +4:18
4044
StorageDead(_2); // scope 0 at $DIR/issue-78442.rs:+4:17: +4:18
4145
_0 = const (); // scope 0 at $DIR/issue-78442.rs:+3:3: +5:2
42-
drop(_1) -> [return: bb3, unwind: bb5]; // scope 0 at $DIR/issue-78442.rs:+5:1: +5:2
46+
drop(_1) -> [return: bb4, unwind: bb7]; // scope 0 at $DIR/issue-78442.rs:+5:1: +5:2
4347
}
4448

45-
bb3: {
49+
bb4: {
4650
return; // scope 0 at $DIR/issue-78442.rs:+5:2: +5:2
4751
}
4852

49-
bb4 (cleanup): {
50-
drop(_1) -> bb5; // scope 0 at $DIR/issue-78442.rs:+5:1: +5:2
53+
bb5 (cleanup): {
54+
drop(_4) -> bb6; // scope 0 at $DIR/issue-78442.rs:+4:17: +4:18
5155
}
5256

53-
bb5 (cleanup): {
57+
bb6 (cleanup): {
58+
drop(_1) -> bb7; // scope 0 at $DIR/issue-78442.rs:+5:1: +5:2
59+
}
60+
61+
bb7 (cleanup): {
5462
resume; // scope 0 at $DIR/issue-78442.rs:+0:1: +5:2
5563
}
5664
}

0 commit comments

Comments
 (0)