Skip to content

Conversation

@tqchen
Copy link
Member

@tqchen tqchen commented Sep 9, 2025

This PR streamlines the macros related to object and ref declaration.

  • TVM_FFI_DECLARE_BASE_OBJECT_INFO => TVM_FFI_DECLARE_OBJECT_INFO
  • TVM_FFI_DECLARE_FINAL_OBJECT_INFO => TVM_FFI_DECLARE_OBJECT_INFO_FINAL
  • Move mutable annotation as field in the object
  • Auto detect mutablity in object ref getter and operator ptr

This PR streamlines the macros related to object and ref declaration.

- TVM_FFI_DECLARE_BASE_OBJECT_INFO => TVM_FFI_DECLARE_OBJECT_INFO
- TVM_FFI_DECLARE_FINAL_OBJECT_INFO => TVM_FFI_DECLARE_OBJECT_INFO_FINAL
- Move mutable annotation as field in the object
- Auto detect mutablity in object ref getter and operator ptr
@Hzfengsy Hzfengsy merged commit abc8ae8 into apache:main Sep 9, 2025
12 of 13 checks passed
@tqchen
Copy link
Member Author

tqchen commented Sep 9, 2025

Upgrade Guide

  • Use TVM_FFI_DECLARE_OBJECT_INFO(TypeKey, TypeName, Parent);

    • Note that type key decl folded into this one
  • TVM_FFI_DECLARE_OBJECT_INFO_PREDEFINED_TYPE_KEY(TypeName, Parent); is the previous TVM_FFI_DECLARE_BASE_OBJECT_INFO, need to add _type_final = true; explicitly if done this way

  • TVM_FFI_DECLARE_OBJECT_INFO_FINAL(TypeKey, TypeName, Parent);

  • TVM_FFI_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS => TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE
    -TVM_FFI_DEFINE_NULLABLE_OBJECT_REF_METHODS => TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE

For macros that contains _MUTABLE, instead declare _type_mutable=true in the object static field

MasterJH5574 added a commit to MasterJH5574/mlc-llm that referenced this pull request Sep 9, 2025
This PR updates the object declaration macros, in order to follow
the recent TVM refactor apache/tvm#18289.
MasterJH5574 added a commit to mlc-ai/mlc-llm that referenced this pull request Sep 9, 2025
This PR updates the object declaration macros, in order to follow
the recent TVM refactor apache/tvm#18289.
@Ubospica
Copy link
Contributor

Ubospica commented Sep 9, 2025

It also looks great to me. Thanks!

static constexpr const char* _type_key = "example.MyIntPair";
// This macro registers the class with the FFI system to set up the right type index
TVM_FFI_DECLARE_FINAL_OBJECT_INFO(MyIntPairObj, tvm::ffi::Object);
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("example.MyIntPair", MyIntPairObj, tvm::ffi::Object);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need formatting here.

// Required: declare type information
static constexpr const char* _type_key = "testing.TestIntPair";
TVM_FFI_DECLARE_FINAL_OBJECT_INFO(TestIntPairObj, tvm::ffi::Object);
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("testing.TestIntPair", TestIntPairObj, tvm::ffi::Object);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto. In markdown we don't have auto formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants