Skip to content

follow up #137, remove duplicated non-constant callsites #139

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
Apr 2, 2021
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
15 changes: 8 additions & 7 deletions src/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ function find_callsites(CI::Union{Core.CodeInfo, IRCode}, stmt_info::Union{Vecto
# we ignore any implicit iterate calls.
return process_info(info.call)
elseif isa(info, ConstCallInfo)
if length(info.results) == 1
result = info.results[1]
return [ConstPropCallInfo(MICallInfo(result.linfo, rt), result)]
else
vcat(process_info(info.call),
map(result->ConstPropCallInfo(MICallInfo(result.linfo, rt), result),
filter(!isnothing, info.results)))
infos = process_info(info.call)
@assert length(infos) == length(info.results)
return map(enumerate(info.results)) do (i, result)
if isnothing(result)
infos[i]
else
ConstPropCallInfo(MICallInfo(result.linfo, rt), result)
end
end
elseif isdefined(Compiler, :OpaqueClosureCallInfo) && isa(info, Compiler.OpaqueClosureCallInfo)
return [OCCallInfo(Core.Compiler.specialize_method(info.match), rt)]
Expand Down
49 changes: 49 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,55 @@ let callsites = find_callsites_by_ftt(f_matches, Tuple{Any, Any}; optimize=false
@test callinfo isa Cthulhu.MultiCallInfo
end

@testset "union-split constant-prop'ed callsites" begin
anonymous_module() = Core.eval(@__MODULE__, :(module $(gensym()) end))::Module

# constant prop' on all the splits
let callsites = (@eval anonymous_module() begin
struct F32
val::Float32
_v::Int
end
struct F64
val::Float64
_v::Int
end

$find_callsites_by_ftt((Union{F32,F64},); optimize = false) do f
f.val
end
end)
@test length(callsites) == 1
callinfo = callsites[1].info
@test isa(callinfo, Cthulhu.MultiCallInfo)
callinfos = callinfo.callinfos
@test length(callinfos) == 2
@test all(ci->isa(ci, Cthulhu.ConstPropCallInfo), callinfos)
end

# successful and unsuccessful constant prop'
let callsites = (@eval anonymous_module() begin
struct F32
val::Float32
_v::Int
end
struct FZero end
Base.getproperty(::FZero, ::Symbol) = 0.0 # constant prop' won't happen here

$find_callsites_by_ftt((Union{F32,FZero},); optimize = false) do f
f.val
end
end)
@test length(callsites) == 1
callinfo = callsites[1].info
@test isa(callinfo, Cthulhu.MultiCallInfo)
callinfos = callinfo.callinfos
@test length(callinfos) == 2
@test count(ci->isa(ci, Cthulhu.MICallInfo), callinfos) == 1
@test count(ci->isa(ci, Cthulhu.ConstPropCallInfo), callinfos) == 1
end
end

# Failed return_type
only_ints(::Integer) = 1
return_type_failure(::T) where T = Base._return_type(only_ints, Tuple{T})
Expand Down