Skip to content

Commit c28c46e

Browse files
committed
Docstring for fresh_copy
1 parent 53304ee commit c28c46e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/copyable_task.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,22 @@ function TapedTask(taped_globals::Any, fargs...; kwargs...)
237237
return TapedTask(taped_globals, all_args, mc, count_ref)
238238
end
239239

240+
"""
241+
fresh_copy(mc::T) where {T<:MistyClosure}
242+
243+
Creates an independent copy of `mc` by (carefully) replacing the `Ref`s it
244+
contains it its `captures`. The resuting `MistyClosure` is safe to run.
245+
246+
This is achieved by replacing most `Ref`s with new `Ref`s of the same (el)type,
247+
but with nothing stored in them -- values will be stored in them when the
248+
new `MistyClosure` is called. The only exception are `DynamicCallable`s and
249+
`LazyCallable`s -- these are constructed when the `MistyClosure`s IR is derived,
250+
so fresh instances of them are placed in the associated `Ref`.
251+
252+
The position counter is reset to `-1` (indicating that execution should proceed
253+
from the start of the IR, rather than eg. jumping to a line following a
254+
`produce` statement.
255+
"""
240256
function fresh_copy(mc::T) where {T<:MistyClosure}
241257
new_captures = map(mc.oc.captures) do r
242258
if eltype(r) <: DynamicCallable

0 commit comments

Comments
 (0)