Skip to content

Commit

Permalink
use CC.cached_return_type if available
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Nov 20, 2023
1 parent 5bd7b20 commit 602d3a0
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/Cthulhu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,23 +234,24 @@ const descend = descend_code_typed
descend_code_typed(interp::AbstractInterpreter, mi::MethodInstance; kwargs...) =
_descend_with_error_handling(interp, mi; iswarn=false, kwargs...)

function codeinst_rt(code::CodeInstance)
@static if VERSION v"1.11.0-DEV.207"
using .CC: cached_return_type
else
function cached_return_type(code::CodeInstance)
rettype = code.rettype
if isdefined(code, :rettype_const)
rettype_const = code.rettype_const
if isa(rettype_const, Vector{Any}) && !(Vector{Any} <: rettype)
return Core.PartialStruct(rettype, rettype_const)
elseif isa(rettype_const, Core.PartialOpaque) && rettype <: Core.OpaqueClosure
return rettype_const
elseif isa(rettype_const, CC.InterConditional) && !(CC.InterConditional <: rettype)
return rettype_const
else
return Const(rettype_const)
end
isdefined(code, :rettype_const) || return rettype
rettype_const = code.rettype_const
if isa(rettype_const, Vector{Any}) && !(Vector{Any} <: rettype)
return Core.PartialStruct(rettype, rettype_const)
elseif isa(rettype_const, Core.PartialOpaque) && rettype <: Core.OpaqueClosure
return rettype_const
elseif isa(rettype_const, CC.InterConditional) && !(CC.InterConditional <: rettype)
return rettype_const
else
return rettype
return Const(rettype_const)
end
end
end

get_effects(codeinst::CodeInstance) = CC.decode_effects(codeinst.ipo_purity_bits)
get_effects(codeinst::CodeInfo) = CC.decode_effects(codeinst.purity)
Expand All @@ -277,7 +278,7 @@ end

function lookup_optimized(interp::CthulhuInterpreter, mi::MethodInstance, allow_no_src::Bool=false)
codeinst = interp.opt[mi]
rt = codeinst_rt(codeinst)
rt = cached_return_type(codeinst)
opt = codeinst.inferred
if opt !== nothing
opt = opt::OptimizedSource
Expand Down

0 comments on commit 602d3a0

Please sign in to comment.