Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 4 additions & 5 deletions src/CthulhuBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const ArgTypes = Vector{Any}
using Base: get_world_counter

get_mi(ci::CodeInstance) = CC.get_ci_mi(ci)
get_mi(mi::MethodInstance) = mi

Base.@kwdef mutable struct CthulhuConfig
enable_highlighter::Bool = false
Expand Down Expand Up @@ -574,7 +575,7 @@ function _descend(term::AbstractTerminal, interp::AbstractInterpreter, curs::Abs
display_CI = false
elseif toggle === :dump_params
@info "Dumping inference cache."
Core.show(mapany(((i, x),) -> (i, x.result, x.linfo), enumerate(get_inference_cache(interp))))
Core.show(mapany(((i, x),) -> (i, x.result, x.linfo), enumerate(CC.get_inference_cache(interp))))
Core.println()
display_CI = false
elseif toggle === :bookmark
Expand Down Expand Up @@ -735,10 +736,8 @@ function ascend_impl(term, mi; interp::AbstractInterpreter=NativeInterpreter(),
end
# The main application of `ascend` is finding cases of non-inferrability, so the
# warn highlighting is useful.
interp′ = CthulhuInterpreter(interp)
do_typeinf!(interp′, mi)
browsecodetyped && _descend(term, interp′, mi; annotate_source=true, iswarn=true, optimize=false, interruptexc=false, kwargs...)
browsecodetyped && _descend(term, mi; interp, annotate_source=true, iswarn=true, optimize=false, interruptexc=false, kwargs...)
end
end
end
ascend_impl(mi; kwargs...) = ascend(default_terminal(), mi; kwargs...)
ascend_impl(mi; kwargs...) = ascend_impl(default_terminal(), mi; kwargs...)
8 changes: 6 additions & 2 deletions src/backedges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ function nextnode end

backedges(mi::MethodInstance) = isdefined(mi, :backedges) ? mi.backedges : _emptybackedges
method(mi::MethodInstance) = mi.def
method(edge::CodeInstance) = method(get_mi(edge))
specTypes(mi::MethodInstance) = mi.specTypes
specTypes(edge::CodeInstance) = specTypes(get_mi(edge))
instance(mi::MethodInstance) = mi
nextnode(mi, edge) = edge

Expand Down Expand Up @@ -182,9 +184,11 @@ function treelist!(parent::Node, io::IO, mi, indent::AbstractString, visited::Ba
push!(visited, imi)
indent *= " "
for edge in backedges(mi)
isa(edge, MethodInstance) || isa(edge, CodeInstance) || continue
str = indent * callstring(io, edge)
child = Node(typeof(parent.data)(str, instance(edge)), parent)
treelist!(child, io, nextnode(mi, edge), indent, visited)
edge_mi = get_mi(edge)
child = Node(typeof(parent.data)(str, instance(edge_mi)), parent)
treelist!(child, io, nextnode(mi, edge_mi), indent, visited)
end
return parent
end
Expand Down
8 changes: 4 additions & 4 deletions src/codeview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ function cthulhu_ast(io::IO, mi, ::CodeInfo, optimize::Bool, debuginfo, world::U
end

function cthulhu_ast(io::IO, mi, ::Bool, debuginfo, ::UInt, config::CthulhuConfig)
meth = mi.def::Method
ast = definition(Expr, meth)
if ast!==nothing
method = mi.def::Method
ast = definition(Expr, method)
if ast !== nothing
if !config.pretty_ast
dump(io, ast; maxdepth=typemax(Int))
else
Expand All @@ -65,7 +65,7 @@ function cthulhu_ast(io::IO, mi, ::Bool, debuginfo, ::UInt, config::CthulhuConfi
# Could even highlight the above as some kind-of LISP
end
else
@warn "Could not retrieve AST of $meth. AST display requires Revise.jl to be loaded."
@warn "Could not retrieve AST of $method. AST display requires Revise.jl to be loaded."
end
end

Expand Down
15 changes: 9 additions & 6 deletions test/FakeTerminals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module FakeTerminals
import REPL
using Test

export fake_terminal
export fake_terminal, cleanup_fake_terminal

function fake_terminal(f; options::REPL.Options=REPL.Options(confirm_exit=false))
function fake_terminal(; options::REPL.Options=REPL.Options(confirm_exit=false))
# Use pipes so we can easily do blocking reads
# In the future if we want we can add a test that the right object
# gets displayed by intercepting the display
Expand All @@ -17,15 +17,18 @@ function fake_terminal(f; options::REPL.Options=REPL.Options(confirm_exit=false)
Base.link_pipe!(err, reader_supports_async=true, writer_supports_async=true)

term_env = get(ENV, "TERM", @static Sys.iswindows() ? "" : "dumb")
term = REPL.Terminals.TTYTerminal(term_env, input.out, IOContext(output.in, :color=>get(stdout, :color, false)), err.in)
f(term, input.in, output.out, err)
t = @async begin
terminal = REPL.Terminals.TTYTerminal(term_env, input.out, IOContext(output.in, :color=>get(stdout, :color, false)), err.in)
return terminal, input, output, err
end

function cleanup_fake_terminal(terminal, input, output, err)
task = @async begin
close(input.in)
close(output.in)
close(err.in)
end
@test read(err.out, String) == ""
wait(t)
wait(task)
end

end
34 changes: 7 additions & 27 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,14 @@ using Test, PerformanceTestTools
using Core: Const # allows correct printing as `Const` instead of `Core.Const`

@testset "runtests.jl" begin
@testset "test_Cthulhu.jl" begin
include("test_Cthulhu.jl")
end

@testset "test_codeview.jl" begin
include("test_codeview.jl")
end

@testset "Core functionality" include("test_Cthulhu.jl")
@testset "Code view" include("test_codeview.jl")
@testset "Terminal tests" include("test_terminal.jl")
@testset "AbstractInterpreter" include("test_AbstractInterpreter.jl")
# TODO enable these tests
if false
@testset "test_irshow.jl" begin
include("test_irshow.jl")
end
else
@info "skipped test_irshow.jl"
end
if false
@testset "test_terminal.jl" begin
include("test_terminal.jl")
end
else
@info "skipped test_terminal.jl"
end

@testset "test_AbstractInterpreter.jl" begin
include("test_AbstractInterpreter.jl")
end
end
false || return @info "skipped test_irshow.jl"
@testset "IRShow display tests" include("test_irshow.jl")
end;

# TODO enable the VSCode-related tests

Expand Down
Loading
Loading