You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "junrushao (via GitHub)" <gi...@apache.org> on 2026/01/05 08:23:10 UTC
[PR] add docs for any [tvm-ffi]
junrushao opened a new pull request, #382:
URL: https://github.com/apache/tvm-ffi/pull/382
(no comment)
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] doc: Add documentation for Any and AnyView [tvm-ffi]
Posted by "junrushao (via GitHub)" <gi...@apache.org>.
junrushao commented on PR #382:
URL: https://github.com/apache/tvm-ffi/pull/382#issuecomment-3722807920
/gemini Review
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] doc: Add documentation for Any and AnyView [tvm-ffi]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #382:
URL: https://github.com/apache/tvm-ffi/pull/382#discussion_r2671437147
##########
docs/concepts/any.rst:
##########
@@ -0,0 +1,441 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+.. http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+Any and AnyView
+===============
+
+TVM-FFI has :cpp:class:`tvm::ffi::Any` and :cpp:class:`tvm::ffi::AnyView`,
+type-erased containers that hold any supported value and transport it across
+C, C++, Python, and Rust boundaries through a stable ABI.
+
+Similar to ``std::any``, :cpp:class:`~tvm::ffi::Any` is a tagged union that store
+values of wide variety of types, including primitive types, objects, strings, etc.
+Unlike ``std::any``, it is designed for RTTI-free zero-copy inter-language exchange,
+with a fixed 16-byte layout and built-in support for reference counting and ownership.
+
+This tutorial covers all about Any: its common usage patterns, ownership semantics,
+and memory layout.
+
+
+Common Usecases
+---------------
+
+Function inputs and outputs
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Use :cpp:class:`~tvm::ffi::AnyView` for function parameters,
+which avoids reference count churn or unnecessary copies, and :cpp:class:`~tvm::ffi::Any` for return values,
+which transfers ownership to the caller.
+
+.. code-block:: cpp
+
+ ffi::Any func_cpp_signature(ffi::AnyView arg0, ffi::AnyView arg1) {
+ ffi::Any result = arg0.cast<int>() + arg1.cast<int>();
+ return result;
+ }
+
+ // Variant: variadic function
+ void func_cpp_variadic(PackedArgs args, Any* ret) {
+ int32_t num_args = args.size();
+ int x0 = args[0].cast<int>();
+ int x1 = args[1].cast<int>();
+ int y = x0 + x1;
+ *ret = y;
+ }
+
+ // Variant: variadic function with C ABI signature
+ int func_c_abi_variadic(void*, const TVMFFIAny* args, int32_t num_args, TVMFFIAny* ret) {
+ TVM_FFI_SAFE_CALL_BEGIN();
+ int x0 = reinterpret_cast<const AnyView*>(args)[0].cast<int>();
+ int x1 = reinterpret_cast<const AnyView*>(args)[1].cast<int>();
+ int y = x0 + x1;
+ reinterpret_cast<Any*>(ret)[0] = y;
+ TVM_FFI_SAFE_CALL_END();
+ }
+
+
+Container Storage
+~~~~~~~~~~~~~~~~~
+
+:cpp:class:`~tvm::ffi::Any` can be stored in containers like :cpp:class:`~tvm::ffi::Map` and :cpp:class:`~tvm::ffi::Array`:
+
+.. code-block:: cpp
+
+ ffi::Map<ffi::String, ffi::Any> config;
+ config.Set("learning_rate", 0.001);
+ config.Set("batch_size", 32);
+ config.Set("device", DLDevice{kDLCUDA, 0});
+
+Extracting Values
+~~~~~~~~~~~~~~~~~
+
+Three methods pull values out of :cpp:class:`~tvm::ffi::Any`
+and :cpp:class:`~tvm::ffi::AnyView`, each with different strictness:
+
+.. list-table::
+ :header-rows: 1
+ :widths: 20 45 30
+
+ * - Method
+ - Behavior
+ - Use When
+ * - :cpp:func:`cast\<T\>() <tvm::ffi::Any::cast>`
+ - Returns ``T`` or throws :cpp:class:`tvm::ffi::Error`
+ - You know the type and want to throw on type mismatch
+ * - :cpp:func:`try_cast\<T\>() <tvm::ffi::Any::try_cast>`
+ - Returns ``std::optional<T>``
+ - Returns None on type mismatch, allows type conversion
+ * - :cpp:func:`as\<T\>() <tvm::ffi::Any::as>`
+ - Returns ``std::optional<T>`` or ``const T*`` (for TVM-FFI object types)
+ - Returns None on type mismatch, but doesn't allow type conversion
+
+.. dropdown:: Example of :cpp:func:`cast\<T\>() <tvm::ffi::Any::cast>`
+
+ :cpp:func:`cast\<T\>() <tvm::ffi::Any::cast>` is the workhorse. It returns the value or throws:
+
+ .. code-block:: cpp
+
+ ffi::Any value = 42;
+ int x = value.cast<int>(); // OK: 42
+ double y = value.cast<double>(); // OK: 42.0 (int → double)
+
+ try {
+ ffi::String s = value.cast<ffi::String>(); // Throws TypeError
+ } catch (const ffi::Error& e) {
+ // "Cannot convert from type `int` to `ffi.Str`"
+ }
+
+.. dropdown:: Example of :cpp:func:`try_cast\<T\>() <tvm::ffi::Any::try_cast>`
+
+ :cpp:func:`try_cast\<T\>() <tvm::ffi::Any::try_cast>` allows type coercion:
+
+ .. code-block:: cpp
+
+ ffi::Any value = 42;
+
+ std::optional<double> opt_float = value.try_cast<double>();
+ // opt_float.has_value() == true, *opt_float == 42.0
+
+ std::optional<bool> opt_bool = value.try_cast<bool>();
+ // opt_bool.has_value() == true, *opt_bool == true
+
+
+.. dropdown:: Example of :cpp:func:`as\<T\>() <tvm::ffi::Any::as>`
+
+ :cpp:func:`as\<T\>() <tvm::ffi::Any::as>` is strict - it only succeeds if the stored type exactly matches:
+
+ .. code-block:: cpp
+
+ ffi::Any value = 42;
+
+ std::optional<int64_t> opt_int = value.as<int64_t>();
+ // opt_int.has_value() == true
+
+ std::optional<double> opt_float = value.as<double>();
+ // opt_float.has_value() == false (int stored, not float)
+
+ ffi::Any value = ffi::String("hello, world!");
+ if (const ffi::Object* obj = value.as<ffi::Object>()) {
+ // Use obj without copying
+ }
+
+
+Nullability Checks
+~~~~~~~~~~~~~~~~~~
+
+Compare with ``nullptr`` to check for ``None``:
+
+.. code-block:: cpp
+
+ ffi::Any value = std::nullopt;
+ if (value == nullptr) {
+ // Handle None case
+ } else {
+ // Process value
+ }
+
+
+Ownership
+---------
+
+The core distinction between :cpp:class:`tvm::ffi::Any` and
+:cpp:class:`tvm::ffi::AnyView` is **ownership**:
+
+.. list-table::
+ :header-rows: 1
+ :widths: 25 35 40
+
+ * - Aspect
+ - :cpp:class:`~tvm::ffi::AnyView`
+ - :cpp:class:`~tvm::ffi::Any`
+ * - Ownership
+ - Non-owning (like ``std::string_view``)
+ - Owning (like ``std::string``)
+ * - Reference counting
+ - No reference count changes on copy
+ - Increments reference count on copy; decrements on destroy
+ * - Lifetime
+ - Valid only while source lives
+ - Extends object lifetime
+ * - Primary use
+ - Function inputs
+ - Return values, storage
+
+Code Examples
+~~~~~~~~~~~~~~
+
+:cpp:class:`~tvm::ffi::AnyView` is a lightweight view. Copying it just copies 16 bytes
+- no reference count updates. This makes it perfect for passing arguments without overhead:
+
+.. code-block:: cpp
+
+ void process(ffi::AnyView value) {}
+
+:cpp:class:`~tvm::ffi::Any` is a managed container. Copy an :cpp:class:`~tvm::ffi::Any` holding an object, and the reference
+count goes up. Destroy it, and the count goes down:
+
+.. code-block:: cpp
+
+ ffi::Any create_value() {
+ ffi::Any result;
+ {
+ ffi::String str = "hello"; // refcount = 1 (str created)
+ result = str; // refcount 1 -> 2 (result owns str)
+ } // refcount 2 -> 1 (str is destroyed)
+ return result; // refcount = 1 (result returns to caller)
+ }
+
+
+ABI Boundary
+~~~~~~~~~~~~
+
+TVM-FFI's function calling convention follows a simple rule:
+
+- **Inputs are non-owning**: Arguments are passed as :cpp:class:`~tvm::ffi::AnyView`. The caller
+ retains ownership; the callee borrows them for the duration of the call.
+- **Outputs are owning**: The return value is an :cpp:class:`~tvm::ffi::Any`. Ownership transfers
+ to the caller, who becomes responsible for the value's lifetime.
+
+.. code-block:: cpp
+
+ // TVM-FFI C ABI
+ int32_t tvm_ffi_c_abi(
+ void* handle,
+ const AnyView* args, // (Non-owning) args: AnyView[num_args]
+ int32_t num_args,
+ Any* result, // (Owning) result: Any (caller takes ownership)
+ );
+
+Destruction Semantics in C
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+In C, which doesn't have RAII, you need to manually destroy the :cpp:class:`~tvm::ffi::Any` object
+by calling :cpp:func:`TVMFFIObjectDecRef` for heap-allocated objects.
+
+.. code-block:: cpp
+
+ void destroy_any(TVMFFIAny* any) {
+ if (any->type_index >= kTVMFFIStaticObjectBegin) {
+ // Decrement the reference count of the heap-allocated object
+ TVMFFIObjectDecRef(any->v_obj);
+ }
+ empty_any_just_to_be_safe(any);
+ }
+
+ void empty_any_just_to_be_safe(Any* any) {
+ any->type_index = kTVMFFINone;
+ any->zero_padding = 0;
+ any->v_int64 = 0;
+ }
Review Comment:

