From 9c7b1fd694a016835ba88288c218aca29f30a8ab Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com> Date: Sat, 2 Oct 2021 10:28:04 +0900 Subject: [PATCH] compiler: remove dead code (#42460) - inferenceresult.jl: just dead allocations - inlining.jl: `UnionSplitSignature` (and its `SimpleCartesian` helper) is no longer used - abstractinterpretation.jl: the use of `precise_container_type` seems to be introduced in #26826, but `getfield_tfunc` at this moment is precise enough to propagate elements of constant tuples. --- base/compiler/abstractinterpretation.jl | 11 +----- base/compiler/inferenceresult.jl | 2 -- base/compiler/ssair/inlining.jl | 45 ------------------------- 3 files changed, 1 insertion(+), 57 deletions(-) diff --git a/base/compiler/abstractinterpretation.jl b/base/compiler/abstractinterpretation.jl index a10e1878ad52fd..7e76d2f70b5319 100644 --- a/base/compiler/abstractinterpretation.jl +++ b/base/compiler/abstractinterpretation.jl @@ -1086,16 +1086,7 @@ function abstract_call_builtin(interp::AbstractInterpreter, f::Builtin, fargs::U end end rt = builtin_tfunction(interp, f, argtypes[2:end], sv) - if f === getfield && isa(fargs, Vector{Any}) && la == 3 && - (a3 = argtypes[3]; isa(a3, Const)) && (idx = a3.val; isa(idx, Int)) && - (a2 = argtypes[2]; a2 ⊑ Tuple) - # TODO: why doesn't this use the getfield_tfunc? - cti_info = precise_container_type(interp, iterate, a2, sv) - cti = cti_info[1]::Vector{Any} - if 1 <= idx <= length(cti) - rt = unwrapva(cti[idx]) - end - elseif (rt === Bool || (isa(rt, Const) && isa(rt.val, Bool))) && isa(fargs, Vector{Any}) + if (rt === Bool || (isa(rt, Const) && isa(rt.val, Bool))) && isa(fargs, Vector{Any}) # perform very limited back-propagation of type information for `is` and `isa` if f === isa a = ssa_def_slot(fargs[2], sv) diff --git a/base/compiler/inferenceresult.jl b/base/compiler/inferenceresult.jl index 483e2f38d9ee84..cbeeb84b464bb6 100644 --- a/base/compiler/inferenceresult.jl +++ b/base/compiler/inferenceresult.jl @@ -71,10 +71,8 @@ function most_general_argtypes(method::Union{Method, Nothing}, @nospecialize(spe va = linfo_argtypes[linfo_argtypes_length] if isvarargtype(va) new_va = rewrap_unionall(unconstrain_vararg_length(va), specTypes) - vargtype_elements = Any[new_va] vargtype = Tuple{new_va} else - vargtype_elements = Any[] vargtype = Tuple{} end else diff --git a/base/compiler/ssair/inlining.jl b/base/compiler/ssair/inlining.jl index 015f3319008d9f..141b40709acb79 100644 --- a/base/compiler/ssair/inlining.jl +++ b/base/compiler/ssair/inlining.jl @@ -842,51 +842,6 @@ function InliningTodo(mi::MethodInstance, src::Union{CodeInfo, Array{UInt8, 1}}) end end -# Neither the product iterator not CartesianIndices are available -# here, so use this poor man's version -struct SimpleCartesian - ranges::Vector{UnitRange{Int}} -end -function iterate(s::SimpleCartesian, state::Vector{Int}=Int[1 for _ in 1:length(s.ranges)]) - state[end] > last(s.ranges[end]) && return nothing - vals = copy(state) - any = false - for i = 1:length(s.ranges) - if state[i] < last(s.ranges[i]) - for j = 1:(i-1) - state[j] = first(s.ranges[j]) - end - state[i] += 1 - any = true - break - end - end - if !any - state[end] += 1 - end - (vals, state) -end - -# Given a signure, iterate over the signatures to union split over -struct UnionSplitSignature - it::SimpleCartesian - typs::Vector{Any} -end - -function UnionSplitSignature(atypes::Vector{Any}) - typs = Any[uniontypes(widenconst(atypes[i])) for i = 1:length(atypes)] - ranges = UnitRange{Int}[1:length(typs[i]) for i = 1:length(typs)] - return UnionSplitSignature(SimpleCartesian(ranges), typs) -end - -function iterate(split::UnionSplitSignature, state::Vector{Int}...) - y = iterate(split.it, state...) - y === nothing && return nothing - idxs, state = y - sig = Any[split.typs[i][j] for (i, j) in enumerate(idxs)] - return (sig, state) -end - function handle_single_case!(ir::IRCode, stmt::Expr, idx::Int, @nospecialize(case), isinvoke::Bool, todo::Vector{Pair{Int, Any}}) if isa(case, ConstantCase) ir[SSAValue(idx)] = case.val