-
Notifications
You must be signed in to change notification settings - Fork 41
/
test_codeview.jl
116 lines (103 loc) · 3.92 KB
/
test_codeview.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
module test_codeview
using Cthulhu, Test, Revise
include("setup.jl")
# NOTE setup for `cthulhu_ast`
include("TestCodeViewSandbox.jl")
using .TestCodeViewSandbox
Revise.track(TestCodeViewSandbox, normpath(@__DIR__, "TestCodeViewSandbox.jl"))
@testset "printer test" begin
(; interp, src, infos, mi, rt, exct, effects, slottypes) = cthulhu_info(testf_revise);
tf = (true, false)
@testset "codeview: $codeview" for codeview in Cthulhu.CODEVIEWS
if !@isdefined(Revise)
codeview == Cthulhu.cthulhu_ast && continue
end
@testset "optimize: $optimize" for optimize in tf
@testset "debuginfo: $debuginfo" for debuginfo in instances(Cthulhu.DInfo.DebugInfo)
config = Cthulhu.CONFIG
io = IOBuffer()
codeview(io, mi, optimize, debuginfo, Cthulhu.get_inference_world(interp), config)
@test !isempty(String(take!(io))) # just check it works
end
end
end
@testset "debuginfo: $debuginfo" for debuginfo in instances(Cthulhu.DInfo.DebugInfo)
@testset "iswarn: $iswarn" for iswarn in tf
@testset "hide_type_stable: $hide_type_stable" for hide_type_stable in tf
@testset "inline_cost: $inline_cost" for inline_cost in tf
@testset "type_annotations: $type_annotations" for type_annotations in tf
io = IOBuffer()
Cthulhu.cthulhu_typed(io, debuginfo,
src, rt, exct, effects, mi;
iswarn, hide_type_stable, inline_cost, type_annotations)
@test !isempty(String(take!(io))) # just check it works
end
end
end
end
end
end
@testset "hide type-stable statements" begin
let # optimize code
(; src, infos, mi, rt, exct, effects, slottypes) = @eval Module() begin
const globalvar = Ref(42)
$cthulhu_info() do
a = sin(globalvar[])
b = sin(undefvar)
return (a, b)
end
end
function prints(; kwargs...)
io = IOBuffer()
Cthulhu.cthulhu_typed(io, :none, src, rt, exct, effects, mi; kwargs...)
return String(take!(io))
end
let # by default, should print every statement
s = prints()
@test occursin("globalvar", s)
@test occursin("undefvar", s)
end
let # should omit type stable statements
s = prints(; hide_type_stable=true)
@test !occursin("globalvar", s)
@test occursin("undefvar", s)
end
end
let # unoptimize code
(; src, infos, mi, rt, exct, effects, slottypes) = @eval Module() begin
const globalvar = Ref(42)
$cthulhu_info(; optimize=false) do
a = sin(globalvar[])
b = sin(undefvar)
return (a, b)
end
end
function prints(; kwargs...)
io = IOBuffer()
Cthulhu.cthulhu_typed(io, :none, src, rt, exct, effects, mi; kwargs...)
return String(take!(io))
end
let # by default, should print every statement
s = prints()
@test occursin("globalvar", s)
@test occursin("undefvar", s)
end
let # should omit type stable statements
s = prints(; hide_type_stable=true)
@test !occursin("globalvar", s)
@test occursin("undefvar", s)
end
# should work for warn mode
let
s = prints(; iswarn=true)
@test occursin("globalvar", s)
@test occursin("undefvar", s)
end
let
s = prints(; iswarn=true, hide_type_stable=true)
@test !occursin("globalvar", s)
@test occursin("undefvar", s)
end
end
end
end # module test_codeview