|
2 | 2 | using Revise; include(joinpath("test", "test_depth_limited_type_printing.jl")) |
3 | 3 | =# |
4 | 4 | import Cthulhu |
| 5 | + |
| 6 | +Base.@kwdef struct Nested{A,B} |
| 7 | + num::Int = 1 |
| 8 | +end |
5 | 9 | struct F49231{a,b,c,d,e,f,g} |
6 | 10 | num::g |
7 | 11 | end; |
8 | | -f = F49231{Float64,Float32,Int,String,AbstractString,6,Float64}(1); |
9 | 12 | bar(x) = rand() > 0.5 ? x : Any[0][1] |
10 | 13 | mysum(x) = sum(y-> bar(x.num), 1:5; init=0) |
| 14 | +nest_val(na, nb, ::Val{1}) = Nested{na, nb}() |
| 15 | +nest_val(na, nb, ::Val{n}) where {n} = nest_val(Nested{na, nb}, Nested{na, nb}, Val(n-1)) |
| 16 | +nest_val(na, nb, n::Int) = nest_val(na, nb, Val(n)) |
| 17 | +nest_val(n) = nest_val(1, 1, n) |
| 18 | + |
| 19 | +# type_depth_limit(f; maxtypedepth=2) # works |
| 20 | +# type_depth_limit(typeof(f); maxtypedepth=2) # works |
| 21 | +f = nest_val(5) |
11 | 22 | a = Any[f]; |
12 | 23 | mysum(a[1]) # make sure it runs |
13 | 24 | Cthulhu.@descend mysum(a[1]) # navigate to sum -> sum, and F49231 will be there |
| 25 | + |
| 26 | +# f = F49231{Float64,Float32,Int,String,AbstractString,6,Float64}(1); |
| 27 | +# a = Any[f]; |
| 28 | +# mysum(a[1]) # make sure it runs |
| 29 | +# Cthulhu.@descend mysum(a[1]) # navigate to sum -> sum, and F49231 will be there |
| 30 | + |
| 31 | + |
| 32 | +# struct F49231{a,b,c,d,e,f,g} |
| 33 | +# num::g |
| 34 | +# end; |
| 35 | +# struct Nested{A,B} end |
| 36 | +# nest_val(na, nb, ::Val{1}) = Nested{na, nb} |
| 37 | +# nest_val(na, nb, ::Val{n}) where {n} = nest_val(Nested{na, nb}, Nested{na, nb}, Val(n-1)) |
| 38 | +# nest_val(na, nb, n::Int) = nest_val(na, nb, Val(n)) |
| 39 | +# nest_val(n) = nest_val(1, 1, n) |
| 40 | +# nested = nest_val(5)() |
| 41 | +# function type_depth_limit(io::IO, s::String; maxtypedepth::Union{Nothing,Int}) |
| 42 | +# sz = get(io, :displaysize, displaysize(io))::Tuple{Int, Int} |
| 43 | +# return Base.type_depth_limit(s, max(sz[2], 120); maxdepth=maxtypedepth) |
| 44 | +# end |
| 45 | +# function type_depth_limit(data; maxtypedepth::Union{Nothing,Int}=2) |
| 46 | +# buf = IOBuffer() |
| 47 | +# io = IOContext(buf, :limit => true) |
| 48 | +# type_depth_limit(io, string(typeof(data)); maxtypedepth=maxtypedepth) |
| 49 | +# end |
| 50 | +# type_depth_limit(nested;maxtypedepth=2) |
| 51 | + |
| 52 | +# f = F49231{Float64,Float32,Int,String,AbstractString,6,Float64}(1); |
| 53 | + |
| 54 | +# buf = IOBuffer() |
| 55 | +# io = IOContext(buf, :limit => true) |
| 56 | +# write(io, type_depth_limit(io, string(typeof(f)); maxtypedepth=2)) |
| 57 | +# s = String(take!(buf)) |
| 58 | +# @show s |
0 commit comments