Skip to content

Commit

Permalink
inference: rm unused vtypes arguments (JuliaLang#37042)
Browse files Browse the repository at this point in the history
These were left over from when our IR wasn't quite linear yet
and it was possible to have to evaluate another slot deep in
the nesting context. Since that's not true anymore, these
arguments are all unused.
  • Loading branch information
Keno committed Aug 14, 2020
1 parent fb2e1ef commit 8554a21
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
46 changes: 23 additions & 23 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ end
# refine its type to an array of element types.
# Union of Tuples of the same length is converted to Tuple of Unions.
# returns an array of types
function precise_container_type(interp::AbstractInterpreter, @nospecialize(itft), @nospecialize(typ), vtypes::VarTable, sv::InferenceState)
function precise_container_type(interp::AbstractInterpreter, @nospecialize(itft), @nospecialize(typ), sv::InferenceState)
if isa(typ, PartialStruct) && typ.typ.name === Tuple.name
return typ.fields, nothing
end
Expand Down Expand Up @@ -558,12 +558,12 @@ function precise_container_type(interp::AbstractInterpreter, @nospecialize(itft)
elseif tti0 <: Array
return Any[Vararg{eltype(tti0)}], nothing
else
return abstract_iteration(interp, itft, typ, vtypes, sv)
return abstract_iteration(interp, itft, typ, sv)
end
end

# simulate iteration protocol on container type up to fixpoint
function abstract_iteration(interp::AbstractInterpreter, @nospecialize(itft), @nospecialize(itertype), vtypes::VarTable, sv::InferenceState)
function abstract_iteration(interp::AbstractInterpreter, @nospecialize(itft), @nospecialize(itertype), sv::InferenceState)
if !isdefined(Main, :Base) || !isdefined(Main.Base, :iterate) || !isconst(Main.Base, :iterate)
return Any[Vararg{Any}], nothing
end
Expand All @@ -576,7 +576,7 @@ function abstract_iteration(interp::AbstractInterpreter, @nospecialize(itft), @n
return Any[Vararg{Any}], nothing
end
@assert !isvarargtype(itertype)
call = abstract_call_known(interp, iteratef, nothing, Any[itft, itertype], vtypes, sv)
call = abstract_call_known(interp, iteratef, nothing, Any[itft, itertype], sv)
stateordonet = call.rt
info = call.info
# Return Bottom if this is not an iterator.
Expand Down Expand Up @@ -609,7 +609,7 @@ function abstract_iteration(interp::AbstractInterpreter, @nospecialize(itft), @n
valtype = getfield_tfunc(stateordonet, Const(1))
push!(ret, valtype)
statetype = nstatetype
call = abstract_call_known(interp, iteratef, nothing, Any[Const(iteratef), itertype, statetype], vtypes, sv)
call = abstract_call_known(interp, iteratef, nothing, Any[Const(iteratef), itertype, statetype], sv)
stateordonet = call.rt
push!(calls, call)
end
Expand All @@ -618,7 +618,7 @@ function abstract_iteration(interp::AbstractInterpreter, @nospecialize(itft), @n
statetype = widenconst(statetype)
valtype = widenconst(valtype)
while valtype !== Any
stateordonet = abstract_call_known(interp, iteratef, nothing, Any[Const(iteratef), itertype, statetype], vtypes, sv).rt
stateordonet = abstract_call_known(interp, iteratef, nothing, Any[Const(iteratef), itertype, statetype], sv).rt
stateordonet = widenconst(stateordonet)
nounion = typesubtract(stateordonet, Nothing)
if !isa(nounion, DataType) || !(nounion <: Tuple) || isvatuple(nounion) || length(nounion.parameters) != 2
Expand All @@ -640,7 +640,7 @@ function abstract_iteration(interp::AbstractInterpreter, @nospecialize(itft), @n
end

# do apply(af, fargs...), where af is a function value
function abstract_apply(interp::AbstractInterpreter, @nospecialize(itft), @nospecialize(aft), aargtypes::Vector{Any}, vtypes::VarTable, sv::InferenceState,
function abstract_apply(interp::AbstractInterpreter, @nospecialize(itft), @nospecialize(aft), aargtypes::Vector{Any}, sv::InferenceState,
max_methods::Int = InferenceParams(interp).MAX_METHODS)
aftw = widenconst(aft)
if !isa(aft, Const) && (!isType(aftw) || has_free_typevars(aftw))
Expand All @@ -661,9 +661,9 @@ function abstract_apply(interp::AbstractInterpreter, @nospecialize(itft), @nospe
infos′ = []
for ti in (splitunions ? uniontypes(aargtypes[i]) : Any[aargtypes[i]])
if !isvarargtype(ti)
cti, info = precise_container_type(interp, itft, ti, vtypes, sv)
cti, info = precise_container_type(interp, itft, ti, sv)
else
cti, info = precise_container_type(interp, itft, unwrapva(ti), vtypes, sv)
cti, info = precise_container_type(interp, itft, unwrapva(ti), sv)
# We can't represent a repeating sequence of the same types,
# so tmerge everything together to get one type that represents
# everything.
Expand Down Expand Up @@ -711,7 +711,7 @@ function abstract_apply(interp::AbstractInterpreter, @nospecialize(itft), @nospe
break
end
end
call = abstract_call(interp, nothing, ct, vtypes, sv, max_methods)
call = abstract_call(interp, nothing, ct, sv, max_methods)
push!(retinfos, ApplyCallInfo(call.info, arginfo))
res = tmerge(res, call.rt)
if res === Any
Expand Down Expand Up @@ -774,7 +774,7 @@ function argtype_tail(argtypes::Vector{Any}, i::Int)
end

function abstract_call_builtin(interp::AbstractInterpreter, f::Builtin, fargs::Union{Nothing,Vector{Any}},
argtypes::Vector{Any}, vtypes::VarTable, sv::InferenceState, max_methods::Int)
argtypes::Vector{Any}, sv::InferenceState, max_methods::Int)
la = length(argtypes)
if f === ifelse && fargs isa Vector{Any} && la == 4 && argtypes[2] isa Conditional
# try to simulate this as a real conditional (`cnd ? x : y`), so that the penalty for using `ifelse` instead isn't too high
Expand All @@ -793,7 +793,7 @@ function abstract_call_builtin(interp::AbstractInterpreter, f::Builtin, fargs::U
end
rt = builtin_tfunction(interp, f, argtypes[2:end], sv)
if f === getfield && isa(fargs, Vector{Any}) && la == 3 && isa(argtypes[3], Const) && isa(argtypes[3].val, Int) && argtypes[2] Tuple
cti, _ = precise_container_type(interp, nothing, argtypes[2], vtypes, sv)
cti, _ = precise_container_type(interp, nothing, argtypes[2], sv)
idx = argtypes[3].val
if 1 <= idx <= length(cti)
rt = unwrapva(cti[idx])
Expand Down Expand Up @@ -905,7 +905,7 @@ end
# call where the function is known exactly
function abstract_call_known(interp::AbstractInterpreter, @nospecialize(f),
fargs::Union{Nothing,Vector{Any}}, argtypes::Vector{Any},
vtypes::VarTable, sv::InferenceState,
sv::InferenceState,
max_methods::Int = InferenceParams(interp).MAX_METHODS)

la = length(argtypes)
Expand All @@ -914,14 +914,14 @@ function abstract_call_known(interp::AbstractInterpreter, @nospecialize(f),
if f === _apply
ft = argtype_by_index(argtypes, 2)
ft === Bottom && return CallMeta(Bottom, false)
return abstract_apply(interp, nothing, ft, argtype_tail(argtypes, 3), vtypes, sv, max_methods)
return abstract_apply(interp, nothing, ft, argtype_tail(argtypes, 3), sv, max_methods)
elseif f === _apply_iterate
itft = argtype_by_index(argtypes, 2)
ft = argtype_by_index(argtypes, 3)
(itft === Bottom || ft === Bottom) && return CallMeta(Bottom, false)
return abstract_apply(interp, itft, ft, argtype_tail(argtypes, 4), vtypes, sv, max_methods)
return abstract_apply(interp, itft, ft, argtype_tail(argtypes, 4), sv, max_methods)
end
return CallMeta(abstract_call_builtin(interp, f, fargs, argtypes, vtypes, sv, max_methods), nothing)
return CallMeta(abstract_call_builtin(interp, f, fargs, argtypes, sv, max_methods), nothing)
elseif f === Core.kwfunc
if la == 2
ft = widenconst(argtypes[2])
Expand Down Expand Up @@ -949,7 +949,7 @@ function abstract_call_known(interp::AbstractInterpreter, @nospecialize(f),
elseif f === Tuple && la == 2 && !isconcretetype(widenconst(argtypes[2]))
return CallMeta(Tuple, false)
elseif is_return_type(f)
rt_rt = return_type_tfunc(interp, argtypes, vtypes, sv)
rt_rt = return_type_tfunc(interp, argtypes, sv)
if rt_rt !== nothing
return CallMeta(rt_rt, nothing)
end
Expand All @@ -963,7 +963,7 @@ function abstract_call_known(interp::AbstractInterpreter, @nospecialize(f),
end
elseif la == 3 && istopfunction(f, :!==)
# mark !== as exactly a negated call to ===
rty = abstract_call_known(interp, (===), fargs, argtypes, vtypes, sv).rt
rty = abstract_call_known(interp, (===), fargs, argtypes, sv).rt
if isa(rty, Conditional)
return CallMeta(Conditional(rty.var, rty.elsetype, rty.vtype), nothing) # swap if-else
elseif isa(rty, Const)
Expand All @@ -979,7 +979,7 @@ function abstract_call_known(interp::AbstractInterpreter, @nospecialize(f),
fargs = nothing
end
argtypes = Any[typeof(<:), argtypes[3], argtypes[2]]
return CallMeta(abstract_call_known(interp, <:, fargs, argtypes, vtypes, sv).rt, false)
return CallMeta(abstract_call_known(interp, <:, fargs, argtypes, sv).rt, false)
elseif la == 2 && isa(argtypes[2], Const) && isa(argtypes[2].val, SimpleVector) && istopfunction(f, :length)
# mark length(::SimpleVector) as @pure
return CallMeta(Const(length(argtypes[2].val)), false)
Expand All @@ -1005,7 +1005,7 @@ end

# call where the function is any lattice element
function abstract_call(interp::AbstractInterpreter, fargs::Union{Nothing,Vector{Any}}, argtypes::Vector{Any},
vtypes::VarTable, sv::InferenceState, max_methods::Int = InferenceParams(interp).MAX_METHODS)
sv::InferenceState, max_methods::Int = InferenceParams(interp).MAX_METHODS)
#print("call ", e.args[1], argtypes, "\n\n")
ft = argtypes[1]
if isa(ft, Const)
Expand All @@ -1023,7 +1023,7 @@ function abstract_call(interp::AbstractInterpreter, fargs::Union{Nothing,Vector{
end
return abstract_call_gf_by_type(interp, nothing, argtypes, argtypes_to_type(argtypes), sv, max_methods)
end
return abstract_call_known(interp, f, fargs, argtypes, vtypes, sv, max_methods)
return abstract_call_known(interp, f, fargs, argtypes, sv, max_methods)
end

function sp_type_rewrap(@nospecialize(T), linfo::MethodInstance, isreturn::Bool)
Expand Down Expand Up @@ -1072,7 +1072,7 @@ function abstract_eval_cfunction(interp::AbstractInterpreter, e::Expr, vtypes::V
# this may be the wrong world for the call,
# but some of the result is likely to be valid anyways
# and that may help generate better codegen
abstract_call(interp, nothing, at, vtypes, sv)
abstract_call(interp, nothing, at, sv)
nothing
end

Expand Down Expand Up @@ -1129,7 +1129,7 @@ function abstract_eval_statement(interp::AbstractInterpreter, @nospecialize(e),
end
argtypes[i] = ai
end
callinfo = abstract_call(interp, ea, argtypes, vtypes, sv)
callinfo = abstract_call(interp, ea, argtypes, sv)
sv.stmt_info[sv.currpc] = callinfo.info
t = callinfo.rt
elseif e.head === :new
Expand Down
4 changes: 2 additions & 2 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,7 @@ end
# TODO: this function is a very buggy and poor model of the return_type function
# since abstract_call_gf_by_type is a very inaccurate model of _method and of typeinf_type,
# while this assumes that it is an absolutely precise and accurate and exact model of both
function return_type_tfunc(interp::AbstractInterpreter, argtypes::Vector{Any}, vtypes::VarTable, sv::InferenceState)
function return_type_tfunc(interp::AbstractInterpreter, argtypes::Vector{Any}, sv::InferenceState)
if length(argtypes) == 3
tt = argtypes[3]
if isa(tt, Const) || (isType(tt) && !has_free_typevars(tt))
Expand All @@ -1564,7 +1564,7 @@ function return_type_tfunc(interp::AbstractInterpreter, argtypes::Vector{Any}, v
if contains_is(argtypes_vec, Union{})
return Const(Union{})
end
rt = abstract_call(interp, nothing, argtypes_vec, vtypes, sv, -1).rt
rt = abstract_call(interp, nothing, argtypes_vec, sv, -1).rt
if isa(rt, Const)
# output was computed to be constant
return Const(typeof(rt.val))
Expand Down

0 comments on commit 8554a21

Please sign in to comment.