@@ -66,16 +66,18 @@ struct RuntimeGeneratedFunction{argnames, cache_tag, context_tag, id, B} <: Func
66
66
67
67
# For internal use in deserialize() - doesen't check whether the body is in the cache!
68
68
function RuntimeGeneratedFunction {argnames, cache_tag, context_tag, id} (body) where {
69
- argnames,
70
- cache_tag,
71
- context_tag,
72
- id,
73
- }
69
+ argnames,
70
+ cache_tag,
71
+ context_tag,
72
+ id
73
+ }
74
74
new {argnames, cache_tag, context_tag, id, typeof(body)} (body)
75
75
end
76
76
end
77
77
78
- drop_expr (:: RuntimeGeneratedFunction{A, C1, C2, ID} ) where {A, C1, C2, ID} = RuntimeGeneratedFunction {A, C1, C2, ID} (nothing )
78
+ function drop_expr (:: RuntimeGeneratedFunction{A, C1, C2, ID} ) where {A, C1, C2, ID}
79
+ RuntimeGeneratedFunction {A, C1, C2, ID} (nothing )
80
+ end
79
81
80
82
function _check_rgf_initialized (mods... )
81
83
for mod in mods
@@ -172,24 +174,19 @@ function _cache_body(cache_tag, id, body)
172
174
# canonical one rather than `body`. This ensures the lifetime of the
173
175
# body in the cache will always cover the lifetime of the parent
174
176
# `RuntimeGeneratedFunction`s when they share the same `id`.
175
- #
176
- # Tricky case #2: Unless we hold a separate reference to
177
- # `cache[id].value`, the GC can collect it (causing it to become
178
- # `nothing`). So root it in a local variable first.
179
- #
180
- cached_body = haskey (cache, id) ? cache[id]. value : nothing
177
+ cached_body = haskey (cache, id) ? cache[id] : nothing
181
178
cached_body = cached_body != = nothing ? cached_body : body
182
- # Use a WeakRef to allow ` body` to be garbage collected. (After GC, the
183
- # cache will still contain an empty entry with key `id`.)
184
- cache[id] = WeakRef ( cached_body)
179
+ # We cannot use WeakRef because we might drop body to make RGF GPU
180
+ # compatible.
181
+ cache[id] = cached_body
185
182
return cached_body
186
183
end
187
184
end
188
185
189
186
function _lookup_body (cache_tag, id)
190
187
lock (_cache_lock) do
191
188
cache = getfield (parentmodule (cache_tag), _cachename)
192
- cache[id]. value
189
+ cache[id]
193
190
end
194
191
end
195
192
@@ -300,13 +297,14 @@ end
300
297
# We write an explicit deserialize() here to trigger caching of the body on a
301
298
# remote node when using Serialialization.jl (in Distributed.jl and elsewhere)
302
299
function Serialization. deserialize (s:: AbstractSerializer ,
303
- :: Type {<: RuntimeGeneratedFunction {argnames, cache_tag,
304
- context_tag, id}}) where {
305
- argnames,
306
- cache_tag,
307
- context_tag,
308
- id
309
- }
300
+ :: Type {
301
+ <: RuntimeGeneratedFunction {argnames, cache_tag,
302
+ context_tag, id}}) where {
303
+ argnames,
304
+ cache_tag,
305
+ context_tag,
306
+ id
307
+ }
310
308
body = deserialize (s)
311
309
cached_body = _cache_body (cache_tag, id, body)
312
310
RuntimeGeneratedFunction {argnames, cache_tag, context_tag, id} (cached_body)
0 commit comments