I propose we add an associated name to every packed function in order to make the error messages clearer. Right now if you call a packed function with the wrong number of arguments, you get this error: Check failed: nargs == args.size() (3 vs. 2) : Expect 3 arguments but get 2
. If we add a name to each packed function, we can create clearer error messages like TVMError: tir.LT expects 3 arguments, but 2 were provided
.
There are a couple choices around adding names to packed functions:
Naming Convention
What should we call the name field of the packed function? Two possible options:
- A0:
name_hint
: indicates that the name may not exist and may not be unique. Also matches the naming convention on other objects. - A1:
name
: simple, straight forward.
Field Type
How should we store the name?
- B0: Use
String
as the field and add constructor that uses a default name if none is given. - B1: Use
Optional<String>
to avoid the overhead of having aString
object on each member (saves one pointer and oneuint64_t
overString
). - B2: Move
PackedFunc
to the object system and a subclassed version that has a name.
API
Do we treat the name as immutable or not?
- C0: Name is immutable: simple, but may prevent us from setting names on c-callbacks. Also, will have to do mutation to set the name from
TVM_REGISTER_GLOBAL
. - C1: Name is mutable via setter method.
- C2: Name is write once. If we use
Optional<String>
, we allow setting the name only if the optional is not set.
What are everyones thoughts on this?