diff --git a/src/ast/node.h b/src/ast/node.h index cfc1111bce..10546b0f71 100644 --- a/src/ast/node.h +++ b/src/ast/node.h @@ -18,7 +18,6 @@ #include #include "src/clone_context.h" -#include "src/program_id.h" namespace tint { diff --git a/src/program_id.cc b/src/program_id.cc index c27ac452a1..13fdc53ca2 100644 --- a/src/program_id.cc +++ b/src/program_id.cc @@ -32,4 +32,27 @@ ProgramID ProgramID::New() { return ProgramID(next_program_id++); } +namespace detail { + +/// AssertProgramIDsEqual is called by TINT_ASSERT_PROGRAM_IDS_EQUAL() and +/// TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID() to assert that the ProgramIDs +/// `a` and `b` are equal. +void AssertProgramIDsEqual(ProgramID a, + ProgramID b, + bool if_valid, + diag::System system, + const char* msg, + const char* file, + size_t line) { + if (a == b) { + return; // matched + } + if (if_valid && (!a || !b)) { + return; // a or b were not valid + } + diag::List diagnostics; + tint::InternalCompilerError(file, line, system, diagnostics) << msg; +} + +} // namespace detail } // namespace tint diff --git a/src/program_id.h b/src/program_id.h index bd98220b72..92e341af80 100644 --- a/src/program_id.h +++ b/src/program_id.h @@ -83,27 +83,15 @@ inline std::ostream& operator<<(std::ostream& out, ProgramID id) { namespace detail { /// AssertProgramIDsEqual is called by TINT_ASSERT_PROGRAM_IDS_EQUAL() and -/// TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID() to assert that the ProgramIDs of +/// TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID() to assert that the ProgramIDs /// `a` and `b` are equal. -template -void AssertProgramIDsEqual(A&& a, - B&& b, +void AssertProgramIDsEqual(ProgramID a, + ProgramID b, bool if_valid, diag::System system, const char* msg, const char* file, - size_t line) { - auto a_id = ProgramIDOf(std::forward(a)); - auto b_id = ProgramIDOf(std::forward(b)); - if (a_id == b_id) { - return; // matched - } - if (if_valid && (!a_id || !b_id)) { - return; // a or b were not valid - } - diag::List diagnostics; - tint::InternalCompilerError(file, line, system, diagnostics) << msg; -} + size_t line); } // namespace detail @@ -114,14 +102,14 @@ void AssertProgramIDsEqual(A&& a, /// that the program identifiers for A and B are equal, if both A and B have /// valid program identifiers. #if TINT_CHECK_FOR_CROSS_PROGRAM_LEAKS -#define TINT_ASSERT_PROGRAM_IDS_EQUAL(system, a, b) \ - detail::AssertProgramIDsEqual(a, b, false, tint::diag::System::system, \ - "TINT_ASSERT_PROGRAM_IDS_EQUAL(" #system \ - "," #a ", " #b ")", \ - __FILE__, __LINE__) +#define TINT_ASSERT_PROGRAM_IDS_EQUAL(system, a, b) \ + detail::AssertProgramIDsEqual( \ + ProgramIDOf(a), ProgramIDOf(b), false, tint::diag::System::system, \ + "TINT_ASSERT_PROGRAM_IDS_EQUAL(" #system "," #a ", " #b ")", __FILE__, \ + __LINE__) #define TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(system, a, b) \ detail::AssertProgramIDsEqual( \ - a, b, true, tint::diag::System::system, \ + ProgramIDOf(a), ProgramIDOf(b), true, tint::diag::System::system, \ "TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(" #system ", " #a ", " #b ")", \ __FILE__, __LINE__) #else