@@ -10,26 +10,17 @@ export @RuntimeGeneratedFunction
10
10
11
11
This type should be constructed via the macro @RuntimeGeneratedFunction.
12
12
"""
13
- struct RuntimeGeneratedFunction{moduletag,id,argnames}
13
+ struct RuntimeGeneratedFunction{argnames, moduletag,id} <: Function
14
14
body:: Expr
15
15
function RuntimeGeneratedFunction (moduletag, ex)
16
16
def = splitdef (ex)
17
17
args, body = normalize_args (def[:args ]), def[:body ]
18
- id = expr2bytes (body)
18
+ id = expr_to_id (body)
19
19
cached_body = _cache_body (moduletag, id, body)
20
- new {moduletag,id, Tuple(args)} (cached_body)
20
+ new {Tuple(args),moduletag,id } (cached_body)
21
21
end
22
22
end
23
23
24
- function Base. show (io:: IO , :: Type{<:RuntimeGeneratedFunction{mod,id,arg}} ) where {mod,id,arg}
25
- print (io, " RuntimeGeneratedFunction{$arg }" )
26
- end
27
-
28
- # don't override typeof
29
- function Base. show (io:: IO , :: MIME"text/plain" , :: Type{<:RuntimeGeneratedFunction{mod,id,arg}} ) where {mod,id,arg}
30
- print (io, " RuntimeGeneratedFunction{$mod , $id , $arg }" )
31
- end
32
-
33
24
"""
34
25
@RuntimeGeneratedFunction(function_expression)
35
26
@@ -68,7 +59,7 @@ macro RuntimeGeneratedFunction(ex)
68
59
end
69
60
end
70
61
71
- function Base. show (io:: IO , f:: RuntimeGeneratedFunction{moduletag, id, argnames } ) where {moduletag,id,argnames }
62
+ function Base. show (io:: IO , f:: RuntimeGeneratedFunction{argnames, moduletag, id } ) where {argnames, moduletag,id}
72
63
mod = parentmodule (moduletag)
73
64
func_expr = Expr (:-> , Expr (:tuple , argnames... ), f. body)
74
65
print (io, " RuntimeGeneratedFunction(#=in $mod =#, " , repr (func_expr), " )" )
80
71
# @RuntimeGeneratedFunction
81
72
function generated_callfunc end
82
73
83
- function generated_callfunc_body (moduletag, id, argnames , __args)
74
+ function generated_callfunc_body (argnames, moduletag, id , __args)
84
75
setup = (:($ (argnames[i]) = @inbounds __args[$ i]) for i in 1 : length (argnames))
85
76
body = _lookup_body (moduletag, id)
86
77
@assert body != = nothing
110
101
# @generated function.
111
102
_cache_lock = Threads. SpinLock ()
112
103
_cachename = Symbol (" #_RuntimeGeneratedFunctions_cache" )
113
- _tagname = Symbol (" #_RuntimeGeneratedFunctions_ModTag " )
104
+ _tagname = Symbol (" #_RGF_ModTag " )
114
105
115
106
function _cache_body (moduletag, id, body)
116
107
lock (_cache_lock) do
@@ -168,8 +159,8 @@ function init(mod)
168
159
# or so. See:
169
160
# https://github.com/JuliaLang/julia/pull/32902
170
161
# https://github.com/NHDaly/StagedFunctions.jl/blob/master/src/StagedFunctions.jl#L30
171
- @inline @generated function $RuntimeGeneratedFunctions. generated_callfunc (f:: $RuntimeGeneratedFunctions.RuntimeGeneratedFunction{$_tagname, id, argnames } , __args... ) where {id, argnames}
172
- $ RuntimeGeneratedFunctions. generated_callfunc_body ($ _tagname, id, argnames , __args)
162
+ @inline @generated function $RuntimeGeneratedFunctions. generated_callfunc (f:: $RuntimeGeneratedFunctions.RuntimeGeneratedFunction{argnames, $_tagname, id} , __args... ) where {argnames,id }
163
+ $ RuntimeGeneratedFunctions. generated_callfunc_body (argnames, $ _tagname, id, __args)
173
164
end
174
165
end )
175
166
end
@@ -186,10 +177,10 @@ function normalize_args(arg::Expr)
186
177
arg. args[1 ]
187
178
end
188
179
189
- function expr2bytes (ex)
180
+ function expr_to_id (ex)
190
181
io = IOBuffer ()
191
182
Serialization. serialize (io, ex)
192
- return Tuple (sha512 ( take! (io)))
183
+ return Tuple (reinterpret (UInt32, sha1 ( take! (io) )))
193
184
end
194
185
195
186
end
0 commit comments