Commit 73cbd98
authored
Convert Location to a namedtuple, and associated cleanup (#205)
This change makes the `Location` dataclass, which does not change
frequently, into a new `SourceLocation` namedtuple, and changes the
`SourceLocation` serialization. As a result, with this change:
* `embossc` runs about 25% faster on a large (7kLOC) input; `python3
-OO emboss` runs about 19% faster on the same input.
* Serialized IR is about 45% smaller.
Details:
* Replace the `ir_data.Location` dataclass with a new
`parser_types.SourceLocation` namedtuple. The rename helps clarify
the difference between a location within source code
(`SourceLocation`) and a location within a structure
(`FieldLocation`).
* Similarly, replace `ir_data.Position` with
`parser_types.SourcePosition`.
* Update any place that edits a `SourceLocation` with an appropriate
assignment; e.g., `x.source_location.end = y` becomes
`x.source_location = x.source_location._replace(end=y)`. In most
cases, several fields were updated consecutively; those updates are
been merged.
* Update the JSON serialization to use the compact format.
* Replace `format_location()` and `format_position()` with
`__str__()` methods on `SourceLocation` and `SourcePosition`,
respectively.
* Replace `parse_location()` and `parse_position()` with `from_str()`
class methods on `SourceLocation` and `SourcePosition`,
respectively.
* Move the `make_location()` functionality into
`SourceLocation.__new__()`.
* Update `_to_dict` and `_from_dict` in `IrDataSerializer` to
stringify and destringify `SourceLocation`. It is tempting to
try to do this during the JSON serialization step (with a `default=`
parameter to `json.dumps` and an `object_hook=` parameter to
`json.loads`), but it is tricky to get the `object_hook` to know
when to convert.1 parent 46423da commit 73cbd98
File tree
29 files changed
+780
-1523
lines changed- compiler
- back_end/cpp
- front_end
- util
- testdata/golden
29 files changed
+780
-1523
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1747 | 1747 | | |
1748 | 1748 | | |
1749 | 1749 | | |
1750 | | - | |
1751 | | - | |
1752 | | - | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
1753 | 1758 | | |
1754 | 1759 | | |
1755 | 1760 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
135 | 134 | | |
136 | 135 | | |
137 | 136 | | |
| |||
156 | 155 | | |
157 | 156 | | |
158 | 157 | | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
165 | 163 | | |
166 | 164 | | |
167 | 165 | | |
| |||
186 | 184 | | |
187 | 185 | | |
188 | 186 | | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
195 | 192 | | |
196 | 193 | | |
197 | 194 | | |
| |||
216 | 213 | | |
217 | 214 | | |
218 | 215 | | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
225 | 221 | | |
226 | 222 | | |
227 | 223 | | |
| |||
246 | 242 | | |
247 | 243 | | |
248 | 244 | | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
255 | 250 | | |
256 | 251 | | |
257 | 252 | | |
| |||
274 | 269 | | |
275 | 270 | | |
276 | 271 | | |
277 | | - | |
278 | | - | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
279 | 276 | | |
280 | 277 | | |
281 | 278 | | |
| |||
298 | 295 | | |
299 | 296 | | |
300 | 297 | | |
301 | | - | |
302 | | - | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
303 | 302 | | |
304 | 303 | | |
305 | 304 | | |
| |||
322 | 321 | | |
323 | 322 | | |
324 | 323 | | |
325 | | - | |
326 | | - | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
327 | 328 | | |
328 | 329 | | |
329 | 330 | | |
| |||
346 | 347 | | |
347 | 348 | | |
348 | 349 | | |
349 | | - | |
350 | | - | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
351 | 354 | | |
352 | 355 | | |
353 | 356 | | |
| |||
370 | 373 | | |
371 | 374 | | |
372 | 375 | | |
373 | | - | |
374 | | - | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
375 | 380 | | |
376 | 381 | | |
377 | 382 | | |
| |||
394 | 399 | | |
395 | 400 | | |
396 | 401 | | |
397 | | - | |
398 | | - | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
399 | 406 | | |
400 | 407 | | |
401 | 408 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
| 206 | + | |
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
235 | | - | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
236 | 238 | | |
237 | 239 | | |
238 | 240 | | |
| |||
259 | 261 | | |
260 | 262 | | |
261 | 263 | | |
262 | | - | |
263 | | - | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
264 | 270 | | |
265 | 271 | | |
266 | 272 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
143 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
144 | 146 | | |
145 | 147 | | |
146 | 148 | | |
| |||
690 | 692 | | |
691 | 693 | | |
692 | 694 | | |
693 | | - | |
694 | | - | |
695 | | - | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
| 695 | + | |
713 | 696 | | |
714 | 697 | | |
715 | 698 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
212 | | - | |
| 212 | + | |
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| |||
0 commit comments