Skip to content

Commit 9b36c92

Browse files
committed
don't copy RGF on deepcopy
This achieves similar behavior to normal Julia functions. Fixes #98.
1 parent 6ff33a8 commit 9b36c92

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/RuntimeGeneratedFunctions.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@ function Serialization.deserialize(s::AbstractSerializer,
376376
B === Nothing ? drop_expr(f) : f
377377
end
378378

379+
# achieve deepcopy(f)===f behavior similar to "normal" julia functions
380+
Base.deepcopy_internal(f::RuntimeGeneratedFunction, stackdict::IdDict) = f
381+
379382
@specialize
380383

381384
end

test/runtests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,8 @@ deserialized_f, deserialized_g = deserialize(buf)
184184
@test deserialized_f.body isa Expr
185185
@test deserialized_g(12) == "Serialization with dropped body. y=12"
186186
@test deserialized_g.body isa Nothing
187+
188+
# deepcopy
189+
f = @RuntimeGeneratedFunction(:(x -> [x, x+1]))
190+
@test deepcopy(f) == f
191+
@test deepcopy(f) === f

0 commit comments

Comments
 (0)