Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit58fe37f

Browse files
authored
Rollup merge of#127164 - Nadrieril:clean-lowering-loop, r=matthewjasper
match lowering: Clarify the main loop of the algorithmNow that we expand or-patterns in a single place in the algorithm, we can move it (back) to the main part of the loop. This makes the call-graph of the main loop rather simple: `match_candidates` has three branches that each call back to `match_candidates`. The remaining tricky part is `finalize_or_candidate`.I also factored out the whole "process a prefix of the candidates then process the rest" thing which I think helps legibility.The first two commits are a fix for an indexing mistake I introduced in#126553, already sumitted in#127028 but feel free to merge this first.r? `@matthewjasper`
2 parents5e311f9 +42772e9 commit58fe37f

File tree

21 files changed

+425
-540
lines changed

21 files changed

+425
-540
lines changed

‎compiler/rustc_mir_build/src/build/matches/mod.rs‎

Lines changed: 155 additions & 190 deletions
Large diffs are not rendered by default.

‎tests/mir-opt/building/match/match_false_edges.full_tested_match.built.after.mir‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn full_tested_match() -> () {
6262
_6 = &((_2 as Some).0:i32);
6363
_3 = &fake shallow _2;
6464
StorageLive(_7);
65-
_7 = guard() -> [return:bb8, unwind:bb16];
65+
_7 = guard() -> [return:bb8, unwind:bb15];
6666
}
6767

