Skip to content

Commit

Permalink
Merge pull request #591 from JuliaDebug/sds/fix_586
Browse files Browse the repository at this point in the history
adapt to julia nightly changes
  • Loading branch information
simeonschaub authored Sep 5, 2024
2 parents 709da5c + f083157 commit ba2b5d3
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 70 deletions.
7 changes: 6 additions & 1 deletion TypedSyntax/src/node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,12 @@ function code_typed1_by_method_instance(mi::MethodInstance;
(ccall(:jl_is_in_pure_context, Bool, ()) || world == typemax(UInt)) &&
error("code reflection should not be used from generated functions")
debuginfo = Base.IRShow.debuginfo(debuginfo)
code, rt = Core.Compiler.typeinf_code(interp, mi.def::Method, mi.specTypes, mi.sparam_vals, optimize)
@static if VERSION < v"1.12.0-DEV.669"
code, rt = Core.Compiler.typeinf_code(interp, mi.def::Method, mi.specTypes, mi.sparam_vals, optimize)
else
code = Core.Compiler.typeinf_code(interp, mi.def::Method, mi.specTypes, mi.sparam_vals, optimize)
rt = code.rettype
end
code isa CodeInfo || error("no code is available for ", mi)
debuginfo === :none && Base.remove_linenums!(code)
return Pair{CodeInfo,Any}(code, rt)
Expand Down
13 changes: 11 additions & 2 deletions src/Cthulhu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,12 @@ function _descend(term::AbstractTerminal, interp::AbstractInterpreter, curs::Abs
view_cmd = CODEVIEWS[toggle]
world = get_inference_world(interp)
println(iostream)
view_cmd(iostream, mi, optimize, debuginfo, world, CONFIG)
@static if VERSION < v"1.12.0-DEV.669"
view_cmd(iostream, mi, optimize, debuginfo, world, CONFIG)
else
src = Core.Compiler.typeinf_code(interp, mi, true)
view_cmd(iostream, mi, src, optimize, debuginfo, world, CONFIG)
end
display_CI = false
else
local i = findfirst(ct->ct.toggle === toggle, custom_toggles)
Expand Down Expand Up @@ -828,10 +833,14 @@ end

function do_typeinf!(interp::AbstractInterpreter, mi::MethodInstance)
result = InferenceResult(mi)
@static if isdefined(CC, :engine_reserve)
ci = CC.engine_reserve(interp, mi)
result.ci = ci
end
# we may want to handle the case when `InferenceState(...)` returns `nothing`,
# which indicates code generation of a `@generated` has been failed,
# and show it in the UI in some way?
frame = InferenceState(result, #=cache=#:global, interp)::InferenceState
frame = InferenceState(result, #=cache_mode=#:global, interp)::InferenceState
CC.typeinf(interp, frame)
return nothing
end
Expand Down
206 changes: 145 additions & 61 deletions src/codeview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,68 @@ function highlight(io, x, lexer, config::CthulhuConfig)
end
end

function cthulhu_llvm(io::IO, mi, optimize::Bool, debuginfo, world::UInt,
config::CthulhuConfig, dump_module::Bool=false, raw::Bool=false)
dump = InteractiveUtils._dump_function_llvm(
mi, world,
#=wrapper=# false, !raw,
dump_module, optimize, debuginfo != DInfo.none ? :source : :none,
Base.CodegenParams())
highlight(io, dump, "llvm", config)
end

function cthulhu_native(io::IO, mi, ::Bool, debuginfo, world::UInt,
config::CthulhuConfig, dump_module::Bool=false, raw::Bool=false)
if dump_module
dump = InteractiveUtils._dump_function_native_assembly(
@static if VERSION < v"1.12.0-DEV.669"
function cthulhu_llvm(io::IO, mi, optimize::Bool, debuginfo, world::UInt,
config::CthulhuConfig, dump_module::Bool=false, raw::Bool=false)
dump = InteractiveUtils._dump_function_llvm(
mi, world,
#=wrapper=# false, #=syntax=# config.asm_syntax,
debuginfo != DInfo.none ? :source : :none,
#=binary=# false, raw,
#=wrapper=# false, !raw,
dump_module, optimize, debuginfo != DInfo.none ? :source : :none,
Base.CodegenParams())
else
dump = InteractiveUtils._dump_function_native_disassembly(
mi, world,
#=wrapper=# false, #=syntax=# config.asm_syntax,
debuginfo != DInfo.none ? :source : :none,
#=binary=# false)
highlight(io, dump, "llvm", config)
end

function cthulhu_native(io::IO, mi, ::Bool, debuginfo, world::UInt,
config::CthulhuConfig, dump_module::Bool=false, raw::Bool=false)
if dump_module
dump = InteractiveUtils._dump_function_native_assembly(
mi, world,
#=wrapper=# false, #=syntax=# config.asm_syntax,
debuginfo != DInfo.none ? :source : :none,
#=binary=# false, raw,
Base.CodegenParams())
else
dump = InteractiveUtils._dump_function_native_disassembly(
mi, world,
#=wrapper=# false, #=syntax=# config.asm_syntax,
debuginfo != DInfo.none ? :source : :none,
#=binary=# false)
end
highlight(io, dump, "asm", config)
end
else
function cthulhu_llvm(io::IO, mi, src::CodeInfo, optimize::Bool, debuginfo, world::UInt,
config::CthulhuConfig, dump_module::Bool=false, raw::Bool=false)
dump = InteractiveUtils._dump_function_llvm(
mi, src,
#=wrapper=# false, !raw,
dump_module, optimize, debuginfo != DInfo.none ? :source : :none,
Base.CodegenParams())
highlight(io, dump, "llvm", config)
end

function cthulhu_native(io::IO, mi, src::CodeInfo, ::Bool, debuginfo, world::UInt,
config::CthulhuConfig, dump_module::Bool=false, raw::Bool=false)
if dump_module
dump = InteractiveUtils._dump_function_native_assembly(
mi, src,
#=wrapper=# false, #=syntax=# config.asm_syntax,
debuginfo != DInfo.none ? :source : :none,
#=binary=# false, raw,
Base.CodegenParams())
else
dump = InteractiveUtils._dump_function_native_disassembly(
mi, world,
#=wrapper=# false, #=syntax=# config.asm_syntax,
debuginfo != DInfo.none ? :source : :none,
#=binary=# false)
end
highlight(io, dump, "asm", config)
end

function cthulhu_ast(io::IO, mi, ::CodeInfo, optimize::Bool, debuginfo, world::UInt, config::CthulhuConfig)
return cthulhu_ast(io, mi, optimize, debuginfo, world, config)
end
highlight(io, dump, "asm", config)
end

function cthulhu_ast(io::IO, mi, ::Bool, debuginfo, ::UInt, config::CthulhuConfig)
Expand Down Expand Up @@ -461,42 +496,91 @@ function InteractiveUtils.code_warntype(
end

InteractiveUtils.code_llvm(b::Bookmark; kw...) = InteractiveUtils.code_llvm(stdout::IO, b; kw...)
InteractiveUtils.code_llvm(
io::IO,
b::Bookmark;
optimize = true,
debuginfo = :source,
dump_module = false,
raw = false,
config = CONFIG,
) = cthulhu_llvm(
io,
b.mi,
optimize,
debuginfo === :source,
get_inference_world(b.interp),
config,
dump_module,
raw,
)

InteractiveUtils.code_native(b::Bookmark; kw...) =
InteractiveUtils.code_native(stdout::IO, b; kw...)
InteractiveUtils.code_native(
io::IO,
b::Bookmark;
optimize = true,
debuginfo = :source,
dump_module = false,
raw = false,
config = CONFIG,
) = cthulhu_native(
io,
b.mi,
optimize,
debuginfo === :source,
get_inference_world(b.interp),
config,
dump_module,
raw,
)

@static if VERSION < v"1.12.0-DEV.669"
InteractiveUtils.code_llvm(
io::IO,
b::Bookmark;
optimize = true,
debuginfo = :source,
dump_module = false,
raw = false,
config = CONFIG,
) = cthulhu_llvm(
io,
b.mi,
optimize,
debuginfo === :source,
get_inference_world(b.interp),
config,
dump_module,
raw,
)

InteractiveUtils.code_native(
io::IO,
b::Bookmark;
optimize = true,
debuginfo = :source,
dump_module = false,
raw = false,
config = CONFIG,
) = cthulhu_native(
io,
b.mi,
optimize,
debuginfo === :source,
get_inference_world(b.interp),
config,
dump_module,
raw,
)
else
function InteractiveUtils.code_llvm(
io::IO,
b::Bookmark;
optimize = true,
debuginfo = :source,
dump_module = false,
raw = false,
config = CONFIG,
)
src = Core.Compiler.typeinf_code(b.interp, b.mi, true)
return cthulhu_llvm(
io,
b.mi,
src,
optimize,
debuginfo === :source,
get_inference_world(b.interp),
config,
dump_module,
raw,
)
end

function InteractiveUtils.code_native(
io::IO,
b::Bookmark;
optimize = true,
debuginfo = :source,
dump_module = false,
raw = false,
config = CONFIG,
)
src = Core.Compiler.typeinf_code(b.interp, b.mi, true)
return cthulhu_native(
io,
b.mi,
src,
optimize,
debuginfo === :source,
get_inference_world(b.interp),
config,
dump_module,
raw,
)
end
end
6 changes: 1 addition & 5 deletions test/test_Cthulhu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,7 @@ uncached_call3(a) = uncached_call1(Type{a})
@test isa(ci, Cthulhu.UncachedCallInfo)
effects = Cthulhu.get_effects(ci)
@test !Core.Compiler.is_consistent(effects)
@static if VERSION v"1.11.0-DEV.392"
@test !Core.Compiler.is_effect_free(effects)
else
@test Core.Compiler.is_effect_free(effects)
end
@test Core.Compiler.is_effect_free(effects)
@test !Core.Compiler.is_nothrow(effects)
@test !Core.Compiler.is_terminates(effects)
@test Cthulhu.is_callsite(ci, ci.wrapped.mi)
Expand Down
7 changes: 6 additions & 1 deletion test/test_codeview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ Revise.track(TestCodeViewSandbox, normpath(@__DIR__, "TestCodeViewSandbox.jl"))
config = Cthulhu.CONFIG

io = IOBuffer()
codeview(io, mi, optimize, debuginfo, Cthulhu.get_inference_world(interp), config)
@static if VERSION < v"1.12.0-DEV.669"
codeview(io, mi, optimize, debuginfo, Cthulhu.get_inference_world(interp), config)
else
src = Core.Compiler.typeinf_code(interp, mi, true)
codeview(io, mi, src, optimize, debuginfo, Cthulhu.get_inference_world(interp), config)
end
@test !isempty(String(take!(io))) # just check it works
end
end
Expand Down

0 comments on commit ba2b5d3

Please sign in to comment.