Skip to content

Commit 999f5bc

Browse files
committed
Improve documentation
1 parent 1ba2dfe commit 999f5bc

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

src/copyable_task.jl

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ end
4141

4242
mutable struct TapedTask{Tdynamic_scope,Tfargs,Tmc<:MistyClosure}
4343
dynamic_scope::Tdynamic_scope
44-
fargs::Tfargs
44+
const fargs::Tfargs
4545
const mc::Tmc
4646
const position::Base.RefValue{Int32}
4747
end
@@ -369,7 +369,7 @@ function derive_copyable_task_ir(ir::BBCode)::Tuple{BBCode,Tuple}
369369
end
370370
end
371371

372-
# For each existing basic block, produce a sequence of `NamedTuple`s which
372+
# For each existing basic block, create a sequence of `NamedTuple`s which
373373
# define the manner in which it must be split.
374374
# A block will in general be split as follows:
375375
# 1 - %1 = φ(...)
@@ -666,6 +666,16 @@ function derive_copyable_task_ir(ir::BBCode)::Tuple{BBCode,Tuple}
666666
end
667667
push!(new_blocks, BBlock(splits_ids[n], inst_pairs))
668668
elseif is_produce_stmt(stmt)
669+
# This is a statement of the form
670+
# %n = produce(arg)
671+
#
672+
# We transform this into
673+
# Libtask.set_resume_block!(refs_id, id_of_next_block)
674+
# return ProducedValue(arg)
675+
#
676+
# The point is to ensure that, next time that this `TapedTask` is called,
677+
# computation is resumed from the statement _after_ this produce statement,
678+
# and to return whatever this produce statement returns.
669679

670680
# When this TapedTask is next called, we should resume from the first
671681
# statement of the next split.
@@ -699,7 +709,29 @@ function derive_copyable_task_ir(ir::BBCode)::Tuple{BBCode,Tuple}
699709
push!(new_blocks, BBlock(splits_ids[n], inst_pairs))
700710
else
701711
# The final statement is one which might produce, but is not itself a
702-
# `produce` statement.
712+
# `produce` statement. For example
713+
# y = f(x)
714+
#
715+
# becomes (morally speaking)
716+
# y = f(x)
717+
# if y isa ProducedValue
718+
# set_resume_block!(refs_id, id_of_current_block)
719+
# return y
720+
# end
721+
#
722+
# The point is to ensure that, if `f` "produces" (as indicated by `y` being
723+
# a `ProducedValue`) then the next time that this TapedTask is called, we
724+
# must resume from the call to `f`, as subsequent runs might also produce.
725+
# On the other hand, if anything other than a `ProducedValue` is returned,
726+
# we know that `f` has nothing else to produce, and execution can safely
727+
# continue to the next split.
728+
# In addition to the above, we must do the usual thing and ensure that any
729+
# ssas are read from storage, and write the result of this computation to
730+
# storage before continuing to the next instruction.
731+
#
732+
# You should look at the IR generated by a simple example in the test suite
733+
# which involves calls that might produce, in order to get a sense of what
734+
# the resulting code looks like prior to digging into the code below.
703735

704736
# Create a new basic block from the existing statements, since all new
705737
# statement need to live in their own basic blocks.

0 commit comments

Comments
 (0)