Ubospica opened a new issue, #265:
URL: https://github.com/apache/tvm-ffi/issues/265

   **Goal and motivation.** Supporting function overloading in tvm-ffi. This 
would be helpful for libraries that use overloading in their code. For example, 
[XGrammar](https://github.com/mlc-ai/xgrammar) has a lot of overloading 
functions. Supporting overloading can unblock it from migrating to tvm-ffi.
   
   **Method.** 
   1. According to our guideline that the C ABI should be stable and minimal, 
we should keep the C ABI unchanged.
   2. Extend tvm::ffi::Function to implement a chain to maintain all function 
pointers in the order of registration.
   3. When calling functions, try functions in order until the first matched.
   
   This also aligns with nanobind's method to handle overloaded functions. It 
allocates a contiguous block of memory to store all function overloads. Its 
memory layout:
   ```
   +------------------+  ← nb_func* (PyObject_VAR_HEAD)
   | ob_refcnt        |
   | ob_type          |
   | ob_size          |  ← number of overloads (Py_SIZE)
   +------------------+
   | vectorcall       |  ← function pointer: call dispatcher
   | max_nargs        |  ← maximum number of arguments among all overloads
   | complex_call     |  ← boolean: whether a complex call path is required
   | doc_uniform      |  ← boolean: whether all overloads share the same 
docstring
   +------------------+  ← sizeof(nb_func)
   | func_data[0]     |  ← metadata for the first overload
   |   (overload 0)   |
   +------------------+
   | func_data[1]     |  ← metadata for the second overload
   |   (overload 1)   |
   +------------------+
   | ...              |
   +------------------+
   | func_data[N-1]   |  ← metadata for the last overload
   |   (overload N-1) |
   +------------------+
   ```


-- 
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]

Reply via email to