Skip to content

Improve inference of tail-like functions #29264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,21 @@ function abstract_call_method_with_const_args(@nospecialize(f), argtypes::Vector
atypes = get_argtypes(inf_result)
if method.isva
vargs = argtypes[(nargs + 1):end]
all_vargs_const = true
for i in 1:length(vargs)
a = maybe_widen_conditional(vargs[i])
all_vargs_const &= a isa Const
if i > length(inf_result.vargs)
push!(inf_result.vargs, a)
elseif a isa Const
inf_result.vargs[i] = a
end
end
# If all vargs are const, the result may be a constant
# tuple. If so, we should make sure to treat it as such
if all_vargs_const
atypes[nargs + 1] = builtin_tfunction(tuple, inf_result.vargs, sv)
end
end
for i in 1:nargs
a = maybe_widen_conditional(argtypes[i])
Expand Down
7 changes: 7 additions & 0 deletions test/compiler/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2030,3 +2030,10 @@ get_order_kwargs(; by = identity, func = isless, rev = false) = get_order(by, fu
# test that this doesn't cause an internal error
get_order_kwargs()
end

# Test that tail-like functions don't block constant propagation
my_tail_const_prop(i, tail...) = tail
function foo_tail_const_prop()
Val{my_tail_const_prop(1,2,3,4)}()
end
@test (@inferred foo_tail_const_prop()) == Val{(2,3,4)}()