-
Notifications
You must be signed in to change notification settings - Fork 41
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
Use depth-limited type printing #568
base: master
Are you sure you want to change the base?
Use depth-limited type printing #568
Conversation
0aacc2c
to
5b42185
Compare
TypedSyntax is a separate package that can work without Cthulhu, so the |
I still never managed to exercise |
d23cfff
to
6899a17
Compare
Add helper Use depth-limited type printing
6899a17
to
e542d59
Compare
I'm not sure what the best way is forward for testing, @vchuravy? |
Thanks for this, I've left a couple comments as these seems unnecessarily complicated right now. |
For the tests, https://github.com/JuliaDebug/Cthulhu.jl/blob/master/test/test_codeview.jl looks like a good place to put it and hopefully the other tests in that file will help you in writing one for this. Cthulhu.jl/test/test_codeview.jl Lines 49 to 74 in 17c53a1
You might want to disable this feature by default for tests, maybe in https://github.com/JuliaDebug/Cthulhu.jl/blob/master/test/runtests.jl to prevent this from breaking existing tests. |
Hm, my first attempt doesn't seem to be limiting the types: #=
using Revise; include(joinpath("test", "test_depth_limited_type_printing.jl"))
=#
import Cthulhu
Base.@kwdef struct Nested{A,B}
num::Int = 1
end
bar(x) = rand() > 0.5 ? x : Any[0][1]
mysum(x) = sum(y-> bar(x.num), 1:5; init=0)
nest_val(na, nb, ::Val{1}) = Nested{na, nb}()
nest_val(na, nb, ::Val{n}) where {n} = nest_val(Nested{na, nb}, Nested{na, nb}, Val(n-1))
nest_val(na, nb, n::Int) = nest_val(na, nb, Val(n))
nest_val(n) = nest_val(1, 1, n)
const NV = nest_val(5)
# f = nest_val(5)
# a = Any[f];
# mysum(a[1]) # make sure it runs
# Cthulhu.@descend mysum(a[1]) # navigate to sum -> sum, and Nested will be there
using Test
include("setup.jl")
@testset "hide type-stable statements" begin
let # optimize code
# f = nest_val(5)
# a = Any[f];
# mysum(a[1]) # make sure it runs
# Cthulhu.@descend mysum(a[1]) # navigate to sum -> sum, and Nested will be there
(; src, infos, mi, rt, exct, effects, slottypes) = @eval Module() begin
$cthulhu_info($mysum, ($(typeof(NV)),))
end;
function prints(; kwargs...)
io = IOBuffer()
ioc = IOContext(io, :maxtypedepth => Cthulhu.CONFIG.type_depth_limit)
Cthulhu.cthulhu_typed(ioc, :none, src, rt, exct, effects, mi; kwargs...)
return String(take!(io))
end;
let # by default, should print every statement
s = prints()
println(s)
# @test occursin("::Nested{Nested{…}, Nested{…}}", s)
end
end
end Any pointers? |
I don't see anything obvious but I'm very busy right now so I'm not going to be able to get back to this pr for a few weeks. |
Closes #566.