[ir][validation] Remove operand names This CL removes the operand names from the emitted validation error. This simplifies the code slightly. The missing operand is obvious from the highlight so the name doesn't provide much additional context. Bug: tint:1952 Change-Id: I667803a6863051c5de0ebfe58a0b3dbaefb3e6cb Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/140684 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/src/tint/ir/validate.cc b/src/tint/ir/validate.cc index e43a208..16726c3 100644 --- a/src/tint/ir/validate.cc +++ b/src/tint/ir/validate.cc
@@ -154,26 +154,22 @@ std::string Name(Value* v) { return mod_.NameOf(v).Name(); } - template <typename FUNC> void CheckOperandNotNull(ir::Instruction* inst, ir::Value* operand, size_t idx, - std::string_view name, - FUNC&& cb) { + std::string_view name) { if (operand == nullptr) { - AddError(inst, idx, std::string(name) + ": " + cb(idx) + " operand is undefined"); + AddError(inst, idx, std::string(name) + ": operand is undefined"); } } - template <typename FUNC> void CheckOperandsNotNull(ir::Instruction* inst, size_t start_operand, size_t end_operand, - std::string_view name, - FUNC&& cb) { + std::string_view name) { auto operands = inst->Operands(); for (size_t i = start_operand; i <= end_operand; i++) { - CheckOperandNotNull(inst, operands[i], i, name, cb); + CheckOperandNotNull(inst, operands[i], i, name); } } @@ -362,15 +358,11 @@ } void CheckBinary(ir::Binary* b) { - CheckOperandsNotNull(b, Binary::kLhsOperandOffset, Binary::kRhsOperandOffset, "binary", - [](size_t err_idx) { - return (err_idx == Binary::kLhsOperandOffset) ? "left" : "right"; - }); + CheckOperandsNotNull(b, Binary::kLhsOperandOffset, Binary::kRhsOperandOffset, "binary"); } void CheckUnary(ir::Unary* u) { - CheckOperandNotNull(u, u->Val(), Unary::kValueOperandOffset, "unary", - [](size_t) { return "value"; }); + CheckOperandNotNull(u, u->Val(), Unary::kValueOperandOffset, "unary"); if (u->Result() && u->Val()) { if (u->Result()->Type() != u->Val()->Type()) { @@ -400,8 +392,7 @@ } void CheckIf(If* if_) { - CheckOperandNotNull(if_, if_->Condition(), If::kConditionOperandOffset, "if", - [](size_t) { return "condition"; }); + CheckOperandNotNull(if_, if_->Condition(), If::kConditionOperandOffset, "if"); if (if_->Condition() && !if_->Condition()->Type()->Is<type::Bool>()) { AddError(if_, If::kConditionOperandOffset, "if: condition must be a `bool` type");
diff --git a/src/tint/ir/validate_test.cc b/src/tint/ir/validate_test.cc index db8079f..9a5b253 100644 --- a/src/tint/ir/validate_test.cc +++ b/src/tint/ir/validate_test.cc
@@ -608,7 +608,7 @@ auto res = ir::Validate(mod); ASSERT_FALSE(res); - EXPECT_EQ(res.Failure().str(), R"(:3:8 error: if: condition operand is undefined + EXPECT_EQ(res.Failure().str(), R"(:3:8 error: if: operand is undefined if undef [t: %b2, f: %b3] { # if_1 ^^^^^ @@ -892,7 +892,7 @@ auto res = ir::Validate(mod); ASSERT_FALSE(res); - EXPECT_EQ(res.Failure().str(), R"(:3:18 error: binary: left operand is undefined + EXPECT_EQ(res.Failure().str(), R"(:3:18 error: binary: operand is undefined %2:i32 = add undef, 2i ^^^^^ @@ -919,7 +919,7 @@ auto res = ir::Validate(mod); ASSERT_FALSE(res); - EXPECT_EQ(res.Failure().str(), R"(:3:22 error: binary: right operand is undefined + EXPECT_EQ(res.Failure().str(), R"(:3:22 error: binary: operand is undefined %2:i32 = add 2i, undef ^^^^^ @@ -976,7 +976,7 @@ auto res = ir::Validate(mod); ASSERT_FALSE(res); - EXPECT_EQ(res.Failure().str(), R"(:3:23 error: unary: value operand is undefined + EXPECT_EQ(res.Failure().str(), R"(:3:23 error: unary: operand is undefined %2:i32 = negation undef ^^^^^