@@ -62,6 +62,11 @@ struct RuntimeGeneratedFunction{argnames, cache_tag, context_tag, id} <: Functio
6262 cached_body = _cache_body (cache_tag, id, body)
6363 new {Tuple(args), cache_tag, context_tag, id} (cached_body)
6464 end
65+
66+ # For internal use in deserialize() - doesen't check whether the body is in the cache!
67+ function RuntimeGeneratedFunction {argnames, cache_tag, context_tag, id} (body:: Expr ) where {argnames,cache_tag,context_tag,id}
68+ new {argnames, cache_tag, context_tag, id} (body)
69+ end
6570end
6671
6772function _check_rgf_initialized (mods... )
@@ -273,6 +278,15 @@ function closures_to_opaque(ex::Expr, return_type=nothing)
273278 return Expr (head, Any[closures_to_opaque (x, return_type) for x in args]. .. )
274279end
275280
281+ # We write an explicit deserialize() here to trigger caching of the body on a
282+ # remote node when using Serialialization.jl (in Distributed.jl and elsewhere)
283+ function Serialization. deserialize (s:: AbstractSerializer ,
284+ :: Type{RuntimeGeneratedFunction{argnames, cache_tag, context_tag, id}} ) where {argnames,cache_tag,context_tag,id}
285+ body = deserialize (s)
286+ cached_body = _cache_body (cache_tag, id, body)
287+ RuntimeGeneratedFunction {argnames, cache_tag, context_tag, id} (cached_body)
288+ end
289+
276290@specialize
277291
278292end
0 commit comments