Skip to content

Commit e09d5b4

Browse files
test: test precompilation
1 parent fc2c8e3 commit e09d5b4

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

Project.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ ReadOnlyArrays = "0.2.0"
6767
ReverseDiff = "1"
6868
RuntimeGeneratedFunctions = "0.5.13"
6969
Setfield = "0.7, 0.8, 1"
70+
SnoopCompileCore = "3.0.0"
7071
SparseArrays = "1"
7172
SpecialFunctions = "0.10, 1.0, 2"
7273
StaticArrays = "1.0"
@@ -89,9 +90,11 @@ ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf"
8990
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
9091
RuntimeGeneratedFunctions = "7e49a35a-f44a-4d26-94aa-eba1b4ca6b47"
9192
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
93+
SnoopCompile = "aa65fe97-06da-5843-b5b1-d5d13cad87d2"
94+
SnoopCompileCore = "e2b509da-e806-4183-be48-004708413034"
9295
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
9396
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
9497
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
9598

9699
[targets]
97-
test = ["BenchmarkTools", "Documenter", "LabelledArrays", "Pkg", "PkgBenchmark", "Random", "ReferenceTests", "ReverseDiff", "SafeTestsets", "Test", "Zygote", "OhMyThreads", "RuntimeGeneratedFunctions", "StaticArrays"]
100+
test = ["BenchmarkTools", "Documenter", "LabelledArrays", "Pkg", "PkgBenchmark", "Random", "ReferenceTests", "ReverseDiff", "SafeTestsets", "Test", "Zygote", "OhMyThreads", "RuntimeGeneratedFunctions", "StaticArrays", "SnoopCompile", "SnoopCompileCore"]

test/precompilation.jl

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using SnoopCompileCore, SymbolicUtils, AbstractTrees
2+
3+
syms_inf = @snoop_inference @syms x y
4+
@syms x y z
5+
add_inf = @snoop_inference x + y
6+
sub_inf = @snoop_inference x - y
7+
neg_inf = @snoop_inference -x
8+
mul_inf = @snoop_inference x * y
9+
coeff_inf = @snoop_inference 2x
10+
div_inf = @snoop_inference x / y
11+
const_div_inf = @snoop_inference x / 5
12+
pow_inf = @snoop_inference x ^ y
13+
Val{5}()
14+
const_pow_inf = @snoop_inference x ^ 5
15+
expr = x + sin(y) * z
16+
rules = Dict(x => y)
17+
fold = Val{false}()
18+
subs_inf = @snoop_inference substitute(expr, rules; fold)
19+
20+
using SnoopCompile
21+
22+
@testset "$name" for (name, inf) in [
23+
("syms", syms_inf),
24+
("add", add_inf),
25+
("sub", sub_inf),
26+
("neg", neg_inf),
27+
("mul", mul_inf),
28+
("coeff", coeff_inf),
29+
("div", div_inf),
30+
("const_div", const_div_inf),
31+
("pow", pow_inf),
32+
("const_pow", const_pow_inf),
33+
("substitute", subs_inf)
34+
]
35+
@test isempty(staleinstances(inf))
36+
# `setindex!` on TaskLocalValue doesn't infer (COMPARE_FULL)
37+
if inf === subs_inf
38+
@test treesize(inf) == 21
39+
else
40+
@test isempty(children(inf))
41+
end
42+
end
43+

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using Pkg, Test, SafeTestsets
44
if haskey(ENV, "SU_BENCHMARK_ONLY")
55
@safetestset "Benchmark" begin include("benchmark.jl") end
66
else
7+
@safetestset "Precompilation" begin include("precompilation.jl") end
78
@safetestset "Basics" begin include("basics.jl") end
89
@safetestset "Basics" begin include("arrayop.jl") end
910
@safetestset "Order" begin include("order.jl") end

0 commit comments

Comments
 (0)