Commit 65b9be4
authored
improve
Make `cat` inferrable even if its arguments are not fully constant:
```julia
julia> r = rand(Float32, 56, 56, 64, 1);
julia> f(r) = cat(r, r, dims=(3,))
f (generic function with 1 method)
julia> @inferred f(r);
julia> last(@code_typed f(r))
Array{Float32, 4}
```
After descending into its call graph, I found that constant propagation
is prohibited at `cat_t(::Type{T}, X...; dims)` due to the method instance
heuristic, i.e. its body is considered to be too complex for successful
inlining although it's explicitly annotated as `@inline`.
But for this case, the constant propagation is greatly helpful both for
abstract interpretation and optimization since it can improve the return
type inference.
Since it is not an easy task to improve the method instance heuristic,
which is our primary logic for constant propagation, this commit does
a quick fix by helping inference with the `@constprop` annotation.
There is another issue that currently there is no good way to properly
apply `@constprop`/`@inline` effects to a keyword function (as a note,
this is a general issue of macro annotations on a method definition).
So this commit also changes some internal helper functions of `cat`
so that now they are not keyword ones: the changes are also necessary
for the `@inline` annotation on `cat_t` to be effective to trick
the method instance heuristic.cat inferrability (#45028)1 parent 45abec4 commit 65b9be4
File tree
4 files changed
+24
-32
lines changed- base
- stdlib/LinearAlgebra/src
- test
4 files changed
+24
-32
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1716 | 1716 | | |
1717 | 1717 | | |
1718 | 1718 | | |
1719 | | - | |
1720 | | - | |
1721 | | - | |
1722 | | - | |
1723 | | - | |
1724 | | - | |
1725 | | - | |
| 1719 | + | |
1726 | 1720 | | |
1727 | 1721 | | |
1728 | 1722 | | |
1729 | 1723 | | |
1730 | 1724 | | |
1731 | 1725 | | |
1732 | 1726 | | |
1733 | | - | |
| 1727 | + | |
1734 | 1728 | | |
1735 | | - | |
1736 | 1729 | | |
1737 | 1730 | | |
1738 | 1731 | | |
| |||
1742 | 1735 | | |
1743 | 1736 | | |
1744 | 1737 | | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
1745 | 1741 | | |
1746 | 1742 | | |
1747 | 1743 | | |
| |||
1880 | 1876 | | |
1881 | 1877 | | |
1882 | 1878 | | |
1883 | | - | |
1884 | | - | |
| 1879 | + | |
| 1880 | + | |
1885 | 1881 | | |
1886 | 1882 | | |
1887 | 1883 | | |
| |||
1917 | 1913 | | |
1918 | 1914 | | |
1919 | 1915 | | |
1920 | | - | |
| 1916 | + | |
| 1917 | + | |
1921 | 1918 | | |
1922 | 1919 | | |
1923 | 1920 | | |
| |||
1928 | 1925 | | |
1929 | 1926 | | |
1930 | 1927 | | |
1931 | | - | |
1932 | | - | |
1933 | | - | |
1934 | | - | |
1935 | | - | |
1936 | | - | |
| 1928 | + | |
| 1929 | + | |
| 1930 | + | |
| 1931 | + | |
| 1932 | + | |
| 1933 | + | |
1937 | 1934 | | |
1938 | 1935 | | |
1939 | 1936 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
414 | 414 | | |
415 | 415 | | |
416 | 416 | | |
417 | | - | |
| 417 | + | |
418 | 418 | | |
419 | 419 | | |
420 | 420 | | |
421 | 421 | | |
422 | 422 | | |
423 | 423 | | |
424 | | - | |
| 424 | + | |
425 | 425 | | |
426 | 426 | | |
427 | 427 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
733 | 733 | | |
734 | 734 | | |
735 | 735 | | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
736 | 740 | | |
737 | 741 | | |
738 | 742 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
175 | | - | |
176 | | - | |
177 | 175 | | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
187 | 179 | | |
188 | | - | |
189 | 180 | | |
190 | 181 | | |
191 | 182 | | |
| |||
0 commit comments