-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Commit 88c254f
Rollup merge of #145643 - Zalathar:tree, r=SparrowLii
coverage: Build an "expansion tree" and use it to unexpand raw spans
Historically and currently, coverage instrumentation assumes that all of a function's spans are in the same file and have the same syntax context. The spans extracted directly from MIR don't satisfy that assumption, so there is an "unexpansion" step that walks up each span's expansion-call-site tree to find a suitable span in the same context as the function's body span.
(That unexpansion step is what allows us to have somewhat reasonable coverage instrumentation for macros like `println!`, and for syntax like `for` and `?` that undergo desugaring expansion.)
The current unexpansion code mostly works fine in that "flat" single-file single-context world. But it's not suitable for incremental work towards proper expansion-aware coverage instrumentation, which would allow a function's coverage spans to encompass multiple expansion contexts and multiple files.
This PR therefore replaces the current unexpansion code with a more sophisticated system that uses the raw MIR spans to reconstruct an "expansion tree", and then uses that tree to help perform most of the unexpansion work.
Building the tree is "overkill" for current unexpansion needs (though it does give some minor edge-case improvements), but my hope is that having the explicit tree available will be a big help when taking the next steps towards proper expansion-region support.File tree
12 files changed
+286
-162
lines changed- compiler/rustc_mir_transform/src
- coverage
- spans
- tests/coverage
12 files changed
+286
-162
lines changedLines changed: 127 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 | + | ||
2 | + | ||
3 | + | ||
4 | + | ||
5 | + | ||
6 | + | ||
7 | + | ||
8 | + | ||
9 | + | ||
10 | + | ||
11 | + | ||
12 | + | ||
13 | + | ||
14 | + | ||
15 | + | ||
16 | + | ||
17 | + | ||
18 | + | ||
19 | + | ||
20 | + | ||
21 | + | ||
22 | + | ||
23 | + | ||
24 | + | ||
25 | + | ||
26 | + | ||
27 | + | ||
28 | + | ||
29 | + | ||
30 | + | ||
31 | + | ||
32 | + | ||
33 | + | ||
34 | + | ||
35 | + | ||
36 | + | ||
37 | + | ||
38 | + | ||
39 | + | ||
40 | + | ||
41 | + | ||
42 | + | ||
43 | + | ||
44 | + | ||
45 | + | ||
46 | + | ||
47 | + | ||
48 | + | ||
49 | + | ||
50 | + | ||
51 | + | ||
52 | + | ||
53 | + | ||
54 | + | ||
55 | + | ||
56 | + | ||
57 | + | ||
58 | + | ||
59 | + | ||
60 | + | ||
61 | + | ||
62 | + | ||
63 | + | ||
64 | + | ||
65 | + | ||
66 | + | ||
67 | + | ||
68 | + | ||
69 | + | ||
70 | + | ||
71 | + | ||
72 | + | ||
73 | + | ||
74 | + | ||
75 | + | ||
76 | + | ||
77 | + | ||
78 | + | ||
79 | + | ||
80 | + | ||
81 | + | ||
82 | + | ||
83 | + | ||
84 | + | ||
85 | + | ||
86 | + | ||
87 | + | ||
88 | + | ||
89 | + | ||
90 | + | ||
91 | + | ||
92 | + | ||
93 | + | ||
94 | + | ||
95 | + | ||
96 | + | ||
97 | + | ||
98 | + | ||
99 | + | ||
100 | + | ||
101 | + | ||
102 | + | ||
103 | + | ||
104 | + | ||
105 | + | ||
106 | + | ||
107 | + | ||
108 | + | ||
109 | + | ||
110 | + | ||
111 | + | ||
112 | + | ||
113 | + | ||
114 | + | ||
115 | + | ||
116 | + | ||
117 | + | ||
118 | + | ||
119 | + | ||
120 | + | ||
121 | + | ||
122 | + | ||
123 | + | ||
124 | + | ||
125 | + | ||
126 | + | ||
127 | + |
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
8 | 8 |
| |
9 | 9 |
| |
10 | 10 |
| |
11 | + | ||
11 | 12 |
| |
12 | 13 |
| |
13 | 14 |
| |
|
Lines changed: 80 additions & 62 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 | - | ||
2 | 1 |
| |
3 | 2 |
| |
4 | 3 |
| |
5 | 4 |
| |
6 | - | ||
5 | + | ||
7 | 6 |
| |
8 | 7 |
| |
8 | + | ||
9 | 9 |
| |
10 | 10 |
| |
11 | - | ||
12 | - | ||
11 | + | ||
13 | 12 |
| |
14 | 13 |
| |
15 | 14 |
| |
| |||
34 | 33 |
| |
35 | 34 |
| |
36 | 35 |
| |
37 | - | ||
38 | - | ||
39 | - | ||
40 | - | ||
41 | - | ||
42 | - | ||
43 | - | ||
44 | - | ||
45 | - | ||
46 | - | ||
47 | - | ||
48 | - | ||
49 | - | ||
36 | + | ||
37 | + | ||
38 | + | ||
39 | + | ||
40 | + | ||
41 | + | ||
42 | + | ||
43 | + | ||
44 | + | ||
45 | + | ||
46 | + | ||
47 | + | ||
48 | + | ||
49 | + | ||
50 | + | ||
51 | + | ||
52 | + | ||
53 | + | ||
54 | + | ||
55 | + | ||
56 | + | ||
57 | + | ||
58 | + | ||
59 | + | ||
60 | + | ||
61 | + | ||
62 | + | ||
63 | + | ||
64 | + | ||
65 | + | ||
66 | + | ||
67 | + | ||
68 | + | ||
69 | + | ||
70 | + | ||
71 | + | ||
72 | + | ||
73 | + | ||
74 | + | ||
75 | + | ||
76 | + | ||
77 | + | ||
78 | + | ||
79 | + | ||
80 | + | ||
50 | 81 |
| |
51 | 82 |
| |
52 | 83 |
| |
| |||
57 | 88 |
| |
58 | 89 |
| |
59 | 90 |
| |
60 | - | ||
61 | - | ||
62 | - | ||
63 | - | ||
64 | - | ||
65 | - | ||
66 | - | ||
67 | - | ||
68 | - | ||
69 | - | ||
70 | - | ||
91 | + | ||
92 | + | ||
93 | + | ||
94 | + | ||
71 | 95 |
| |
72 | 96 |
| |
73 | 97 |
| |
| |||
117 | 141 |
| |
118 | 142 |
| |
119 | 143 |
| |
120 | - | ||
121 | - | ||
122 | - | ||
123 | - | ||
124 | - | ||
125 | - | ||
126 | - | ||
127 | - | ||
128 | - | ||
129 | - | ||
130 | - | ||
131 | - | ||
132 | - | ||
133 | - | ||
134 | - | ||
135 | - | ||
136 | - | ||
137 | - | ||
138 | - | ||
139 | - | ||
140 | - | ||
141 | - | ||
144 | + | ||
145 | + | ||
146 | + | ||
147 | + | ||
148 | + | ||
149 | + | ||
150 | + | ||
151 | + | ||
152 | + | ||
153 | + | ||
154 | + | ||
155 | + | ||
156 | + | ||
157 | + | ||
158 | + | ||
159 | + | ||
160 | + | ||
142 | 161 |
| |
143 | - | ||
144 | - | ||
145 | - | ||
146 | - | ||
147 | - | ||
148 | - | ||
149 | - | ||
150 | - | ||
162 | + | ||
163 | + | ||
164 | + | ||
165 | + | ||
151 | 166 |
| |
152 | - | ||
153 | - | ||
154 | - | ||
155 | - | ||
167 | + | ||
168 | + | ||
169 | + | ||
170 | + | ||
171 | + | ||
156 | 172 |
| |
173 | + | ||
174 | + | ||
157 | 175 |
| |
158 | 176 |
| |
159 | 177 |
| |
|
Lines changed: 2 additions & 32 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5 | 5 |
| |
6 | 6 |
| |
7 | 7 |
| |
8 | - | ||
8 | + | ||
9 | 9 |
| |
10 | - | ||
11 | - | ||
10 | + | ||
12 | 11 |
| |
13 | 12 |
| |
14 | 13 |
| |
| |||
160 | 159 |
| |
161 | 160 |
| |
162 | 161 |
| |
163 | - | ||
164 | - | ||
165 | - | ||
166 | - | ||
167 | - | ||
168 | - | ||
169 | - | ||
170 | - | ||
171 | - | ||
172 | - | ||
173 | - | ||
174 | - | ||
175 | - | ||
176 | - | ||
177 | - | ||
178 | - | ||
179 | - | ||
180 | - | ||
181 | - | ||
182 | - | ||
183 | - | ||
184 | - | ||
185 | - | ||
186 | - | ||
187 | - | ||
188 | - | ||
189 | - | ||
190 | - | ||
191 | - |
0 commit comments