Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inference: enable constant propagation for union-split signatures
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
- Loading branch information