Skip to content

Commit 1579bff

Browse files
committed
Fix copying
1 parent 94aed2f commit 1579bff

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/copyable_task.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ rather specific semantics of `copy`. Calling `copy` on a `TapedTask` does the fo
4848
`position` field -- for this element we use the copy we made in step 1.
4949
5050
`_tape_copy` doesn't actually make a copy of the object at all if it is not either an
51-
`Array`, a `Ref`, or an instance of one of the types listed in the task's `deepcopy_type`
51+
`Array`, a `Ref`, or an instance of one of the types listed in the task's `deepcopy_types`
5252
field. If it is an instance of one of these types then `_tape_copy` just calls `deepcopy`.
5353
5454
This behaviour is plainly entirely acceptable if the argument to `_tape_copy` is a bits
@@ -77,13 +77,21 @@ this is a viable option.
7777
"""
7878
function Base.copy(t::T) where {T<:TapedTask}
7979
captures = t.mc.oc.captures
80-
new_captures = map(Base.Fix2(_tape_copy, t.deepcopy_types), captures)
80+
new_captures = map(Base.Fix2(_copy_capture, t.deepcopy_types), captures)
8181
new_position = new_captures[end] # baked in later on.
8282
new_args = map(Base.Fix2(_tape_copy, t.deepcopy_types), t.args)
8383
new_mc = Mooncake.replace_captures(t.mc, new_captures)
8484
return T(new_mc, new_args, new_position, t.deepcopy_types)
8585
end
8686

87+
function _copy_capture(r::Ref{T}, deepcopy_types::Type) where {T}
88+
new_capture = Ref{T}()
89+
if isassigned(r)
90+
new_capture[] = _tape_copy(r[], deepcopy_types)
91+
end
92+
return new_capture
93+
end
94+
8795
_tape_copy(v, deepcopy_types::Type) = v isa deepcopy_types ? deepcopy(v) : v
8896

8997
# Not sure that we need this in the new implementation.

0 commit comments

Comments
 (0)