@@ -2,19 +2,22 @@ using TypedCodeUtils
2
2
using Test
3
3
4
4
import TypedCodeUtils: reflect, filter, lookthrough,
5
- DefaultConsumer, Reflection, Callsite,
5
+ DefaultConsumer, Reflection,
6
6
identify_invoke, identify_call,
7
7
process_invoke, process_call
8
8
9
9
# Test simple reflection
10
10
f (x, y) = x + y
11
11
12
- @test reflect (f, Tuple{Int, Int}) != = nothing
13
- @test reflect (f, Tuple{Int, Number}) != = nothing # this probably doesn't do the right thing
14
- # it will give us **a** method instance.
12
+ @test ! isempty (reflect (f, Tuple{Int, Int}))
13
+ @test ! isempty (reflect (f, Tuple{Int, Number}))
15
14
@generated g (x, y) = :(x + y)
16
- @test reflect (g, Tuple{Int, Int}) != = nothing
17
- @test reflect (g, Tuple{Int, Number}) === nothing
15
+ @test ! isempty (reflect (g, Tuple{Int, Int}))
16
+ if VERSION >= v " 1.2.0-rc1"
17
+ @test ! isempty (reflect (g, Tuple{Int, Number}))
18
+ else
19
+ @test isempty (reflect (g, Tuple{Int, Number}))
20
+ end
18
21
19
22
# Cthulhu's inner loop
20
23
function cthulhu (ref:: Reflection )
@@ -24,17 +27,17 @@ function cthulhu(ref::Reflection)
24
27
25
28
invokes = map ((arg) -> process_invoke (DefaultConsumer (), ref, arg... ), invokes)
26
29
calls = map ((arg) -> process_call ( DefaultConsumer (), ref, arg... ), calls)
27
-
30
+
28
31
callsites = append! (invokes, calls)
29
- @show callsites
30
- sort! (callsites, by= (c)-> c. id)
32
+ sort! (callsites, by= (c)-> first (c))
31
33
return callsites
32
34
end
33
35
34
36
params = TypedCodeUtils. current_params ()
35
37
ref = reflect (f, Tuple{Int, Int}, params= params)
36
- calls = cthulhu (ref)
37
- nextrefs = collect (reflect (c) for c in calls if TypedCodeUtils. canreflect (c))
38
+ @test length (ref) == 1
39
+ calls = cthulhu (first (ref))
40
+ nextrefs = collect (first (reflect (c)) for c in calls if TypedCodeUtils. canreflect (c[2 ]))
38
41
39
42
function h (x)
40
43
if x >= 2
46
49
47
50
params = TypedCodeUtils. current_params ()
48
51
ref = reflect (h, Tuple{Int}, params= params)
49
- calls = cthulhu (ref)
50
- nextrefs = collect (reflect (c) for c in calls if TypedCodeUtils. canreflect (c))
52
+ @test length (ref) == 1
53
+ calls = cthulhu (first (ref))
54
+ nextrefs = collect (first (reflect (c)) for c in calls if TypedCodeUtils. canreflect (c[2 ]))
51
55
52
56
if VERSION >= v " 1.1.0-DEV.215" && Base. JLOptions (). check_bounds == 0
53
57
Base. @propagate_inbounds function f (x)
@@ -57,6 +61,8 @@ g(x) = @inbounds f(x)
57
61
58
62
params = TypedCodeUtils. current_params ()
59
63
ref = reflect (g, Tuple{Vector{Float64}}, params= params)
64
+ @test length (ref) == 1
65
+ ref = first (ref)
60
66
@show ref. CI. code
61
67
calls = cthulhu (ref)
62
68
@test ! isempty (calls)
0 commit comments