@@ -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 `
5252field. If it is an instance of one of these types then `_tape_copy` just calls `deepcopy`.
5353
5454This behaviour is plainly entirely acceptable if the argument to `_tape_copy` is a bits
@@ -77,13 +77,21 @@ this is a viable option.
7777"""
7878function 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)
8585end
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