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

adjusts to the latest master #412

Merged
merged 3 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 6 additions & 2 deletions src/codeview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,12 @@ function InteractiveUtils.code_typed(b::Bookmark; optimize::Bool=true)
(; src, rt, codeinf) = lookup(interp, mi, optimize)
src = preprocess_ci!(src, mi, optimize, CONFIG)
if src isa IRCode
nargs = Int((mi.def::Method).nargs) - 1
CC.replace_code_newstyle!(codeinf, src, nargs)
@static if VERSION ≥ v"1.10.0-DEV.870"
CC.replace_code_newstyle!(codeinf, src)
else
nargs = Int((mi.def::Method).nargs) - 1
CC.replace_code_newstyle!(codeinf, src, nargs)
end
end
return codeinf => rt
end
Expand Down
8 changes: 7 additions & 1 deletion src/interpreter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,14 @@ end
function CC.finish(state::InferenceState, interp::CthulhuInterpreter)
res = @invoke CC.finish(state::InferenceState, interp::AbstractInterpreter)
key = CC.any(state.result.overridden_by_const) ? state.result : state.linfo
unoptsrc = copy(state.src)
unoptsrc.slotnames = copy(unoptsrc.slotnames)
unoptsrc.slottypes = let slottypes = unoptsrc.slottypes
slottypes === nothing ? nothing : copy(unoptsrc.slottypes)
end
unoptsrc.slotflags = copy(unoptsrc.slotflags)
interp.unopt[key] = InferredSource(
copy(state.src),
unoptsrc,
copy(state.stmt_info),
isdefined(CC, :Effects) ? state.ipo_effects : nothing,
state.result.result)
Expand Down
6 changes: 5 additions & 1 deletion src/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,11 @@ function preprocess_ci!(ci::CodeInfo, mi::MethodInstance, optimize, config::Cthu
end
ir = CC.inflate_ir(ci, sptypes_from_meth_instance(mi), argtypes)
ir = dce!(ir)
ci = CC.replace_code_newstyle!(ci, ir, length(argtypes)-1)
@static if VERSION ≥ v"1.10.0-DEV.870"
ci = CC.replace_code_newstyle!(ci, ir)
else
ci = CC.replace_code_newstyle!(ci, ir, length(argtypes)-1)
end
end
return ci
end
Expand Down
22 changes: 16 additions & 6 deletions test/test_Cthulhu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ function empty_func(::Bool) end
anykwargs(a; kwargs...) = println(a, " keyword args: ", kwargs...)
hasdefaultargs(a, b=2) = a + b

function first_specialization(m::Method)
specs = m.specializations
if specs isa Core.MethodInstance
return specs
elseif specs isa Core.SimpleVector
return specs[1]::Core.MethodInstance
aviatesk marked this conversation as resolved.
Show resolved Hide resolved
else
throw((m, specs))
end
end

@testset "Callsites" begin
callsites = find_callsites_by_ftt(testf_simple)
@test length(callsites) >= 4
Expand Down Expand Up @@ -53,7 +64,7 @@ hasdefaultargs(a, b=2) = a + b

# Callsite handling in source-view mode: for kwarg functions, strip the body, and use "typed" callsites
for m in (@which(anykwargs("animals")), @which(anykwargs("animals"; cat=1, dog=2)))
mi = m.specializations[1]
mi = first_specialization(m)
src, rt = Cthulhu.TypedSyntax.getsrc(mi)
tsn, mappings = Cthulhu.get_typed_sourcetext(mi, src, rt; warn=false)
str = sprint(printstyled, tsn)
Expand All @@ -62,15 +73,15 @@ hasdefaultargs(a, b=2) = a + b
end
# Likewise for methods that fill in default positional arguments
m = @which hasdefaultargs(1)
mi = m.specializations[1]
mi = first_specialization(m)
src, rt = Cthulhu.TypedSyntax.getsrc(mi)
tsn, mappings = Cthulhu.get_typed_sourcetext(mi, src, rt; warn=false)
str = sprint(printstyled, tsn)
@test occursin("hasdefaultargs(a, b=2)", str)
@test !occursin("a + b", str)
@test isempty(mappings)
m = @which hasdefaultargs(1, 5)
mi = m.specializations[1]
mi = first_specialization(m)
src, rt = Cthulhu.TypedSyntax.getsrc(mi)
tsn, mappings = Cthulhu.get_typed_sourcetext(mi, src, rt; warn=false)
str = sprint(printstyled, tsn)
Expand Down Expand Up @@ -699,8 +710,7 @@ fst5(x) = fst4(x)
@testset "backedges and treelist" begin
@test fbackedge2(0.2) == 1
@test fbackedge2(-0.2) == -1
mspec = @which(fbackedge1()).specializations
mi = isa(mspec, Core.SimpleVector) ? mspec[1] : mspec.func
mi = first_specialization(@which(fbackedge1()))
root = Cthulhu.treelist(mi)
@test Cthulhu.count_open_leaves(root) == 2
@test root.data.callstr == "fbackedge1()"
Expand All @@ -709,7 +719,7 @@ fst5(x) = fst4(x)
# issue #114
unspecva(@nospecialize(i::Int...)) = 1
@test unspecva(1, 2) == 1
mi = something(first(methods(unspecva)).specializations...)
mi = first_specialization(only(methods(unspecva)))
root = Cthulhu.treelist(mi)
@test occursin("Vararg", root.data.callstr)

Expand Down