Skip to content

Commit

Permalink
Drop our aliases for QCHECK().
Browse files Browse the repository at this point in the history
Now that Abseil has released logging, we are removing many of our macros in favor of the Abseil macros they alias. See also the github issue.

Work towards google#1318.

PiperOrigin-RevId: 610789664
  • Loading branch information
grebe authored and copybara-github committed Feb 27, 2024
1 parent 9984073 commit e4d3071
Show file tree
Hide file tree
Showing 48 changed files with 188 additions and 183 deletions.
1 change: 1 addition & 0 deletions third_party/xls_berkeley_softfloat/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ cc_test(
tags = ["optonly"],
deps = [
":fpdiv_2x32_jit_wrapper",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/random",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings:str_format",
Expand Down
7 changes: 4 additions & 3 deletions third_party/xls_berkeley_softfloat/fpdiv_2x32_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <cmath>
#include <tuple>

#include "absl/flags/flag.h"
#include "absl/random/random.h"
#include "absl/status/status.h"
#include "absl/strings/str_format.h"
Expand Down Expand Up @@ -118,8 +119,8 @@ absl::Status RealMain(bool use_opt_ir, uint64_t num_samples, int num_threads) {

int main(int argc, char** argv) {
xls::InitXls(argv[0], argc, argv);
XLS_QCHECK_OK(xls::RealMain(absl::GetFlag(FLAGS_use_opt_ir),
absl::GetFlag(FLAGS_num_samples),
absl::GetFlag(FLAGS_num_threads)));
QCHECK_OK(xls::RealMain(absl::GetFlag(FLAGS_use_opt_ir),
absl::GetFlag(FLAGS_num_samples),
absl::GetFlag(FLAGS_num_threads)));
return 0;
}
4 changes: 4 additions & 0 deletions third_party/xls_go_math/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ cc_test(
tags = ["optonly"],
deps = [
":fpexp_32_jit_wrapper",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/random",
"@com_google_absl//absl/status",
"//xls/common:init_xls",
Expand Down Expand Up @@ -150,6 +151,7 @@ cc_test(
tags = ["optonly"],
deps = [
":fp_sincos_32_jit_wrapper",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/random",
"@com_google_absl//absl/status",
"//xls/common:init_xls",
Expand Down Expand Up @@ -214,6 +216,7 @@ cc_test(
tags = ["optonly"],
deps = [
":fp_trig_reduce_jit_wrapper",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/numeric:int128",
"@com_google_absl//absl/random",
"@com_google_absl//absl/status",
Expand Down Expand Up @@ -275,6 +278,7 @@ cc_test(
tags = ["optonly"],
deps = [
":fpsqrt_32_jit_wrapper",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/random",
"@com_google_absl//absl/status",
"//xls/common:init_xls",
Expand Down
5 changes: 3 additions & 2 deletions third_party/xls_go_math/fp_sincos_32_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <cmath>
#include <tuple>

#include "absl/flags/flag.h"
#include "absl/random/random.h"
#include "absl/status/status.h"
#include "xls/common/file/get_runfile_path.h"
Expand Down Expand Up @@ -120,7 +121,7 @@ absl::Status RealMain(uint32_t num_samples, int num_threads) {

int main(int argc, char** argv) {
xls::InitXls(argv[0], argc, argv);
XLS_QCHECK_OK(xls::RealMain(absl::GetFlag(FLAGS_num_samples),
absl::GetFlag(FLAGS_num_threads)));
QCHECK_OK(xls::RealMain(absl::GetFlag(FLAGS_num_samples),
absl::GetFlag(FLAGS_num_threads)));
return 0;
}
7 changes: 4 additions & 3 deletions third_party/xls_go_math/fp_trig_reduce_64_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <cmath>
#include <tuple>

#include "absl/flags/flag.h"
#include "absl/numeric/int128.h"
#include "absl/random/random.h"
#include "absl/status/status.h"
Expand Down Expand Up @@ -205,8 +206,8 @@ absl::Status RealMain(bool use_opt_ir, uint64_t num_samples, int num_threads) {

int main(int argc, char** argv) {
xls::InitXls(argv[0], argc, argv);
XLS_QCHECK_OK(xls::RealMain(absl::GetFlag(FLAGS_use_opt_ir),
absl::GetFlag(FLAGS_num_samples),
absl::GetFlag(FLAGS_num_threads)));
QCHECK_OK(xls::RealMain(absl::GetFlag(FLAGS_use_opt_ir),
absl::GetFlag(FLAGS_num_samples),
absl::GetFlag(FLAGS_num_threads)));
return 0;
}
5 changes: 3 additions & 2 deletions third_party/xls_go_math/fpexp_32_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <cmath>
#include <limits>

#include "absl/flags/flag.h"
#include "absl/random/random.h"
#include "absl/status/status.h"
#include "xls/common/file/get_runfile_path.h"
Expand Down Expand Up @@ -96,7 +97,7 @@ absl::Status RealMain(uint64_t num_samples, int num_threads) {

int main(int argc, char** argv) {
xls::InitXls(argv[0], argc, argv);
XLS_QCHECK_OK(xls::RealMain(absl::GetFlag(FLAGS_num_samples),
absl::GetFlag(FLAGS_num_threads)));
QCHECK_OK(xls::RealMain(absl::GetFlag(FLAGS_num_samples),
absl::GetFlag(FLAGS_num_threads)));
return 0;
}
5 changes: 3 additions & 2 deletions third_party/xls_go_math/fpsqrt_32_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <cmath>
#include <limits>

#include "absl/flags/flag.h"
#include "absl/random/random.h"
#include "absl/status/status.h"
#include "xls/common/file/get_runfile_path.h"
Expand Down Expand Up @@ -73,7 +74,7 @@ absl::Status RealMain(uint64_t num_samples, int num_threads) {

int main(int argc, char** argv) {
xls::InitXls(argv[0], argc, argv);
XLS_QCHECK_OK(xls::RealMain(absl::GetFlag(FLAGS_num_samples),
absl::GetFlag(FLAGS_num_threads)));
QCHECK_OK(xls::RealMain(absl::GetFlag(FLAGS_num_samples),
absl::GetFlag(FLAGS_num_threads)));
return 0;
}
2 changes: 1 addition & 1 deletion third_party/xls_machsuite/fft/fft_reference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,6 @@ absl::Status RealMain() {

int main(int argc, char** argv) {
xls::InitXls(argv[0], argc, argv);
XLS_QCHECK_OK(xls::RealMain());
QCHECK_OK(xls::RealMain());
return 0;
}
11 changes: 1 addition & 10 deletions xls/common/logging/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
// Even seemingly unconditional statements like `XLS_LOG(INFO)` might be
// disabled at compile-time to minimize binary size or for security reasons.
//
// * Except for the condition in a `XLS_CHECK` or `XLS_QCHECK` statement,
// * Except for the condition in a `XLS_CHECK` or `QCHECK` statement,
// programs must not rely on evaluation of expressions anywhere in logging
// statements for correctness. For example, this is ok:
//
Expand Down Expand Up @@ -221,16 +221,7 @@
#define XLS_CHECK_GE(val1, val2) CHECK_GE(val1, val2)
#define XLS_CHECK_GT(val1, val2) CHECK_GT(val1, val2)

#define XLS_QCHECK(condition) QCHECK(condition)
#define XLS_QCHECK_EQ(val1, val2) QCHECK_EQ(val1, val2)
#define XLS_QCHECK_NE(val1, val2) QCHECK_NE(val1, val2)
#define XLS_QCHECK_LE(val1, val2) QCHECK_LE(val1, val2)
#define XLS_QCHECK_LT(val1, val2) QCHECK_LT(val1, val2)
#define XLS_QCHECK_GE(val1, val2) QCHECK_GE(val1, val2)
#define XLS_QCHECK_GT(val1, val2) QCHECK_GT(val1, val2)

#define XLS_CHECK_OK(val) CHECK_OK(val)
#define XLS_QCHECK_OK(val) QCHECK_OK(val)


#endif // XLS_COMMON_LOGGING_LOGGING_H_
39 changes: 20 additions & 19 deletions xls/common/logging/logging_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ TEST_F(LoggingTest, CheckPrintsStackTraceWhenConditionFails) {
}

TEST_F(LoggingTest, QcheckDoesNothingWhenConditionHolds) {
XLS_QCHECK(true);
QCHECK(true);

EXPECT_EQ(entries_.size(), 0);
}
Expand All @@ -126,7 +126,7 @@ TEST_F(LoggingTest, QcheckCrashesWhenConditionFails) {
EXPECT_DEATH(
{
bool condition_variable = false;
XLS_QCHECK(condition_variable);
QCHECK(condition_variable);
},
HasSubstr("condition_variable"));
}
Expand Down Expand Up @@ -201,63 +201,63 @@ TEST_F(LoggingTest, CheckGtCrashesWhenConditionFails) {
}

TEST_F(LoggingTest, QcheckEqDoesNothingWhenConditionHolds) {
XLS_QCHECK_EQ(1, 1);
QCHECK_EQ(1, 1);

EXPECT_EQ(entries_.size(), 0);
}

TEST_F(LoggingTest, QcheckEqCrashesWhenConditionFails) {
EXPECT_DEATH({ XLS_QCHECK_EQ(1, 2); }, HasSubstr("1 == 2"));
EXPECT_DEATH({ QCHECK_EQ(1, 2); }, HasSubstr("1 == 2"));
}

TEST_F(LoggingTest, QcheckNeDoesNothingWhenConditionHolds) {
XLS_QCHECK_NE(1, 2);
QCHECK_NE(1, 2);

EXPECT_EQ(entries_.size(), 0);
}

TEST_F(LoggingTest, QcheckNeCrashesWhenConditionFails) {
EXPECT_DEATH({ XLS_QCHECK_NE(1, 1); }, HasSubstr("1 != 1"));
EXPECT_DEATH({ QCHECK_NE(1, 1); }, HasSubstr("1 != 1"));
}

TEST_F(LoggingTest, QcheckLeDoesNothingWhenConditionHolds) {
XLS_QCHECK_LE(1, 1);
QCHECK_LE(1, 1);

EXPECT_EQ(entries_.size(), 0);
}

TEST_F(LoggingTest, QcheckLeCrashesWhenConditionFails) {
EXPECT_DEATH({ XLS_QCHECK_LE(2, 1); }, HasSubstr("2 <= 1"));
EXPECT_DEATH({ QCHECK_LE(2, 1); }, HasSubstr("2 <= 1"));
}

TEST_F(LoggingTest, QcheckLtDoesNothingWhenConditionHolds) {
XLS_QCHECK_LT(1, 2);
QCHECK_LT(1, 2);

EXPECT_EQ(entries_.size(), 0);
}

TEST_F(LoggingTest, QcheckLtCrashesWhenConditionFails) {
EXPECT_DEATH({ XLS_QCHECK_LT(1, 1); }, HasSubstr("1 < 1"));
EXPECT_DEATH({ QCHECK_LT(1, 1); }, HasSubstr("1 < 1"));
}

TEST_F(LoggingTest, QcheckGeDoesNothingWhenConditionHolds) {
XLS_QCHECK_GE(1, 1);
QCHECK_GE(1, 1);

EXPECT_EQ(entries_.size(), 0);
}

TEST_F(LoggingTest, QcheckGeCrashesWhenConditionFails) {
EXPECT_DEATH({ XLS_QCHECK_GE(1, 2); }, HasSubstr("1 >= 2"));
EXPECT_DEATH({ QCHECK_GE(1, 2); }, HasSubstr("1 >= 2"));
}

TEST_F(LoggingTest, QcheckGtDoesNothingWhenConditionHolds) {
XLS_QCHECK_GT(2, 1);
QCHECK_GT(2, 1);

EXPECT_EQ(entries_.size(), 0);
}

TEST_F(LoggingTest, QcheckGtCrashesWhenConditionFails) {
EXPECT_DEATH({ XLS_QCHECK_GT(1, 1); }, HasSubstr("1 > 1"));
EXPECT_DEATH({ QCHECK_GT(1, 1); }, HasSubstr("1 > 1"));
}

TEST_F(LoggingTest, CheckOkDoesNothingWithOkStatus) {
Expand All @@ -277,19 +277,20 @@ TEST_F(LoggingTest, CheckOkCrashesWithStackTrace) {
}

TEST_F(LoggingTest, QcheckOkDoesNothingWithOkStatus) {
XLS_QCHECK_OK(absl::OkStatus());
QCHECK_OK(absl::OkStatus());

EXPECT_EQ(entries_.size(), 0);
}

TEST_F(LoggingTest, QcheckOkCrashesWithNonOkStatus) {
EXPECT_DEATH({ XLS_QCHECK_OK(absl::UnknownError("error_msg")); },
HasSubstr("error_msg"));
EXPECT_DEATH(
{ QCHECK_OK(absl::UnknownError("error_msg")); }, HasSubstr("error_msg"));
}

TEST_F(LoggingTest, QcheckOkCrashesWithoutStackTrace) {
EXPECT_DEATH({ XLS_QCHECK_OK(absl::UnknownError("error_msg")); },
Not(HasSubstr("CheckOkCrashesWithStackTrace")));
EXPECT_DEATH(
{ QCHECK_OK(absl::UnknownError("error_msg")); },
Not(HasSubstr("CheckOkCrashesWithStackTrace")));
}

} // namespace
Expand Down
17 changes: 8 additions & 9 deletions xls/contrib/xlscc/xlscc_logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

#define XLSCC_CHECK(condition, loc) \
XLS_CHECK(condition) << ErrorMessage(loc, "")
#define XLSCC_QCHECK(condition, loc) \
XLS_QCHECK(condition) << ErrorMessage(loc, "")
#define XLSCC_QCHECK(condition, loc) QCHECK(condition) << ErrorMessage(loc, "")
#define XLSCC_DCHECK(condition, loc) DCHECK(condition) << ErrorMessage(loc, "")

#define XLSCC_CHECK_EQ(val1, val2, loc) \
Expand All @@ -34,17 +33,17 @@
#define XLSCC_CHECK_GT(val1, val2, loc) \
XLS_CHECK_GT(val1, val2) << ErrorMessage(loc, "")
#define XLSCC_QCHECK_EQ(val1, val2, loc) \
XLS_QCHECK_EQ(val1, val2) << ErrorMessage(loc, "")
QCHECK_EQ(val1, val2) << ErrorMessage(loc, "")
#define XLSCC_QCHECK_NE(val1, val2, loc) \
XLS_QCHECK_NE(val1, val2) << ErrorMessage(loc, "")
QCHECK_NE(val1, val2) << ErrorMessage(loc, "")
#define XLSCC_QCHECK_LE(val1, val2, loc) \
XLS_QCHECK_LE(val1, val2) << ErrorMessage(loc, "")
QCHECK_LE(val1, val2) << ErrorMessage(loc, "")
#define XLSCC_QCHECK_LT(val1, val2, loc) \
XLS_QCHECK_LT(val1, val2) << ErrorMessage(loc, "")
QCHECK_LT(val1, val2) << ErrorMessage(loc, "")
#define XLSCC_QCHECK_GE(val1, val2, loc) \
XLS_QCHECK_GE(val1, val2) << ErrorMessage(loc, "")
QCHECK_GE(val1, val2) << ErrorMessage(loc, "")
#define XLSCC_QCHECK_GT(val1, val2, loc) \
XLS_QCHECK_GT(val1, val2) << ErrorMessage(loc, "")
QCHECK_GT(val1, val2) << ErrorMessage(loc, "")

#define XLSCC_DCHECK_EQ(val1, val2, loc) \
XLSCC_CHECK_EQ(val1, val2) << ErrorMessage(loc, "")
Expand All @@ -60,7 +59,7 @@
XLSCC_CHECK_GT(val1, val2) << ErrorMessage(loc, "")

#define XLSCC_CHECK_OK(val, loc) XLS_CHECK_EQ(val) << ErrorMessage(loc, "")
#define XLSCC_QCHECK_OK(val, loc) XLS_QCHECK_EQ(val) << ErrorMessage(loc, "")
#define XLSCC_QCHECK_OK(val, loc) QCHECK_EQ(val) << ErrorMessage(loc, "")
#define XLSCC_DCHECK_OK(val, loc) DCHECK_EQ(val) << ErrorMessage(loc), ""

#endif // XLSCC_COMMON_LOGGING_LOGGING_H_
3 changes: 1 addition & 2 deletions xls/dslx/bytecode/bytecode_interpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1660,8 +1660,7 @@ absl::StatusOr<ProcRunResult> ProcInstance::Run() {
if (next_args_.size() == proc_->members().size() + 2) {
next_args_[proc_->members().size() + 1] = result_value;
} else {
XLS_QCHECK(result_value.IsTuple() &&
result_value.GetLength().value() == 0);
QCHECK(result_value.IsTuple() && result_value.GetLength().value() == 0);
}

XLS_RETURN_IF_ERROR(interpreter_->InitFrame(next_fn_.get(), next_args_,
Expand Down
4 changes: 2 additions & 2 deletions xls/dslx/cpp_transpiler/cpp_transpiler_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ int main(int argc, char* argv[]) {
}

std::string output_header_path = absl::GetFlag(FLAGS_output_header_path);
XLS_QCHECK(!output_header_path.empty())
QCHECK(!output_header_path.empty())
<< "--output_header_path must be specified.";
std::string output_source_path = absl::GetFlag(FLAGS_output_source_path);
XLS_QCHECK(!output_source_path.empty())
QCHECK(!output_source_path.empty())
<< "--output_source_path must be specified.";
return xls::ExitStatus(xls::dslx::RealMain(
args[0], absl::GetFlag(FLAGS_dslx_stdlib_path), output_header_path,
Expand Down
4 changes: 2 additions & 2 deletions xls/dslx/interpreter_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ int main(int argc, char* argv[]) {
absl::StatusOr<xls::FormatPreference> flag_preference =
xls::FormatPreferenceFromString(absl::GetFlag(FLAGS_format_preference));
// `default` is not a legal overriding format preference.
XLS_QCHECK(flag_preference.ok() &&
absl::GetFlag(FLAGS_format_preference) != "default")
QCHECK(flag_preference.ok() &&
absl::GetFlag(FLAGS_format_preference) != "default")
<< "-format_preference accepts binary|hex|decimal";
preference = flag_preference.value();
}
Expand Down
4 changes: 2 additions & 2 deletions xls/dslx/ir_convert/ir_converter_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ absl::Status RealMain(absl::Span<const std::string_view> paths,
// The following checks are performed inside ConvertFilesToPackage(), but we
// reproduce them here to give nicer error messages.
if (!package_name.has_value()) {
XLS_QCHECK_EQ(paths.size(), 1)
QCHECK_EQ(paths.size(), 1)
<< "-package_name *must* be given when multiple input paths are "
"supplied";
}
if (paths.size() > 1) {
XLS_QCHECK(!top.has_value())
QCHECK(!top.has_value())
<< "-entry cannot be supplied with multiple input paths (need a single "
"input path to know where to resolve the entry function)";
}
Expand Down
3 changes: 3 additions & 0 deletions xls/dslx/type_system/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -616,13 +616,16 @@ cc_binary(
deps = [
":type_info_to_proto",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:span",
"//xls/common:exit_status",
"//xls/common:init_xls",
"//xls/common/file:filesystem",
"//xls/common/logging",
"//xls/common/status:status_macros",
"//xls/dslx:command_line_utils",
"//xls/dslx:create_import_data",
"//xls/dslx:default_dslx_stdlib_path",
Expand Down
Loading

0 comments on commit e4d3071

Please sign in to comment.