The function `empty_any_just_to_be_safe` is defined to take `Any*`, but it's called with a `TVMFFIAny*` in `destroy_any`. This is a type mismatch. The function should take `TVMFFIAny*` to be compatible with its usage. `Any` is a C++ class wrapper, while `TVMFFIAny` is the underlying C struct, which seems to be the intended type here given the C-style memory manipulation.
```suggestion
void empty_any_just_to_be_safe(TVMFFIAny* any) {
any->type_index = kTVMFFINone;
any->zero_padding = 0;
any->v_int64 = 0;
}
```
##########
docs/concepts/any.rst:
##########
@@ -0,0 +1,441 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+.. http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+Any and AnyView
+===============
+
+TVM-FFI has :cpp:class:`tvm::ffi::Any` and :cpp:class:`tvm::ffi::AnyView`,
+type-erased containers that hold any supported value and transport it across
+C, C++, Python, and Rust boundaries through a stable ABI.
+
+Similar to ``std::any``, :cpp:class:`~tvm::ffi::Any` is a tagged union that store
+values of wide variety of types, including primitive types, objects, strings, etc.
+Unlike ``std::any``, it is designed for RTTI-free zero-copy inter-language exchange,
+with a fixed 16-byte layout and built-in support for reference counting and ownership.
+
+This tutorial covers all about Any: its common usage patterns, ownership semantics,
+and memory layout.
+
+
+Common Usecases
+---------------
+
+Function inputs and outputs
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Use :cpp:class:`~tvm::ffi::AnyView` for function parameters,
+which avoids reference count churn or unnecessary copies, and :cpp:class:`~tvm::ffi::Any` for return values,
+which transfers ownership to the caller.
+
+.. code-block:: cpp
+
+ ffi::Any func_cpp_signature(ffi::AnyView arg0, ffi::AnyView arg1) {
+ ffi::Any result = arg0.cast<int>() + arg1.cast<int>();
+ return result;
+ }
+
+ // Variant: variadic function
+ void func_cpp_variadic(PackedArgs args, Any* ret) {
+ int32_t num_args = args.size();
Review Comment:

The variable `num_args` is declared but never used in this function. It's best to remove it to avoid confusion and keep the example clean.
##########
docs/concepts/any.rst:
##########
@@ -0,0 +1,441 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+.. http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+Any and AnyView
+===============
+
+TVM-FFI has :cpp:class:`tvm::ffi::Any` and :cpp:class:`tvm::ffi::AnyView`,
+type-erased containers that hold any supported value and transport it across
+C, C++, Python, and Rust boundaries through a stable ABI.
+
+Similar to ``std::any``, :cpp:class:`~tvm::ffi::Any` is a tagged union that store
+values of wide variety of types, including primitive types, objects, strings, etc.
+Unlike ``std::any``, it is designed for RTTI-free zero-copy inter-language exchange,
+with a fixed 16-byte layout and built-in support for reference counting and ownership.
+
+This tutorial covers all about Any: its common usage patterns, ownership semantics,
+and memory layout.
+
+
+Common Usecases
+---------------
+
+Function inputs and outputs
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Use :cpp:class:`~tvm::ffi::AnyView` for function parameters,
+which avoids reference count churn or unnecessary copies, and :cpp:class:`~tvm::ffi::Any` for return values,
+which transfers ownership to the caller.
+
+.. code-block:: cpp
+
+ ffi::Any func_cpp_signature(ffi::AnyView arg0, ffi::AnyView arg1) {
+ ffi::Any result = arg0.cast<int>() + arg1.cast<int>();
+ return result;
+ }
+
+ // Variant: variadic function
+ void func_cpp_variadic(PackedArgs args, Any* ret) {
+ int32_t num_args = args.size();
+ int x0 = args[0].cast<int>();
+ int x1 = args[1].cast<int>();
+ int y = x0 + x1;
+ *ret = y;
+ }
+
+ // Variant: variadic function with C ABI signature
+ int func_c_abi_variadic(void*, const TVMFFIAny* args, int32_t num_args, TVMFFIAny* ret) {
+ TVM_FFI_SAFE_CALL_BEGIN();
+ int x0 = reinterpret_cast<const AnyView*>(args)[0].cast<int>();
+ int x1 = reinterpret_cast<const AnyView*>(args)[1].cast<int>();
+ int y = x0 + x1;
+ reinterpret_cast<Any*>(ret)[0] = y;
+ TVM_FFI_SAFE_CALL_END();
+ }
+
+
+Container Storage
+~~~~~~~~~~~~~~~~~
+
+:cpp:class:`~tvm::ffi::Any` can be stored in containers like :cpp:class:`~tvm::ffi::Map` and :cpp:class:`~tvm::ffi::Array`:
+
+.. code-block:: cpp
+
+ ffi::Map<ffi::String, ffi::Any> config;
+ config.Set("learning_rate", 0.001);
+ config.Set("batch_size", 32);
+ config.Set("device", DLDevice{kDLCUDA, 0});
+
+Extracting Values
+~~~~~~~~~~~~~~~~~
+
+Three methods pull values out of :cpp:class:`~tvm::ffi::Any`
+and :cpp:class:`~tvm::ffi::AnyView`, each with different strictness:
+
+.. list-table::
+ :header-rows: 1
+ :widths: 20 45 30
+
+ * - Method
+ - Behavior
+ - Use When
+ * - :cpp:func:`cast\<T\>() <tvm::ffi::Any::cast>`
+ - Returns ``T`` or throws :cpp:class:`tvm::ffi::Error`
+ - You know the type and want to throw on type mismatch
+ * - :cpp:func:`try_cast\<T\>() <tvm::ffi::Any::try_cast>`
+ - Returns ``std::optional<T>``
+ - Returns None on type mismatch, allows type conversion
+ * - :cpp:func:`as\<T\>() <tvm::ffi::Any::as>`
+ - Returns ``std::optional<T>`` or ``const T*`` (for TVM-FFI object types)
+ - Returns None on type mismatch, but doesn't allow type conversion
+
+.. dropdown:: Example of :cpp:func:`cast\<T\>() <tvm::ffi::Any::cast>`
+
+ :cpp:func:`cast\<T\>() <tvm::ffi::Any::cast>` is the workhorse. It returns the value or throws:
+
+ .. code-block:: cpp
+
+ ffi::Any value = 42;
+ int x = value.cast<int>(); // OK: 42
+ double y = value.cast<double>(); // OK: 42.0 (int → double)
+
+ try {
+ ffi::String s = value.cast<ffi::String>(); // Throws TypeError
+ } catch (const ffi::Error& e) {
+ // "Cannot convert from type `int` to `ffi.Str`"
+ }
+
+.. dropdown:: Example of :cpp:func:`try_cast\<T\>() <tvm::ffi::Any::try_cast>`
+
+ :cpp:func:`try_cast\<T\>() <tvm::ffi::Any::try_cast>` allows type coercion:
+
+ .. code-block:: cpp
+
+ ffi::Any value = 42;
+
+ std::optional<double> opt_float = value.try_cast<double>();
+ // opt_float.has_value() == true, *opt_float == 42.0
+
+ std::optional<bool> opt_bool = value.try_cast<bool>();
+ // opt_bool.has_value() == true, *opt_bool == true
+
+
+.. dropdown:: Example of :cpp:func:`as\<T\>() <tvm::ffi::Any::as>`
+
+ :cpp:func:`as\<T\>() <tvm::ffi::Any::as>` is strict - it only succeeds if the stored type exactly matches:
+
+ .. code-block:: cpp
+
+ ffi::Any value = 42;
+
+ std::optional<int64_t> opt_int = value.as<int64_t>();
+ // opt_int.has_value() == true
+
+ std::optional<double> opt_float = value.as<double>();
+ // opt_float.has_value() == false (int stored, not float)
+
+ ffi::Any value = ffi::String("hello, world!");
+ if (const ffi::Object* obj = value.as<ffi::Object>()) {
+ // Use obj without copying
+ }
+
+
+Nullability Checks
+~~~~~~~~~~~~~~~~~~
+
+Compare with ``nullptr`` to check for ``None``:
+
+.. code-block:: cpp
+
+ ffi::Any value = std::nullopt;
+ if (value == nullptr) {
+ // Handle None case
+ } else {
+ // Process value
+ }
+
+
+Ownership
+---------
+
+The core distinction between :cpp:class:`tvm::ffi::Any` and
+:cpp:class:`tvm::ffi::AnyView` is **ownership**:
+
+.. list-table::
+ :header-rows: 1
+ :widths: 25 35 40
+
+ * - Aspect
+ - :cpp:class:`~tvm::ffi::AnyView`
+ - :cpp:class:`~tvm::ffi::Any`
+ * - Ownership
+ - Non-owning (like ``std::string_view``)
+ - Owning (like ``std::string``)
+ * - Reference counting
+ - No reference count changes on copy
+ - Increments reference count on copy; decrements on destroy
+ * - Lifetime
+ - Valid only while source lives
+ - Extends object lifetime
+ * - Primary use
+ - Function inputs
+ - Return values, storage
+
+Code Examples
+~~~~~~~~~~~~~~
+
+:cpp:class:`~tvm::ffi::AnyView` is a lightweight view. Copying it just copies 16 bytes
+- no reference count updates. This makes it perfect for passing arguments without overhead:
+
+.. code-block:: cpp
+
+ void process(ffi::AnyView value) {}
+
+:cpp:class:`~tvm::ffi::Any` is a managed container. Copy an :cpp:class:`~tvm::ffi::Any` holding an object, and the reference
+count goes up. Destroy it, and the count goes down:
+
+.. code-block:: cpp
+
+ ffi::Any create_value() {
+ ffi::Any result;
+ {
+ ffi::String str = "hello"; // refcount = 1 (str created)
+ result = str; // refcount 1 -> 2 (result owns str)
+ } // refcount 2 -> 1 (str is destroyed)
+ return result; // refcount = 1 (result returns to caller)
+ }
+
+
+ABI Boundary
+~~~~~~~~~~~~
+
+TVM-FFI's function calling convention follows a simple rule:
+
+- **Inputs are non-owning**: Arguments are passed as :cpp:class:`~tvm::ffi::AnyView`. The caller
+ retains ownership; the callee borrows them for the duration of the call.
+- **Outputs are owning**: The return value is an :cpp:class:`~tvm::ffi::Any`. Ownership transfers
+ to the caller, who becomes responsible for the value's lifetime.
+
+.. code-block:: cpp
+
+ // TVM-FFI C ABI
+ int32_t tvm_ffi_c_abi(
+ void* handle,
+ const AnyView* args, // (Non-owning) args: AnyView[num_args]
+ int32_t num_args,
+ Any* result, // (Owning) result: Any (caller takes ownership)
+ );
+
+Destruction Semantics in C
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+In C, which doesn't have RAII, you need to manually destroy the :cpp:class:`~tvm::ffi::Any` object
+by calling :cpp:func:`TVMFFIObjectDecRef` for heap-allocated objects.
+
+.. code-block:: cpp
+
+ void destroy_any(TVMFFIAny* any) {
+ if (any->type_index >= kTVMFFIStaticObjectBegin) {
+ // Decrement the reference count of the heap-allocated object
+ TVMFFIObjectDecRef(any->v_obj);
+ }
+ empty_any_just_to_be_safe(any);
+ }
+
+ void empty_any_just_to_be_safe(Any* any) {
+ any->type_index = kTVMFFINone;
+ any->zero_padding = 0;
+ any->v_int64 = 0;
+ }
+
+On the contrary, destroying :cpp:class:`~tvm::ffi::AnyView` is effectively a no-op besides emptying its content.
+
+.. code-block:: cpp
+
+ void destroy_any_view(AnyView* any_view) {
+ empty_any_view_just_to_be_safe(any_view);
+ }
+
+
+Layout
+------
+
+Tagged Union
+~~~~~~~~~~~~
+
+At C ABI level, every value lives in a :cpp:class:`TVMFFIAny`:
+
+.. code-block:: cpp
+
+ typedef struct TVMFFIAny {
+ int32_t type_index; // Bytes 0-3: identifies the stored type
+ union {
+ uint32_t zero_padding; // Bytes 4-7: must be zero (or small_str_len)
+ uint32_t small_str_len;
+ };
+ union { // Bytes 8-15: the actual value
+ int64_t v_int64;
+ double v_float64;
+ void* v_ptr;
+ TVMFFIObject* v_obj;
+ DLDevice v_device;
+ char v_bytes[8];
+ // ... other union members
+ };
Review Comment:

The `TVMFFIAny` struct definition in this example is incomplete compared to the `c_api.h` header and the table of atomic types that follows. It's missing `v_c_str`, `v_dtype`, and `v_uint64`. This can be confusing for readers. Please update the struct definition to be more complete and consistent.
```suggestion
union { // Bytes 8-15: the actual value
int64_t v_int64;
double v_float64;
void* v_ptr;
const char* v_c_str;
TVMFFIObject* v_obj;
DLDataType v_dtype;
DLDevice v_device;
char v_bytes[8];
uint64_t v_uint64;
// ... other union members
};
```
##########
docs/concepts/any.rst:
##########
@@ -0,0 +1,441 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+.. http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+Any and AnyView
+===============
+
+TVM-FFI has :cpp:class:`tvm::ffi::Any` and :cpp:class:`tvm::ffi::AnyView`,
+type-erased containers that hold any supported value and transport it across
+C, C++, Python, and Rust boundaries through a stable ABI.
+
+Similar to ``std::any``, :cpp:class:`~tvm::ffi::Any` is a tagged union that store
+values of wide variety of types, including primitive types, objects, strings, etc.
+Unlike ``std::any``, it is designed for RTTI-free zero-copy inter-language exchange,
+with a fixed 16-byte layout and built-in support for reference counting and ownership.
+
+This tutorial covers all about Any: its common usage patterns, ownership semantics,
+and memory layout.
+
+
+Common Usecases
+---------------
+
+Function inputs and outputs
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Use :cpp:class:`~tvm::ffi::AnyView` for function parameters,
+which avoids reference count churn or unnecessary copies, and :cpp:class:`~tvm::ffi::Any` for return values,
+which transfers ownership to the caller.
+
+.. code-block:: cpp
+
+ ffi::Any func_cpp_signature(ffi::AnyView arg0, ffi::AnyView arg1) {
+ ffi::Any result = arg0.cast<int>() + arg1.cast<int>();
+ return result;
+ }
+
+ // Variant: variadic function
+ void func_cpp_variadic(PackedArgs args, Any* ret) {
+ int32_t num_args = args.size();
+ int x0 = args[0].cast<int>();
+ int x1 = args[1].cast<int>();
+ int y = x0 + x1;
+ *ret = y;
+ }
+
+ // Variant: variadic function with C ABI signature
+ int func_c_abi_variadic(void*, const TVMFFIAny* args, int32_t num_args, TVMFFIAny* ret) {
+ TVM_FFI_SAFE_CALL_BEGIN();
+ int x0 = reinterpret_cast<const AnyView*>(args)[0].cast<int>();
+ int x1 = reinterpret_cast<const AnyView*>(args)[1].cast<int>();
+ int y = x0 + x1;
+ reinterpret_cast<Any*>(ret)[0] = y;
+ TVM_FFI_SAFE_CALL_END();
+ }
+
+
+Container Storage
+~~~~~~~~~~~~~~~~~
+
+:cpp:class:`~tvm::ffi::Any` can be stored in containers like :cpp:class:`~tvm::ffi::Map` and :cpp:class:`~tvm::ffi::Array`:
+
+.. code-block:: cpp
+
+ ffi::Map<ffi::String, ffi::Any> config;
+ config.Set("learning_rate", 0.001);
+ config.Set("batch_size", 32);
+ config.Set("device", DLDevice{kDLCUDA, 0});
+
+Extracting Values
+~~~~~~~~~~~~~~~~~
+
+Three methods pull values out of :cpp:class:`~tvm::ffi::Any`
+and :cpp:class:`~tvm::ffi::AnyView`, each with different strictness:
+
+.. list-table::
+ :header-rows: 1
+ :widths: 20 45 30
+
+ * - Method
+ - Behavior
+ - Use When
+ * - :cpp:func:`cast\<T\>() <tvm::ffi::Any::cast>`
+ - Returns ``T`` or throws :cpp:class:`tvm::ffi::Error`
+ - You know the type and want to throw on type mismatch
+ * - :cpp:func:`try_cast\<T\>() <tvm::ffi::Any::try_cast>`
+ - Returns ``std::optional<T>``
+ - Returns None on type mismatch, allows type conversion
+ * - :cpp:func:`as\<T\>() <tvm::ffi::Any::as>`
+ - Returns ``std::optional<T>`` or ``const T*`` (for TVM-FFI object types)
+ - Returns None on type mismatch, but doesn't allow type conversion
+
+.. dropdown:: Example of :cpp:func:`cast\<T\>() <tvm::ffi::Any::cast>`
+
+ :cpp:func:`cast\<T\>() <tvm::ffi::Any::cast>` is the workhorse. It returns the value or throws:
+
+ .. code-block:: cpp
+
+ ffi::Any value = 42;
+ int x = value.cast<int>(); // OK: 42
+ double y = value.cast<double>(); // OK: 42.0 (int → double)
+
+ try {
+ ffi::String s = value.cast<ffi::String>(); // Throws TypeError
+ } catch (const ffi::Error& e) {
+ // "Cannot convert from type `int` to `ffi.Str`"
+ }
+
+.. dropdown:: Example of :cpp:func:`try_cast\<T\>() <tvm::ffi::Any::try_cast>`
+
+ :cpp:func:`try_cast\<T\>() <tvm::ffi::Any::try_cast>` allows type coercion:
+
+ .. code-block:: cpp
+
+ ffi::Any value = 42;
+
+ std::optional<double> opt_float = value.try_cast<double>();
+ // opt_float.has_value() == true, *opt_float == 42.0
+
+ std::optional<bool> opt_bool = value.try_cast<bool>();
+ // opt_bool.has_value() == true, *opt_bool == true
+
+
+.. dropdown:: Example of :cpp:func:`as\<T\>() <tvm::ffi::Any::as>`
+
+ :cpp:func:`as\<T\>() <tvm::ffi::Any::as>` is strict - it only succeeds if the stored type exactly matches:
+
+ .. code-block:: cpp
+
+ ffi::Any value = 42;
+
+ std::optional<int64_t> opt_int = value.as<int64_t>();
+ // opt_int.has_value() == true
+
+ std::optional<double> opt_float = value.as<double>();
+ // opt_float.has_value() == false (int stored, not float)
+
+ ffi::Any value = ffi::String("hello, world!");
+ if (const ffi::Object* obj = value.as<ffi::Object>()) {
+ // Use obj without copying
+ }
+
+
+Nullability Checks
+~~~~~~~~~~~~~~~~~~
+
+Compare with ``nullptr`` to check for ``None``:
+
+.. code-block:: cpp
+
+ ffi::Any value = std::nullopt;
+ if (value == nullptr) {
+ // Handle None case
+ } else {
+ // Process value
+ }
+
+
+Ownership
+---------
+
+The core distinction between :cpp:class:`tvm::ffi::Any` and
+:cpp:class:`tvm::ffi::AnyView` is **ownership**:
+
+.. list-table::
+ :header-rows: 1
+ :widths: 25 35 40
+
+ * - Aspect
+ - :cpp:class:`~tvm::ffi::AnyView`
+ - :cpp:class:`~tvm::ffi::Any`
+ * - Ownership
+ - Non-owning (like ``std::string_view``)
+ - Owning (like ``std::string``)
+ * - Reference counting
+ - No reference count changes on copy
+ - Increments reference count on copy; decrements on destroy
+ * - Lifetime
+ - Valid only while source lives
+ - Extends object lifetime
+ * - Primary use
+ - Function inputs
+ - Return values, storage
+
+Code Examples
+~~~~~~~~~~~~~~
+
+:cpp:class:`~tvm::ffi::AnyView` is a lightweight view. Copying it just copies 16 bytes
+- no reference count updates. This makes it perfect for passing arguments without overhead:
+
+.. code-block:: cpp
+
+ void process(ffi::AnyView value) {}
+
+:cpp:class:`~tvm::ffi::Any` is a managed container. Copy an :cpp:class:`~tvm::ffi::Any` holding an object, and the reference
+count goes up. Destroy it, and the count goes down:
+
+.. code-block:: cpp
+
+ ffi::Any create_value() {
+ ffi::Any result;
+ {
+ ffi::String str = "hello"; // refcount = 1 (str created)
+ result = str; // refcount 1 -> 2 (result owns str)
+ } // refcount 2 -> 1 (str is destroyed)
+ return result; // refcount = 1 (result returns to caller)
+ }
+
+
+ABI Boundary
+~~~~~~~~~~~~
+
+TVM-FFI's function calling convention follows a simple rule:
+
+- **Inputs are non-owning**: Arguments are passed as :cpp:class:`~tvm::ffi::AnyView`. The caller
+ retains ownership; the callee borrows them for the duration of the call.
+- **Outputs are owning**: The return value is an :cpp:class:`~tvm::ffi::Any`. Ownership transfers
+ to the caller, who becomes responsible for the value's lifetime.
+
+.. code-block:: cpp
+
+ // TVM-FFI C ABI
+ int32_t tvm_ffi_c_abi(
+ void* handle,
+ const AnyView* args, // (Non-owning) args: AnyView[num_args]
+ int32_t num_args,
+ Any* result, // (Owning) result: Any (caller takes ownership)
+ );
+
+Destruction Semantics in C
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+In C, which doesn't have RAII, you need to manually destroy the :cpp:class:`~tvm::ffi::Any` object
+by calling :cpp:func:`TVMFFIObjectDecRef` for heap-allocated objects.
+
+.. code-block:: cpp
+
+ void destroy_any(TVMFFIAny* any) {
+ if (any->type_index >= kTVMFFIStaticObjectBegin) {
+ // Decrement the reference count of the heap-allocated object
+ TVMFFIObjectDecRef(any->v_obj);
+ }
+ empty_any_just_to_be_safe(any);
+ }
+
+ void empty_any_just_to_be_safe(Any* any) {
+ any->type_index = kTVMFFINone;
+ any->zero_padding = 0;
+ any->v_int64 = 0;
+ }
+
+On the contrary, destroying :cpp:class:`~tvm::ffi::AnyView` is effectively a no-op besides emptying its content.
+
+.. code-block:: cpp
+
+ void destroy_any_view(AnyView* any_view) {
+ empty_any_view_just_to_be_safe(any_view);
+ }
Review Comment:

The function `empty_any_view_just_to_be_safe` is not defined; this seems to be a typo for `empty_any_just_to_be_safe`. Additionally, assuming `empty_any_just_to_be_safe` is corrected to take a `TVMFFIAny*` as suggested in another comment, `any_view` (which is `AnyView*`) needs to be cast to `TVMFFIAny*`.
The `reinterpret_cast` is appropriate here because `AnyView` is designed to have the same memory layout as `TVMFFIAny`.
```suggestion
void destroy_any_view(AnyView* any_view) {
empty_any_just_to_be_safe(reinterpret_cast<TVMFFIAny*>(any_view));
}
```
##########
docs/concepts/any.rst:
##########
@@ -0,0 +1,441 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+.. http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+Any and AnyView
+===============
+
+TVM-FFI has :cpp:class:`tvm::ffi::Any` and :cpp:class:`tvm::ffi::AnyView`,
+type-erased containers that hold any supported value and transport it across
+C, C++, Python, and Rust boundaries through a stable ABI.
+
+Similar to ``std::any``, :cpp:class:`~tvm::ffi::Any` is a tagged union that store
+values of wide variety of types, including primitive types, objects, strings, etc.
+Unlike ``std::any``, it is designed for RTTI-free zero-copy inter-language exchange,
+with a fixed 16-byte layout and built-in support for reference counting and ownership.
+
+This tutorial covers all about Any: its common usage patterns, ownership semantics,
+and memory layout.
Review Comment:

Some minor grammatical and wording improvements for better clarity and formality in the introduction.
```suggestion
Similar to ``std::any``, :cpp:class:`~tvm::ffi::Any` is a tagged union that stores
values of a wide variety of types, including primitive types, objects, strings, etc.
Unlike ``std::any``, it is designed for RTTI-free zero-copy inter-language exchange,
with a fixed 16-byte layout and built-in support for reference counting and ownership.
This tutorial covers `Any` in detail: its common usage patterns, ownership semantics,
and memory layout.
```
##########
docs/concepts/any.rst:
##########
@@ -0,0 +1,441 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+.. http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+Any and AnyView
+===============
+
+TVM-FFI has :cpp:class:`tvm::ffi::Any` and :cpp:class:`tvm::ffi::AnyView`,
+type-erased containers that hold any supported value and transport it across
+C, C++, Python, and Rust boundaries through a stable ABI.
+
+Similar to ``std::any``, :cpp:class:`~tvm::ffi::Any` is a tagged union that store
+values of wide variety of types, including primitive types, objects, strings, etc.
+Unlike ``std::any``, it is designed for RTTI-free zero-copy inter-language exchange,
+with a fixed 16-byte layout and built-in support for reference counting and ownership.
+
+This tutorial covers all about Any: its common usage patterns, ownership semantics,
+and memory layout.
+
+
+Common Usecases
+---------------
+
+Function inputs and outputs
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Use :cpp:class:`~tvm::ffi::AnyView` for function parameters,
+which avoids reference count churn or unnecessary copies, and :cpp:class:`~tvm::ffi::Any` for return values,
+which transfers ownership to the caller.
+
+.. code-block:: cpp
+
+ ffi::Any func_cpp_signature(ffi::AnyView arg0, ffi::AnyView arg1) {
+ ffi::Any result = arg0.cast<int>() + arg1.cast<int>();
+ return result;
+ }
+
+ // Variant: variadic function
+ void func_cpp_variadic(PackedArgs args, Any* ret) {
+ int32_t num_args = args.size();
+ int x0 = args[0].cast<int>();
+ int x1 = args[1].cast<int>();
+ int y = x0 + x1;
+ *ret = y;
+ }
+
+ // Variant: variadic function with C ABI signature
+ int func_c_abi_variadic(void*, const TVMFFIAny* args, int32_t num_args, TVMFFIAny* ret) {
+ TVM_FFI_SAFE_CALL_BEGIN();
+ int x0 = reinterpret_cast<const AnyView*>(args)[0].cast<int>();
+ int x1 = reinterpret_cast<const AnyView*>(args)[1].cast<int>();
+ int y = x0 + x1;
+ reinterpret_cast<Any*>(ret)[0] = y;
+ TVM_FFI_SAFE_CALL_END();
+ }
+
+
+Container Storage
+~~~~~~~~~~~~~~~~~
+
+:cpp:class:`~tvm::ffi::Any` can be stored in containers like :cpp:class:`~tvm::ffi::Map` and :cpp:class:`~tvm::ffi::Array`:
+
+.. code-block:: cpp
+
+ ffi::Map<ffi::String, ffi::Any> config;
+ config.Set("learning_rate", 0.001);
+ config.Set("batch_size", 32);
+ config.Set("device", DLDevice{kDLCUDA, 0});
+
+Extracting Values
+~~~~~~~~~~~~~~~~~
+
+Three methods pull values out of :cpp:class:`~tvm::ffi::Any`
+and :cpp:class:`~tvm::ffi::AnyView`, each with different strictness:
+
+.. list-table::
+ :header-rows: 1
+ :widths: 20 45 30
+
+ * - Method
+ - Behavior
+ - Use When
+ * - :cpp:func:`cast\<T\>() <tvm::ffi::Any::cast>`
+ - Returns ``T`` or throws :cpp:class:`tvm::ffi::Error`
+ - You know the type and want to throw on type mismatch
+ * - :cpp:func:`try_cast\<T\>() <tvm::ffi::Any::try_cast>`
+ - Returns ``std::optional<T>``
+ - Returns None on type mismatch, allows type conversion
+ * - :cpp:func:`as\<T\>() <tvm::ffi::Any::as>`
+ - Returns ``std::optional<T>`` or ``const T*`` (for TVM-FFI object types)
+ - Returns None on type mismatch, but doesn't allow type conversion
Review Comment:

In a C++ context, "None" is ambiguous. It's clearer to state that `try_cast` and `as` return `std::nullopt` on type mismatch.
```suggestion
* - :cpp:func:`try_cast\<T\>() <tvm::ffi::Any::try_cast>`
- Returns ``std::optional<T>``
- Returns ``std::nullopt`` on type mismatch, allows type conversion
* - :cpp:func:`as\<T\>() <tvm::ffi::Any::as>`
- Returns ``std::optional<T>`` or ``const T*`` (for TVM-FFI object types)
- Returns ``std::nullopt`` on type mismatch, but doesn't allow type conversion
```
##########
docs/concepts/any.rst:
##########
@@ -0,0 +1,441 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+.. http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+Any and AnyView
+===============
+
+TVM-FFI has :cpp:class:`tvm::ffi::Any` and :cpp:class:`tvm::ffi::AnyView`,
+type-erased containers that hold any supported value and transport it across
+C, C++, Python, and Rust boundaries through a stable ABI.
+
+Similar to ``std::any``, :cpp:class:`~tvm::ffi::Any` is a tagged union that store
+values of wide variety of types, including primitive types, objects, strings, etc.
+Unlike ``std::any``, it is designed for RTTI-free zero-copy inter-language exchange,
+with a fixed 16-byte layout and built-in support for reference counting and ownership.
+
+This tutorial covers all about Any: its common usage patterns, ownership semantics,
+and memory layout.
+
+
+Common Usecases
+---------------
+
+Function inputs and outputs
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Use :cpp:class:`~tvm::ffi::AnyView` for function parameters,
+which avoids reference count churn or unnecessary copies, and :cpp:class:`~tvm::ffi::Any` for return values,
+which transfers ownership to the caller.
+
+.. code-block:: cpp
+
+ ffi::Any func_cpp_signature(ffi::AnyView arg0, ffi::AnyView arg1) {
+ ffi::Any result = arg0.cast<int>() + arg1.cast<int>();
+ return result;
+ }
+
+ // Variant: variadic function
+ void func_cpp_variadic(PackedArgs args, Any* ret) {
+ int32_t num_args = args.size();
+ int x0 = args[0].cast<int>();
+ int x1 = args[1].cast<int>();
+ int y = x0 + x1;
+ *ret = y;
+ }
+
+ // Variant: variadic function with C ABI signature
+ int func_c_abi_variadic(void*, const TVMFFIAny* args, int32_t num_args, TVMFFIAny* ret) {
+ TVM_FFI_SAFE_CALL_BEGIN();
+ int x0 = reinterpret_cast<const AnyView*>(args)[0].cast<int>();
+ int x1 = reinterpret_cast<const AnyView*>(args)[1].cast<int>();
+ int y = x0 + x1;
+ reinterpret_cast<Any*>(ret)[0] = y;
+ TVM_FFI_SAFE_CALL_END();
+ }
+
+
+Container Storage
+~~~~~~~~~~~~~~~~~
+
+:cpp:class:`~tvm::ffi::Any` can be stored in containers like :cpp:class:`~tvm::ffi::Map` and :cpp:class:`~tvm::ffi::Array`:
+
+.. code-block:: cpp
+
+ ffi::Map<ffi::String, ffi::Any> config;
+ config.Set("learning_rate", 0.001);
+ config.Set("batch_size", 32);
+ config.Set("device", DLDevice{kDLCUDA, 0});
+
+Extracting Values
+~~~~~~~~~~~~~~~~~
+
+Three methods pull values out of :cpp:class:`~tvm::ffi::Any`
+and :cpp:class:`~tvm::ffi::AnyView`, each with different strictness:
+
+.. list-table::
+ :header-rows: 1
+ :widths: 20 45 30
+
+ * - Method
+ - Behavior
+ - Use When
+ * - :cpp:func:`cast\<T\>() <tvm::ffi::Any::cast>`
+ - Returns ``T`` or throws :cpp:class:`tvm::ffi::Error`
+ - You know the type and want to throw on type mismatch
+ * - :cpp:func:`try_cast\<T\>() <tvm::ffi::Any::try_cast>`
+ - Returns ``std::optional<T>``
+ - Returns None on type mismatch, allows type conversion
+ * - :cpp:func:`as\<T\>() <tvm::ffi::Any::as>`
+ - Returns ``std::optional<T>`` or ``const T*`` (for TVM-FFI object types)
+ - Returns None on type mismatch, but doesn't allow type conversion
+
+.. dropdown:: Example of :cpp:func:`cast\<T\>() <tvm::ffi::Any::cast>`
+
+ :cpp:func:`cast\<T\>() <tvm::ffi::Any::cast>` is the workhorse. It returns the value or throws:
+
+ .. code-block:: cpp
+
+ ffi::Any value = 42;
+ int x = value.cast<int>(); // OK: 42
+ double y = value.cast<double>(); // OK: 42.0 (int → double)
+
+ try {
+ ffi::String s = value.cast<ffi::String>(); // Throws TypeError
+ } catch (const ffi::Error& e) {
+ // "Cannot convert from type `int` to `ffi.Str`"
+ }
+
+.. dropdown:: Example of :cpp:func:`try_cast\<T\>() <tvm::ffi::Any::try_cast>`
+
+ :cpp:func:`try_cast\<T\>() <tvm::ffi::Any::try_cast>` allows type coercion:
+
+ .. code-block:: cpp
+
+ ffi::Any value = 42;
+
+ std::optional<double> opt_float = value.try_cast<double>();
+ // opt_float.has_value() == true, *opt_float == 42.0
+
+ std::optional<bool> opt_bool = value.try_cast<bool>();
+ // opt_bool.has_value() == true, *opt_bool == true
+
+
+.. dropdown:: Example of :cpp:func:`as\<T\>() <tvm::ffi::Any::as>`
+
+ :cpp:func:`as\<T\>() <tvm::ffi::Any::as>` is strict - it only succeeds if the stored type exactly matches:
+
+ .. code-block:: cpp
+
+ ffi::Any value = 42;
+
+ std::optional<int64_t> opt_int = value.as<int64_t>();
+ // opt_int.has_value() == true
+
+ std::optional<double> opt_float = value.as<double>();
+ // opt_float.has_value() == false (int stored, not float)
+
+ ffi::Any value = ffi::String("hello, world!");
+ if (const ffi::Object* obj = value.as<ffi::Object>()) {
+ // Use obj without copying
+ }
Review Comment:

The variable `value` is redeclared in the same scope, which is a C++ compilation error. Please use a different variable name for the string example to avoid confusion.
```suggestion
ffi::Any str_value = ffi::String("hello, world!");
if (const ffi::Object* obj = str_value.as<ffi::Object>()) {
// Use obj without copying
}
```
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] doc: Any and AnyView [tvm-ffi]
Posted by "junrushao (via GitHub)" <gi...@apache.org>.
junrushao merged PR #382:
URL: https://github.com/apache/tvm-ffi/pull/382
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] add docs for any [tvm-ffi]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #382:
URL: https://github.com/apache/tvm-ffi/pull/382#discussion_r2660657359
##########
docs/concepts/any.rst:
##########
@@ -0,0 +1,460 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+.. http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+Any and AnyView
+===============
+
+How do you pass arbitrary values across language boundaries - integers, floats, tensors,
+functions, custom objects - without writing marshalling code for every type combination?
+
+TVM-FFI's answer is :cpp:class:`tvm::ffi::Any` and :cpp:class:`tvm::ffi::AnyView`:
+a type-erased container that can hold any supported value and transport it across
+C, C++, Python, and Rust boundaries through a stable ABI.
+
+Similar to ``std::any``, :cpp:class:`~tvm::ffi::Any` is a tagged union that can store
+values of any type. Unlike ``std::any``, it is designed for inter-language
+communication, with a fixed 16-byte layout and built-in support for reference counting
+and ownership semantics.
+
+This tutorial covers the full Any system: its ownership semantics, memory layout,
+and the patterns that make cross-language interop seamless.
+
+
+Ownership
+---------
+
+The core distinction between :cpp:class:`tvm::ffi::Any` and
+:cpp:class:`tvm::ffi::AnyView` is **ownership**:
+
+.. list-table::
+ :header-rows: 1
+ :widths: 25 35 40
+
+ * - Aspect
+ - :cpp:class:`~tvm::ffi::AnyView`
+ - :cpp:class:`~tvm::ffi::Any`
+ * - Ownership
+ - Non-owning (like ``std::string_view``)
+ - Owning (like ``std::string``)
+ * - Reference counting
+ - No refcount changes on copy
+ - Increments refcount on copy; decrements on destroy
+ * - Lifetime
+ - Valid only while source lives
+ - Extends object lifetime
+ * - Primary use
+ - Function inputs
+ - Return values, storage
+
+:cpp:class:`~tvm::ffi::AnyView` is a lightweight view. Copying it just copies 16 bytes - no reference
+count updates. This makes it perfect for passing arguments without overhead:
+
+.. code-block:: cpp
+
+ void process(ffi::AnyView value) {
+ // value is a view into the caller's data
+ // Zero refcount overhead
+ int x = value.cast<int>();
+ }
+
+:cpp:class:`~tvm::ffi::Any` is a managed container. Copy an :cpp:class:`~tvm::ffi::Any` holding an object, and the reference
+count goes up. Destroy it, and the count goes down:
+
+.. code-block:: cpp
+
+ ffi::Any create_value() {
+ ffi::String str = "hello";
+ ffi::Any result = str; // refcount: 1 → 2
+ return result; // str destroyed, refcount: 2 → 1
+ } // result owns the string
+
+
+Ownership at the C ABI Boundary
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+TVM-FFI's function calling convention follows a simple rule:
+
+- **Inputs are non-owning**: Arguments are passed as :cpp:class:`~tvm::ffi::AnyView`. The caller
+ retains ownership; the callee borrows them for the duration of the call.
+- **Outputs are owning**: The return value is an :cpp:class:`~tvm::ffi::Any`. Ownership transfers
+ to the caller, who becomes responsible for the value's lifetime.
+
+.. code-block:: cpp
+
+ // At the C ABI level (TVMFFISafeCallType):
+ int my_function(
+ void* handle,
+ const TVMFFIAny* args, // Non-owning: caller owns these
+ int32_t num_args,
+ TVMFFIAny* result // Owning: caller takes ownership of result
+ );
+
+This convention enables zero-copy argument passing while ensuring returned
+values don't dangle.
+
+
+Converting AnyView to Any
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+When an :cpp:class:`~tvm::ffi::AnyView` is assigned to an :cpp:class:`~tvm::ffi::Any`, TVM-FFI automatically handles the
+ownership transition:
+
+- **POD types**: Direct copy (no ownership semantics needed)
+- **Objects**: Reference count incremented
+- **Raw strings** (``const char*``): Copied into a managed :cpp:class:`~tvm::ffi::String` object
+
+.. code-block:: cpp
+
+ void example() {
+ ffi::AnyView view = "raw string"; // kTVMFFIRawStr, no allocation
+ ffi::Any owned = view; // Converted to kTVMFFIStr or kTVMFFISmallStr
+ }
+
+
+Layout
+------
+
+The Any system is built on three abstraction layers:
+
+.. code-block:: text
+
+ ┌─────────────────────────────────────────┐
+ │ C++ Layer: Any (owning), AnyView │ ← (0 bytes) RAII wrapper or view
+ ├─────────────────────────────────────────┤
+ │ C Layer: TVMFFIAny │ ← (16 bytes) Stable ABI
+ ├─────────────────────────────────────────┤
+ │ Payload: Atomic values or pointers │ ← Actual data
+ └─────────────────────────────────────────┘
+
+**Bottom layer**: The payload is either a primitive value (int, float, device) stored
+directly, or a pointer to a heap-allocated, reference-counted object.
+
+**Middle layer**: :cpp:class:`TVMFFIAny` is a 16-byte C struct that provides the stable
+ABI. This is what crosses language boundaries.
+
+**Top layer**: :cpp:class:`tvm::ffi::Any` and :cpp:class:`tvm::ffi::AnyView` are C++
+wrappers that add type safety, RAII, and ergonomic APIs.
+
+
+.. figure:: https://raw.githubusercontent.com/tlc-pack/web-data/main/images/tvm-ffi/stable-c-abi-layout-any.svg
+ :alt: Layout of the 128-bit Any tagged union
+ :align: center
+
+ Figure 1. Layout of the :cpp:class:`TVMFFIAny` tagged union.
+
+
+.. tip::
+
+ Think of :cpp:class:`TVMFFIAny` as the "wire format" and :cpp:class:`~tvm::ffi::Any`/:cpp:class:`~tvm::ffi::AnyView` as the
+ "application API". You work with the C++ classes; the C struct handles ABI stability.
+
+
+Tagged Union
+~~~~~~~~~~~~
+
+At the ABI level, every value lives in a :cpp:class:`TVMFFIAny`:
+
+.. code-block:: c
+
+ typedef struct TVMFFIAny {
+ int32_t type_index; // Bytes 0-3: identifies the stored type
+ union {
+ uint32_t zero_padding; // Bytes 4-7: must be zero (or small_str_len)
+ uint32_t small_str_len;
+ };
+ union { // Bytes 8-15: the actual value
+ int64_t v_int64;
+ double v_float64;
+ void* v_ptr;
+ TVMFFIObject* v_obj;
+ DLDevice v_device;
+ char v_bytes[8];
+ // ... other union members
+ };
+ } TVMFFIAny;
+
+It is effectively a layout-stable 16-byte tagged union.
+
+* The first 4-byte :cpp:member:`TVMFFIAny::type_index` is a tag that tells you the type of the stored value.
+* The last 8-byte field holds the actual value, either directly stored in place as an atomic value (e.g. ``int64_t``, ``float64_t``, ``void*``) or as a pointer to a heap object.
+
+Strings and bytes get special treatment: those 7 bytes or shorter are stored inline using
+the **small string optimization**, avoiding heap allocation entirely:
+
+.. code-block:: cpp
+
+ ffi::Any small = "hello"; // kTVMFFISmallStr, in v_bytes
+ ffi::Any large = "this is a longer string"; // kTVMFFIStr, heap allocated
+
+Atomic Types
+~~~~~~~~~~~~
+
+Primitive values - integers, floats, booleans, devices, and raw pointers - are stored
+directly in the 8-byte payload. No heap allocation or no reference counting.
+
+.. list-table:: Figure 2. Common atomic types stored directly in :cpp:class:`TVMFFIAny`
+ :header-rows: 1
+ :name: atomic-types-table
+ :widths: 40 40 30
+
+ * - Type
+ - type_index
+ - Payload Field
+ * - ``None`` / ``nullptr``
+ - :cpp:enumerator:`kTVMFFINone <TVMFFITypeIndex::kTVMFFINone>` = 0
+ - :cpp:member:`~TVMFFIAny::v_int64` (must be 0)
+ * - ``int64_t``
+ - :cpp:enumerator:`kTVMFFIInt <TVMFFITypeIndex::kTVMFFIInt>` = 1
+ - :cpp:member:`~TVMFFIAny::v_int64`
+ * - ``bool``
+ - :cpp:enumerator:`kTVMFFIBool <TVMFFITypeIndex::kTVMFFIBool>` = 2
+ - :cpp:member:`~TVMFFIAny::v_int64` (0 or 1)
+ * - ``float64_t``
+ - :cpp:enumerator:`kTVMFFIFloat <TVMFFITypeIndex::kTVMFFIFloat>` = 3
+ - :cpp:member:`~TVMFFIAny::v_float64`
+ * - ``void*`` (opaque pointer)
+ - :cpp:enumerator:`kTVMFFIOpaquePtr <TVMFFITypeIndex::kTVMFFIOpaquePtr>` = 4
+ - :cpp:member:`~TVMFFIAny::v_ptr`
+ * - :c:struct:`DLDataType <DLDataType>`
+ - :cpp:enumerator:`kTVMFFIDataType <TVMFFITypeIndex::kTVMFFIDataType>` = 5
+ - :cpp:member:`~TVMFFIAny::v_dtype`
+ * - :c:struct:`DLDevice <DLDevice>`
+ - :cpp:enumerator:`kTVMFFIDevice <TVMFFITypeIndex::kTVMFFIDevice>` = 6
+ - :cpp:member:`~TVMFFIAny::v_device`
+ * - :c:struct:`DLTensor* <DLTensor>`
+ - :cpp:enumerator:`kTVMFFIDLTensorPtr <TVMFFITypeIndex::kTVMFFIDLTensorPtr>` = 7
+ - :cpp:member:`~TVMFFIAny::v_ptr`
+ * - ``const char*`` (raw string)
+ - :cpp:enumerator:`kTVMFFIRawStr <TVMFFITypeIndex::kTVMFFIRawStr>` = 8
+ - :cpp:member:`~TVMFFIAny::v_c_str`
+ * - :cpp:class:`TVMFFIByteArray* <TVMFFIByteArray>`
+ - :cpp:enumerator:`kTVMFFIByteArrayPtr <TVMFFITypeIndex::kTVMFFIByteArrayPtr>` = 9
+ - :cpp:member:`~TVMFFIAny::v_ptr`
+
+:ref:`Figure 2 <atomic-types-table>` shows common atomic types stored in-place inside the
+:cpp:class:`TVMFFIAny` payload.
+
+.. code-block:: cpp
+
+ AnyView int_val = 42; // v_int64 = 42
+ AnyView float_val = 3.14; // v_float64 = 3.14
+ AnyView bool_val = true; // v_int64 = 1
+ AnyView device = DLDevice{kDLCUDA, 0}; // v_device
+ DLTensor tensor;
+ AnyView view = &tensor; // v_ptr = &tensor
+
+Note that raw pointers like :c:struct:`DLTensor* <DLTensor>` and ``char *`` also fit here. They carry no ownership.
+It means the caller must ensure the pointed-to data outlives the :cpp:class:`~tvm::ffi::AnyView` or :cpp:class:`~tvm::ffi::Any`.
+
+Heap-Allocated Objects
+~~~~~~~~~~~~~~~~~~~~~~
+
+.. list-table:: Figure 3. Common TVM-FFI object types stored as pointers in :cpp:member:`TVMFFIAny::v_obj`.
+ :header-rows: 1
+ :widths: 40 40 30
+
+ * - Type
+ - type_index
+ - Payload Field
+ * - :cpp:class:`ErrorObj* <tvm::ffi::ErrorObj>`
+ - :cpp:enumerator:`kTVMFFIError <TVMFFITypeIndex::kTVMFFIError>` = 67
+ - :cpp:member:`~TVMFFIAny::v_obj`
+ * - :cpp:class:`FunctionObj* <tvm::ffi::FunctionObj>`
+ - :cpp:enumerator:`kTVMFFIFunction <TVMFFITypeIndex::kTVMFFIFunction>` = 68
+ - :cpp:member:`~TVMFFIAny::v_obj`
+ * - :cpp:class:`TensorObj* <tvm::ffi::TensorObj>`
+ - :cpp:enumerator:`kTVMFFITensor <TVMFFITypeIndex::kTVMFFITensor>` = 70
+ - :cpp:member:`~TVMFFIAny::v_obj`
+ * - :cpp:class:`ArrayObj* <tvm::ffi::ArrayObj>`
+ - :cpp:enumerator:`kTVMFFIArray <TVMFFITypeIndex::kTVMFFIArray>` = 71
+ - :cpp:member:`~TVMFFIAny::v_obj`
+ * - :cpp:class:`MapObj* <tvm::ffi::MapObj>`
+ - :cpp:enumerator:`kTVMFFIMap <TVMFFITypeIndex::kTVMFFIMap>` = 72
+ - :cpp:member:`~TVMFFIAny::v_obj`
+ * - :cpp:class:`ModuleObj* <tvm::ffi::ModuleObj>`
+ - :cpp:enumerator:`kTVMFFIModule <TVMFFITypeIndex::kTVMFFIModule>` = 73
+ - :cpp:member:`~TVMFFIAny::v_obj`
+
+
+Heap-allocated objects - :cpp:class:`~tvm::ffi::String`, :cpp:class:`~tvm::ffi::Function`, :cpp:class:`~tvm::ffi::Tensor`, :cpp:class:`~tvm::ffi::Array`, :cpp:class:`~tvm::ffi::Map`, and custom types - are
+stored as pointers to reference-counted :cpp:class:`TVMFFIObject` headers:
+
+.. code-block:: cpp
+
+ ffi::String str = "hello world";
+ ffi::Any any_str = str; // v_obj points to StringObj
+
+ // Object layout in memory:
+ // [TVMFFIObject header (24 bytes)][object-specific data]
+
+
+Common Patterns
+---------------
+
+Extracting Values
+~~~~~~~~~~~~~~~~~
+
+Three methods pull values out of :cpp:class:`~tvm::ffi::Any` and :cpp:class:`~tvm::ffi::AnyView`, each with different
+strictness:
+
+.. list-table::
+ :header-rows: 1
+ :widths: 20 40 40
+
+ * - Method
+ - Behavior
+ - Use When
+ * - :cpp:func:`~tvm::ffi::Any::cast`
+ - Returns ``T`` or throws :cpp:class:`~tvm::ffi::Error`
+ - You know the type
+ * - :cpp:func:`~tvm::ffi::Any::as`
+ - Returns ``std::optional<T>`` (strict)
+ - Type must match exactly
+ * - :cpp:func:`~tvm::ffi::Any::try_cast`
+ - Returns ``std::optional<T>`` (with coercion)
+ - Allow type conversion
+
+:cpp:func:`~tvm::ffi::Any::cast` is the workhorse. It returns the value or throws:
+
+.. code-block:: cpp
+
+ ffi::Any value = 42;
+ int x = value.cast<int>(); // OK: 42
+ double y = value.cast<double>(); // OK: 42.0 (int → double)
+
+ try {
+ ffi::String s = value.cast<ffi::String>(); // Throws TypeError
+ } catch (const ffi::Error& e) {
+ // "Cannot convert from type `int` to `ffi.Str`"
+ }
+
+:cpp:func:`~tvm::ffi::Any::as` is strict - it only succeeds if the stored type exactly matches:
+
+.. code-block:: cpp
+
+ ffi::Any value = 42;
+
+ std::optional<int64_t> opt_int = value.as<int64_t>();
+ // opt_int.has_value() == true
+
+ std::optional<double> opt_float = value.as<double>();
+ // opt_float.has_value() == false (int stored, not float)
+
+:cpp:func:`~tvm::ffi::Any::try_cast` allows type coercion:
+
+.. code-block:: cpp
+
+ ffi::Any value = 42;
+
+ std::optional<double> opt_float = value.try_cast<double>();
+ // opt_float.has_value() == true, *opt_float == 42.0
+
+ std::optional<bool> opt_bool = value.try_cast<bool>();
+ // opt_bool.has_value() == true, *opt_bool == true
+
+**Conversion rules** (what :cpp:func:`~tvm::ffi::Any::try_cast` allows):
+
+- ``int`` ↔ ``bool``: integers convert to bool (0 = false, non-zero = true)
+- ``int`` → ``float``: integers convert to floating point
+- ``bool`` → ``int``: bools convert to 0 or 1
+- Object downcasting: :cpp:class:`~tvm::ffi::ObjectRef` → derived type if runtime type matches
Review Comment:

