Skip to content

Commit

Permalink
Fix #36531 - Error in abstract_iteration
Browse files Browse the repository at this point in the history
The issue here is passing a `Vargarg` to `precise_container_type`, which
doesn't really make sense. Instead, we need to have the caller unwrap
the vararg, request the precise container type of the inner type and
then re-wrap the answer in a vararg.
  • Loading branch information
Keno committed Jul 6, 2020
1 parent 6cd329c commit 65aeffd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
18 changes: 17 additions & 1 deletion base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ function abstract_iteration(interp::AbstractInterpreter, @nospecialize(itft), @n
else
return Any[Vararg{Any}]
end
@assert !isvarargtype(itertype)
stateordonet = abstract_call_known(interp, iteratef, nothing, Any[itft, itertype], vtypes, sv)
# Return Bottom if this is not an iterator.
# WARNING: Changes to the iteration protocol must be reflected here,
Expand Down Expand Up @@ -612,7 +613,22 @@ function abstract_apply(interp::AbstractInterpreter, @nospecialize(itft), @nospe
for i = 1:nargs
ctypes´ = []
for ti in (splitunions ? uniontypes(aargtypes[i]) : Any[aargtypes[i]])
cti = precise_container_type(interp, itft, ti, vtypes, sv)
if !isvarargtype(ti)
cti = precise_container_type(interp, itft, ti, vtypes, sv)
else
cti = precise_container_type(interp, itft, unwrapva(ti), vtypes, sv)
# We can't represent a repeating sequence of the same types,
# so tmerge everything together to get one type that represents
# everything.
argt = cti[end]
if isvarargtype(argt)
argt = unwrapva(argt)
end
for i in 1:(length(cti)-1)
argt = tmerge(argt, cti[i])
end
cti = Any[Vararg{argt}]
end
if _any(t -> t === Bottom, cti)
continue
end
Expand Down
5 changes: 5 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2660,3 +2660,8 @@ function symcmp36230(vec)
return false
end
@test Base.return_types(symcmp36230, (Vector{Any},)) == Any[Bool]

# Issue #36531, double varargs in abstract_iteration
f36531(args...) = tuple((args...)...)
@test @inferred(f36531(1,2,3)) == (1,2,3)
@test code_typed(f36531, Tuple{Vararg{Int}}) isa Vector

0 comments on commit 65aeffd

Please sign in to comment.