! * \brief Call the custom any hash function registered in type attribute column. * \param custom_any_hash The custom any hash function object or function pointer. * \param src The source Any. * \return The hash value. */
| 658 | * \return The hash value. |
| 659 | */ |
| 660 | static uint64_t CallCustomAnyHash(const TVMFFIAny& custom_any_hash, const Any& src) { |
| 661 | // NOTE: we explicitly use low-level ABI here since we do not want to have dep on function.h |
| 662 | // it also keeps the logic simple |
| 663 | if (custom_any_hash.type_index == TypeIndex::kTVMFFIOpaquePtr) { |
| 664 | // we allow this attribute to be a function pointer for fast path |
| 665 | using FCustomAnyHashPtr = int64_t (*)(const Any&); |
| 666 | FCustomAnyHashPtr hash_func = reinterpret_cast<FCustomAnyHashPtr>(custom_any_hash.v_ptr); |
| 667 | TVM_FFI_ICHECK_NOTNULL(hash_func); |
| 668 | return static_cast<uint64_t>( |
| 669 | (*hash_func)(src)); // NOLINT(clang-analyzer-core.CallAndMessage) |
| 670 | } else { |
| 671 | // alternatively it can be a ffi.Function object. |
| 672 | TVM_FFI_ICHECK_EQ(custom_any_hash.type_index, TypeIndex::kTVMFFIFunction); |
| 673 | TVMFFIAny arg = src.data_; |
| 674 | TVMFFIAny result; |
| 675 | result.type_index = TypeIndex::kTVMFFINone; |
| 676 | result.zero_padding = 0; |
| 677 | result.v_int64 = 0; |
| 678 | TVMFFIFunctionCell* func_cell = TVMFFIFunctionGetCellPtr(custom_any_hash.v_obj); |
| 679 | if (func_cell->cpp_call != nullptr) { |
| 680 | // Fast path: invoke C++ ABI call directly when available. |
| 681 | using FCppCall = void (*)(const void*, const TVMFFIAny*, int32_t, TVMFFIAny*); |
| 682 | reinterpret_cast<FCppCall>(func_cell->cpp_call)(custom_any_hash.v_obj, &arg, 1, &result); |
| 683 | } else { |
| 684 | if (func_cell->safe_call(custom_any_hash.v_obj, &arg, 1, &result) != 0) { |
| 685 | throw details::MoveFromSafeCallRaised(); |
| 686 | } |
| 687 | } |
| 688 | Any result_any = details::AnyUnsafe::MoveTVMFFIAnyToAny(&result); |
| 689 | TVM_FFI_ICHECK_EQ(result_any.type_index(), TypeIndex::kTVMFFIInt); |
| 690 | return static_cast<uint64_t>(result_any.data_.v_int64); |
| 691 | } |
| 692 | } |
| 693 | }; |
| 694 | |
| 695 | /*! \brief String-aware Any hash functor */ |
nothing calls this directly
no test coverage detected