The current description of conversion rules is a bit redundant and the use of `↔` could be clearer. The rule for `int ↔ bool` is described, and then a separate rule for `bool → int` is also listed.
To improve clarity and remove redundancy, I suggest rephrasing these rules to be more direct and distinct.
```suggestion
- ``int`` to ``bool``: Non-zero integers convert to `true`, while `0` converts to `false`.
- ``bool`` to ``int``: `true` converts to `1`, while `false` converts to `0`.
- ``int`` to ``float``: Standard integer to floating-point conversion.
- Object downcasting: :cpp:class:`~tvm::ffi::ObjectRef` → derived type if runtime type matches
```
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] add docs for any [tvm-ffi]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on PR #382:
URL: https://github.com/apache/tvm-ffi/pull/382#issuecomment-3709392075
## Summary of Changes
Hello @junrushao, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request significantly enhances the documentation for the `Any` and `AnyView` types within the TVM-FFI system. It introduces a dedicated, comprehensive guide that clarifies their fundamental role in enabling seamless cross-language communication, detailing their ownership models, memory representation, and practical usage. The new documentation is integrated into the existing structure, making it easily discoverable for developers working with TVM-FFI.
### Highlights
* **New Comprehensive Documentation**: A new, detailed documentation file (`docs/concepts/any.rst`) has been added, providing an in-depth explanation of `tvm::ffi::Any` and `tvm::ffi::AnyView`. This document covers ownership semantics, memory layout, the stable C ABI, and common usage patterns for these crucial types in cross-language communication.
* **Documentation Integration**: Existing documentation files (`docs/concepts/abi_overview.md` and `docs/guides/cpp_lang_guide.md`) have been updated with 'seealso' references, pointing to the newly added `any` documentation for more comprehensive details. This improves discoverability and context for users seeking information on `Any` and `AnyView`.
* **Table of Contents Update**: The main documentation index (`docs/index.rst`) has been modified to include the new `concepts/any.rst` under the 'Concepts' section, ensuring it is properly listed and accessible within the overall documentation structure.
🧠 **New Feature in Public Preview:** You can now enable **Memory** to help **Gemini Code Assist** learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. **Click [here](https://codeassist.google/code-review/login) to enable Memory in your admin console.**
<details>
<summary><b>Using Gemini Code Assist</b></summary>
<br>
The full guide for Gemini Code Assist can be found on our [documentation page](https://developers.google.com/gemini-code-assist/docs/review-github-code), here are some quick tips.
<b>Invoking Gemini</b>
You can request assistance from Gemini at any point by creating a comment using either `/gemini <command>` or `@gemini-code-assist <command>`. Below is a summary of the supported commands on the current page.
Feature | Command | Description
--- | --- | ---
Code Review | `/gemini review` | Performs a code review for the current pull request in its current state.
Pull Request Summary | `/gemini summary` | Provides a summary of the current pull request in its current state.
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help | `/gemini help` | Displays a list of available commands.
<b>Customization</b>
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a `.gemini/` folder in the base of the repository. Detailed instructions can be found [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).
<b>Limitations & Feedback</b>
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up [here](https://google.qualtrics.com/jfe/form/SV_2cyuGuTWsEw84yG).
<b>You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the [Gemini Code Assist IDE Extension](https://cloud.google.com/products/gemini/code-assist).</b>
</details>
[^1]: Review the [Privacy Notices](https://policies.google.com/privacy), [Generative AI Prohibited Use Policy](https://policies.google.com/terms/generative-ai/use-policy), [Terms of Service](https://policies.google.com/terms), and learn how to configure Gemini Code Assist in GitHub [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github). Gemini can make mistakes, so double check it and [use code with caution](https://support.google.com/legal/answer/13505487).
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org