Skip to content

Deprecate ET_LOG{,_MSG}_AND_RETURN_IF_FALSE #8451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions runtime/core/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ using ::executorch::runtime::error_code_t;
} \
}

/**
* A convenience macro to be used in utility functions that check whether input
* tensor(s) are valid, which are expected to return a boolean. Checks whether
* `cond` is true; if not, log the failed check with `message` and return false.
*
* @param[in] cond the condition to check
* @param[in] message an additional message to log with `cond`
*/
#define ET_CHECK_OR_RETURN_FALSE(cond__, message__, ...) \
{ \
if (!(cond__)) { \
ET_LOG(Error, "Check failed (%s): " message__, #cond__, ##__VA_ARGS__); \
return false; \
} \
}

/**
* If error__ is not Error::Ok, optionally log a message and return the error
* from the current function, which must be of return type
Expand Down
27 changes: 7 additions & 20 deletions runtime/core/exec_aten/util/tensor_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,35 +332,22 @@
})

/**
* DEPRECATED: Please use ET_CHECK_OR_RETURN_FALSE instead and provide
* an informative message. (For example, the values of any variables used in
* `cond` would not be reported automatically by this macro.)
*
* A convenience macro to be used in utility functions that check whether input
* tensor(s) are valid, which are expected to return a boolean. Checks whether
* `cond` is true; if not, log the failed check and return false.
*
* @param[in] cond the condition to check
*/
#define ET_LOG_AND_RETURN_IF_FALSE(cond) \
do { \
if (!(cond)) { \
ET_LOG(Error, "Check failed (%s): ", #cond); \
return false; \
} \
} while (false)
#define ET_LOG_AND_RETURN_IF_FALSE(cond) ET_CHECK_OR_RETURN_FALSE(cond, "")

/**
* A convenience macro to be used in utility functions that check whether input
* tensor(s) are valid, which are expected to return a boolean. Checks whether
* `cond` is true; if not, log the failed check with `message` and return false.
*
* @param[in] cond the condition to check
* @param[in] message an additional message to log with `cond`
* DEPRECATED: Please use ET_CHECK_OR_RETURN_FALSE instead.
*/
#define ET_LOG_MSG_AND_RETURN_IF_FALSE(cond, message, ...) \
do { \
if (!(cond)) { \
ET_LOG(Error, "Check failed (%s): " message, #cond, ##__VA_ARGS__); \
return false; \
} \
} while (false)
#define ET_LOG_MSG_AND_RETURN_IF_FALSE ET_CHECK_OR_RETURN_FALSE

/**
* If `cond` is false, log `cond` and return from the kernel with a failure
Expand Down
Loading