Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

callsite inlining interacts very badly with source deletion #42078

Closed
aviatesk opened this issue Sep 1, 2021 · 0 comments
Closed

callsite inlining interacts very badly with source deletion #42078

aviatesk opened this issue Sep 1, 2021 · 0 comments
Labels
compiler:optimizer Optimization passes (mostly in base/compiler/ssair/)

Comments

@aviatesk
Copy link
Member

aviatesk commented Sep 1, 2021

There are several points in our codegen pipeline that discard the inferred source code that is not "inlineable",
and it easily breaks the idempotency of callsite inlining, e.g.:

julia> using LinearAlgebra

julia> const CC = Core.Compiler;

julia> function getsource(mi)
           codeinf = CC.get(CC.code_cache(CC.NativeInterpreter()), mi, nothing)
           return isnothing(codeinf) ? nothing : 
                  isdefined(codeinf, :inferrred) ? nothing :
                  typeof(codeinf.inferred)
       end
getsource (generic function with 1 method)

julia> code_typed1(args...; kwargs...) = first(only(code_typed(args...; kwargs...))).code
code_typed1 (generic function with 1 method)

julia> mi = only(methods(factorize, (Matrix{Float64},))).specializations[1]
MethodInstance for LinearAlgebra.factorize(::Matrix{Float64})

julia> getsource(mi)

julia> code_typed1() do
           A = Array(Bidiagonal(fill(1.0, (5, 5)), :U))
           @inline factorize(A)
       end |> length
431 # succeed in inlining

julia> getsource(mi)
Vector{UInt8} (alias for Array{UInt8, 1})

julia> let # run the codegen pipeline
           A = Array(Bidiagonal(fill(1.0, (5, 5)), :U))
           factorize(A)
       end;

julia> getsource(mi)
Nothing # the inferred source has been discarded

julia> code_typed1() do
           A = Array(Bidiagonal(fill(1.0, (5, 5)), :U))
           @inline factorize(A)
       end |> length
37 # inlining failed, becuase there is no inferred source available

julia> getsource(mi)
Nothing

We can keep the idempotency If we turn off following lines:

but of course this leads to the fat sysimages...:

master

❯ ls -la ./usr/lib/julia/
total 434420
drwxr-xr-x 2 aviatesk aviatesk      4096 Sep  1 03:44 .
drwxr-xr-x 5 aviatesk aviatesk     16384 Sep  1 01:23 ..
-rw-r--r-- 1 aviatesk aviatesk  14742218 Sep  1 03:38 corecompiler.ji
-rw-r--r-- 1 aviatesk aviatesk  92237537 Sep  1 03:40 sys.ji
-rw-r--r-- 1 aviatesk aviatesk 177971028 Sep  1 03:44 sys-o.a
-rwxr-xr-x 1 aviatesk aviatesk 159864072 Sep  1 03:44 sys.so

with source deletion turned off

 ls -la ./usr/lib/julia/
total 457132
drwxr-xr-x 2 aviatesk aviatesk      4096 Sep  1 03:49 .
drwxr-xr-x 5 aviatesk aviatesk     16384 Sep  1 03:39 ..
-rw-r--r-- 1 aviatesk aviatesk  16111154 Sep  1 03:43 corecompiler.ji
-rw-r--r-- 1 aviatesk aviatesk  95654621 Sep  1 03:45 sys.ji
-rw-r--r-- 1 aviatesk aviatesk 187393556 Sep  1 03:49 sys-o.a
-rwxr-xr-x 1 aviatesk aviatesk 168911408 Sep  1 03:49 sys.so

So that actually means, we really want "re-inference" stuff here after all ?

else
# maybe we want to make inference keep the source in a local cache if a statement is going to inlined
# and re-optimize it here with disabling further inlining to avoid infinite optimization loop
# (we can even naively try to re-infer it entirely)
# but it seems like that "single-level-inlining" is more trouble and complex than it's worth
# see https://github.com/JuliaLang/julia/pull/41328/commits/0fc0f71a42b8c9d04b0dafabf3f1f17703abf2e7
return nothing

@aviatesk aviatesk added the compiler:optimizer Optimization passes (mostly in base/compiler/ssair/) label Sep 1, 2021
aviatesk added a commit that referenced this issue Sep 1, 2021
After #41328, inference can observe statement flags and try to re-infer
a discarded source if it's going to be inlined.
The re-inferred source will only be cached into the inference-local
cache, and won't be cached globally.
aviatesk added a commit that referenced this issue Sep 2, 2021
After #41328, inference can observe statement flags and try to re-infer
a discarded source if it's going to be inlined.
The re-inferred source will only be cached into the inference-local
cache, and won't be cached globally.
aviatesk added a commit that referenced this issue Sep 3, 2021
After #41328, inference can observe statement flags and try to re-infer
a discarded source if it's going to be inlined.
The re-inferred source will only be cached into the inference-local
cache, and won't be cached globally.
LilithHafner pushed a commit to LilithHafner/julia that referenced this issue Feb 22, 2022
…liaLang#42082)

After JuliaLang#41328, inference can observe statement flags and try to re-infer
a discarded source if it's going to be inlined.
The re-inferred source will only be cached into the inference-local
cache, and won't be cached globally.
LilithHafner pushed a commit to LilithHafner/julia that referenced this issue Mar 8, 2022
…liaLang#42082)

After JuliaLang#41328, inference can observe statement flags and try to re-infer
a discarded source if it's going to be inlined.
The re-inferred source will only be cached into the inference-local
cache, and won't be cached globally.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:optimizer Optimization passes (mostly in base/compiler/ssair/)
Projects
None yet
Development

No branches or pull requests

1 participant