From 0dfbaa9ef98dbc221e2abcf27cde2b5644031b25 Mon Sep 17 00:00:00 2001 From: Antonio Maiorano Date: Tue, 13 Sep 2022 18:16:11 +0000 Subject: [PATCH] tint: Make ForEachElemPair return value an enum instead of a bool Bug: tint:1581 Change-Id: Ia16a548c03f7dff4ebc45599e20c0004834da6ae Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/102121 Commit-Queue: Antonio Maiorano Reviewed-by: Ben Clayton --- src/tint/resolver/const_eval_test.cc | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/tint/resolver/const_eval_test.cc b/src/tint/resolver/const_eval_test.cc index ce7aacd4f1..1d5b7d2596 100644 --- a/src/tint/resolver/const_eval_test.cc +++ b/src/tint/resolver/const_eval_test.cc @@ -3111,11 +3111,13 @@ std::ostream& operator<<(std::ostream& o, const Types& types) { return o; } -// Calls `f` on deepest elements of both `a` and `b`. If function returns false, it stops -// traversing, and return false, otherwise it continues and returns true. +// Calls `f` on deepest elements of both `a` and `b`. If function returns Action::kStop, it stops +// traversing, and return Action::kStop; if the function returns Action::kContinue, it continues and +// returns Action::kContinue when done. // TODO(amaiorano): Move to Constant.h? +enum class Action { kStop, kContinue }; template -bool ForEachElemPair(const sem::Constant* a, const sem::Constant* b, Func&& f) { +Action ForEachElemPair(const sem::Constant* a, const sem::Constant* b, Func&& f) { EXPECT_EQ(a->Type(), b->Type()); size_t i = 0; while (true) { @@ -3124,15 +3126,15 @@ bool ForEachElemPair(const sem::Constant* a, const sem::Constant* b, Func&& f) { break; } auto* b_elem = b->Index(i); - if (!ForEachElemPair(a_elem, b_elem, f)) { - return false; + if (ForEachElemPair(a_elem, b_elem, f) == Action::kStop) { + return Action::kStop; } i++; } if (i == 0) { return f(a, b); } - return true; + return Action::kContinue; } template @@ -3209,7 +3211,7 @@ TEST_P(ResolverConstEvalUnaryOpTest, Test) { // data in the MSBs that are outside of the bit-width of T. EXPECT_EQ(a->As(), b->As()); } - return !HasFailure(); + return HasFailure() ? Action::kStop : Action::kContinue; }); }, c.expected); @@ -3390,7 +3392,7 @@ TEST_P(ResolverConstEvalBinaryOpTest, Test) { // data in the MSBs that are outside of the bit-width of T. EXPECT_EQ(a->As(), b->As()); } - return !HasFailure(); + return HasFailure() ? Action::kStop : Action::kContinue; }); }, c.expected); @@ -3859,7 +3861,7 @@ TEST_F(ResolverConstEvalTest, NotAndOrOfVecs) { ForEachElemPair(value, expected_value, [&](const sem::Constant* a, const sem::Constant* b) { EXPECT_EQ(a->As(), b->As()); - return !HasFailure(); + return HasFailure() ? Action::kStop : Action::kContinue; }); }