Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spec: Rephrase confusing paragraph about TailLoop inputs/outputs #567

Merged
merged 3 commits into from
Oct 16, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions specification/hugr.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,15 @@ 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 computes a value of 2-ary `Predicate(#i, #o)`, as well as
a row `#x` of other values (perhaps empty). The first variant means to
repeat the loop with the computed values fed in at the top of the DSG,
which has inputs `#i,#x`; the second variant means to exit the loop
and output `#o,#x` from the TailLoop node. (In both cases the tuple
within the Predicate is unpacked.) Thus, the contained graph may be
evaluated more than once, with the first iteration using the inputs
to the TailLoop node: `#i,#x`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better but I still feel it would be better with notation. Something like

Suggested change
These provide tail-controlled loops: the dataflow sibling graph within the
TailLoop-node computes a value of 2-ary `Predicate(#i, #o)`, as well as
a row `#x` of other values (perhaps empty). The first variant means to
repeat the loop with the computed values fed in at the top of the DSG,
which has inputs `#i,#x`; the second variant means to exit the loop
and output `#o,#x` from the TailLoop node. (In both cases the tuple
within the Predicate is unpacked.) Thus, the contained graph may be
evaluated more than once, with the first iteration using the inputs
to the TailLoop node: `#i,#x`.
These provide tail-controlled loops. The node has a `FunctionType`
```
#I:#X -> #O:#X
```
where `#I, #O, #X` are rows and `:` expresses row concatenation.
Correspondingly, the dataflow sibling graph inside the TailLoop-node has `FunctionType`
```
#I :#X -> (Predicate(#I, #O)):#X
```
The `Predicate` type variants signal loop continuation or termination.
The first variant means to
repeat the loop with the computed values (`#I:#X`) fed in at the top of the DSG;
the second variant means to exit the loop
and output `#O:#X` from the TailLoop node. (In both cases the tuple
within the Predicate is unpacked.) Thus, the contained graph may be
evaluated more than once, with the first iteration using the inputs
to the TailLoop node.

I'm not sure what notation to pick to be consistent with the rest of the spec - there isn't much elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so I haven't found a definitive notation either, but have rewritten as something of an intermediate form to what you suggest. It feels that there are a lot of concepts to get across altogether, but many have also been used for Conditional, so if this doesn't pass muster, maybe we should define more row operations/notations in common to the Control Flow section?


##### Control Flow Graphs

Expand Down