Skip to content
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

Fix inlining's rewrite of _apply atypes #29324

Merged
merged 1 commit into from
Sep 24, 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
20 changes: 13 additions & 7 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -593,14 +593,20 @@ function rewrite_apply_exprargs!(ir::IRCode, idx::Int, argexprs::Vector{Any}, at
def_atypes = sv.result_vargs
else
def_atypes = Any[]
for p in widenconst(atypes[i]).parameters
if isa(p, DataType) && isdefined(p, :instance)
# replace singleton types with their equivalent Const object
p = Const(p.instance)
elseif isconstType(p)
p = Const(p.parameters[1])
if isa(atypes[i], Const)
for p in atypes[i].val
push!(def_atypes, Const(p))
end
else
for p in widenconst(atypes[i]).parameters
if isa(p, DataType) && isdefined(p, :instance)
# replace singleton types with their equivalent Const object
p = Const(p.instance)
elseif isconstType(p)
p = Const(p.parameters[1])
end
push!(def_atypes, p)
end
push!(def_atypes, p)
end
end
# now push flattened types into new_atypes and getfield exprs into new_argexprs
Expand Down
37 changes: 37 additions & 0 deletions test/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,40 @@ function f_ifelse(x)
end
# 2 for now because the compiler leaves a GotoNode around
@test_broken length(code_typed(f_ifelse, (String,))[1][1].code) <= 2

# Test that inlining of _apply properly hits the inference cache
@noinline cprop_inline_foo1() = (1, 1)
@noinline cprop_inline_foo2() = (2, 2)
function cprop_inline_bar(x...)
if x === (1, 1, 1, 1)
return x
else
# What you put here doesn't really matter,
# the point is to prevent inlining when
# x is not known to be (1, 1, 1, 1)
println(stdout, "Hello")
println(stdout, "World")
println(stdout, "Hello")
println(stdout, "World")
println(stdout, "Hello")
println(stdout, "World")
println(stdout, "Hello")
println(stdout, "World")
println(stdout, "Hello")
println(stdout, "World")
println(stdout, "Hello")
println(stdout, "World")
return x
end
x
end

function cprop_inline_baz1()
return cprop_inline_bar(cprop_inline_foo1()..., cprop_inline_foo1()...)
end
@test length(code_typed(cprop_inline_baz1, ())[1][1].code) == 1

function cprop_inline_baz2()
return cprop_inline_bar(cprop_inline_foo2()..., cprop_inline_foo2()...)
end
@test length(code_typed(cprop_inline_baz2, ())[1][1].code) == 2