Commit a121721
authored
inference: form
* inference: form `PartialStruct` for extra type information propagation
This commit forms `PartialStruct` whenever there is any type-level
refinement available about a field, even if it's not "constant" information.
In Julia "definitions" are allowed to be abstract whereas "usages"
(i.e. callsites) are often concrete. The basic idea is to allow inference
to make more use of such precise callsite type information by encoding it
as `PartialStruct`.
This may increase optimization possibilities of "unidiomatic" Julia code,
which may contain poorly-typed definitions, like this very contrived example:
```julia
struct Problem
n; s; c; t
end
function main(args...)
prob = Problem(args...)
s = 0
for i in 1:prob.n
m = mod(i, 3)
s += m == 0 ? sin(prob.s) : m == 1 ? cos(prob.c) : tan(prob.t)
end
return prob, s
end
main(10000, 1, 2, 3)
```
One of the obvious limitation is that this extra type information can be
propagated inter-procedurally only as a const-propagation.
I'm not sure this kind of "just a type-level" refinement can often make
constant-prop' successful (i.e. shape-up a method body and allow it to
be inlined, encoding the extra type information into the generated code),
thus I didn't not modify any part of const-prop' heuristics.
So the improvements from this change might not be very useful for general
inter-procedural analysis currently, but they should definitely improve the
accuracy of local analysis and very simple inter-procedural analysis.PartialStruct for extra type information propagation (#42831)1 parent 6c274ed commit a121721
File tree
4 files changed
+81
-45
lines changed- base/compiler
- test/compiler
4 files changed
+81
-45
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
345 | 345 | | |
346 | 346 | | |
347 | 347 | | |
348 | | - | |
| 348 | + | |
349 | 349 | | |
350 | | - | |
| 350 | + | |
351 | 351 | | |
352 | 352 | | |
353 | 353 | | |
| |||
1598 | 1598 | | |
1599 | 1599 | | |
1600 | 1600 | | |
1601 | | - | |
1602 | | - | |
1603 | | - | |
1604 | | - | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
1605 | 1605 | | |
1606 | 1606 | | |
1607 | | - | |
1608 | | - | |
1609 | | - | |
1610 | | - | |
| 1607 | + | |
| 1608 | + | |
1611 | 1609 | | |
1612 | 1610 | | |
1613 | | - | |
1614 | | - | |
1615 | | - | |
1616 | | - | |
1617 | | - | |
1618 | | - | |
1619 | | - | |
1620 | | - | |
1621 | | - | |
1622 | | - | |
| 1611 | + | |
| 1612 | + | |
1623 | 1613 | | |
1624 | 1614 | | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
1625 | 1620 | | |
1626 | 1621 | | |
1627 | | - | |
| 1622 | + | |
1628 | 1623 | | |
1629 | | - | |
1630 | | - | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
1631 | 1630 | | |
1632 | 1631 | | |
1633 | 1632 | | |
| |||
1638 | 1637 | | |
1639 | 1638 | | |
1640 | 1639 | | |
1641 | | - | |
| 1640 | + | |
1642 | 1641 | | |
1643 | 1642 | | |
1644 | 1643 | | |
| |||
1718 | 1717 | | |
1719 | 1718 | | |
1720 | 1719 | | |
| 1720 | + | |
1721 | 1721 | | |
1722 | 1722 | | |
1723 | 1723 | | |
| |||
1801 | 1801 | | |
1802 | 1802 | | |
1803 | 1803 | | |
1804 | | - | |
| 1804 | + | |
1805 | 1805 | | |
1806 | 1806 | | |
1807 | 1807 | | |
1808 | | - | |
| 1808 | + | |
1809 | 1809 | | |
1810 | | - | |
| 1810 | + | |
| 1811 | + | |
1811 | 1812 | | |
1812 | 1813 | | |
1813 | 1814 | | |
1814 | | - | |
| 1815 | + | |
1815 | 1816 | | |
1816 | 1817 | | |
1817 | 1818 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
143 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
144 | 149 | | |
145 | 150 | | |
146 | 151 | | |
| |||
232 | 237 | | |
233 | 238 | | |
234 | 239 | | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
235 | 256 | | |
236 | 257 | | |
237 | 258 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3669 | 3669 | | |
3670 | 3670 | | |
3671 | 3671 | | |
| 3672 | + | |
| 3673 | + | |
| 3674 | + | |
| 3675 | + | |
| 3676 | + | |
| 3677 | + | |
| 3678 | + | |
| 3679 | + | |
| 3680 | + | |
| 3681 | + | |
| 3682 | + | |
| 3683 | + | |
| 3684 | + | |
| 3685 | + | |
| 3686 | + | |
| 3687 | + | |
| 3688 | + | |
| 3689 | + | |
| 3690 | + | |
| 3691 | + | |
| 3692 | + | |
| 3693 | + | |
| 3694 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
426 | 426 | | |
427 | 427 | | |
428 | 428 | | |
429 | | - | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
430 | 432 | | |
431 | | - | |
| 433 | + | |
432 | 434 | | |
433 | 435 | | |
434 | 436 | | |
435 | 437 | | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
| 438 | + | |
444 | 439 | | |
445 | 440 | | |
446 | | - | |
447 | | - | |
| 441 | + | |
| 442 | + | |
448 | 443 | | |
449 | 444 | | |
450 | 445 | | |
451 | 446 | | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | 447 | | |
0 commit comments