Skip to content

Commit

Permalink
compiler: remove dead code
Browse files Browse the repository at this point in the history
- 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 I think `getfield_tfunc` at this
  moment is precise enough to propagate elements of constant tuples.
  • Loading branch information
aviatesk committed Oct 1, 2021
1 parent 5a98032 commit 9b0075c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 55 deletions.
11 changes: 1 addition & 10 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
45 changes: 0 additions & 45 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9b0075c

Please sign in to comment.