<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Apr 10, 2018 at 12:52 PM, Caio Marcelo de Oliveira Filho <span dir="ltr"><<a href="mailto:caio.oliveira@intel.com" target="_blank">caio.oliveira@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The matching code doesn't make real use of the return value. The main<br>
function return value is ignored, and while the worker function<br>
propagate its return value, the actual callback never returns false.<br></blockquote><div><br></div><div>When I wrote this, I don't think I realized it was only going to have the one use.  I was mostly following the pattern we'd used for all the other foreach functions in NIR.  That said, I think this is better.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
---<br>
 src/compiler/nir/nir_lower_<wbr>vars_to_ssa.c | 73 +++++++++++-------------<br>
 1 file changed, 32 insertions(+), 41 deletions(-)<br>
<br>
diff --git a/src/compiler/nir/nir_lower_<wbr>vars_to_ssa.c b/src/compiler/nir/nir_lower_<wbr>vars_to_ssa.c<br>
index 4c41dd69cf..f84ad067ee 100644<br>
--- a/src/compiler/nir/nir_lower_<wbr>vars_to_ssa.c<br>
+++ b/src/compiler/nir/nir_lower_<wbr>vars_to_ssa.c<br>
@@ -217,45 +217,40 @@ get_deref_node(nir_deref_var *deref, struct lower_variables_state *state)<br>
 }<br>
<br>
 /* \sa foreach_deref_node_match */<br>
-static bool<br>
+static void<br>
 foreach_deref_node_worker(<wbr>struct deref_node *node, nir_deref *deref,<br>
-                          bool (* cb)(struct deref_node *node,<br>
+                          void (* cb)(struct deref_node *node,<br>
                                       struct lower_variables_state *state),<br>
                           struct lower_variables_state *state)<br>
 {<br>
    if (deref->child == NULL) {<br>
-      return cb(node, state);<br>
-   } else {<br>
-      switch (deref->child->deref_type) {<br>
-      case nir_deref_type_array: {<br>
-         nir_deref_array *arr = nir_deref_as_array(deref-><wbr>child);<br>
-         assert(arr->deref_array_type == nir_deref_array_type_direct);<br>
-         if (node->children[arr->base_<wbr>offset] &&<br>
-             !foreach_deref_node_worker(<wbr>node->children[arr->base_<wbr>offset],<br>
-                                        deref->child, cb, state))<br>
-            return false;<br>
-<br>
-         if (node->wildcard &&<br>
-             !foreach_deref_node_worker(<wbr>node->wildcard,<br>
-                                        deref->child, cb, state))<br>
-            return false;<br>
-<br>
-         return true;<br>
-      }<br>
+      cb(node, state);<br>
+      return;<br>
+   }<br>
<br>
-      case nir_deref_type_struct: {<br>
-         nir_deref_struct *str = nir_deref_as_struct(deref-><wbr>child);<br>
-         if (node->children[str->index] &&<br>
-             !foreach_deref_node_worker(<wbr>node->children[str->index],<br>
-                                        deref->child, cb, state))<br>
-            return false;<br>
+   switch (deref->child->deref_type) {<br>
+   case nir_deref_type_array: {<br>
+      nir_deref_array *arr = nir_deref_as_array(deref-><wbr>child);<br>
+      assert(arr->deref_array_type == nir_deref_array_type_direct);<br>
+<br>
+      if (node->children[arr->base_<wbr>offset])<br>
+         foreach_deref_node_worker(<wbr>node->children[arr->base_<wbr>offset],<br>
+                                   deref->child, cb, state);<br></blockquote><div><br></div><div>When a block contains multiple lines, we use { } regardless of whether or not it's just a single statement.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+      if (node->wildcard)<br>
+         foreach_deref_node_worker(<wbr>node->wildcard, deref->child, cb, state);<br>
+      break;<br>
+   }<br>
<br>
-         return true;<br>
-      }<br>
+   case nir_deref_type_struct: {<br>
+      nir_deref_struct *str = nir_deref_as_struct(deref-><wbr>child);<br>
+      if (node->children[str->index])<br>
+         foreach_deref_node_worker(<wbr>node->children[str->index],<br>
+                                   deref->child, cb, state);<br></blockquote><div><br></div><div>Same here.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+      break;<br>
+   }<br>
<br>
-      default:<br>
-         unreachable("Invalid deref child type");<br>
-      }<br>
+   default:<br>
+      unreachable("Invalid deref child type");<br>
    }<br>
 }<br>
<br>
@@ -271,9 +266,9 @@ foreach_deref_node_worker(<wbr>struct deref_node *node, nir_deref *deref,<br>
  * The given deref must be a full-length and fully qualified (no wildcards<br>
  * or indirects) deref chain.<br>
  */<br>
-static bool<br>
+static void<br>
 foreach_deref_node_match(nir_<wbr>deref_var *deref,<br>
-                         bool (* cb)(struct deref_node *node,<br>
+                         void (* cb)(struct deref_node *node,<br>
                                      struct lower_variables_state *state),<br>
                          struct lower_variables_state *state)<br>
 {<br>
@@ -281,10 +276,8 @@ foreach_deref_node_match(nir_<wbr>deref_var *deref,<br>
    var_deref.deref.child = NULL;<br>
    struct deref_node *node = get_deref_node(&var_deref, state);<br>
<br>
-   if (node == NULL)<br>
-      return false;<br></blockquote><div><br></div><div>I think I still like the early return a tad bit better.  I'm not going to be insistent though.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
-<br>
-   return foreach_deref_node_worker(<wbr>node, &deref->deref, cb, state);<br>
+   if (node)<br>
+      foreach_deref_node_worker(<wbr>node, &deref->deref, cb, state);<br>
 }<br>
<br>
 /* \sa deref_may_be_aliased */<br>
@@ -440,12 +433,12 @@ register_variable_uses_block(<wbr>nir_block *block,<br>
 /* Walks over all of the copy instructions to or from the given deref_node<br>
  * and lowers them to load/store intrinsics.<br>
  */<br>
-static bool<br>
+static void<br>
 lower_copies_to_load_store(<wbr>struct deref_node *node,<br>
                            struct lower_variables_state *state)<br>
 {<br>
    if (!node->copies)<br>
-      return true;<br>
+      return;<br>
<br>
    struct set_entry *copy_entry;<br>
    set_foreach(node->copies, copy_entry) {<br>
@@ -470,8 +463,6 @@ lower_copies_to_load_store(<wbr>struct deref_node *node,<br>
    }<br>
<br>
    node->copies = NULL;<br>
-<br>
-   return true;<br>
 }<br>
<br>
 /* Performs variable renaming<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.17.0<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>