@@ -11,48 +11,25 @@ Base.iterate(cache::WalkCache, state...) = iterate(cache.cache, state...)
1111Base. setindex! (cache:: WalkCache , value, key) = setindex! (cache. cache, value, key)
1212Base. getindex (cache:: WalkCache , x) = cache. cache[x]
1313
14- @static if VERSION >= v " 1.10.0-DEV.609"
15- function __cacheget_generator__ (world, source, self, cache, x, args #= for `return_type` only =# )
16- # :(return cache.cache[x]::(return_type(cache.walk, typeof(args))))
17- walk = cache. parameters[3 ]
18- RT = Core. Compiler. return_type (Tuple{walk, args... }, world)
19- body = Expr (:call , GlobalRef (Base, :getindex ), Expr (:., :cache , QuoteNode (:cache )), :x )
20- if RT != Any
21- body = Expr (:(:: ), body, RT)
22- end
23- expr = Expr (:lambda , [Symbol (" #self#" ), :cache , :x , :args ],
24- Expr (Symbol (" scope-block" ), Expr (:block , Expr (:meta , :inline ), Expr (:return , body))))
25- ci = ccall (:jl_expand , Any, (Any, Any), expr, @__MODULE__ )
26- ci. inlineable = true
27- return ci
28- end
29- @eval function cacheget (cache:: WalkCache , x, args... )
30- $ (Expr (:meta , :generated , __cacheget_generator__))
31- $ (Expr (:meta , :generated_only ))
32- end
33- else
34- @generated function cacheget (cache:: WalkCache , x, args... )
35- walk = cache. parameters[3 ]
36- world = typemax (UInt)
37- @static if VERSION >= v " 1.8"
38- RT = Core. Compiler. return_type (Tuple{walk, args... }, world)
39- else
40- if isdefined (walk, :instance )
41- RT = Core. Compiler. return_type (walk. instance, Tuple{args... }, world)
42- else
43- RT = Any
44- end
45- end
46- body = Expr (:call , GlobalRef (Base, :getindex ), Expr (:., :cache , QuoteNode (:cache )), :x )
47- if RT != Any
48- body = Expr (:(:: ), body, RT)
49- end
50- expr = Expr (:lambda , [Symbol (" #self#" ), :cache , :x , :args ],
51- Expr (Symbol (" scope-block" ), Expr (:block , Expr (:meta , :inline ), Expr (:return , body))))
52- ci = ccall (:jl_expand , Any, (Any, Any), expr, @__MODULE__ )
53- ci. inlineable = true
54- return ci
14+ function __cacheget_generator__ (world, source, self, cache, x, args #= for `return_type` only =# )
15+ # :(return cache.cache[x]::(return_type(cache.walk, typeof(args))))
16+ walk = cache. parameters[3 ]
17+ RT = Core. Compiler. return_type (Tuple{walk, args... }, world)
18+ body = Expr (:call , GlobalRef (Base, :getindex ), Expr (:., :cache , QuoteNode (:cache )), :x )
19+ if RT != Any
20+ body = Expr (:(:: ), body, RT)
5521 end
22+ expr = Expr (:lambda , [Symbol (" #self#" ), :cache , :x , :args ],
23+ Expr (Symbol (" scope-block" ), Expr (:block , Expr (:meta , :inline ), Expr (:return , body))))
24+ ci = ccall (:jl_expand , Any, (Any, Any), expr, @__MODULE__ )
25+ ci. inlineable = true
26+ return ci
5627end
28+
29+ @eval function cacheget (cache:: WalkCache , x, args... )
30+ $ (Expr (:meta , :generated , __cacheget_generator__))
31+ $ (Expr (:meta , :generated_only ))
32+ end
33+
5734# fallback behavior that only lookup for `x`
5835@inline cacheget (cache:: AbstractDict , x, args... ) = cache[x]
0 commit comments