Revision 1510eaa93e60c9c8d7e92fd1d296b78ded49d52e authored by Shuhei Kadowaki on 24 October 2021, 16:35:12 UTC, committed by Shuhei Kadowaki on 26 October 2021, 12:28:27 UTC
This commit complements #39754 and #39305: implements a logic to use
constant-prop'ed results for inlining at union-split callsite.
Currently it works only for cases when constant-prop' succeeded for all
(union-split) signatures.

> example
```julia
julia> mutable struct X
           # NOTE in order to confuse `fieldtype_tfunc`, we need to have at least two fields with different types
           a::Union{Nothing, Int}
           b::Symbol
       end;

julia> code_typed((X, Union{Nothing,Int})) do x, a
           # this `setproperty` call would be union-split and constant-prop will happen for
           # each signature: inlining would fail if we don't use constant-prop'ed source
           # since the approximated inlining cost of `convert(fieldtype(X, sym), a)` would
           # end up very high if we don't propagate `sym::Const(:a)`
           x.a = a
           x
       end |> only |> first
```

> before this commit
```julia
CodeInfo(
1 ─ %1 = Base.setproperty!::typeof(setproperty!)
│   %2 = (isa)(a, Nothing)::Bool
└──      goto #3 if not %2
2 ─ %4 = π (a, Nothing)
│        invoke %1(_2::X, :a::Symbol, %4::Nothing)::Any
└──      goto #6
3 ─ %7 = (isa)(a, Int64)::Bool
└──      goto #5 if not %7
4 ─ %9 = π (a, Int64)
│        invoke %1(_2::X, :a::Symbol, %9::Int64)::Any
└──      goto #6
5 ─      Core.throw(ErrorException("fatal error in type inference (type bound)"))::Union{}
└──      unreachable
6 ┄      return x
)
```

> after this commit
```julia
CodeInfo(
1 ─ %1 = (isa)(a, Nothing)::Bool
└──      goto #3 if not %1
2 ─      Base.setfield!(x, :a, nothing)::Nothing
└──      goto #6
3 ─ %5 = (isa)(a, Int64)::Bool
└──      goto #5 if not %5
4 ─ %7 = π (a, Int64)
│        Base.setfield!(x, :a, %7)::Int64
└──      goto #6
5 ─      Core.throw(ErrorException("fatal error in type inference (type bound)"))::Union{}
└──      unreachable
6 ┄      return x
)
```
1 parent 2e388e3
History
File Mode Size
.buildkite
.devcontainer
.github
base
cli
contrib
deps
doc
etc
src
stdlib
test
.clang-format -rw-r--r-- 3.3 KB
.codecov.yml -rw-r--r-- 52 bytes
.gitattributes -rw-r--r-- 65 bytes
.gitignore -rw-r--r-- 291 bytes
.mailmap -rw-r--r-- 11.1 KB
CITATION.bib -rw-r--r-- 513 bytes
CITATION.cff -rw-r--r-- 942 bytes
CONTRIBUTING.md -rw-r--r-- 19.8 KB
HISTORY.md -rw-r--r-- 333.2 KB
LICENSE.md -rw-r--r-- 1.3 KB
Make.inc -rw-r--r-- 49.1 KB
Makefile -rw-r--r-- 25.5 KB
NEWS.md -rw-r--r-- 5.9 KB
README.md -rw-r--r-- 7.4 KB
THIRDPARTY.md -rw-r--r-- 3.6 KB
VERSION -rw-r--r-- 10 bytes
sysimage.mk -rw-r--r-- 4.0 KB

README.md

back to top