Skip to content

Commit

Permalink
apparently i was barking up the wrong tree, try something simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
chandlerc committed Sep 9, 2024
1 parent c2f0fb8 commit 2451fbd
Showing 1 changed file with 1 addition and 38 deletions.
39 changes: 1 addition & 38 deletions common/check_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
#ifndef CARBON_COMMON_CHECK_INTERNAL_H_
#define CARBON_COMMON_CHECK_INTERNAL_H_

#include "llvm/Support/FormatVariadic.h"

#ifdef NDEBUG
#include "common/template_string.h"
#endif
#include "llvm/Support/FormatVariadic.h"

namespace Carbon::Internal {

Expand All @@ -26,29 +23,6 @@ namespace Carbon::Internal {
//
// The format string and values are directly passed to `llvm::formatv` which
// handles all of the formatting of output.
//
// We have different forms of this in debug builds and normal builds to minimize
// the code size cost.
#ifndef NDEBUG
// Uses a runtime format string in debug builds to avoid encoding the format
// string into the mangle name and having a duplicate function for every single
// check function.
template <typename... Ts>
[[noreturn, gnu::cold]] auto CheckFail(const char* kind, const char* file,
int line, const char* condition_str,
const char* format_str, Ts&&... values)
-> void {
if constexpr (sizeof...(values) == 0) {
CheckFailImpl(kind, file, line, condition_str, format_str);
} else {
CheckFailImpl(kind, file, line, condition_str,
llvm::formatv(format_str, std::forward<Ts>(values)...).str());
}
}
#else
// Use a template parameter for the format string in optimized builds. This will
// result in essentially every check generating a separate function, but makes
// the impact on the caller slightly smaller.
template <TemplateString Kind, TemplateString File, int Line,
TemplateString ConditionStr, TemplateString FormatStr, typename... Ts>
[[noreturn, gnu::cold, clang::noinline, clang::preserve_most]] auto CheckFail(
Expand All @@ -62,27 +36,16 @@ template <TemplateString Kind, TemplateString File, int Line,
llvm::formatv(FormatStr.c_str(), std::forward<Ts>(values)...).str());
}
}
#endif

} // namespace Carbon::Internal

// Dispatch helper between debug and optimized builds for the different
// formulation of the actual check function.
#ifndef NDEBUG
// Pass the format string as a runtime parameter in debug builds.
#define CARBON_INTERNAL_CHECK_IMPL_CALL(kind, file, line, condition_str, \
format_str, ...) \
Carbon::Internal::CheckFail(kind, file, line, condition_str, \
format_str __VA_OPT__(, ) __VA_ARGS__)
#else
// Pass the format string as a template parameter in optimized builds. Note that
// the template arguments include commas and so require extra parentheses to use
// within a macro.
#define CARBON_INTERNAL_CHECK_IMPL_CALL(kind, file, line, condition_str, \
format_str, ...) \
(Carbon::Internal::CheckFail<kind, file, line, condition_str, format_str>( \
__VA_ARGS__))
#endif

// Calls `CheckFail` with the provided message plus a newline and with no
// parameters. This implements check messages without any formatted values.
Expand Down

0 comments on commit 2451fbd

Please sign in to comment.