Functions: support cycles in lazy-function graph
Lazy-function graphs are now evaluated properly even if they contain cycles. Note that cycles are only ok if there is no data dependency cycle. For example, a node might output something that is fed back into itself. As long as the output can be computed without the input that it feeds into, everything is ok. The code that builds the graph is responsible for making sure that there are no actual data dependencies.
This commit is contained in:
@@ -36,8 +36,22 @@ void LazyFunction::destruct_storage(void *storage) const
|
||||
UNUSED_VARS_NDEBUG(storage);
|
||||
}
|
||||
|
||||
void LazyFunction::possible_output_dependencies(const int /*output_index*/,
|
||||
const FunctionRef<void(Span<int>)> fn) const
|
||||
{
|
||||
/* The output depends on all inputs by default. */
|
||||
Vector<int, 16> indices(inputs_.size());
|
||||
for (const int i : inputs_.index_range()) {
|
||||
indices[i] = i;
|
||||
}
|
||||
fn(indices);
|
||||
}
|
||||
|
||||
bool LazyFunction::always_used_inputs_available(const Params ¶ms) const
|
||||
{
|
||||
if (allow_missing_requested_inputs_) {
|
||||
return true;
|
||||
}
|
||||
for (const int i : inputs_.index_range()) {
|
||||
const Input &fn_input = inputs_[i];
|
||||
if (fn_input.usage == ValueUsage::Used) {
|
||||
|
||||
Reference in New Issue
Block a user