Revision 2a406b243730a0a50aa99355786b3ac41340a386 authored by Keno Fischer on 06 July 2023, 21:20:40 UTC, committed by GitHub on 06 July 2023, 21:20:40 UTC
* Add pattern matching for `typeof` into field type tparam

This PR allows full elimination of the following, even in
ill-typed code.
```
struct TParamTypeofTest{T}
    x::T
    @eval TParamTypeofTest(x) = $(Expr(:new, :(TParamTypeofTest{typeof(x)}), :x))
end
function tparam_typeof_test_elim(x)
    TParamTypeofTest(x).x
end
```

Before this PR, we would get:
```
julia> code_typed(tparam_typeof_test_elim, Tuple{Any})
1-element Vector{Any}:
 CodeInfo(
1 ─ %1 = Main.typeof(x)::DataType
│   %2 = Core.apply_type(Main.TParamTypeofTest, %1)::Type{TParamTypeofTest{_A}} where _A
│        %new(%2, x)::TParamTypeofTest
└──      return x
```

Where the `new` is non-eliminable, because the compiler did not know that
`x::_A`. Fix this by pattern matching this particular pattern (where the
condition is guaranteed, because we computed `_A` by `typeof`).
This is not particularly general, but this pattern comes up a lot,
so it's surprisingly effective.

* add test case for optimizing multiple abstract fields

* improve robustness

---------

Co-authored-by: Shuhei Kadowaki <aviatesk@gmail.com>
1 parent 46477cc
History
File Mode Size
asan
bpftrace
mac
tsan
windows
README.md -rw-r--r-- 2.9 KB
add_license_to_files.jl -rw-r--r-- 7.0 KB
check-whitespace.jl -rwxr-xr-x 1.7 KB
commit-name.sh -rwxr-xr-x 1.2 KB
debug_bootstrap.gdb -rw-r--r-- 76 bytes
delete-all-rpaths.sh -rwxr-xr-x 925 bytes
download_cmake.sh -rwxr-xr-x 2.1 KB
fixup-libgfortran.sh -rwxr-xr-x 6.0 KB
fixup-libstdc++.sh -rwxr-xr-x 1.1 KB
fixup-rpath.sh -rwxr-xr-x 1.0 KB
generate_precompile.jl -rw-r--r-- 18.4 KB
httpbin-prod-swagger-apigateway.yaml -rw-r--r-- 3.0 KB
install.sh -rwxr-xr-x 695 bytes
julia-config.jl -rwxr-xr-x 3.6 KB
julia.appdata.xml -rw-r--r-- 1.4 KB
julia.desktop -rw-r--r-- 367 bytes
julia.png -rw-r--r-- 1.6 KB
julia.svg -rw-r--r-- 1.1 KB
new-stdlib.sh -rwxr-xr-x 1.8 KB
normalize_triplet.py -rwxr-xr-x 4.4 KB
prepare_release.sh -rwxr-xr-x 4.8 KB
print_sorted_stdlibs.jl -rw-r--r-- 3.1 KB
refresh_checksums.mk -rw-r--r-- 6.7 KB
relative_path.py -rwxr-xr-x 537 bytes
stringreplace.c -rw-r--r-- 942 bytes
updateSPDX.jl -rw-r--r-- 1.1 KB
valgrind-julia.supp -rw-r--r-- 156 bytes

README.md

back to top