Commit 102fe0e
authored
[OBJECT] Make object info macro compatible with CRTP (#636)
This PR makes `TVM_FFI_DECLARE_OBJECT_INFO_PREDEFINED_TYPE_KEY`
compatible with CRTP-style object declarations, and fixes the MSVC build
failure seen with that pattern.
When the macro is expanded inside a CRTP base template, the cached
`_type_index` member is declared in the current CRTP base
specialization. The `_type_index` initializer now calls
`_GetOrAllocRuntimeTypeIndex()` through current-class lookup instead of
qualifying that function through the CRTP leaf type, which avoids MSVC
lookup failures on incomplete CRTP leaf types.
Other `TypeName::` lookups are preserved so leaf-provided metadata such
as `_type_key` and child-slot overrides continue to be used.
A generic `CRTPObject<T>` / `LeafObject` regression test is added in
`test_object.cc`.
Validation:
- `cmake -S . -B build-crtp -G Ninja -DCMAKE_BUILD_TYPE=Release
-DTVM_FFI_USE_EXTRA_CXX_API=ON -DTVM_FFI_BUILD_TESTS=ON`
- `ninja -C build-crtp tvm_ffi_tests`
- `./build-crtp/lib/tvm_ffi_tests
--gtest_filter=Object.CRTPObjectInfo:Object.TypeInfo`
- `./build-crtp/lib/tvm_ffi_tests --gtest_filter=Object.*`
- `pre-commit run --files include/tvm/ffi/object.h
tests/cpp/test_object.cc`1 parent 9844079 commit 102fe0e
2 files changed
Lines changed: 27 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
971 | 971 | | |
972 | 972 | | |
973 | 973 | | |
974 | | - | |
| 974 | + | |
975 | 975 | | |
976 | 976 | | |
977 | 977 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
30 | 47 | | |
31 | 48 | | |
32 | 49 | | |
| |||
60 | 77 | | |
61 | 78 | | |
62 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
63 | 89 | | |
64 | 90 | | |
65 | 91 | | |
| |||
0 commit comments