6868
bb8:{
@@ -118,11 +118,7 @@ fn full_tested_match() -> () {
118118
unreachable;
119119
}
120120

121-
bb15:{
122-
goto -> bb14;
123-
}
124-
125-
bb16 (cleanup):{
121+
bb15 (cleanup):{
126122
resume;
127123
}
128124
}

‎tests/mir-opt/building/match/match_false_edges.full_tested_match2.built.after.mir‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn full_tested_match2() -> () {
6868
_6 = &((_2 as Some).0:i32);
6969
_3 = &fake shallow _2;
7070
StorageLive(_7);
71-
_7 = guard() -> [return:bb8, unwind:bb16];
71+
_7 = guard() -> [return:bb8, unwind:bb15];
7272
}
7373

7474
bb8:{
@@ -118,11 +118,7 @@ fn full_tested_match2() -> () {
118118
unreachable;
119119
}
120120

121-
bb15:{
122-
goto -> bb14;
123-
}
124-
125-
bb16 (cleanup):{
121+
bb15 (cleanup):{
126122
resume;
127123
}
128124
}

‎tests/mir-opt/building/match/match_false_edges.main.built.after.mir‎

Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -38,65 +38,61 @@ fn main() -> () {
3838
StorageLive(_2);
3939
_2 = Option::<i32>::Some(const 1_i32);
4040
PlaceMention(_2);
41-
_5 = discriminant(_2);
42-
switchInt(move_5) -> [1:bb8, otherwise:bb2];
41+
_4 = discriminant(_2);
42+
switchInt(move_4) -> [1:bb2, otherwise:bb1];
4343
}
4444

4545
bb1:{
46-
FakeRead(ForMatchedPlace(None), _2);
47-
unreachable;
46+
falseEdge -> [real:bb14, imaginary: bb4];
4847
}
4948

5049
bb2:{
51-
falseEdge -> [real:bb15, imaginary:bb3];
50+
falseEdge -> [real:bb9, imaginary:bb1];
5251
}
5352

5453
bb3:{
55-
_4 = discriminant(_2);
56-
switchInt(move _4) -> [1:bb6, otherwise: bb4];
54+
goto -> bb1;
5755
}
5856

5957
bb4:{
58+
_5 = discriminant(_2);
59+
switchInt(move _5) -> [1:bb6, otherwise: bb5];
60+
}
61+
62+
bb5:{
6063
StorageLive(_14);
6164
_14 = _2;
6265
_1 = const 4_i32;
6366
StorageDead(_14);
64-
goto -> bb21;
65-
}
66-
67-
bb5:{
68-
goto -> bb1;
67+
goto -> bb20;
6968
}
7069

7170
bb6:{
72-
falseEdge -> [real:bb16, imaginary:bb4];
71+
falseEdge -> [real:bb15, imaginary:bb5];
7372
}
7473

7574
bb7:{
76-
goto ->bb4;
75+
goto ->bb5;
7776
}
7877

7978
bb8:{
80-
falseEdge -> [real:bb10, imaginary: bb2];
79+
FakeRead(ForMatchedPlace(None), _2);
80+
unreachable;
8181
}
8282

8383
bb9:{
84-
goto -> bb2;
85-
}
86-
87-
bb10:{
8884
StorageLive(_7);
8985
_7 = &((_2 as Some).0:i32);
9086
_3 = &fake shallow _2;
9187
StorageLive(_8);
92-
_8 = guard() -> [return:bb11, unwind:bb24];
88+
_8 = guard() -> [return:bb10, unwind:bb22];
9389
}
9490

95-
bb11:{
96-
switchInt(move _8) -> [0:bb13, otherwise:bb12];
91+
bb10:{
92+
switchInt(move _8) -> [0:bb12, otherwise:bb11];
9793
}
9894

99-
bb12:{
95+
bb11:{
10096
StorageDead(_8);
10197
FakeRead(ForMatchGuard, _3);
10298
FakeRead(ForGuardBinding, _7);
@@ -105,42 +101,42 @@ fn main() -> () {
105101
_1 = const 1_i32;
106102
StorageDead(_6);
107103
StorageDead(_7);
108-
goto ->bb21;
104+
goto ->bb20;
109105
}
110106

111-
bb13:{
112-
goto ->bb14;
107+
bb12:{
108+
goto ->bb13;
113109
}
114110

115-
bb14:{
111+
bb13:{
116112
StorageDead(_8);
117113
StorageDead(_7);
118-
falseEdge -> [real:bb9, imaginary:bb2];
114+
falseEdge -> [real:bb3, imaginary:bb1];
119115
}
120116

121-
bb15:{
117+
bb14:{
122118
StorageLive(_9);
123119
_9 = _2;
124120
_1 = const 2_i32;
125121
StorageDead(_9);
126-
goto ->bb21;
122+
goto ->bb20;
127123
}
128124

129-
bb16:{
125+
bb15:{
130126
StorageLive(_11);
131127
_11 = &((_2 as Some).0:i32);
132128
_3 = &fake shallow _2;
133129
StorageLive(_12);
134130
StorageLive(_13);
135131
_13 = (*_11);
136-
_12 = guard2(move _13) -> [return:bb17, unwind:bb24];
132+
_12 = guard2(move _13) -> [return:bb16, unwind:bb22];
137133
}
138134

139-
bb17:{
140-
switchInt(move _12) -> [0:bb19, otherwise:bb18];
135+
bb16:{
136+
switchInt(move _12) -> [0:bb18, otherwise:bb17];
141137
}
142138

143-
bb18:{
139+
bb17:{
144140
StorageDead(_13);
145141
StorageDead(_12);
146142
FakeRead(ForMatchGuard, _3);
@@ -150,38 +146,34 @@ fn main() -> () {
150146
_1 = const 3_i32;
151147
StorageDead(_10);
152148
StorageDead(_11);
153-
goto ->bb21;
149+
goto ->bb20;
154150
}
155151

156-
bb19:{
157-
goto ->bb20;
152+
bb18:{
153+
goto ->bb19;
158154
}
159155

160-
bb20:{
156+
bb19:{
161157
StorageDead(_13);
162158
StorageDead(_12);
163159
StorageDead(_11);
164-
falseEdge -> [real:bb7, imaginary:bb4];
160+
falseEdge -> [real:bb7, imaginary:bb5];
165161
}
166162

167-
bb21:{
163+
bb20:{
168164
PlaceMention(_1);
169165
StorageDead(_2);
170166
StorageDead(_1);
171167
_0 = const ();
172168
return;
173169
}
174170

175-
bb22:{
171+
bb21:{
176172
FakeRead(ForMatchedPlace(None), _1);
177173
unreachable;
178174
}
179175

180-
bb23:{
181-
goto -> bb22;
182-
}
183-
184-
bb24 (cleanup):{
176+
bb22 (cleanup):{
185177
resume;
186178
}
187179
}

‎tests/mir-opt/building/match/simple_match.match_bool.built.after.mir‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,33 @@ fn match_bool(_1: bool) -> usize {
66

77
bb0:{
88
PlaceMention(_1);
9-
switchInt(_1) -> [0:bb2, otherwise:bb4];
9+
switchInt(_1) -> [0:bb1, otherwise:bb2];
1010
}
1111

1212
bb1:{
13-
FakeRead(ForMatchedPlace(None), _1);
14-
unreachable;
13+
_0 = const 20_usize;
14+
goto -> bb6;
1515
}
1616

1717
bb2:{
18-
_0 = const 20_usize;
19-
goto -> bb7;
18+
falseEdge -> [real:bb5, imaginary: bb1];
2019
}
2120

2221
bb3:{
2322
goto -> bb1;
2423
}
2524

2625
bb4:{
27-
falseEdge -> [real:bb6, imaginary: bb2];
26+
FakeRead(ForMatchedPlace(None), _1);
27+
unreachable;
2828
}
2929

3030
bb5:{
31-
goto -> bb2;
32-
}
33-
34-
bb6:{
3531
_0 = const 10_usize;
36-
goto ->bb7;
32+
goto ->bb6;
3733
}
3834

39-
bb7:{
35+
bb6:{
4036
return;
4137
}
4238
}

‎tests/mir-opt/building/match/simple_match.match_enum.built.after.mir‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn match_enum(_1: E1) -> bool {
88
bb0:{
99
PlaceMention(_1);
1010
_2 = discriminant(_1);
11-
switchInt(move _2) -> [0:bb3, 1:bb5, 2:bb7, otherwise:bb2];
11+
switchInt(move _2) -> [0:bb2, 1:bb4, 2:bb6, otherwise:bb1];
1212
}
1313

1414
bb1:{
@@ -17,44 +17,40 @@ fn match_enum(_1: E1) -> bool {
1717
}
1818

1919
bb2:{
20-
goto ->bb1;
20+
goto ->bb8;
2121
}
2222

2323
bb3:{
24-
goto ->bb9;
24+
goto ->bb1;
2525
}
2626

2727
bb4:{
28-
goto ->bb2;
28+
goto ->bb8;
2929
}
3030

3131
bb5:{
32-
goto ->bb9;
32+
goto ->bb1;
3333
}
3434

3535
bb6:{
36-
goto -> bb2;
36+
_0 = const false;
37+
goto -> bb10;
3738
}
3839

3940
bb7:{
40-
_0 = const false;
41-
goto -> bb11;
41+
goto -> bb1;
4242
}
4343

4444
bb8:{
45-
goto ->bb2;
45+
falseEdge ->[real:bb9, imaginary: bb6];
4646
}
4747

4848
bb9:{
49-
falseEdge -> [real:bb10, imaginary: bb7];
50-
}
51-
52-
bb10:{
5349
_0 = const true;
54-
goto ->bb11;
50+
goto ->bb10;
5551
}
5652

57-
bb11:{
53+
bb10:{
5854
return;
5955
}
6056
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp