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

fix #37610, allow constant prop on signatures with unions #37637

Closed
wants to merge 2 commits into from

Conversation

JeffBezanson
Copy link
Member

@JeffBezanson JeffBezanson commented Sep 18, 2020

Constant prop looks at nonbot (# of non-Bottom-returning method signatures) to determine whether there is only one match. If we split Union types though, there appears to be more than one, so we don't do constant prop, which is the source of the issue. This fixes it by also splitting the argtypes array that includes constant information, and still constant prop'ing as long as there is only one actual method match. I have not seen any measurable latency impact so far.

I added inline declarations to some indexed_iterate methods for good measure, though it is not really necessary to fix this.

While working on this I noticed that the two methods of alloc_buf_hook returned spuriously different types, so I changed them to consistently return Ptr{Cvoid}, Int. I'm totally indifferent as to whether we return Ptr{UInt8}, UInt instead though if anybody prefers that 😂

fix #37610

@JeffBezanson JeffBezanson added the compiler:inference Type inference label Sep 18, 2020
Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm inclined to think we should majorly refactor this part of the code, so that we can make more intelligent decisions here, but this LGTM.

In particular, abstract_call_method_with_const_args could be split into the policy and mechanism, that way we can check whether, for each split call, whether there is value in attempting constant splitting for that particular call site, before attempting it, (and then also remove the restriction heuristics that there's only one method match).

EDIT: as I wrote the above, I realized there's possibly an issue with this currently. The abstract_call_method_with_const_args call signals failures by returning Any (no improved information). That worked because it assumed we only would use it once. But that'll significantly degrade the reliability of the information that this is supposed to provide, because of the immediate tmerge.

@JeffBezanson
Copy link
Member Author

If abstract_call_method_with_const_args returns Any for any of the split signatures, shouldn't we just bail out of constant prop though (which I believe the current version of the code does)?

@vtjnash
Copy link
Member

vtjnash commented Sep 21, 2020

No, that seems like it'd be highly unreliable, since that assumes all useful type information must have been derived from constant propagation, but that's expected to be nearly always false. Perhaps uncommon it'll matter, but that feels more related to the unlikeliness that the extra effort in this PR to constant propagate harder will be able to improve the inferred result than the unlikeliness that the function may result in the same answer for different input constants.

@aviatesk
Copy link
Member

@JeffBezanson @vtjnash
Can I take the initiative on this ? I've opened #39305 that has the same goal as this without noticing this..
I agree with @vtjnash 's comment, and I'd like to refactor abstract_call_method_with_const_args so that we can make more sensible decision earlier about whether to do constant prop' before we ends up Any return result on 2nd or subsequent constant prop' trial.

tpl = rewrap_unionall(Tuple{t...}, origt)
push!(tunion, tpl)
if origt === nothing
push!(tunion, t)
Copy link
Member

@aviatesk aviatesk Jan 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
push!(tunion, t)
push!(tunion, copy(t))

I think we need to copy t here, otherwise it will be mutated at t[i] = ti in recursion.

aviatesk added a commit to aviatesk/julia that referenced this pull request Jan 20, 2021
The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate 
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation

The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```

> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```

> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
aviatesk added a commit to aviatesk/julia that referenced this pull request Jan 21, 2021
The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation

The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```

> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```

> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
aviatesk added a commit to aviatesk/julia that referenced this pull request Jan 21, 2021
The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation

The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```

> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```

> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
aviatesk added a commit to aviatesk/julia that referenced this pull request Jan 22, 2021
The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation

The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```

> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```

> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
aviatesk added a commit to aviatesk/julia that referenced this pull request Jan 26, 2021
The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation

The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```

> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```

> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
aviatesk added a commit to aviatesk/julia that referenced this pull request Jan 28, 2021
The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation

The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```

> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```

> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
aviatesk added a commit to aviatesk/julia that referenced this pull request Jan 29, 2021
The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation

The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```

> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```

> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
aviatesk added a commit to aviatesk/julia that referenced this pull request Jan 30, 2021
The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation

The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```

> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```

> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
aviatesk added a commit to aviatesk/julia that referenced this pull request Jan 31, 2021
The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation

The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```

> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```

> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
aviatesk added a commit to aviatesk/julia that referenced this pull request Feb 5, 2021
The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation

The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```

> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```

> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
aviatesk added a commit to aviatesk/julia that referenced this pull request Feb 6, 2021
The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation

The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```

> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```

> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
aviatesk added a commit to aviatesk/julia that referenced this pull request Feb 10, 2021
The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation

The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```

> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```

> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
aviatesk added a commit to aviatesk/julia that referenced this pull request Feb 13, 2021
The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation

The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```

> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```

> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
aviatesk added a commit to aviatesk/julia that referenced this pull request Feb 16, 2021
The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation

The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```

> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```

> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
aviatesk added a commit to aviatesk/julia that referenced this pull request Feb 17, 2021
The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation

The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```

> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```

> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
aviatesk added a commit to aviatesk/julia that referenced this pull request Feb 28, 2021
The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation
The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```
> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```
> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
aviatesk added a commit to aviatesk/julia that referenced this pull request Feb 28, 2021
The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation
The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```
> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```
> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
aviatesk added a commit to aviatesk/julia that referenced this pull request Mar 2, 2021
The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation
The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```
> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```
> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
aviatesk added a commit to aviatesk/julia that referenced this pull request Mar 3, 2021
The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation
The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```
> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```
> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
aviatesk added a commit to aviatesk/julia that referenced this pull request Mar 5, 2021
The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation
The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```
> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```
> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
aviatesk added a commit to aviatesk/julia that referenced this pull request Mar 6, 2021
The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation
The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```
> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```
> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
aviatesk added a commit to aviatesk/julia that referenced this pull request Mar 10, 2021
The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation
The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```
> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```
> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
vtjnash pushed a commit that referenced this pull request Mar 10, 2021
…9305)

The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation
The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```
> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```
> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes #37610
- some part of this code was taken from #37637
- this PR is originally supposed to be alternative and more generalized
  version of #39296
@vtjnash
Copy link
Member

vtjnash commented Mar 10, 2021

@JeffBezanson do you want to make a separate PR for 2e01da6

@vtjnash vtjnash closed this Mar 10, 2021
@vtjnash vtjnash deleted the jb/fix37610 branch March 10, 2021 20:26
ElOceanografo pushed a commit to ElOceanografo/julia that referenced this pull request May 4, 2021
…liaLang#39305)

The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation
The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```
> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```
> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
antoine-levitt pushed a commit to antoine-levitt/julia that referenced this pull request May 9, 2021
…liaLang#39305)

The inference precision of certain functions really relies on constant
propagation, but currently constant prop' won't happen when a call
signature is union split and so sometimes inference ends up looser
return type: e.g.
```julia
julia>
Base.return_types((Union{Tuple{Int,Nothing},Tuple{Int,Missing}},)) do t
           a, b = t
           a # I expected a::Int, but a::Union{Missing,Nothing,Int}
       end |> first Union{Missing, Nothing, Int64}
```

This PR:
- enables constant prop' for each union signatures, by calling
  `abstract_call_method_with_const_args` just after each
  `abstract_call_method`
- refactor `abstract_call_method_with_const_args` into two separate
  parts, 1.) heuristics to decide whether to do constant prop', 2.) try
  constant propagation
The added test cases will should showcase the cases where the
inference result could be improved by that.

---

I've not seen notable regression in latency with this PR.
Here is a sample benchmark of the impact of this PR on latency,
from which I guess this PR is acceptable ?

> build time: master (caeacef)
```bash
Sysimage built. Summary:
Total ───────  61.615938 seconds
Base: ───────  26.575732 seconds 43.1313%
Stdlibs: ────  35.038024 seconds 56.8652%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1378/1378
Precompilation complete. Summary:
Total ─────── 116.417013 seconds
Generation ──  81.077365 seconds 69.6439%
Execution ───  35.339648 seconds 30.3561%
    LINK usr/lib/julia/sys.dylib
```
> build time: this PR
```bash
Stdlibs total  ──── 34.077962 seconds
Sysimage built. Summary:
Total ───────  61.804573 seconds
Base: ───────  27.724077 seconds 44.8576%
Stdlibs: ────  34.077962 seconds 55.1383%
    JULIA usr/lib/julia/sys-o.a
Generating REPL precompile statements... 30/30
Executing precompile statements... 1362/1362
Precompilation complete. Summary:
Total ─────── 111.262672 seconds
Generation ──  83.535305 seconds 75.0794%
Execution ───  27.727367 seconds 24.9206%
    LINK usr/lib/julia/sys.dylib
```

> first time to plot: master (caeacef)
```julia
julia> using Plots; @time plot(rand(10,3))
  3.614168 seconds (5.47 M allocations: 324.564 MiB, 5.73% gc time,
53.02% compilation time)
```
> first time to plot: this PR
```julia
julia> using Plots; @time plot(rand(10,3))
  3.557919 seconds (5.53 M allocations: 328.812 MiB, 2.89% gc time,
51.94% compilation time)
```

---

- fixes JuliaLang#37610
- some part of this code was taken from JuliaLang#37637
- this PR is originally supposed to be alternative and more generalized
  version of JuliaLang#39296
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Imprecise inference when iterating a Pair with constant first type but varying second type.
3 participants