Skip to content

Commit

Permalink
attempt to fix vararg type caching when there are constraints on vara…
Browse files Browse the repository at this point in the history
…rg length
  • Loading branch information
jrevels committed Apr 18, 2018
1 parent 6eb27fd commit 9d620dc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 8 additions & 5 deletions base/compiler/inferenceresult.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,19 @@ function get_argtypes(result::InferenceResult)
if nargs > laty
va = atypes[laty]
if isvarargtype(va)
# assumes that we should never see Vararg{T, x}, where x is a constant (should be guaranteed by construction)
va = rewrap_unionall(va, linfo.specTypes)
vararg_type_vec = Any[va]
vararg_type = Tuple{va}
new_va = rewrap_unionall(unconstrain_vararg_length(va), linfo.specTypes)
vararg_type_vec = Any[new_va]
vararg_type = Tuple{new_va}
else
vararg_type_vec = Any[]
vararg_type = Tuple{}
end
else
vararg_type_vec = Any[rewrap_unionall(p, linfo.specTypes) for p in atypes[nargs:laty]]
vararg_type_vec = Any[]
for p in atypes[nargs:laty]
p = isvarargtype(p) ? unconstrain_vararg_length(p) : p
push!(vararg_type_vec, rewrap_unionall(p, linfo.specTypes))
end
vararg_type = tuple_tfunc(Tuple{vararg_type_vec...})
for i in 1:length(vararg_type_vec)
atyp = vararg_type_vec[i]
Expand Down
8 changes: 8 additions & 0 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ function unwrapva(@nospecialize(t))
isvarargtype(t2) ? rewrap_unionall(t2.parameters[1],t) : t
end

function unconstrain_vararg_length(@nospecialize(va))
# construct a new Vararg type where its length is unconstrained,
# but its element type still captures any dependencies the input
# element type may have had on the input length
T = unwrap_unionall(va).parameters[1]
return rewrap_unionall(Vararg{T}, va)
end

typename(a) = error("typename does not apply to this type")
typename(a::DataType) = a.name
function typename(a::Union)
Expand Down

0 comments on commit 9d620dc

Please sign in to comment.