Skip to content

Commit

Permalink
Improve inference of tail-like functions (#29264)
Browse files Browse the repository at this point in the history
Previously these sorts of function would block constant propagation.
Hopfully #28955 will just fix this, but until then, add a surgical
fix and a test.
  • Loading branch information
Keno authored Sep 19, 2018
1 parent 5105977 commit d28a7d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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)}()

0 comments on commit d28a7d5

Please sign in to comment.