@@ -10,14 +10,14 @@ export @RuntimeGeneratedFunction
1010
1111This type should be constructed via the macro @RuntimeGeneratedFunction.
1212"""
13- struct RuntimeGeneratedFunction{moduletag,id,argnames }
13+ struct RuntimeGeneratedFunction{argnames, moduletag,id}
1414 body:: Expr
1515 function RuntimeGeneratedFunction (moduletag, ex)
1616 def = splitdef (ex)
1717 args, body = normalize_args (def[:args ]), def[:body ]
18- id = expr2bytes (body)
18+ id = expr_to_id (body)
1919 cached_body = _cache_body (moduletag, id, body)
20- new {moduletag,id, Tuple(args)} (cached_body)
20+ new {Tuple(args),moduletag,id } (cached_body)
2121 end
2222end
2323
@@ -59,7 +59,7 @@ macro RuntimeGeneratedFunction(ex)
5959 end
6060end
6161
62- 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}
6363 mod = parentmodule (moduletag)
6464 func_expr = Expr (:-> , Expr (:tuple , argnames... ), f. body)
6565 print (io, " RuntimeGeneratedFunction(#=in $mod =#, " , repr (func_expr), " )" )
7171# @RuntimeGeneratedFunction
7272function generated_callfunc end
7373
74- function generated_callfunc_body (moduletag, id, argnames , __args)
74+ function generated_callfunc_body (argnames, moduletag, id , __args)
7575 setup = (:($ (argnames[i]) = @inbounds __args[$ i]) for i in 1 : length (argnames))
7676 body = _lookup_body (moduletag, id)
7777 @assert body != = nothing
101101# @generated function.
102102_cache_lock = Threads. SpinLock ()
103103_cachename = Symbol (" #_RuntimeGeneratedFunctions_cache" )
104- _tagname = Symbol (" #_RuntimeGeneratedFunctions_ModTag " )
104+ _tagname = Symbol (" #_RGF_ModTag " )
105105
106106function _cache_body (moduletag, id, body)
107107 lock (_cache_lock) do
@@ -159,8 +159,8 @@ function init(mod)
159159 # or so. See:
160160 # https://github.com/JuliaLang/julia/pull/32902
161161 # https://github.com/NHDaly/StagedFunctions.jl/blob/master/src/StagedFunctions.jl#L30
162- @inline @generated function $RuntimeGeneratedFunctions. generated_callfunc (f:: $RuntimeGeneratedFunctions.RuntimeGeneratedFunction{$_tagname, id, argnames } , __args... ) where {id, argnames}
163- $ 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)
164164 end
165165 end )
166166 end
@@ -177,10 +177,10 @@ function normalize_args(arg::Expr)
177177 arg. args[1 ]
178178end
179179
180- function expr2bytes (ex)
180+ function expr_to_id (ex)
181181 io = IOBuffer ()
182182 Serialization. serialize (io, ex)
183- return Tuple (sha512 ( take! (io)))
183+ return Tuple (reinterpret (UInt32, sha1 ( take! (io) )))
184184end
185185
186186end
0 commit comments