Skip to content

Commit

Permalink
spec: Rephrase confusing paragraph about TailLoop inputs/outputs (#567)
Browse files Browse the repository at this point in the history
I read this as part of #557 and was just bewildered, so thought I'd see
if I can do better. Admit it's not easy! How does this strike you?
  • Loading branch information
acl-cqc authored Oct 16, 2023
1 parent 9f7ebfd commit b53510c
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions specification/hugr.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,20 @@ flowchart

##### `TailLoop` nodes

These provide tail-controlled loops: the data sibling graph within the
TailLoop-node computes a value of 2-ary `Predicate(#i, #o)`; the first
variant means to repeat the loop with the values of the tuple unpacked
and “fed” in at at the top; the second variant means to exit the loop
with those values unpacked. The graph may additionally take in a row
`#x` (appended to `#i`) and return the same row (appended to `#o`). The
contained graph may thus be evaluated more than once.
These provide tail-controlled loops. The dataflow sibling graph within the
TailLoop-node defines the loop body: this computes a row of outputs, whose
first element has type `Predicate(#I, #O)` and the remainder is a row `#X`
(perhaps empty). Inputs to the contained graph and to the TailLoop node itself
are the row `#I:#X`, where `:` indicates row concatenation (with the tuple
inside the `Predicate` unpacked).

Evaluation of the node begins by feeding the node inputs into the child graph
and evaluating it. The `Predicate` produced controls iteration of the loop:
* The first variant (`#I`) means that these values, along with the other
sibling-graph outputs `#X`, are fed back into the top of the loop,
and the body is evaluated again (thus perhaps many times)
* The second variant (`#O`) means that evaluation of the `TailLoop` node
terminates, returning all the values produced as a row of outputs `#O:#X`.

##### Control Flow Graphs

Expand Down

0 comments on commit b53510c

Please sign in to comment.