wip: structural map#649
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the StructuralMapper and StructuralMapperObj APIs in include/tvm/ffi/extra/structural_map.h to support structural mapping and in-place mutation of object-backed values. It also adds corresponding custom hooks (kStructuralMap and kStructuralInplaceMutate), registers test leaf objects, and includes comprehensive unit tests. The review feedback suggests two minor optimizations in structural_map.h: avoiding a const_cast when obtaining the field address, and reusing the calculated field address instead of recalculating it for the field setter.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| const void* field_addr = reinterpret_cast<const char*>(new_obj) + field_info->offset; | ||
| int ret_code = field_info->getter(const_cast<void*>(field_addr), | ||
| reinterpret_cast<TVMFFIAny*>(&field_value)); |
There was a problem hiding this comment.
Since new_obj is a non-const pointer (Object*), we can avoid the const_cast on field_addr by declaring it as void* and using reinterpret_cast<char*>(new_obj).
void* field_addr = reinterpret_cast<char*>(new_obj) + field_info->offset;
int ret_code = field_info->getter(field_addr,
reinterpret_cast<TVMFFIAny*>(&field_value));| void* new_field_addr = reinterpret_cast<char*>(new_obj) + field_info->offset; | ||
| ret_code = reflection::CallFieldSetter(field_info, new_field_addr, | ||
| reinterpret_cast<const TVMFFIAny*>(&new_field)); |
89efca8 to
37b4d66
Compare
2d1fe02 to
94ef772
Compare
No description provided.