-
Notifications
You must be signed in to change notification settings - Fork 43
feat: add Rust binding for Array<T>
#348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @khj809, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request delivers a robust and memory-safe Rust binding for the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a Rust binding for the Array<T> container, a fundamental component for TVM's FFI. The implementation includes core functionalities like dynamic mutation and integration with Rust's type system. However, the review has uncovered several critical issues concerning memory safety and correctness, primarily within the unsafe blocks. Specifically, there's a missing Drop implementation for ArrayObj which will cause memory leaks. The mutable methods lack copy-on-write (COW) semantics, leading to potentially unsound shared state mutation. Furthermore, the type casting logic is flawed, permitting unsafe casts between different Array specializations. I have also provided suggestions for performance improvements and API consistency. These critical issues should be addressed to ensure the implementation is safe and robust.
|
Nice work! Likely we will need Apache license headers on each file :) |
|
@junrushao Thanks. I added it :) |
|
Looks like there's a test failure: |
|
@junrushao Hmm it's strange because |
|
@junrushao Due to the unexpected link errors of testing functions on CI environment, I decided to use global functions which definitely exist in libtvm_ffi dylib. |
|
CC @tqchen please take a look when you got time, as I'm not very experienced in Rust |
|
Thanks a lot for contributions, i maybe a bit off recently but should be able to come back and take closer look around Jan. would be good to also get some eyes for rust reviews. cc @DarkSharpness @Ubospica if u have bandwidth Some high-level feedbacks:
|
|
@tqchen Thanks for the review.
|
This PR introduces a Rust implementation of the
Arraycontainer.Key Features
ObjectRefelements. It ensuresinc_refis called during retrieval (get) anddec_refis called when elements are removed or the array is cleared.push,pop,insert,remove, andclear. It handles internal growth and reallocation while maintaining compatibility with the underlying C++ memory layout.datapointer withinArrayObjto allow C++ TVM functions to traverse the array using standard pointer arithmetic.AnyCompatible, allowingArray<T>to be erased intoAnyandAnyViewand recovered viaTryFrom.FromIteratorandExtend, enabling seamless integration with Rust's iterator ecosystem.Tests
Verified with a comprehensive test suite in
tvm-ffi/tests/test_array.rscovering:AnyandAnyView.TensorandShapetypes.