@@ -127,7 +127,7 @@ class FunctionObjImpl : public FunctionObj {
127
127
/* ! \brief The type of derived object class */
128
128
using TSelf = FunctionObjImpl<TCallable>;
129
129
/* !
130
- * \brief Derived object class for constructing PackedFuncObj .
130
+ * \brief Derived object class for constructing ffi::FunctionObj .
131
131
* \param callable The type-erased callable object.
132
132
*/
133
133
explicit FunctionObjImpl (TCallable callable) : callable_(callable) {
@@ -292,15 +292,15 @@ class PackedArgs {
292
292
293
293
/* !
294
294
* \brief ffi::Function is a type-erased function.
295
- * The arguments are passed by packed format.
295
+ * The arguments are passed by " packed format" via AnyView
296
296
*/
297
297
class Function : public ObjectRef {
298
298
public:
299
299
/* ! \brief Constructor from null */
300
300
Function (std::nullptr_t ) : ObjectRef(nullptr ) {} // NOLINT(*)
301
301
/* !
302
302
* \brief Constructing a packed function from a callable type
303
- * whose signature is consistent with `PackedFunc `
303
+ * whose signature is consistent with `ffi::Function `
304
304
* \param packed_call The packed function signature
305
305
* \note legacy purpose, should change to Function::FromPacked for mostfuture use.
306
306
*/
@@ -310,7 +310,7 @@ class Function : public ObjectRef {
310
310
}
311
311
/* !
312
312
* \brief Constructing a packed function from a callable type
313
- * whose signature is consistent with `PackedFunc `
313
+ * whose signature is consistent with `ffi::Function `
314
314
* \param packed_call The packed function signature
315
315
*/
316
316
template <typename TCallable>
@@ -462,7 +462,7 @@ class Function : public ObjectRef {
462
462
* \param callable the internal container of packed function.
463
463
*/
464
464
template <typename TCallable>
465
- static Function FromUnpacked (TCallable callable) {
465
+ static Function FromTyped (TCallable callable) {
466
466
using FuncInfo = details::FunctionInfo<TCallable>;
467
467
auto call_packed = [callable](const AnyView* args, int32_t num_args, Any* rv) mutable -> void {
468
468
details::unpack_call<typename FuncInfo::RetType>(
@@ -477,7 +477,7 @@ class Function : public ObjectRef {
477
477
* \param name optional name attacked to the function.
478
478
*/
479
479
template <typename TCallable>
480
- static Function FromUnpacked (TCallable callable, std::string name) {
480
+ static Function FromTyped (TCallable callable, std::string name) {
481
481
using FuncInfo = details::FunctionInfo<TCallable>;
482
482
auto call_packed = [callable, name](const AnyView* args, int32_t num_args,
483
483
Any* rv) mutable -> void {
@@ -540,7 +540,7 @@ class Function : public ObjectRef {
540
540
private:
541
541
/* !
542
542
* \brief Constructing a packed function from a callable type
543
- * whose signature is consistent with `PackedFunc `
543
+ * whose signature is consistent with `ffi::Function `
544
544
* \param packed_call The packed function signature
545
545
*/
546
546
template <typename TCallable>
@@ -560,16 +560,16 @@ class TypedFunction;
560
560
561
561
/* !
562
562
* \anchor TypedFunctionAnchor
563
- * \brief A PackedFunc wrapper to provide typed function signature.
564
- * It is backed by a PackedFunc internally.
563
+ * \brief A ffi::Function wrapper to provide typed function signature.
564
+ * It is backed by a ffi::Function internally.
565
565
*
566
566
* TypedFunction enables compile time type checking.
567
567
* TypedFunction works with the runtime system:
568
- * - It can be passed as an argument of PackedFunc .
569
- * - It can be assigned to TVMRetValue .
570
- * - It can be directly converted to a type-erased PackedFunc .
568
+ * - It can be passed as an argument of ffi::Function .
569
+ * - It can be assigned to ffi::Any .
570
+ * - It can be directly converted to a type-erased ffi::Function .
571
571
*
572
- * Developers should prefer TypedFunction over PackedFunc in C++ code
572
+ * Developers should prefer TypedFunction over ffi::Function in C++ code
573
573
* as it enables compile time checking.
574
574
* We can construct a TypedFunction from a lambda function
575
575
* with the same signature.
@@ -584,8 +584,8 @@ class TypedFunction;
584
584
* TypedFunction<int(int)> ftyped(addone);
585
585
* // invoke the function.
586
586
* int y = ftyped(1);
587
- * // Can be directly converted to PackedFunc
588
- * PackedFunc packed = ftype;
587
+ * // Can be directly converted to ffi::Function
588
+ * ffi::Function packed = ftype;
589
589
* \endcode
590
590
* \tparam R The return value of the function.
591
591
* \tparam Args The argument signature of the function.
@@ -623,7 +623,7 @@ class TypedFunction<R(Args...)> {
623
623
template <typename FLambda, typename = typename std::enable_if<std::is_convertible<
624
624
FLambda, std::function<R(Args...)>>::value>::type>
625
625
TypedFunction (FLambda typed_lambda, std::string name) { // NOLINT(*)
626
- packed_ = Function::FromUnpacked (typed_lambda, name);
626
+ packed_ = Function::FromTyped (typed_lambda, name);
627
627
}
628
628
/* !
629
629
* \brief construct from a lambda function with the same signature.
@@ -646,7 +646,7 @@ class TypedFunction<R(Args...)> {
646
646
template <typename FLambda, typename = typename std::enable_if<std::is_convertible<
647
647
FLambda, std::function<R(Args...)>>::value>::type>
648
648
TypedFunction (const FLambda& typed_lambda) { // NOLINT(*)
649
- packed_ = Function::FromUnpacked (typed_lambda);
649
+ packed_ = Function::FromTyped (typed_lambda);
650
650
}
651
651
/* !
652
652
* \brief copy assignment operator from typed lambda
@@ -668,11 +668,11 @@ class TypedFunction<R(Args...)> {
668
668
std::is_convertible<FLambda,
669
669
std::function<R(Args...)>>::value>::type>
670
670
TSelf& operator =(FLambda typed_lambda) { // NOLINT(*)
671
- packed_ = Function::FromUnpacked (typed_lambda);
671
+ packed_ = Function::FromTyped (typed_lambda);
672
672
return *this ;
673
673
}
674
674
/* !
675
- * \brief copy assignment operator from PackedFunc .
675
+ * \brief copy assignment operator from ffi::Function .
676
676
* \param packed The packed function.
677
677
* \returns reference to self.
678
678
*/
@@ -698,16 +698,16 @@ class TypedFunction<R(Args...)> {
698
698
}
699
699
}
700
700
/* !
701
- * \brief convert to PackedFunc
702
- * \return the internal PackedFunc
701
+ * \brief convert to ffi::Function
702
+ * \return the internal ffi::Function
703
703
*/
704
704
operator Function () const { return packed (); }
705
705
/* !
706
- * \return reference the internal PackedFunc
706
+ * \return reference the internal ffi::Function
707
707
*/
708
708
const Function& packed () const & { return packed_; }
709
709
/* !
710
- * \return r-value reference the internal PackedFunc
710
+ * \return r-value reference the internal ffi::Function
711
711
*/
712
712
constexpr Function&& packed() && { return std::move (packed_); }
713
713
/* ! \return Whether the packed function is nullptr */
@@ -797,7 +797,7 @@ class Function::Registry {
797
797
*/
798
798
template <typename FLambda>
799
799
Registry& set_body_typed (FLambda f) {
800
- return Register (Function::FromUnpacked (f, name_));
800
+ return Register (Function::FromTyped (f, name_));
801
801
}
802
802
803
803
/* !
@@ -838,14 +838,14 @@ class Function::Registry {
838
838
// call method pointer
839
839
return (target.*f)(params...);
840
840
};
841
- return Register (ffi::Function::FromUnpacked (fwrap, name_));
841
+ return Register (ffi::Function::FromTyped (fwrap, name_));
842
842
}
843
843
if constexpr (std::is_base_of_v<Object, T>) {
844
844
auto fwrap = [f](const T* target, Args... params) -> R {
845
845
// call method pointer
846
846
return (const_cast <T*>(target)->*f)(params...);
847
847
};
848
- return Register (ffi::Function::FromUnpacked (fwrap, name_));
848
+ return Register (ffi::Function::FromTyped (fwrap, name_));
849
849
}
850
850
return *this ;
851
851
}
@@ -859,14 +859,14 @@ class Function::Registry {
859
859
// call method pointer
860
860
return (target.*f)(params...);
861
861
};
862
- return Register (ffi::Function::FromUnpacked (fwrap, name_));
862
+ return Register (ffi::Function::FromTyped (fwrap, name_));
863
863
}
864
864
if constexpr (std::is_base_of_v<Object, T>) {
865
865
auto fwrap = [f](const T* target, Args... params) -> R {
866
866
// call method pointer
867
867
return (target->*f)(params...);
868
868
};
869
- return Register (ffi::Function::FromUnpacked (fwrap, name_));
869
+ return Register (ffi::Function::FromTyped (fwrap, name_));
870
870
}
871
871
return *this ;
872
872
}
0 commit comments