Kathryn-cat commented on code in PR #399:
URL: https://github.com/apache/tvm-ffi/pull/399#discussion_r2723246677
##########
include/tvm/ffi/function_details.h:
##########
@@ -67,10 +72,23 @@ static constexpr bool ArgSupported =
std::is_same_v<std::remove_const_t<std::remove_reference_t<T>>, AnyView>
||
TypeTraitsNoCR<T>::convert_enabled));
+template <typename T>
+struct is_expected : std::false_type {
+ using value_type = void;
+};
+
+template <typename T>
+struct is_expected<Expected<T>> : std::true_type {
+ using value_type = T;
+};
+
+template <typename T>
+inline constexpr bool is_expected_v = is_expected<T>::value;
+
// NOTE: return type can only support non-reference managed returns
template <typename T>
-static constexpr bool RetSupported =
- (std::is_same_v<T, Any> || std::is_void_v<T> ||
TypeTraits<T>::convert_enabled);
+static constexpr bool RetSupported = (std::is_same_v<T, Any> ||
std::is_void_v<T> ||
+ TypeTraits<T>::convert_enabled ||
is_expected_v<T>);
Review Comment:
I think `convert_enabled` is already True here, `is_expected_v` might be
redundant
##########
include/tvm/ffi/function_details.h:
##########
@@ -219,6 +237,14 @@ TVM_FFI_INLINE void
unpack_call(std::index_sequence<Is...>, const std::string* o
// use index sequence to do recursive-less unpacking
if constexpr (std::is_same_v<R, void>) {
f(ArgValueWithContext<std::tuple_element_t<Is, PackedArgs>>{args, Is,
optional_name, f_sig}...);
+ } else if constexpr (is_expected_v<R>) {
+ R expected_result = f(ArgValueWithContext<std::tuple_element_t<Is,
PackedArgs>>{
+ args, Is, optional_name, f_sig}...);
+ if (expected_result.is_ok()) {
+ *rv = expected_result.value();
+ } else {
+ throw expected_result.error();
Review Comment:
Perhaps use move?
```
if (expected_result.is_ok()) {
*rv = std::move(expected_result).value();
} else {
throw std::move(expected_result).error();
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]