Commit 6a5b3d0
Flow analysis: don't capture type information in equalityOperand_end.
There are two pieces of information flow analysis needs to know about
an equality test operand (i.e., an operands of `==`, `!=`, or
`identical()`):
- Their static types. This is used for reachability (e.g., flow
analysis knows that if `f()` has type `Null`, then the body of `if
(f() != null)` is unreachable).
- Whether they take the form of a null literal or a reference to
something promotable. This is used to determine when an `if` test
should promote a something to a non-nullable type.
Previous to this change, both pieces of information were captured by
`FlowAnalysis.equalityOperand_end` into an `ExpressionInfo` object,
and then those objects were passed into
`FlowAnalysis.equalityOperation_end`.
With this change, the client is now responsible for passing the static
types of the operands as separate arguments to
`FlowAnalysis.equalityOperation_end`, and the only information
captured by `equalityOperand_end` is whether the operand is a null
literal or a reference to something promotable.
This has two advantages:
- It avoids unnecessary allocations when analyzing code that doesn't
have flow analysis consequences, since flow analysis no longer needs
to allocate an `ExpressionInfo` for every equality test operand; it
only has to allocate them for null literals and references to things
that are promotable (which is a much smaller number of allocations).
- It means that `FlowAnalysis.equalityOperation_end` no longer needs
to use the `type` field of `ExpressionInfo`. This helps build toward
an eventual goal I have of removing this field, so that
`ExpressionInfo` will simply be a container for a pair of flow
models (one representing the flow state if the expression is `true`,
one representing the flow state if the expression is `false`). I
believe this will make flow analysis easier to reason about, and
will help build toward a long term goal of cleaning up bugs in the
"why not promoted" logic.
Making this change required adding a little bit of plumbing to the
analyzer, so that when analyzing an invocation of `identical`, it
keeps track of both the `ExpressionInfo` and the static type of the
operands; previously it just had to keep track of an `ExpressionInfo`
for each operand. The performance impact of this additional tracking
should be negligible, since this tracking doesn't happen for
invocations of anything other than `identical`.
Change-Id: I3e5473af095f3c8a747e9f527d7e14a21269dc95
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389361
Commit-Queue: Paul Berry <[email protected]>
Reviewed-by: Kallen Tu <[email protected]>
Reviewed-by: Johnni Winther <[email protected]>1 parent e567b0a commit 6a5b3d0
File tree
6 files changed
+95
-60
lines changed- pkg
- analyzer/lib/src/dart/resolver
- front_end/lib/src/type_inference
6 files changed
+95
-60
lines changedLines changed: 34 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
405 | 405 | | |
406 | 406 | | |
407 | 407 | | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
| 408 | + | |
412 | 409 | | |
413 | 410 | | |
414 | 411 | | |
415 | 412 | | |
416 | 413 | | |
417 | | - | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
418 | 417 | | |
419 | 418 | | |
420 | 419 | | |
| 420 | + | |
421 | 421 | | |
| 422 | + | |
422 | 423 | | |
423 | 424 | | |
424 | 425 | | |
| |||
1412 | 1413 | | |
1413 | 1414 | | |
1414 | 1415 | | |
1415 | | - | |
1416 | | - | |
1417 | | - | |
1418 | | - | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
1419 | 1420 | | |
1420 | 1421 | | |
1421 | 1422 | | |
1422 | 1423 | | |
1423 | 1424 | | |
| 1425 | + | |
1424 | 1426 | | |
| 1427 | + | |
1425 | 1428 | | |
1426 | 1429 | | |
1427 | 1430 | | |
1428 | | - | |
1429 | | - | |
1430 | | - | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
1431 | 1435 | | |
1432 | 1436 | | |
1433 | 1437 | | |
| |||
4689 | 4693 | | |
4690 | 4694 | | |
4691 | 4695 | | |
4692 | | - | |
4693 | | - | |
4694 | | - | |
| 4696 | + | |
| 4697 | + | |
4695 | 4698 | | |
4696 | 4699 | | |
4697 | 4700 | | |
4698 | 4701 | | |
4699 | 4702 | | |
| 4703 | + | |
4700 | 4704 | | |
| 4705 | + | |
4701 | 4706 | | |
4702 | 4707 | | |
4703 | 4708 | | |
4704 | 4709 | | |
4705 | 4710 | | |
4706 | 4711 | | |
4707 | | - | |
4708 | | - | |
| 4712 | + | |
| 4713 | + | |
4709 | 4714 | | |
4710 | 4715 | | |
4711 | 4716 | | |
| |||
5760 | 5765 | | |
5761 | 5766 | | |
5762 | 5767 | | |
5763 | | - | |
5764 | | - | |
5765 | | - | |
| 5768 | + | |
| 5769 | + | |
| 5770 | + | |
5766 | 5771 | | |
5767 | | - | |
| 5772 | + | |
5768 | 5773 | | |
5769 | | - | |
| 5774 | + | |
5770 | 5775 | | |
5771 | 5776 | | |
5772 | 5777 | | |
| |||
5781 | 5786 | | |
5782 | 5787 | | |
5783 | 5788 | | |
5784 | | - | |
| 5789 | + | |
5785 | 5790 | | |
5786 | 5791 | | |
5787 | 5792 | | |
5788 | | - | |
| 5793 | + | |
5789 | 5794 | | |
5790 | 5795 | | |
5791 | 5796 | | |
| |||
5967 | 5972 | | |
5968 | 5973 | | |
5969 | 5974 | | |
5970 | | - | |
5971 | | - | |
| 5975 | + | |
| 5976 | + | |
5972 | 5977 | | |
5973 | 5978 | | |
5974 | 5979 | | |
| |||
6560 | 6565 | | |
6561 | 6566 | | |
6562 | 6567 | | |
6563 | | - | |
6564 | | - | |
| 6568 | + | |
6565 | 6569 | | |
6566 | 6570 | | |
6567 | 6571 | | |
6568 | 6572 | | |
6569 | 6573 | | |
| 6574 | + | |
6570 | 6575 | | |
| 6576 | + | |
6571 | 6577 | | |
6572 | 6578 | | |
6573 | 6579 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5529 | 5529 | | |
5530 | 5530 | | |
5531 | 5531 | | |
5532 | | - | |
| 5532 | + | |
5533 | 5533 | | |
5534 | 5534 | | |
5535 | 5535 | | |
5536 | 5536 | | |
5537 | 5537 | | |
5538 | 5538 | | |
5539 | | - | |
| 5539 | + | |
5540 | 5540 | | |
5541 | 5541 | | |
5542 | 5542 | | |
| |||
Lines changed: 7 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
103 | | - | |
| 102 | + | |
104 | 103 | | |
105 | 104 | | |
106 | 105 | | |
| |||
109 | 108 | | |
110 | 109 | | |
111 | 110 | | |
112 | | - | |
113 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
114 | 117 | | |
115 | 118 | | |
116 | 119 | | |
| |||
Lines changed: 38 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
244 | | - | |
| 244 | + | |
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | | - | |
| 249 | + | |
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
| |||
264 | 264 | | |
265 | 265 | | |
266 | 266 | | |
267 | | - | |
| 267 | + | |
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
| |||
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
292 | | - | |
| 292 | + | |
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
| |||
472 | 472 | | |
473 | 473 | | |
474 | 474 | | |
475 | | - | |
476 | | - | |
| 475 | + | |
| 476 | + | |
477 | 477 | | |
478 | | - | |
479 | | - | |
480 | | - | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
481 | 487 | | |
482 | 488 | | |
483 | 489 | | |
484 | 490 | | |
485 | 491 | | |
486 | 492 | | |
487 | | - | |
| 493 | + | |
488 | 494 | | |
489 | 495 | | |
490 | 496 | | |
| |||
506 | 512 | | |
507 | 513 | | |
508 | 514 | | |
509 | | - | |
510 | | - | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
511 | 518 | | |
512 | 519 | | |
513 | 520 | | |
| |||
522 | 529 | | |
523 | 530 | | |
524 | 531 | | |
525 | | - | |
| 532 | + | |
526 | 533 | | |
527 | 534 | | |
528 | 535 | | |
| |||
549 | 556 | | |
550 | 557 | | |
551 | 558 | | |
552 | | - | |
| 559 | + | |
553 | 560 | | |
554 | 561 | | |
555 | 562 | | |
| |||
569 | 576 | | |
570 | 577 | | |
571 | 578 | | |
572 | | - | |
573 | | - | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
574 | 582 | | |
575 | 583 | | |
576 | 584 | | |
| |||
712 | 720 | | |
713 | 721 | | |
714 | 722 | | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
715 | 737 | | |
716 | 738 | | |
717 | 739 | | |
| |||
Lines changed: 7 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6744 | 6744 | | |
6745 | 6745 | | |
6746 | 6746 | | |
6747 | | - | |
| 6747 | + | |
6748 | 6748 | | |
6749 | 6749 | | |
6750 | 6750 | | |
| |||
6762 | 6762 | | |
6763 | 6763 | | |
6764 | 6764 | | |
6765 | | - | |
6766 | | - | |
| 6765 | + | |
| 6766 | + | |
| 6767 | + | |
6767 | 6768 | | |
6768 | 6769 | | |
6769 | 6770 | | |
| |||
6811 | 6812 | | |
6812 | 6813 | | |
6813 | 6814 | | |
6814 | | - | |
6815 | | - | |
| 6815 | + | |
| 6816 | + | |
| 6817 | + | |
6816 | 6818 | | |
6817 | 6819 | | |
6818 | 6820 | | |
| |||
Lines changed: 7 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1802 | 1802 | | |
1803 | 1803 | | |
1804 | 1804 | | |
1805 | | - | |
1806 | | - | |
| 1805 | + | |
1807 | 1806 | | |
1808 | 1807 | | |
1809 | 1808 | | |
| |||
1843 | 1842 | | |
1844 | 1843 | | |
1845 | 1844 | | |
1846 | | - | |
1847 | | - | |
| 1845 | + | |
1848 | 1846 | | |
1849 | 1847 | | |
1850 | 1848 | | |
| |||
1862 | 1860 | | |
1863 | 1861 | | |
1864 | 1862 | | |
1865 | | - | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
1866 | 1868 | | |
1867 | 1869 | | |
1868 | 1870 | | |
| |||
0 commit comments