Skip to content

Commit

Permalink
inference: remove ability to infer (svec(a, b, c)...) (#29935)
Browse files Browse the repository at this point in the history
It seems unlikely that this code pattern is used anywhere, and it is the last instance of this inference hack
we have remaining (after the PartialTuple work). If some package does end up needing it,
we can reimplement it (via adding PartialSimpleVector), but I strongly suspect this is effectively dead-code,
and thus not worthwhile to maintain.
  • Loading branch information
vtjnash authored Nov 13, 2018
1 parent 96ce5ba commit b4d8795
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 33 deletions.
25 changes: 8 additions & 17 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,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(@nospecialize(arg), @nospecialize(typ), vtypes::VarTable, sv::InferenceState)
function precise_container_type(@nospecialize(typ), vtypes::VarTable, sv::InferenceState)
if isa(typ, PartialTuple)
return typ.fields
end
Expand All @@ -393,19 +393,11 @@ function precise_container_type(@nospecialize(arg), @nospecialize(typ), vtypes::
end
end

arg = ssa_def_expr(arg, sv)
tti0 = widenconst(typ)
tti = unwrap_unionall(tti0)
if isa(arg, Expr) && arg.head === :call && abstract_evals_to_constant(arg.args[1], svec, vtypes, sv)
aa = arg.args
result = Any[ abstract_eval(aa[j],vtypes,sv) for j=2:length(aa) ]
if _any(isvarargtype, result)
return Any[Vararg{Any}]
end
return result
elseif isa(tti, Union)
if isa(tti, Union)
utis = uniontypes(tti)
if _any(t -> !isa(t,DataType) || !(t <: Tuple) || !isknownlength(t), utis)
if _any(t -> !isa(t, DataType) || !(t <: Tuple) || !isknownlength(t), utis)
return Any[Vararg{Any}]
end
result = Any[rewrap_unionall(p, tti0) for p in utis[1].parameters]
Expand All @@ -418,7 +410,7 @@ function precise_container_type(@nospecialize(arg), @nospecialize(typ), vtypes::
end
end
return result
elseif isa(tti0,DataType) && tti0 <: Tuple
elseif isa(tti0, DataType) && tti0 <: Tuple
if isvatuple(tti0) && length(tti0.parameters) == 1
return Any[Vararg{unwrapva(tti0.parameters[1])}]
else
Expand Down Expand Up @@ -481,7 +473,7 @@ function abstract_iteration(@nospecialize(itertype), vtypes::VarTable, sv::Infer
end

# do apply(af, fargs...), where af is a function value
function abstract_apply(@nospecialize(aft), fargs::Union{Tuple{},Vector{Any}}, aargtypes::Vector{Any}, vtypes::VarTable, sv::InferenceState)
function abstract_apply(@nospecialize(aft), aargtypes::Vector{Any}, vtypes::VarTable, sv::InferenceState)
if !isa(aft, Const) && (!isType(aft) || has_free_typevars(aft))
if !isconcretetype(aft) || (aft <: Builtin)
# non-constant function of unknown type: bail now,
Expand All @@ -492,13 +484,12 @@ function abstract_apply(@nospecialize(aft), fargs::Union{Tuple{},Vector{Any}}, a
end
res = Union{}
nargs = length(aargtypes)
@assert fargs === () || nargs == length(fargs)
splitunions = 1 < countunionsplit(aargtypes) <= sv.params.MAX_APPLY_UNION_ENUM
ctypes = Any[Any[aft]]
for i = 1:nargs
ctypes´ = []
for ti in (splitunions ? uniontypes(aargtypes[i]) : Any[aargtypes[i]])
cti = precise_container_type(fargs === () ? nothing : fargs[i], ti, vtypes, sv)
cti = precise_container_type(ti, vtypes, sv)
if _any(t -> t === Bottom, cti)
continue
end
Expand Down Expand Up @@ -563,7 +554,7 @@ end

function abstract_call(@nospecialize(f), fargs::Union{Tuple{},Vector{Any}}, argtypes::Vector{Any}, vtypes::VarTable, sv::InferenceState)
if f === _apply
return abstract_apply(argtypes[2], fargs[3:end], argtypes[3:end], vtypes, sv)
return abstract_apply(argtypes[2], argtypes[3:end], vtypes, sv)
end

la = length(argtypes)
Expand Down Expand Up @@ -591,7 +582,7 @@ function abstract_call(@nospecialize(f), fargs::Union{Tuple{},Vector{Any}}, argt
end
rt = builtin_tfunction(f, argtypes[2:end], sv)
if f === getfield && isa(fargs, Vector{Any}) && length(argtypes) == 3 && isa(argtypes[3], Const) && isa(argtypes[3].val, Int) && argtypes[2] Tuple
cti = precise_container_type(fargs[2], argtypes[2], vtypes, sv)
cti = precise_container_type(argtypes[2], vtypes, sv)
idx = argtypes[3].val
if 1 <= idx <= length(cti)
rt = unwrapva(cti[idx])
Expand Down
16 changes: 0 additions & 16 deletions test/compiler/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -960,22 +960,6 @@ f21653() = f21653()
@test code_typed(f21653, Tuple{}, optimize=false)[1] isa Pair{CodeInfo, typeof(Union{})}
@test which(f21653, ()).specializations.func.rettype === Union{}

# ensure _apply can "see-through" SSAValue to infer precise container types
let f, m
f() = 0
m = first(methods(f))
m.source = Base.uncompressed_ast(m)::CodeInfo
m.source.code = Any[
Expr(:call, GlobalRef(Core, :svec), 1, 2, 3),
Expr(:call, Core._apply, GlobalRef(Base, :+), SSAValue(1)),
Expr(:return, SSAValue(2))
]
nstmts = length(m.source.code)
m.source.ssavaluetypes = nstmts
m.source.codelocs = fill(Int32(1), nstmts)
@test @inferred(f()) == 6
end

# issue #22290
f22290() = return 3
for i in 1:3
Expand Down

0 comments on commit b4d8795

Please sign in to comment.