-
Notifications
You must be signed in to change notification settings - Fork 39
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Goal and motivation. Supporting function overloading in tvm-ffi. This would be helpful for libraries that use overloading in their code. For example, XGrammar has a lot of overloading functions. Supporting overloading can unblock it from migrating to tvm-ffi.
Method.
- According to our guideline that the C ABI should be stable and minimal, we should keep the C ABI unchanged.
- Extend tvm::ffi::Function to implement a chain to maintain all function pointers in the order of registration.
- 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) |
+------------------+
DarkSharpness
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request