From 331982a5a27e98acb5450e71bdd96fe21c1af7a2 Mon Sep 17 00:00:00 2001 From: Alan Lawrence Date: Wed, 27 Sep 2023 18:53:21 +0100 Subject: [PATCH 1/3] spec: Rephrase confusing paragraph about TailLoop inputs/outputs --- specification/hugr.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/specification/hugr.md b/specification/hugr.md index 97cccf829..9e433b0e6 100644 --- a/specification/hugr.md +++ b/specification/hugr.md @@ -370,12 +370,13 @@ 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 +TailLoop-node computes a value of 2-ary `Predicate(#i, #o)`, where `#i` +are inputs to the TailLoop node and `#o` are outputs from it. 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. +with those values unpacked. The contained graph may thus be evaluated +more than once. There may be an additional row `#x` appended to both +inputs and outputs of both graph and node. ##### Control Flow Graphs From 7cfd7c07cbaa768f8aa63b6c8e5c20c341964cca Mon Sep 17 00:00:00 2001 From: Alan Lawrence Date: Thu, 28 Sep 2023 16:04:56 +0100 Subject: [PATCH 2/3] Take 2: use #i,#x throughout --- specification/hugr.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/specification/hugr.md b/specification/hugr.md index 9e433b0e6..fc326b40f 100644 --- a/specification/hugr.md +++ b/specification/hugr.md @@ -369,14 +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)`, where `#i` -are inputs to the TailLoop node and `#o` are outputs from it. 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 contained graph may thus be evaluated -more than once. There may be an additional row `#x` appended to both -inputs and outputs of both graph and node. +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`. ##### Control Flow Graphs From 94b7139a5fdb48b55c0cdaec7fcfe2bf3edf8a2f Mon Sep 17 00:00:00 2001 From: Alan Lawrence Date: Tue, 10 Oct 2023 12:55:15 +0100 Subject: [PATCH 3/3] Refine/intermediate --- specification/hugr.md | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/specification/hugr.md b/specification/hugr.md index fc326b40f..2c0ed40d5 100644 --- a/specification/hugr.md +++ b/specification/hugr.md @@ -369,15 +369,20 @@ flowchart ##### `TailLoop` nodes -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 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