Skip to content

Commit 426f95e

Browse files
wip
1 parent cec3eec commit 426f95e

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

TypedSyntax/src/show.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ end
3232
function Base.printstyled(io::IO, rootnode::MaybeTypedSyntaxNode;
3333
type_annotations::Bool=true, iswarn::Bool=true, hide_type_stable::Bool=true,
3434
with_linenumber::Bool=true,
35-
idxend = last_byte(rootnode)
36-
)
35+
idxend = last_byte(rootnode))
3736
rt = gettyp(rootnode)
3837
nd = with_linenumber ? ndigits_linenumbers(rootnode, idxend) : 0
3938
rootnode = get_function_def(rootnode)
@@ -157,7 +156,9 @@ function show_annotation(io, @nospecialize(T), post, node, position; iswarn::Boo
157156
if isa(T, Core.Const) && isa(T.val, Type)
158157
T = Type{T.val}
159158
end
160-
T_str = string(T)
159+
T_str_long = string(T)
160+
sz = get(io, :displaysize, displaysize(io))::Tuple{Int, Int}
161+
T_str = Base.type_depth_limit(T_str_long, max(sz[2], 120); maxdepth=maxtypedepth)
161162
if iswarn && is_type_unstable(T)
162163
color = is_small_union_or_tunion(T) ? :yellow : :red
163164
printstyled(io, "::", T_str; color)

src/codeview.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ function cthulhu_typed(io::IO, debuginfo::Symbol,
189189

190190
callsite_diagnostics = TypedSyntax.Diagnostic[]
191191
if (diagnostics_vscode || inlay_types_vscode)
192-
vscode_io = IOContext(devnull, :inlay_hints=>vscode_io[:inlay_hints], :diagnostics=>vscode_io[:diagnostics], maxtypedepth=CONFIG.type_depth_limit)
192+
vscode_io = IOContext(devnull, :inlay_hints=>vscode_io[:inlay_hints], :diagnostics=>vscode_io[:diagnostics], :maxtypedepth=>CONFIG.type_depth_limit)
193193
callsite_mis = Dict() # type annotation is a bit long so I skipped it, doesn't seem to affect performance
194194
visited_mis = Set{MethodInstance}((mi,))
195195
add_callsites!(callsite_mis, visited_mis, callsite_diagnostics, mi; optimize, annotate_source, interp)

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using Test, PerformanceTestTools
22
using Core: Const # allows correct printing as `Const` instead of `Core.Const`
33

4+
using Cthulhu
5+
Cthulhu.CONFIG.type_depth_limit = nothing # disable type-depth limit printing in tests
6+
47
@testset "runtests.jl" begin
58
@testset "test_Cthulhu.jl" begin
69
include("test_Cthulhu.jl")

test/test_depth_limited_type_printing.jl

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,46 @@ using Revise; include(joinpath("test", "test_depth_limited_type_printing.jl"))
33
=#
44
import Cthulhu
55

6+
using Cthulhu
7+
Cthulhu.CONFIG.type_depth_limit = 2
8+
69
Base.@kwdef struct Nested{A,B}
710
num::Int = 1
811
end
9-
struct F49231{a,b,c,d,e,f,g}
10-
num::g
11-
end;
1212
bar(x) = rand() > 0.5 ? x : Any[0][1]
1313
mysum(x) = sum(y-> bar(x.num), 1:5; init=0)
1414
nest_val(na, nb, ::Val{1}) = Nested{na, nb}()
1515
nest_val(na, nb, ::Val{n}) where {n} = nest_val(Nested{na, nb}, Nested{na, nb}, Val(n-1))
1616
nest_val(na, nb, n::Int) = nest_val(na, nb, Val(n))
1717
nest_val(n) = nest_val(1, 1, n)
18+
const NV = nest_val(5)
19+
20+
# f = nest_val(5)
21+
# a = Any[f];
22+
# mysum(a[1]) # make sure it runs
23+
# Cthulhu.@descend mysum(a[1]) # navigate to sum -> sum, and Nested will be there
24+
using Test
25+
include("setup.jl")
26+
@testset "hide type-stable statements" begin
27+
let # optimize code
28+
# f = nest_val(5)
29+
# a = Any[f];
30+
# mysum(a[1]) # make sure it runs
31+
# Cthulhu.@descend mysum(a[1]) # navigate to sum -> sum, and Nested will be there
32+
(; src, infos, mi, rt, exct, effects, slottypes) = @eval Module() begin
33+
$cthulhu_info($mysum, ($(typeof(NV)),))
34+
end;
35+
function prints(; kwargs...)
36+
io = IOBuffer()
37+
ioc = IOContext(io, :maxtypedepth => Cthulhu.CONFIG.type_depth_limit)
38+
Cthulhu.cthulhu_typed(ioc, :none, src, rt, exct, effects, mi; kwargs...)
39+
return String(take!(io))
40+
end;
1841

19-
f = nest_val(5)
20-
a = Any[f];
21-
mysum(a[1]) # make sure it runs
22-
Cthulhu.@descend mysum(a[1]) # navigate to sum -> sum, and F49231 will be there
42+
let # by default, should print every statement
43+
s = prints()
44+
println(s)
45+
# @test occursin("::Nested{Nested{…}, Nested{…}}", s)
46+
end
47+
end
48+
end

0 commit comments

Comments
 (0)